globalModal.spec.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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)
  42. .find('.modal .close')
  43. .click();
  44. await tick();
  45. wrapper.update();
  46. expect(closeSpy).toHaveBeenCalled();
  47. });
  48. it('calls onClose handler when closeModal prop is called', async function() {
  49. const wrapper = mount(<GlobalModal />);
  50. const closeSpy = jest.fn();
  51. openModal(({closeModal: cm}) => <button onClick={cm} />, {onClose: closeSpy});
  52. await tick();
  53. wrapper.update();
  54. wrapper.find('button').simulate('click');
  55. await tick();
  56. wrapper.update();
  57. expect(closeSpy).toHaveBeenCalled();
  58. });
  59. });