Cover frontend middleware auth/locale logic, i18n config/routing/request/navigation, and vi/en message parity — 91 new tests across 6 files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
const { mockCreateNavigation } = vi.hoisted(() => ({
|
|
mockCreateNavigation: vi.fn(() => ({
|
|
Link: 'MockLink',
|
|
redirect: 'mockRedirect',
|
|
usePathname: 'mockUsePathname',
|
|
useRouter: 'mockUseRouter',
|
|
})),
|
|
}));
|
|
|
|
// Mock routing config
|
|
vi.mock('../routing', () => ({
|
|
routing: {
|
|
locales: ['vi', 'en'] as const,
|
|
defaultLocale: 'vi',
|
|
localePrefix: 'as-needed',
|
|
},
|
|
}));
|
|
|
|
vi.mock('next-intl/navigation', () => ({
|
|
createNavigation: mockCreateNavigation,
|
|
}));
|
|
|
|
import { Link, redirect, usePathname, useRouter } from '../navigation';
|
|
|
|
describe('i18n/navigation', () => {
|
|
it('calls createNavigation with the routing config', () => {
|
|
expect(mockCreateNavigation).toHaveBeenCalledWith({
|
|
locales: ['vi', 'en'],
|
|
defaultLocale: 'vi',
|
|
localePrefix: 'as-needed',
|
|
});
|
|
});
|
|
|
|
it('exports Link from createNavigation', () => {
|
|
expect(Link).toBeDefined();
|
|
});
|
|
|
|
it('exports redirect from createNavigation', () => {
|
|
expect(redirect).toBeDefined();
|
|
});
|
|
|
|
it('exports usePathname from createNavigation', () => {
|
|
expect(usePathname).toBeDefined();
|
|
});
|
|
|
|
it('exports useRouter from createNavigation', () => {
|
|
expect(useRouter).toBeDefined();
|
|
});
|
|
});
|