Common front-end components for Web using the Tesseract design system, written for React. https://make.modal.sh/tesseract/web/react/common
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Checkbox.test.tsx 2.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. })