2026-07-31 11:14:07 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
|
|
|
|
const css = readFileSync(fileURLToPath(new URL('../src/client/ModelsSection.module.css', import.meta.url)), 'utf8')
|
2026-08-04 14:53:17 +08:00
|
|
|
const tokens = readFileSync(
|
|
|
|
|
fileURLToPath(new URL('../../ui-theme/src/styles/design-platform.css', import.meta.url)),
|
|
|
|
|
'utf8',
|
|
|
|
|
)
|
2026-07-31 11:14:07 +08:00
|
|
|
|
2026-07-31 15:11:02 +08:00
|
|
|
/** The declarations of one top-level rule, by selector. */
|
|
|
|
|
function block(selector: string): string {
|
|
|
|
|
const match = new RegExp(`^\\${selector} \\{([^}]*)\\}`, 'm').exec(css)
|
|
|
|
|
if (match === null) throw new Error(`ModelsSection.module.css has no \`${selector}\` rule`)
|
|
|
|
|
return match[1] ?? ''
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-31 11:14:07 +08:00
|
|
|
describe('ModelsSection theme styles', () => {
|
2026-08-04 14:53:17 +08:00
|
|
|
it('names only theme variables the token sheet defines', () => {
|
|
|
|
|
// A `--dsw-*` name the sheet never declares is not a near miss: it silently
|
|
|
|
|
// resolves to whatever literal sits in its fallback slot, which is how this
|
|
|
|
|
// section stayed light under the dark theme before. Undeclared names have
|
|
|
|
|
// no fallback at all and inherit, so both spellings must fail here.
|
|
|
|
|
const named = [...css.matchAll(/var\((--dsw-[a-z0-9-]+)/g)].map(match => match[1])
|
|
|
|
|
const undeclared = [...new Set(named)].filter(name => !tokens.includes(` ${String(name)}:`))
|
|
|
|
|
expect(undeclared).toEqual([])
|
2026-07-31 11:14:07 +08:00
|
|
|
expect(css).not.toMatch(/var\(--(?:surface|text-|border|accent-strong)/)
|
|
|
|
|
})
|
2026-07-31 15:11:02 +08:00
|
|
|
|
|
|
|
|
it('separates the row card from the editor it expands into', () => {
|
|
|
|
|
// `bg-layer-3` and `bg-module-platform` both resolve to neutral-bluish-800
|
|
|
|
|
// under the dark theme, so filling the row with either erases the nested
|
|
|
|
|
// editor's boundary. The row is outlined; the fill is the editor's alone.
|
|
|
|
|
expect(block('.editor')).toContain('background: var(--dsw-alias-bg-module-platform)')
|
|
|
|
|
expect(block('.rowCard')).toContain('border: 1px solid var(--dsw-alias-border-l2)')
|
|
|
|
|
expect(block('.rowCard')).not.toMatch(/\bbackground\s*:/)
|
|
|
|
|
})
|
2026-07-31 11:14:07 +08:00
|
|
|
})
|