multipleCheckbox.spec.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import MultipleCheckbox from 'sentry/components/forms/controls/multipleCheckbox';
  3. describe('MultipleCheckbox', function () {
  4. it('renders', function () {
  5. const {container} = render(
  6. <MultipleCheckbox
  7. choices={[
  8. [0, 'Choice A'],
  9. [1, 'Choice B'],
  10. [2, 'Choice C'],
  11. ]}
  12. value={[1]}
  13. />
  14. );
  15. expect(container).toSnapshot();
  16. });
  17. it('unselects a checked input', function () {
  18. const onChange = jest.fn();
  19. render(
  20. <MultipleCheckbox
  21. choices={[
  22. [0, 'Choice A'],
  23. [1, 'Choice B'],
  24. [2, 'Choice C'],
  25. ]}
  26. value={[1]}
  27. onChange={onChange}
  28. />
  29. );
  30. userEvent.click(screen.getByLabelText('Choice B'));
  31. expect(onChange).toHaveBeenCalledWith([], expect.anything());
  32. });
  33. it('selects an unchecked input', function () {
  34. const onChange = jest.fn();
  35. render(
  36. <MultipleCheckbox
  37. choices={[
  38. [0, 'Choice A'],
  39. [1, 'Choice B'],
  40. [2, 'Choice C'],
  41. ]}
  42. value={[1]}
  43. onChange={onChange}
  44. />
  45. );
  46. userEvent.click(screen.getByLabelText('Choice A'));
  47. expect(onChange).toHaveBeenCalledWith([1, 0], expect.anything());
  48. });
  49. });