test(web): add middleware + i18n + messages test suites (GOO-60)
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>
This commit is contained in:
51
apps/web/i18n/__tests__/navigation.spec.ts
Normal file
51
apps/web/i18n/__tests__/navigation.spec.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user