globalModal.spec.jsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React from 'react';
  2. import {shallow, 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 = shallow(<GlobalModal />);
  8. expect(wrapper).toMatchSnapshot();
  9. });
  10. it('uses actionCreators to open and close Modal', function(done) {
  11. const wrapper = mount(<GlobalModal />);
  12. openModal(() => <div id="modal-test">Hi</div>);
  13. // async :<
  14. setTimeout(() => {
  15. wrapper.update();
  16. const modal = $(document.body).find('.modal');
  17. expect(modal.text()).toBe('Hi');
  18. expect(wrapper.find('GlobalModal').prop('visible')).toBe(true);
  19. closeModal();
  20. setTimeout(() => {
  21. wrapper.update();
  22. expect(wrapper.find('GlobalModal').prop('visible')).toBe(false);
  23. done();
  24. }, 1);
  25. }, 1);
  26. });
  27. it('calls onClose handler when modal closes', function(done) {
  28. const wrapper = mount(<GlobalModal />);
  29. const closeSpy = jest.fn();
  30. openModal(
  31. ({Header}) => (
  32. <div id="modal-test">
  33. <Header closeButton>Header</Header>Hi
  34. </div>
  35. ),
  36. {onClose: closeSpy}
  37. );
  38. // async :<
  39. setTimeout(() => {
  40. wrapper.update();
  41. const modal = $(document.body).find('.modal');
  42. modal.find('.close').click();
  43. setTimeout(() => {
  44. wrapper.update();
  45. expect(closeSpy).toHaveBeenCalled();
  46. done();
  47. }, 1);
  48. }, 1);
  49. });
  50. });