globalModal.spec.jsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import {closeModal, openModal} from 'app/actionCreators/modal';
  4. import GlobalModal from 'app/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. });