Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 rivejä
2.0 KiB

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