Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

81 wiersze
2.1 KiB

  1. import * as fc from 'fast-check'
  2. import * as Enzyme from 'enzyme'
  3. import * as Axe from 'jest-axe'
  4. import * as React from 'react'
  5. import RadioButton from './RadioButton'
  6. import stringify from '../../services/stringify'
  7. it('should exist', () => {
  8. expect(RadioButton).toBeDefined()
  9. })
  10. it('should be a component', () => {
  11. expect(RadioButton).toBeComponent()
  12. })
  13. it('should render without crashing given required props', () => {
  14. expect(() => <RadioButton name="foo" />).not.toThrow()
  15. })
  16. it("should render a label to indicate the nature of the component's value", () => {
  17. const wrapper = Enzyme.shallow(<RadioButton name="foo" label="foo" />)
  18. expect(wrapper.find('label').children()).toHaveLength(4)
  19. })
  20. it('should render a label to describe the intrinsic value of the component', () => {
  21. fc.assert(
  22. fc.property(fc.anything(), (label) => {
  23. const wrapper = Enzyme.shallow(<RadioButton label={label} name="foo" />)
  24. expect(
  25. wrapper
  26. .find('label')
  27. .children()
  28. .last(),
  29. ).toHaveText(stringify(label))
  30. }),
  31. {
  32. numRuns: 300,
  33. },
  34. )
  35. })
  36. it('should render the label when undefined or null', () => {
  37. fc.assert(
  38. fc.property(fc.oneof(fc.constant(void 0), fc.constant(null)), (label) => {
  39. const wrapper = Enzyme.shallow(<RadioButton name="foo" label={label} />)
  40. expect(
  41. wrapper
  42. .find('label')
  43. .children()
  44. .last()
  45. .text(),
  46. ).toHaveLength(0)
  47. }),
  48. )
  49. })
  50. it('should render the input', () => {
  51. const wrapper = Enzyme.shallow(<RadioButton name="foo" />)
  52. expect(wrapper.find('label').find('input')).toHaveLength(1)
  53. })
  54. it('should guarantee minimal accessibility', async () => {
  55. await fc.assert(
  56. fc.asyncProperty(fc.string().filter((s) => s.trim().length > 0), async (s) => {
  57. const wrapper = Enzyme.mount(
  58. <div role="application">
  59. <RadioButton name="foo" label={s} />
  60. </div>,
  61. )
  62. const results = await Axe.axe(wrapper.getDOMNode<HTMLHtmlElement>())
  63. expect(results).toHaveNoViolations()
  64. }),
  65. )
  66. })