icons.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @vitest-environment jsdom
  2. import { cleanup, render } from '@testing-library/react'
  3. import { afterEach, describe, expect, it } from 'vitest'
  4. import * as primitives from '@deepseek-ai/dsh-client-ui-primitives'
  5. import { IconApiOutline14, IconFolderClose16, IconSendOutline16 } from '@deepseek-ai/dsh-client-ui-primitives'
  6. afterEach(cleanup)
  7. // Icon components all share the IconProps signature; the barrel also exports
  8. // non-icon atoms (different props shapes), so filter by prefix BEFORE typing.
  9. const icons = Object.fromEntries(
  10. Object.entries(primitives).filter(([name]) => name.startsWith('Icon')),
  11. ) as Record<string, (p: primitives.IconProps) => React.JSX.Element>
  12. const iconNames = Object.keys(icons)
  13. describe('ic_ds_ icon set', () => {
  14. it('exports the full P-I set (43 deepsuite + 12 figma extracts)', () => {
  15. expect(iconNames.length).toBe(55)
  16. })
  17. it.each(iconNames)('%s renders an svg with currentColor fills and no hardcoded palette', name => {
  18. const Icon = icons[name]!
  19. const { container } = render(<Icon />)
  20. const svg = container.querySelector('svg')
  21. expect(svg).not.toBeNull()
  22. const markup = container.innerHTML
  23. expect(markup).not.toMatch(/#[0-9a-fA-F]{3,8}"/)
  24. expect(markup).toContain('currentColor')
  25. })
  26. it('size and className props land on the root svg', () => {
  27. const { container } = render(<IconSendOutline16 size={20} className="x" />)
  28. const svg = container.querySelector('svg')!
  29. expect(svg.getAttribute('width')).toBe('20')
  30. expect(svg.getAttribute('height')).toBe('20')
  31. expect(svg.classList.contains('x')).toBe(true)
  32. })
  33. it('native defaults: 14-glyphs default 14, 16-glyphs default 16', () => {
  34. const api = render(<IconApiOutline14 />)
  35. expect(api.container.querySelector('svg')!.getAttribute('width')).toBe('14')
  36. const folder = render(<IconFolderClose16 />)
  37. expect(folder.container.querySelector('svg')!.getAttribute('width')).toBe('16')
  38. })
  39. })
  40. describe('FishLogo', () => {
  41. it('renders the fish path in currentColor at the native ratio', () => {
  42. const { container } = render(<primitives.FishLogo />)
  43. const svg = container.querySelector('svg')!
  44. expect(svg.getAttribute('width')).toBe('24')
  45. expect(Number(svg.getAttribute('height'))).toBeCloseTo(17.66, 1)
  46. expect(svg.getAttribute('viewBox')).toBe('0 0 23.16 17.04')
  47. expect(container.querySelectorAll('path')).toHaveLength(1)
  48. expect(container.innerHTML).toContain('currentColor')
  49. expect(container.innerHTML).not.toContain('M0 0L23.16')
  50. })
  51. })