state-dot.client.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // @vitest-environment jsdom
  2. import { cleanup, render } from '@testing-library/react'
  3. import { afterEach, describe, expect, it } from 'vitest'
  4. import { StateDot } from '@deepseek-ai/dsh-client-ui-primitives'
  5. import type { StateDotState } from '@deepseek-ai/dsh-client-ui-primitives'
  6. afterEach(cleanup)
  7. describe('StateDot', () => {
  8. it.each(['done', 'warning', 'ongoing', 'error', 'idle'] as const)('renders state %s as data-state', (state) => {
  9. const { container } = render(<StateDot state={state} />)
  10. const dot = container.firstElementChild as HTMLElement
  11. expect(dot.dataset['state']).toBe(state)
  12. expect(dot.getAttribute('aria-hidden')).toBe('true')
  13. })
  14. it('solid states are spans; ongoing is an svg pixel matrix', () => {
  15. const { container, rerender } = render(<StateDot state="done" />)
  16. expect(container.firstElementChild?.tagName).toBe('SPAN')
  17. rerender(<StateDot state="ongoing" />)
  18. const matrix = container.firstElementChild as SVGSVGElement
  19. expect(matrix.tagName).toBe('svg')
  20. const cells = matrix.querySelectorAll('rect')
  21. expect(cells).toHaveLength(8)
  22. // Chase phase: every cell carries its own negative animation delay.
  23. const delays = [...cells].map(cell => (cell).style.animationDelay)
  24. expect(new Set(delays).size).toBe(8)
  25. })
  26. it('sizes via the size prop in both shapes', () => {
  27. const { container, rerender } = render(<StateDot state="done" size={12} />)
  28. const dot = container.firstElementChild as HTMLElement
  29. expect(dot.style.width).toBe('12px')
  30. expect(dot.style.height).toBe('12px')
  31. rerender(<StateDot state="ongoing" size={12} />)
  32. const ring = container.firstElementChild as SVGSVGElement
  33. expect(ring.getAttribute('width')).toBe('12')
  34. expect(ring.getAttribute('height')).toBe('12')
  35. })
  36. it('rejects unknown states at the type level', () => {
  37. const bad = (state: StateDotState) => state
  38. // @ts-expect-error 'paused' is not one of the five states
  39. expect(bad('paused')).toBe('paused')
  40. })
  41. })