fix(web): resolve 7 TypeScript errors and 2 failing test files

Add vitest/globals types to web tsconfig to fix TS2593 errors in 7 test
files. Fix pricing and subscription test mocks to include all required
lucide-react icons and module dependencies (payment-api, auth-store,
next-intl, i18n/navigation).

All 66 test files now pass (593 tests), typecheck clean, lint clean.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-12 20:15:33 +07:00
parent 505455b6f8
commit 51c4ecbf4e
3 changed files with 53 additions and 1 deletions

View File

@@ -32,6 +32,30 @@ const mockBilling = {
payments: [],
};
vi.mock('next-intl', () => ({
useTranslations: () => (key: string) => key,
useLocale: () => 'vi',
NextIntlClientProvider: ({ children }: { children: React.ReactNode }) => children,
}));
vi.mock('@/i18n/navigation', () => ({
Link: ({ children, href, ...props }: { children: React.ReactNode; href: string; [key: string]: unknown }) => (
<a href={href} {...props}>{children}</a>
),
useRouter: () => ({ push: vi.fn(), replace: vi.fn() }),
usePathname: () => '/dashboard/subscription',
redirect: vi.fn(),
}));
vi.mock('lucide-react', () => ({
AlertCircle: () => <span data-testid="icon-alert-circle" />,
Check: () => <span data-testid="icon-check" />,
CreditCard: () => <span data-testid="icon-credit-card" />,
Loader2: () => <span data-testid="icon-loader2" />,
Smartphone: () => <span data-testid="icon-smartphone" />,
Wallet: () => <span data-testid="icon-wallet" />,
}));
vi.mock('@/lib/hooks/use-subscription', () => ({
usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false })),
useBillingHistory: vi.fn(() => ({ data: mockBilling, isLoading: false })),
@@ -43,9 +67,19 @@ vi.mock('@/lib/subscription-api', () => ({
subscriptionApi: {
createSubscription: vi.fn(),
upgradeSubscription: vi.fn(),
createCheckout: vi.fn(),
},
}));
vi.mock('@/lib/payment-api', () => ({
createPayment: vi.fn(),
getPaymentMethods: vi.fn(() => []),
}));
vi.mock('@/lib/auth-store', () => ({
useAuthStore: vi.fn(() => ({ user: null, token: null })),
}));
vi.mock('@tanstack/react-query', async (importOriginal) => {
const actual = (await importOriginal()) as Record<string, unknown>;
return {

View File

@@ -43,10 +43,15 @@ vi.mock('@/i18n/navigation', () => ({
}));
vi.mock('lucide-react', () => ({
AlertCircle: () => <span data-testid="icon-alert-circle" />,
Check: () => <span data-testid="icon-check"></span>,
CreditCard: () => <span data-testid="icon-credit-card" />,
Crown: () => <span data-testid="icon-crown" />,
Loader2: () => <span data-testid="icon-loader2" />,
Rocket: () => <span data-testid="icon-rocket" />,
Shield: () => <span data-testid="icon-shield" />,
Smartphone: () => <span data-testid="icon-smartphone" />,
Wallet: () => <span data-testid="icon-wallet" />,
X: () => <span data-testid="icon-x"></span>,
Zap: () => <span data-testid="icon-zap" />,
}));
@@ -78,9 +83,21 @@ const mockPlans = [
vi.mock('@/lib/hooks/use-subscription', () => ({
usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false, error: null })),
useBillingHistory: vi.fn(() => ({ data: [], isLoading: false, error: null })),
}));
vi.mock('@/lib/subscription-api', () => ({}));
vi.mock('@/lib/subscription-api', () => ({
subscriptionApi: { createCheckout: vi.fn() },
}));
vi.mock('@/lib/payment-api', () => ({
createPayment: vi.fn(),
getPaymentMethods: vi.fn(() => []),
}));
vi.mock('@/lib/auth-store', () => ({
useAuthStore: vi.fn(() => ({ user: null, token: null })),
}));
import PricingPage from '../pricing/page';