confirmDelete.spec.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import ConfirmDelete from 'app/components/confirmDelete';
  4. describe('ConfirmDelete', function () {
  5. it('renders', async function () {
  6. const mock = jest.fn();
  7. const wrapper = mountWithTheme(
  8. <ConfirmDelete message="Are you sure?" onConfirm={mock} confirmInput="CoolOrg">
  9. <button>Confirm?</button>
  10. </ConfirmDelete>,
  11. TestStubs.routerContext()
  12. );
  13. wrapper.find('button').simulate('click');
  14. const modal = await mountGlobalModal();
  15. // jest had an issue rendering root component snapshot so using ModalDialog instead
  16. expect(modal.find('Modal')).toSnapshot();
  17. });
  18. it('confirm button is disabled and bypass prop is false when modal opens', async function () {
  19. const mock = jest.fn();
  20. const wrapper = mountWithTheme(
  21. <ConfirmDelete message="Are you sure?" onConfirm={mock} confirmInput="CoolOrg">
  22. <button>Confirm?</button>
  23. </ConfirmDelete>,
  24. TestStubs.routerContext()
  25. );
  26. wrapper.find('button').simulate('click');
  27. const modal = await mountGlobalModal();
  28. expect(wrapper.find('Confirm').prop('bypass')).toBe(false);
  29. expect(modal.find('Button[priority="primary"][disabled=true]').exists()).toBe(true);
  30. });
  31. it('confirm button stays disabled with non-matching input', async function () {
  32. const mock = jest.fn();
  33. const wrapper = mountWithTheme(
  34. <ConfirmDelete message="Are you sure?" onConfirm={mock} confirmInput="CoolOrg">
  35. <button>Confirm?</button>
  36. </ConfirmDelete>,
  37. TestStubs.routerContext()
  38. );
  39. wrapper.find('button').simulate('click');
  40. const modal = await mountGlobalModal();
  41. modal.find('input').simulate('change', {target: {value: 'Cool'}});
  42. expect(modal.find('Button[priority="primary"][disabled=true]').exists()).toBe(true);
  43. });
  44. it('confirm button is enabled when confirm input matches', async function () {
  45. const mock = jest.fn();
  46. const wrapper = mountWithTheme(
  47. <ConfirmDelete message="Are you sure?" onConfirm={mock} confirmInput="CoolOrg">
  48. <button>Confirm?</button>
  49. </ConfirmDelete>,
  50. TestStubs.routerContext()
  51. );
  52. wrapper.find('button').simulate('click');
  53. const modal = await mountGlobalModal();
  54. modal.find('input').simulate('change', {target: {value: 'CoolOrg'}});
  55. expect(modal.find('Button[priority="primary"][disabled=false]').exists()).toBe(true);
  56. modal.find('Button[priority="primary"]').simulate('click');
  57. expect(mock).toHaveBeenCalled();
  58. expect(mock.mock.calls).toHaveLength(1);
  59. });
  60. });