multipleCheckbox.spec.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import {shallow, 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 = shallow(
  7. <MultipleCheckbox
  8. choices={[[0, 'Choice A'], [1, 'Choice B'], [2, 'Choice C']]}
  9. value={[1]}
  10. />
  11. );
  12. expect(wrapper).toMatchSnapshot();
  13. });
  14. it('unselects a checked input', function() {
  15. const onChange = jest.fn();
  16. const wrapper = mount(
  17. <MultipleCheckbox
  18. choices={[[0, 'Choice A'], [1, 'Choice B'], [2, 'Choice C']]}
  19. value={[1]}
  20. onChange={onChange}
  21. />
  22. );
  23. wrapper
  24. .find('input')
  25. .at(1)
  26. .simulate('change', {target: {checked: false}});
  27. expect(onChange).toHaveBeenCalledWith([], expect.anything());
  28. });
  29. it('selects an unchecked input', function() {
  30. const onChange = jest.fn();
  31. const wrapper = mount(
  32. <MultipleCheckbox
  33. choices={[[0, 'Choice A'], [1, 'Choice B'], [2, 'Choice C']]}
  34. value={[1]}
  35. onChange={onChange}
  36. />
  37. );
  38. wrapper
  39. .find('input')
  40. .at(0)
  41. .simulate('change', {target: {checked: true}});
  42. expect(onChange).toHaveBeenCalledWith([1, 0], expect.anything());
  43. });
  44. });