Files
Portfolio/src/app/core/routing/route-paths.spec.ts

47 lines
1.6 KiB
TypeScript

import { APP_LOCALES } from '../i18n/locale';
import { ROUTE_IDS, type RouteId } from './route-ids';
import { prerenderablePaths, routePath, ROUTE_SEGMENTS } from './route-paths';
describe('route paths', () => {
const addressableIds = ROUTE_IDS.filter((routeId) => routeId !== 'notFound');
it('defines every route id in both locales', () => {
for (const locale of APP_LOCALES) {
for (const routeId of ROUTE_IDS) {
expect(ROUTE_SEGMENTS[locale][routeId]).toBeTypeOf('string');
}
}
});
it('has no duplicate addressable paths within a locale', () => {
for (const locale of APP_LOCALES) {
const paths = addressableIds.map((routeId) => routePath(routeId, locale));
expect(new Set(paths).size).toBe(paths.length);
}
});
it('builds the expected home and projects paths', () => {
expect(routePath('home', 'de')).toBe('/');
expect(routePath('home', 'en')).toBe('/en');
expect(routePath('projects', 'de')).toBe('/projekte');
expect(routePath('projects', 'en')).toBe('/en/projects');
});
it('includes both locales in prerenderable paths and excludes the wildcard', () => {
const paths = prerenderablePaths();
expect(paths).toContain('/');
expect(paths).toContain('/en');
expect(paths).toContain('/projekte');
expect(paths).toContain('/en/projects');
expect(paths.some((path) => path.includes('**'))).toBe(false);
expect(paths).not.toContain('');
for (const locale of APP_LOCALES) {
for (const routeId of addressableIds) {
expect(paths).toContain(routePath(routeId as RouteId, locale));
}
}
});
});