panel-styles.client.spec.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * WorkflowRunPanel's font-size-axis adoption as CSS text. jsdom has no
  3. * layout, so these read the declarations that make the run/phase headers and
  4. * the expanded member rows follow the Settings font-size preference: member
  5. * labels at the body size (--dsh-content-font-size / --dsh-content-font-delta),
  6. * the chrome around them on the secondary tier
  7. * (--dsh-content-font-size-secondary / --dsh-content-font-delta-secondary).
  8. */
  9. import { readFileSync } from 'node:fs'
  10. import { fileURLToPath } from 'node:url'
  11. import { describe, expect, it } from 'vitest'
  12. const css = readFileSync(
  13. fileURLToPath(new URL('../src/client/WorkflowRunPanel.module.css', import.meta.url)),
  14. 'utf8',
  15. )
  16. const declarationText = css.replace(/\/\*[\s\S]*?\*\//g, ' ')
  17. function declarations(selector: string): string[] {
  18. const rule = new RegExp(`(?:^|\\})\\s*${selector.replace(/[.[\]():*+^$\\,\s]/g, '\\$&')}\\s*\\{([^{}]*)\\}`).exec(declarationText)
  19. if (rule === null) throw new Error(`WorkflowRunPanel.module.css has no \`${selector}\` rule`)
  20. return (rule[1] ?? '').split(';').map(part => part.trim()).filter(Boolean)
  21. }
  22. describe('WorkflowRunPanel.module.css font-size axis', () => {
  23. it('member labels ride the axis at the body size with matching row geometry', () => {
  24. expect(declarations('.memberLabel')).toEqual(expect.arrayContaining([
  25. 'font-size: var(--dsh-content-font-size, 14px)',
  26. 'line-height: calc(24px + var(--dsh-content-font-delta, 0px))',
  27. ]))
  28. expect(declarations('.memberLabelWrap')).toEqual(expect.arrayContaining([
  29. 'height: calc(24px + var(--dsh-content-font-delta, 0px))',
  30. ]))
  31. })
  32. it('member status and the empty placeholder read the secondary tier', () => {
  33. for (const selector of ['.memberStatus', '.empty']) {
  34. expect(declarations(selector)).toEqual(expect.arrayContaining([
  35. 'font-size: var(--dsh-content-font-size-secondary, 13px)',
  36. 'line-height: calc(20px + var(--dsh-content-font-delta-secondary, 0px))',
  37. ]))
  38. }
  39. })
  40. it('the phase status column widens with the text so larger sizes do not truncate', () => {
  41. expect(declarations('.phaseStatus')).toEqual(expect.arrayContaining([
  42. 'width: calc(132px + var(--dsh-content-font-delta-secondary, 0px) * 10)',
  43. ]))
  44. })
  45. })