reference-chip.client.spec.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. // @vitest-environment jsdom
  2. /**
  3. * ReferenceChip visual face: icon selection per appearance, the trigger
  4. * marker fallback, label truncation container, and invalid styling.
  5. */
  6. import { afterEach, describe, expect, it } from 'vitest'
  7. import { cleanup, render } from '@testing-library/react'
  8. import { ReferenceChip } from '../src/client/input/editor/ReferenceChip.tsx'
  9. afterEach(cleanup)
  10. describe('ReferenceChip', () => {
  11. it('renders the domain icon and the label', () => {
  12. const { container, getByTitle } = render(
  13. <ReferenceChip label="Research notes" appearance="session" invalid={false} />,
  14. )
  15. expect(getByTitle('Research notes')).toBeTruthy()
  16. expect(container.querySelector('svg')).not.toBeNull()
  17. expect(container.textContent).toBe('Research notes')
  18. })
  19. it('falls back to the trigger marker without an appearance', () => {
  20. const { container } = render(<ReferenceChip label="commit-helper" invalid={false} />)
  21. expect(container.querySelector('svg')).toBeNull()
  22. expect(container.textContent).toBe('@commit-helper')
  23. })
  24. it('applies the invalid styling bit', () => {
  25. const { container } = render(<ReferenceChip label="gone" appearance="folder" invalid />)
  26. const chip = container.firstElementChild
  27. expect(chip).not.toBeNull()
  28. expect([...(chip?.classList ?? [])].some(name => name.includes('invalid'))).toBe(true)
  29. })
  30. })