globalModal.spec.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import {closeModal, openModal} from 'sentry/actionCreators/modal';
  4. import GlobalModal from 'sentry/components/globalModal';
  5. describe('GlobalModal', function () {
  6. it('renders', function () {
  7. const wrapper = mountWithTheme(<GlobalModal />);
  8. wrapper.unmount();
  9. });
  10. it('uses actionCreators to open and close Modal', async function () {
  11. const wrapper = mountWithTheme(<GlobalModal />);
  12. openModal(() => <div id="modal-test">Hi</div>);
  13. const modal = await mountGlobalModal();
  14. expect(modal.text()).toBe('Hi');
  15. wrapper.update();
  16. expect(wrapper.find('GlobalModal').prop('visible')).toBe(true);
  17. closeModal();
  18. await tick();
  19. wrapper.update();
  20. expect(wrapper.find('GlobalModal').prop('visible')).toBe(false);
  21. });
  22. it('calls onClose handler when modal is clicked out of', async function () {
  23. const wrapper = mountWithTheme(<GlobalModal />);
  24. const closeSpy = jest.fn();
  25. openModal(
  26. ({Header}) => (
  27. <div id="modal-test">
  28. <Header closeButton>Header</Header>Hi
  29. </div>
  30. ),
  31. {onClose: closeSpy}
  32. );
  33. const modal = await mountGlobalModal();
  34. modal.find('CloseButton').simulate('click');
  35. await tick();
  36. wrapper.update();
  37. expect(closeSpy).toHaveBeenCalled();
  38. });
  39. it('calls onClose handler when closeModal prop is called', async function () {
  40. const wrapper = mountWithTheme(<GlobalModal />);
  41. const closeSpy = jest.fn();
  42. openModal(({closeModal: cm}) => <button onClick={cm} />, {onClose: closeSpy});
  43. await tick();
  44. wrapper.update();
  45. wrapper.find('button').simulate('click');
  46. await tick();
  47. wrapper.update();
  48. expect(closeSpy).toHaveBeenCalled();
  49. });
  50. it('calls ignores click out when the allowClickClose option is false', async function () {
  51. const wrapper = mountWithTheme(
  52. <div id="outside-test">
  53. <GlobalModal />
  54. </div>
  55. );
  56. openModal(
  57. ({Header}) => (
  58. <div id="modal-test">
  59. <Header closeButton>Header</Header>Hi
  60. </div>
  61. ),
  62. {allowClickClose: false}
  63. );
  64. await tick();
  65. wrapper.update();
  66. expect(wrapper.find('GlobalModal').prop('visible')).toBe(true);
  67. wrapper.find('#outside-test').simulate('click');
  68. await tick();
  69. wrapper.update();
  70. expect(wrapper.find('GlobalModal').prop('visible')).toBe(true);
  71. wrapper.find('CloseButton').simulate('click');
  72. await tick();
  73. wrapper.update();
  74. expect(wrapper.find('GlobalModal').prop('visible')).toBe(false);
  75. });
  76. });