Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : agentilab-web8 * File : tests/unit/contrast.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 { readFileSync } from 'node:fs';44import path from 'node:path';45import { describe, expect, it } from 'vitest';4647const css = readFileSync(path.join(process.cwd(), 'app', 'globals.css'), 'utf8');4849function tokens(selector: string): Record<string, string> {50 const start = css.indexOf(`${selector} {`);51 const block = css.slice(start, css.indexOf('}', start));52 return Object.fromEntries([...block.matchAll(/--([a-z-]+):\s*(#[0-9a-f]{6})/g)].map((m) => [m[1], m[2]]));53}54const light = tokens(':root');55const dark = { ...light, ...tokens("[data-tone='dark']") };5657function luminance(hex: string): number {58 const [r, g, b] = [1, 3, 5].map((i) => {59 const c = parseInt(hex.slice(i, i + 2), 16) / 255;60 return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;61 }) as [number, number, number];62 return 0.2126 * r + 0.7152 * g + 0.0722 * b;63}64function contrast(a: string, b: string): number {65 const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x) as [number, number];66 return (hi + 0.05) / (lo + 0.05);67}6869/** [avant-plan, arrière-plan, ratio minimal WCAG AA] */70const PAIRS: [string, string, number][] = [71 ['foreground', 'background', 4.5],72 ['foreground', 'surface', 4.5],73 ['muted', 'background', 4.5],74 ['muted', 'surface', 4.5],75 ['accent', 'background', 4.5],76 ['accent', 'surface', 4.5],77 ['background', 'foreground', 4.5], // bouton principal78 ['background', 'accent', 4.5], // bouton principal au survol79 ['on-accent', 'accent-solid', 4.5],80 ['success', 'surface', 4.5],81 ['danger', 'surface', 4.5],82 ['focus', 'background', 3], // indicateur de focus (composant d’interface)83 ['focus', 'surface', 3],84 ['accent-solid', 'background', 3], // filets et points d’accent85];8687describe.each([['clair', light], ['sombre', dark]] as const)('contrastes WCAG AA — ton %s', (_name, t) => {88 it.each(PAIRS)('%s sur %s ≥ %d:1', (fg, bg, min) => {89 expect(t[fg], fg).toBeDefined();90 expect(t[bg], bg).toBeDefined();91 expect(contrast(t[fg] as string, t[bg] as string)).toBeGreaterThanOrEqual(min);92 });93});9495describe('palette de marque', () => {96 it('conserve les quatre couleurs du mandat', () => {97 expect(light.ink).toBe('#090e19');98 expect(light.paper).toBe('#f7f9fc');99 expect(light.blue).toBe('#528cdb');100 expect(light.slate).toBe('#66758a');101 });102});103