Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

76 rader
1.9 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 Checkbox from './Checkbox'
  6. import stringify from '../../services/stringify'
  7. it('should exist', () => {
  8. expect(Checkbox).toBeDefined()
  9. })
  10. it('should be a component', () => {
  11. expect(Checkbox).toBeComponent()
  12. })
  13. it('should render without crashing given required props', () => {
  14. expect(() => <Checkbox />).not.toThrow()
  15. })
  16. it('should render a label to describe the intrinsic value of the component', () => {
  17. const wrapper = Enzyme.shallow(<Checkbox label="foo" />)
  18. expect(wrapper.find('label').children()).toHaveLength(4)
  19. })
  20. it('should render the label when not undefined or null', () => {
  21. fc.assert(
  22. fc.property(fc.anything().filter((v) => !Array.isArray(v) && typeof v !== 'undefined' && v !== null), (label) => {
  23. const wrapper = Enzyme.shallow(<Checkbox label={label} />)
  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(<Checkbox 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(<Checkbox />)
  52. expect(wrapper.find('label').find('input')).toHaveLength(1)
  53. })
  54. it('should guarantee minimal accessibility', () => {
  55. fc.assert(
  56. fc.asyncProperty(fc.string(1, 20), async (s) => {
  57. const wrapper = Enzyme.mount(<Checkbox label={s} />)
  58. const results = await Axe.axe(wrapper.getDOMNode())
  59. expect(results).toHaveNoViolations()
  60. }),
  61. )
  62. })