globalModal.spec.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react';
  2. import {mountWithTheme, mount} from 'sentry-test/enzyme';
  3. import GlobalModal from 'app/components/globalModal';
  4. import {openModal, closeModal} from 'app/actionCreators/modal';
  5. describe('GlobalModal', function () {
  6. it('renders', function () {
  7. const wrapper = mountWithTheme(<GlobalModal />);
  8. expect(wrapper).toSnapshot();
  9. wrapper.unmount();
  10. });
  11. it('uses actionCreators to open and close Modal', function (done) {
  12. const wrapper = mount(<GlobalModal />);
  13. openModal(() => <div id="modal-test">Hi</div>);
  14. // async :<
  15. setTimeout(() => {
  16. wrapper.update();
  17. const modal = $(document.body).find('.modal');
  18. expect(modal.text()).toBe('Hi');
  19. expect(wrapper.find('GlobalModal').prop('visible')).toBe(true);
  20. closeModal();
  21. setTimeout(() => {
  22. wrapper.update();
  23. expect(wrapper.find('GlobalModal').prop('visible')).toBe(false);
  24. done();
  25. }, 1);
  26. }, 1);
  27. });
  28. it('calls onClose handler when modal is clicked out of', async function () {
  29. const wrapper = mount(<GlobalModal />);
  30. const closeSpy = jest.fn();
  31. openModal(
  32. ({Header}) => (
  33. <div id="modal-test">
  34. <Header closeButton>Header</Header>Hi
  35. </div>
  36. ),
  37. {onClose: closeSpy}
  38. );
  39. await tick();
  40. wrapper.update();
  41. $(document.body).find('.modal .close').click();
  42. await tick();
  43. wrapper.update();
  44. expect(closeSpy).toHaveBeenCalled();
  45. });
  46. it('calls onClose handler when closeModal prop is called', async function () {
  47. const wrapper = mount(<GlobalModal />);
  48. const closeSpy = jest.fn();
  49. openModal(({closeModal: cm}) => <button onClick={cm} />, {onClose: closeSpy});
  50. await tick();
  51. wrapper.update();
  52. wrapper.find('button').simulate('click');
  53. await tick();
  54. wrapper.update();
  55. expect(closeSpy).toHaveBeenCalled();
  56. });
  57. });