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:
53
apps/web/i18n/__tests__/routing.spec.ts
Normal file
53
apps/web/i18n/__tests__/routing.spec.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const { mockDefineRouting } = vi.hoisted(() => ({
|
||||
mockDefineRouting: vi.fn((config: unknown) => config),
|
||||
}));
|
||||
|
||||
// Mock the config module before importing routing
|
||||
vi.mock('../config', () => ({
|
||||
locales: ['vi', 'en'] as const,
|
||||
defaultLocale: 'vi' as const,
|
||||
}));
|
||||
|
||||
// Mock next-intl/routing
|
||||
vi.mock('next-intl/routing', () => ({
|
||||
defineRouting: mockDefineRouting,
|
||||
}));
|
||||
|
||||
import { routing } from '../routing';
|
||||
|
||||
describe('i18n/routing', () => {
|
||||
it('calls defineRouting with the correct configuration', () => {
|
||||
expect(mockDefineRouting).toHaveBeenCalledWith({
|
||||
locales: ['vi', 'en'],
|
||||
defaultLocale: 'vi',
|
||||
localePrefix: 'as-needed',
|
||||
});
|
||||
});
|
||||
|
||||
it('exports a routing object', () => {
|
||||
expect(routing).toBeDefined();
|
||||
});
|
||||
|
||||
it('includes all supported locales', () => {
|
||||
const routingConfig = mockDefineRouting.mock.calls[0][0] as {
|
||||
locales: readonly string[];
|
||||
};
|
||||
expect(routingConfig.locales).toEqual(['vi', 'en']);
|
||||
});
|
||||
|
||||
it('sets defaultLocale to vi', () => {
|
||||
const routingConfig = mockDefineRouting.mock.calls[0][0] as {
|
||||
defaultLocale: string;
|
||||
};
|
||||
expect(routingConfig.defaultLocale).toBe('vi');
|
||||
});
|
||||
|
||||
it('uses as-needed locale prefix strategy', () => {
|
||||
const routingConfig = mockDefineRouting.mock.calls[0][0] as {
|
||||
localePrefix: string;
|
||||
};
|
||||
expect(routingConfig.localePrefix).toBe('as-needed');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user