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.
 
 
 
 

84 lines
2.2 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 RadioButton from './RadioButton'
  8. import stringify from '../../services/stringify'
  9. it('should exist', () => {
  10. expect(RadioButton).toBeDefined()
  11. })
  12. it('should be a component', () => {
  13. expect(RadioButton).toBeComponent()
  14. })
  15. it('should render without crashing given required props', () => {
  16. expect(() => <RadioButton name="foo" />).not.toThrow()
  17. })
  18. it("should render a label to indicate the nature of the component's value", () => {
  19. const wrapper = Enzyme.shallow(<RadioButton name="foo" label="foo" />)
  20. expect(wrapper.find('label').children()).toHaveLength(4)
  21. })
  22. it('should render a label to describe the intrinsic value of the component', () => {
  23. fc.assert(
  24. fc.property(fc.anything(), (label) => {
  25. const wrapper = Enzyme.shallow(<RadioButton label={label} name="foo" />)
  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(<RadioButton name="foo" 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(<RadioButton name="foo" />)
  54. expect(wrapper.find('label').find('input')).toHaveLength(1)
  55. })
  56. it('should guarantee minimal accessibility', async () => {
  57. await fc.assert(
  58. fc.asyncProperty(fc.string().filter((s) => s.trim().length > 0), async (s) => {
  59. const wrapper = Enzyme.mount(
  60. <div role="application">
  61. <RadioButton name="foo" label={s} />
  62. </div>,
  63. )
  64. const results = await Axe.axe(wrapper.getDOMNode<HTMLHtmlElement>())
  65. expect(results).toHaveNoViolations()
  66. }),
  67. )
  68. })