radioGroup.spec.jsx 2.0 KB

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