Files
ims/tests/design/tokens.test.ts
T

86 lines
3.1 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { readFileSync } from 'fs'
import path from 'path'
const css = readFileSync(path.resolve(__dirname, '../../app/globals.css'), 'utf8')
describe('IMS Admin tokens in globals.css', () => {
it.each([
['--color-ink', '#1f1f1f'],
['--color-ink-2', '#303030'],
['--color-ink-3', '#4a4a4a'],
['--color-muted', '#616161'],
['--color-faint', '#8a8a8a'],
['--color-rule', '#ebebeb'],
['--color-rule-2', '#e3e3e3'],
['--color-ring', '#d4d4d4'],
['--color-surface', '#ffffff'],
['--color-surface-2', '#f7f7f7'],
['--color-ground', '#f1f1f1'],
['--color-accent', '#0f766e'],
['--color-accent-tint', '#f2f7f6'],
['--color-accent-tint-2', '#e6f4f1'],
['--color-danger', '#b3261e'],
['--color-topbar', '#1a1a1a'],
])('declares %s as %s', (name, value) => {
expect(css).toMatch(new RegExp(`${name}:\\s*${value}\\b`, 'i'))
})
it.each([
['amber', '#fff1c2', '#6b4a00'],
['blue', '#e0efff', '#00527c'],
['violet', '#ede7ff', '#4b2e99'],
['orange', '#ffe6cf', '#7a3a00'],
['indigo', '#e3e8ff', '#2c3e8f'],
['green', '#d7f4e3', '#0c5132'],
['grey', '#ebebeb', '#4a4a4a'],
['red', '#fee3e0', '#8e1f0b'],
])('declares the %s status pair', (hue, bg, fg) => {
expect(css).toMatch(new RegExp(`--color-st-${hue}-bg:\\s*${bg}`, 'i'))
expect(css).toMatch(new RegExp(`--color-st-${hue}-fg:\\s*${fg}`, 'i'))
})
it('sets the radius scale: md 8, xl 12', () => {
expect(css).toMatch(/--radius-md:\s*8px/)
expect(css).toMatch(/--radius-xl:\s*12px/)
})
it('declares the card and floating shadows', () => {
expect(css).toMatch(/--shadow-card:\s*0 0 0 1px rgba\(0, ?0, ?0, ?\.08\), 0 1px 2px rgba\(0, ?0, ?0, ?\.06\)/)
expect(css).toMatch(/--shadow-float:\s*0 0 0 1px rgba\(0, ?0, ?0, ?\.1\), 0 12px 32px rgba\(0, ?0, ?0, ?\.18\)/)
})
it('declares the component shadows', () => {
for (const name of ['drawer', 'primary', 'secondary', 'input', 'chip', 'chip-set']) {
expect(css).toMatch(new RegExp(`--shadow-${name}:`))
}
})
it('uses Geist through the next/font variables', () => {
expect(css).toMatch(/--font-sans:\s*var\(--font-geist\)/)
expect(css).toMatch(/--font-mono:\s*var\(--font-geist-mono\)/)
})
it('keeps the legacy remaps so unmigrated pages still render', () => {
expect(css).toMatch(/--color-gray-100:\s*var\(--color-neutral-200\)/)
expect(css).toMatch(/--color-blue-600:\s*var\(--color-accent\)/)
expect(css).toMatch(/--color-red-600:\s*var\(--color-danger\)/)
expect(css).toMatch(/--color-divider:/)
})
it('styles keyboard focus with the 2px accent ring', () => {
expect(css).toMatch(/:focus-visible\s*\{[^}]*outline:\s*2px solid var\(--color-accent\)/)
})
it('has no dark mode block and no Modernist leftovers', () => {
expect(css).not.toContain('prefers-color-scheme')
expect(css).not.toMatch(/ec3013/i)
expect(css).not.toMatch(/archivo/i)
})
it('has no stray comment terminator before @theme', () => {
const head = css.slice(0, css.indexOf('@theme'))
expect(head.match(/\*\//g)?.length).toBe(head.match(/\/\*/g)?.length)
})
})