radio-chip.test.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { expect } from 'chai'
  2. import { render, screen } from '@testing-library/react'
  3. import RadioChip from '@/shared/components/radio-chip'
  4. describe('<RadioChip />', function () {
  5. const defaultProps = {
  6. name: 'test',
  7. label: 'Test',
  8. value: 'testValue',
  9. onChange: () => {},
  10. }
  11. describe('component renders and with label', function () {
  12. it('renders and label is provided', function () {
  13. render(<RadioChip {...defaultProps} />)
  14. screen.getByText('Test')
  15. })
  16. })
  17. describe('props', function () {
  18. it('should be checked when the checked prop is provided', function () {
  19. render(<RadioChip {...defaultProps} checked />)
  20. const radioChip = screen.getByRole('radio') as HTMLInputElement
  21. expect(radioChip.checked).to.equal(true)
  22. })
  23. it('should be disabled when the disabled prop is provided', function () {
  24. render(<RadioChip {...defaultProps} disabled />)
  25. const radioChip = screen.getByRole('radio') as HTMLInputElement
  26. expect(radioChip.disabled).to.equal(true)
  27. })
  28. it('should have the required attribute when the required prop is provided', function () {
  29. render(<RadioChip {...defaultProps} required />)
  30. const radioChip = screen.getByRole('radio') as HTMLInputElement
  31. expect(radioChip.required).to.equal(true)
  32. })
  33. it('should use the provided name prop', function () {
  34. render(<RadioChip {...defaultProps} name="testName" />)
  35. const radioChip = screen.getByRole('radio') as HTMLInputElement
  36. expect(radioChip.name).to.equal('testName')
  37. })
  38. it('should use the provided value prop', function () {
  39. render(<RadioChip {...defaultProps} />)
  40. const radioChip = screen.getByRole('radio') as HTMLInputElement
  41. expect(radioChip.value).to.equal('testValue')
  42. })
  43. it('should have the data-disabled attribute when the disabled prop is provided', function () {
  44. render(<RadioChip {...defaultProps} disabled />)
  45. const label = screen.getByText('Test')?.closest('label')
  46. expect(label?.getAttribute('data-disabled')).to.equal('true')
  47. })
  48. })
  49. })