diff --git a/src/lib/hero-contrast.test.ts b/src/lib/hero-contrast.test.ts new file mode 100644 index 0000000..1dbd1e5 --- /dev/null +++ b/src/lib/hero-contrast.test.ts @@ -0,0 +1,32 @@ +import { readFileSync } from 'node:fs' +import { describe, expect, it } from 'vitest' + +// QLFW-24: первый экран контрастный (заголовок, подзаголовок, кнопка «Направления»). +const css = readFileSync('src/app/(site)/globals.css', 'utf8') +const page = readFileSync('src/app/(site)/[locale]/page.tsx', 'utf8') + +const color = (name: string) => css.match(new RegExp(`--color-${name}:\\s*(#[0-9a-f]{6})`, 'i'))![1] +const lum = (hex: string) => { + const c = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255) + .map((v) => (v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4)) + return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2] +} +const ratio = (a: string, b: string) => { + const [x, y] = [lum(a), lum(b)].sort((p, q) => q - p) + return (x + 0.05) / (y + 0.05) +} + +describe('QLFW-24: контраст первого экрана', () => { + it('заголовок и подзаголовок тёмные на светлом фоне (не ниже 7:1)', () => { + expect(ratio(color('graphite'), color('paper'))).toBeGreaterThanOrEqual(7) + expect(page).toMatch(/
{ + expect(ratio(color('burgundy'), '#ffffff')).toBeGreaterThanOrEqual(4.5) + expect(page).toMatch(/href="#directions"[^>]*bg-burgundy[^>]*text-white/) + }) + it('анимация не меняет прозрачность текста', () => { + expect(css).not.toMatch(/@keyframes rise[^}]*opacity/) + }) +})