Initial commit
This commit is contained in:
30
landing/src/app/core/api.spec.ts
Normal file
30
landing/src/app/core/api.spec.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { DEFAULT_LOCALE, localeFromUrl, resolveLocale } from './api';
|
||||
|
||||
describe('resolveLocale', () => {
|
||||
it('accepts the locales the API declares', () => {
|
||||
expect(resolveLocale('ca')).toBe('ca');
|
||||
expect(resolveLocale('en')).toBe('en');
|
||||
});
|
||||
|
||||
it('falls back to the application default for anything else', () => {
|
||||
expect(resolveLocale('fr')).toBe(DEFAULT_LOCALE);
|
||||
expect(resolveLocale(undefined)).toBe(DEFAULT_LOCALE);
|
||||
expect(resolveLocale(42)).toBe(DEFAULT_LOCALE);
|
||||
});
|
||||
});
|
||||
|
||||
describe('localeFromUrl', () => {
|
||||
it('reads ?lang from a path-only URL', () => {
|
||||
expect(localeFromUrl('/api/_analog/pages/-home-?lang=ca')).toBe('ca');
|
||||
});
|
||||
|
||||
it('ignores an unsupported language rather than passing it on', () => {
|
||||
expect(localeFromUrl('/?lang=de')).toBe(DEFAULT_LOCALE);
|
||||
});
|
||||
|
||||
it('survives a missing URL', () => {
|
||||
expect(localeFromUrl(undefined)).toBe(DEFAULT_LOCALE);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user