Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : agentilab-web8 * File : tests/unit/i18n.test.ts9 * Module : Tests10 * Repository : https://git.spboucher.ai/agentilab-web11 * Project Website : Not specified12 * Created : 2026-12-0513 * Last Modified : 2026-12-0514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : Proprietary34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { describe, expect, it } from 'vitest';44import { fr } from '@/content/public/copy/fr';45import { en } from '@/content/public/copy/en';46import { technologies } from '@/content/public/technologies';47import { legalIdentity } from '@/content/public/legal';48import { href, routeIds, routes, trail } from '@/lib/i18n/routes';49import { formatDate } from '@/lib/i18n/config';5051/** Chemins de toutes les feuilles d’un dictionnaire, avec leur type. */52function leaves(value: unknown, prefix = ''): Map<string, unknown> {53 const out = new Map<string, unknown>();54 if (value && typeof value === 'object') {55 for (const [key, child] of Object.entries(value)) for (const [k, v] of leaves(child, `${prefix}${key}.`)) out.set(k, v);56 } else out.set(prefix.slice(0, -1), value);57 return out;58}59const words = (text: string) => text.trim().split(/\s+/).length;60/** Clés volontairement vides en français (mention « site en français », inutile dans cette langue). */61const MAY_BE_EMPTY = new Set(['labels.siteLanguageNote', 'groupeKa.siteNote']);6263describe('dictionnaires', () => {64 const a = leaves(fr);65 const b = leaves(en);6667 it('ont exactement la même structure', () => {68 expect([...b.keys()].sort()).toEqual([...a.keys()].sort());69 });7071 it('n’ont aucun texte vide ni reliquat', () => {72 for (const [dict, name] of [[a, 'fr'], [b, 'en']] as const) {73 for (const [key, value] of dict) {74 if (typeof value !== 'string') continue;75 if (!MAY_BE_EMPTY.has(key)) expect(value.trim(), `${name}:${key}`).not.toBe('');76 expect(value, `${name}:${key}`).not.toMatch(/lorem|TODO|TBD|xxx|@agentilab\.ai/i);77 }78 }79 });8081 it('ne laissent pas de texte identique non traduit (hors noms propres)', () => {82 const same = [...a].filter(([key, value]) => typeof value === 'string' && value.length > 25 && b.get(key) === value).map(([key]) => key);83 expect(same).toEqual([]);84 });8586 it('gardent la dénomination légale en français dans les deux langues', () => {87 expect(JSON.stringify(en)).toContain('Société de développement de logiciels, AgentiLab Technologies inc.');88 expect(legalIdentity.legalName).toBe('Société de développement de logiciels, AgentiLab Technologies inc.');89 });9091 it('respectent les longueurs éditoriales (chapeau 35–55 mots, domaines 40–70 mots)', () => {92 for (const copy of [fr, en]) {93 expect(words(copy.home.lead)).toBeGreaterThanOrEqual(35);94 expect(words(copy.home.lead)).toBeLessThanOrEqual(55);95 }96 for (const tech of technologies) {97 for (const locale of ['fr', 'en'] as const) {98 expect(words(tech.text[locale]), `${tech.id}.${locale}`).toBeGreaterThanOrEqual(40);99 expect(words(tech.text[locale]), `${tech.id}.${locale}`).toBeLessThanOrEqual(70);100 }101 }102 });103});104105describe('matrice des routes', () => {106 it('donne à chaque page une adresse unique par langue', () => {107 const all = routeIds.flatMap((id) => [routes[id].fr, routes[id].en]);108 expect(new Set(all).size).toBe(all.length);109 });110 it('place l’anglais sous /en et le français à la racine', () => {111 for (const id of routeIds) {112 expect(href(id, 'en')).toMatch(/^\/en(\/|$)/);113 expect(href(id, 'fr')).not.toMatch(/^\/en(\/|$)/);114 }115 });116 it('construit le fil d’Ariane depuis l’accueil', () => {117 expect(trail('orix')).toEqual(['home', 'ecosystem', 'orix']);118 });119});120121describe('dates', () => {122 it('sont formatées selon la langue sans glisser de jour', () => {123 expect(formatDate('2025-10-15', 'fr')).toBe('15 octobre 2025');124 expect(formatDate('2025-10-15', 'en')).toBe('October 15, 2025');125 });126});127