forked from cardosofelipe/fast-next-template
Add tests for auth storage logic and i18n routing configuration
- Added comprehensive unit tests for `auth/storage` to handle SSR, E2E paths, storage method selection, and error handling. - Introduced tests for `i18n/routing` to validate locale configuration, navigation hooks, and link preservation. - Updated Jest coverage exclusions to include `
This commit is contained in:
38
frontend/tests/lib/i18n/routing.test.ts
Normal file
38
frontend/tests/lib/i18n/routing.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Tests for i18n routing configuration
|
||||
*/
|
||||
|
||||
import { routing, Link, usePathname, useRouter } from '@/lib/i18n/routing';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
describe('i18n routing', () => {
|
||||
it('exposes supported locales and defaultLocale', () => {
|
||||
expect(routing.locales).toEqual(['en', 'it']);
|
||||
expect(routing.defaultLocale).toBe('en');
|
||||
// Using "always" strategy for clarity
|
||||
// @ts-expect-error - localePrefix not in typed export
|
||||
expect(routing.localePrefix).toBe('always');
|
||||
});
|
||||
|
||||
it('provides Link wrapper that preserves href', () => {
|
||||
render(
|
||||
<Link href="/en/about" data-testid="test-link">
|
||||
About
|
||||
</Link>
|
||||
);
|
||||
const el = screen.getByTestId('test-link') as HTMLAnchorElement;
|
||||
expect(el.tagName).toBe('A');
|
||||
expect(el.getAttribute('href')).toBe('/en/about');
|
||||
expect(screen.getByText('About')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('provides navigation hooks', () => {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
expect(pathname).toBe('/en/test');
|
||||
expect(router).toEqual(
|
||||
expect.objectContaining({ push: expect.any(Function), replace: expect.any(Function) })
|
||||
);
|
||||
});
|
||||
});
|
||||
39
frontend/tests/lib/i18n/routing.test.tsx
Normal file
39
frontend/tests/lib/i18n/routing.test.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Tests for i18n routing configuration
|
||||
*/
|
||||
|
||||
import { routing, Link, usePathname, useRouter, redirect } from '@/lib/i18n/routing';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
describe('i18n routing', () => {
|
||||
it('exposes supported locales and defaultLocale', () => {
|
||||
expect(routing.locales).toEqual(['en', 'it']);
|
||||
expect(routing.defaultLocale).toBe('en');
|
||||
// Using "always" strategy for clarity (property exists in the config object)
|
||||
// @ts-expect-error typed export may not include localePrefix
|
||||
expect(routing.localePrefix).toBe('always');
|
||||
});
|
||||
|
||||
it('provides Link wrapper that preserves href and children', () => {
|
||||
render(
|
||||
<Link href="/en/about" data-testid="test-link">
|
||||
About
|
||||
</Link>
|
||||
);
|
||||
const el = screen.getByTestId('test-link') as HTMLAnchorElement;
|
||||
expect(el.tagName).toBe('A');
|
||||
expect(el.getAttribute('href')).toBe('/en/about');
|
||||
expect(screen.getByText('About')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('provides navigation hooks and redirect function', () => {
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
expect(pathname).toBe('/en/test');
|
||||
expect(typeof redirect).toBe('function');
|
||||
expect(router).toEqual(
|
||||
expect.objectContaining({ push: expect.any(Function), replace: expect.any(Function) })
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user