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

RadioButton.test.tsx 2.2 KiB

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