46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { findViolations, ROUND_ALLOWED } 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', () => {
|
|
it('flags rounded corner classes', () => {
|
|
expect(rules('<div className="rounded-lg p-2" />')).toContain('no-rounded')
|
|
expect(rules('<div className="p-2 hover:rounded-md" />')).toContain('no-rounded')
|
|
})
|
|
|
|
it('flags rounded-full outside the allowlist and accepts it inside', () => {
|
|
expect(rules('<div className="rounded-full" />')).toContain('no-rounded-full')
|
|
expect(rules('<div className="rounded-full" />', ROUND_ALLOWED[0])).not.toContain('no-rounded-full')
|
|
})
|
|
|
|
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('flags hard-coded hex colors', () => {
|
|
expect(rules('<div style={{ color: "#ec3013" }} />')).toContain('no-hex')
|
|
expect(rules('<p>'quoted'</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="rounded-md" />', 'components/y.tsx')
|
|
expect(v[0]).toMatchObject({ file: 'components/y.tsx', line: 2, rule: 'no-rounded' })
|
|
})
|
|
|
|
it('accepts clean on-system markup', () => {
|
|
expect(rules('<div className="bg-surface border border-divider p-4 text-ink shadow-sm" />')).toEqual([])
|
|
})
|
|
})
|