Files
ims/tests/scripts/check-design-gates.test.ts
T

56 lines
2.3 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { findViolations } from '../../scripts/check-design-gates.mjs'
const rules = (src: string, file = 'components/x.tsx'): string[] =>
(findViolations(src, file) as Array<{ rule: string }>).map(v => v.rule)
describe('design gates (IMS Admin refresh)', () => {
it('allows the radius scale, including rounded-full', () => {
expect(rules('<div className="rounded-md rounded-xl rounded-[5px] rounded-full" />')).toEqual([])
})
it.each(['border-2', 'border-b-2', 'border-t-2', 'border-l-2', 'border-r-2'])('flags %s', cls => {
expect(rules(`<div className="${cls}" />`)).toContain('no-2px-border')
})
it('accepts 1px rules', () => {
expect(rules('<div className="border border-b border-rule" />')).toEqual([])
})
it('flags the retired Archivo font', () => {
expect(rules("import { Archivo } from 'next/font/google'")).toContain('no-archivo')
})
it('flags off-palette colors but accepts remapped gray, blue and red', () => {
expect(rules('<p className="text-green-700" />')).toContain('off-palette')
expect(rules('<p className="bg-purple-100" />')).toContain('off-palette')
expect(rules('<p className="text-gray-500 text-blue-700 bg-red-50" />')).toEqual([])
})
it('accepts the status token classes', () => {
expect(rules('<span className="bg-st-green-bg text-st-green-fg" />')).toEqual([])
})
it('flags hard-coded hex colors, including the retired Modernist red', () => {
expect(rules('<div style={{ color: "#ec3013" }} />')).toContain('no-hex')
expect(rules('<p>&#39;quoted&#39;</p>')).not.toContain('no-hex')
})
it('flags centered button labels', () => {
expect(rules('<button className="text-center px-2">x</button>')).toContain('no-centered-button')
})
it('flags leftovers the codemod should have replaced', () => {
expect(rules('<div className="bg-white shadow-2xl" />')).toEqual(expect.arrayContaining(['no-bg-white', 'no-heavy-shadow']))
})
it('reports file and 1-based line numbers', () => {
const v = findViolations('a\n<div className="border-2" />', 'components/y.tsx')
expect(v[0]).toMatchObject({ file: 'components/y.tsx', line: 2, rule: 'no-2px-border' })
})
it('accepts clean on-system markup', () => {
expect(rules('<div className="bg-surface border border-rule p-4 text-ink shadow-card rounded-xl" />')).toEqual([])
})
})