user-text-styles.client.spec.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * UserText's font-size-axis adoption as CSS text. jsdom has no layout, so
  3. * this reads the declaration that keeps inline reference glyphs riding the
  4. * consumer's text size in both surfaces the projection serves (bubble and
  5. * queue preview).
  6. */
  7. import { readFileSync } from 'node:fs'
  8. import { fileURLToPath } from 'node:url'
  9. import { describe, expect, it } from 'vitest'
  10. const css = readFileSync(fileURLToPath(new URL('../src/user-text.module.css', import.meta.url)), 'utf8')
  11. const declarationText = css.replace(/\/\*[\s\S]*?\*\//g, ' ')
  12. function declarations(selector: string): string[] {
  13. const rule = new RegExp(`(?:^|\\})\\s*${selector.replace(/[.[\]():*+^$\\]/g, '\\$&')}\\s*\\{([^{}]*)\\}`).exec(declarationText)
  14. if (rule === null) throw new Error(`user-text.module.css has no \`${selector}\` rule`)
  15. return (rule[1] ?? '').split(';').map(part => part.trim()).filter(Boolean)
  16. }
  17. describe('user-text.module.css font-size axis', () => {
  18. it('scales reference glyphs with the consumer font', () => {
  19. expect(declarations('.refIcon')).toEqual(expect.arrayContaining([
  20. 'width: 1em',
  21. 'height: 1em',
  22. ]))
  23. })
  24. it('sets slash chips in the code face at the consumer size', () => {
  25. // Skill and command tokens read as code — the family the theme publishes
  26. // for code — while the size and line height stay the consumer's, so the
  27. // chip rides the bubble line like the plain runs around it.
  28. const slashChip = declarations('.slashChip')
  29. expect(slashChip.some(declaration => /^font-family: var\(--dsw-font-/.test(declaration))).toBe(true)
  30. expect(slashChip.some(declaration => /^(font|font-size|line-height):/.test(declaration))).toBe(false)
  31. })
  32. })