multipleCheckbox.spec.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import {mountWithTheme, mount} from 'sentry-test/enzyme';
  3. import MultipleCheckbox from 'app/views/settings/components/forms/controls/multipleCheckbox';
  4. describe('MultipleCheckbox', function() {
  5. it('renders', function() {
  6. const wrapper = mountWithTheme(
  7. <MultipleCheckbox
  8. choices={[
  9. [0, 'Choice A'],
  10. [1, 'Choice B'],
  11. [2, 'Choice C'],
  12. ]}
  13. value={[1]}
  14. />
  15. );
  16. expect(wrapper).toSnapshot();
  17. });
  18. it('unselects a checked input', function() {
  19. const onChange = jest.fn();
  20. const wrapper = mount(
  21. <MultipleCheckbox
  22. choices={[
  23. [0, 'Choice A'],
  24. [1, 'Choice B'],
  25. [2, 'Choice C'],
  26. ]}
  27. value={[1]}
  28. onChange={onChange}
  29. />
  30. );
  31. wrapper
  32. .find('input')
  33. .at(1)
  34. .simulate('change', {target: {checked: false}});
  35. expect(onChange).toHaveBeenCalledWith([], expect.anything());
  36. });
  37. it('selects an unchecked input', function() {
  38. const onChange = jest.fn();
  39. const wrapper = mount(
  40. <MultipleCheckbox
  41. choices={[
  42. [0, 'Choice A'],
  43. [1, 'Choice B'],
  44. [2, 'Choice C'],
  45. ]}
  46. value={[1]}
  47. onChange={onChange}
  48. />
  49. );
  50. wrapper
  51. .find('input')
  52. .at(0)
  53. .simulate('change', {target: {checked: true}});
  54. expect(onChange).toHaveBeenCalledWith([1, 0], expect.anything());
  55. });
  56. });