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:
@@ -32,6 +32,30 @@ const mockBilling = {
|
|||||||
payments: [],
|
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', () => ({
|
vi.mock('@/lib/hooks/use-subscription', () => ({
|
||||||
usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false })),
|
usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false })),
|
||||||
useBillingHistory: vi.fn(() => ({ data: mockBilling, isLoading: false })),
|
useBillingHistory: vi.fn(() => ({ data: mockBilling, isLoading: false })),
|
||||||
@@ -43,9 +67,19 @@ vi.mock('@/lib/subscription-api', () => ({
|
|||||||
subscriptionApi: {
|
subscriptionApi: {
|
||||||
createSubscription: vi.fn(),
|
createSubscription: vi.fn(),
|
||||||
upgradeSubscription: 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) => {
|
vi.mock('@tanstack/react-query', async (importOriginal) => {
|
||||||
const actual = (await importOriginal()) as Record<string, unknown>;
|
const actual = (await importOriginal()) as Record<string, unknown>;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -43,10 +43,15 @@ vi.mock('@/i18n/navigation', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('lucide-react', () => ({
|
vi.mock('lucide-react', () => ({
|
||||||
|
AlertCircle: () => <span data-testid="icon-alert-circle" />,
|
||||||
Check: () => <span data-testid="icon-check">✓</span>,
|
Check: () => <span data-testid="icon-check">✓</span>,
|
||||||
|
CreditCard: () => <span data-testid="icon-credit-card" />,
|
||||||
Crown: () => <span data-testid="icon-crown" />,
|
Crown: () => <span data-testid="icon-crown" />,
|
||||||
|
Loader2: () => <span data-testid="icon-loader2" />,
|
||||||
Rocket: () => <span data-testid="icon-rocket" />,
|
Rocket: () => <span data-testid="icon-rocket" />,
|
||||||
Shield: () => <span data-testid="icon-shield" />,
|
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>,
|
X: () => <span data-testid="icon-x">✗</span>,
|
||||||
Zap: () => <span data-testid="icon-zap" />,
|
Zap: () => <span data-testid="icon-zap" />,
|
||||||
}));
|
}));
|
||||||
@@ -78,9 +83,21 @@ const mockPlans = [
|
|||||||
|
|
||||||
vi.mock('@/lib/hooks/use-subscription', () => ({
|
vi.mock('@/lib/hooks/use-subscription', () => ({
|
||||||
usePlans: vi.fn(() => ({ data: mockPlans, isLoading: false, error: null })),
|
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';
|
import PricingPage from '../pricing/page';
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"name": "next"
|
"name": "next"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"types": ["vitest/globals"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./*"]
|
"@/*": ["./*"]
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user