You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import frTranslations from '~/i18n/fr';
|
|
import type { TranslationKey } from '~/i18n/fr';
|
|
|
|
describe('i18n', () => {
|
|
describe('French translations', () => {
|
|
it('should have all expected nav keys', () => {
|
|
expect(frTranslations['nav.syntheses']).toBe('Syntheses');
|
|
expect(frTranslations['nav.sources']).toBe('Sources personnalisees');
|
|
expect(frTranslations['nav.logout']).toBe('Deconnexion');
|
|
});
|
|
|
|
it('should have all expected auth keys', () => {
|
|
expect(frTranslations['auth.loginTitle']).toBe('AI Weekly Synth');
|
|
expect(frTranslations['auth.requestLink']).toBe(
|
|
'Recevoir un lien de connexion',
|
|
);
|
|
expect(frTranslations['auth.createAccount']).toBe('Creer un compte');
|
|
});
|
|
|
|
it('should have all expected settings keys', () => {
|
|
expect(frTranslations['settings.title']).toBe(
|
|
'Parametres de generation',
|
|
);
|
|
expect(frTranslations['settings.save']).toBe(
|
|
'Enregistrer les parametres',
|
|
);
|
|
});
|
|
|
|
it('should have all expected common keys', () => {
|
|
expect(frTranslations['common.loading']).toBe('Chargement...');
|
|
expect(frTranslations['common.error']).toBe('Une erreur est survenue.');
|
|
expect(frTranslations['common.retry']).toBe('Reessayer');
|
|
});
|
|
});
|
|
|
|
describe('t() function behavior', () => {
|
|
// We test the t function logic directly (same as in i18n/index.ts)
|
|
const translations: Record<string, string> = frTranslations;
|
|
|
|
const t = (
|
|
key: TranslationKey,
|
|
params?: Record<string, string | number>,
|
|
): string => {
|
|
let value: string = translations[key] ?? key;
|
|
if (params) {
|
|
Object.entries(params).forEach(([k, v]) => {
|
|
value = value.replace(`{${k}}`, String(v));
|
|
});
|
|
}
|
|
return value;
|
|
};
|
|
|
|
it('should return the correct translation for a known key', () => {
|
|
expect(t('nav.syntheses')).toBe('Syntheses');
|
|
});
|
|
|
|
it('should return the key itself for an unknown key', () => {
|
|
expect(t('unknown.key' as TranslationKey)).toBe('unknown.key');
|
|
});
|
|
|
|
it('should interpolate parameters', () => {
|
|
const result = t('auth.linkSent', { email: 'test@example.com' });
|
|
expect(result).toBe(
|
|
'Un lien de connexion vous a ete envoye a test@example.com.',
|
|
);
|
|
});
|
|
|
|
it('should interpolate numeric parameters', () => {
|
|
const result = t('auth.resendIn', { seconds: 45 });
|
|
expect(result).toBe('Renvoyer dans 45s');
|
|
});
|
|
|
|
it('should leave unreplaced placeholders if params are missing', () => {
|
|
const result = t('auth.linkSent');
|
|
expect(result).toContain('{email}');
|
|
});
|
|
});
|
|
});
|