styles.spec.ts 1.9 KB

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