openpencil/tools/checks/architecture/tests/dynamic-classes.test.ts
Danila Poyarkov 1aa10a4fed
build(tools): group tools by role and gate them like the rest of the repo (#791)
Tools live under tools/<role>/<domain> (checks, generate, release, ci, dev), every tool is a workspace named @open-pencil/<domain>-tools, a shared tools/tsconfig.json backs the new check:tools gate that fixed 55 latent type errors, test:tools runs through bun --filter, the placement check is its own checks/test-homes package, and every tool resolves the repository through resolveWorkspaceRoot. Bun, Node, and mdast types live in a tools-root workspace so they never reach the app program.
2026-09-30 05:00:31 +04:00

72 lines
2.4 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import {
dynamicClassDiagnostics,
vueTemplateGuardrailDiagnostics
} from '../src/steiger-rules/dynamic-tailwind-classes'
function component(classBinding: string) {
return `<template><button :class="${classBinding}" /></template>`
}
describe('Vue template UI guardrails', () => {
test('reports use*UI calls inside bindings', () => {
const source = `<template><button :class="useButtonUI({ tone: 'accent' }).base" /></template>`
expect(vueTemplateGuardrailDiagnostics('src/components/Test.vue', source)).toHaveLength(1)
})
test('reports raw SVG elements and permits icon components', () => {
expect(
vueTemplateGuardrailDiagnostics(
'src/components/Test.vue',
'<template><div><svg /><icon-lucide-check /></div></template>'
)
).toHaveLength(1)
})
})
describe('dynamic Tailwind state classes', () => {
test('reports conditional utility strings', () => {
const diagnostics = dynamicClassDiagnostics(
'src/components/example/ExampleButton.vue',
component("active ? 'bg-accent text-white' : 'text-muted'")
)
expect(diagnostics).toHaveLength(1)
})
test('reports object-style utility maps', () => {
const diagnostics = dynamicClassDiagnostics(
'src/components/example/ExampleButton.vue',
component("{ 'opacity-50': disabled }")
)
expect(diagnostics).toHaveLength(1)
})
test('rejects dynamic utility state in previously audited files', () => {
const audited = `<template>${'\n'.repeat(36)}<button :class="active ? 'bg-hover' : 'text-muted'" /></template>`
expect(
dynamicClassDiagnostics('src/components/CollabPanel/CollabAvatarStack.vue', audited)
).toHaveLength(1)
expect(
dynamicClassDiagnostics(
'src/components/LayersPanel.vue',
component("active ? 'bg-hover' : 'text-muted'")
)
).toHaveLength(1)
})
test('allows resolved theme slots and semantic state', () => {
const source = `<template><button :data-active="active || undefined" :class="styles.button({ class: ui?.button })" /></template>`
expect(dynamicClassDiagnostics('src/components/example/ExampleButton.vue', source)).toEqual([])
})
test('ignores static classes', () => {
expect(
dynamicClassDiagnostics(
'src/components/example/ExampleButton.vue',
'<template><button class="bg-transparent text-muted hover:bg-hover" /></template>'
)
).toEqual([])
})
})