radioGroup.spec.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import React from 'react';
  2. import {mount, shallow} from 'enzyme';
  3. import RadioGroup from 'app/views/settings/components/forms/controls/radioGroup';
  4. describe('RadioGroup', function() {
  5. describe('render()', function() {
  6. it('renders', function() {
  7. const wrapper = shallow(
  8. <RadioGroup
  9. name="radio"
  10. value="choice_one"
  11. choices={[
  12. ['choice_one', 'Choice One'],
  13. ['choice_two', 'Choice Two'],
  14. ['choice_three', 'Choice Three'],
  15. ]}
  16. />
  17. );
  18. expect(wrapper).toMatchSnapshot();
  19. });
  20. it('renders disabled', function() {
  21. const wrapper = mount(
  22. <RadioGroup
  23. name="radio"
  24. value="choice_one"
  25. disabled={true}
  26. choices={[['choice_one', 'Choice One']]}
  27. />
  28. );
  29. expect(wrapper).toMatchSnapshot();
  30. expect(wrapper.find('RadioLineText').props().disabled).toBe(true);
  31. expect(wrapper.find('RadioLineButtonFill').props().disabled).toBe(true);
  32. });
  33. it('can select a different item', function() {
  34. const wrapper = shallow(
  35. <RadioGroup
  36. name="radio"
  37. value="choice_three"
  38. choices={[
  39. ['choice_one', 'Choice One'],
  40. ['choice_two', 'Choice Two'],
  41. ['choice_three', 'Choice Three'],
  42. ]}
  43. />
  44. );
  45. expect(wrapper).toMatchSnapshot();
  46. });
  47. it('calls onChange when clicked', function() {
  48. const mock = jest.fn();
  49. const wrapper = mount(
  50. <RadioGroup
  51. name="radio"
  52. value="choice_one"
  53. choices={[
  54. ['choice_one', 'Choice One'],
  55. ['choice_two', 'Choice Two'],
  56. ['choice_three', 'Choice Three'],
  57. ]}
  58. onChange={mock}
  59. />
  60. );
  61. wrapper
  62. .find('[role="radio"]')
  63. .last()
  64. .simulate('click');
  65. expect(mock).toHaveBeenCalledWith(expect.any(String), expect.any(Object));
  66. });
  67. });
  68. });