createIncidentModal.spec.jsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {Modal} from 'react-bootstrap';
  2. import {browserHistory} from 'react-router';
  3. import React from 'react';
  4. import {mount} from 'enzyme';
  5. import CreateIncidentModal from 'app/components/modals/createIncidentModal';
  6. describe('CreateIncidentModal', function() {
  7. const org = TestStubs.Organization();
  8. const closeModal = jest.fn();
  9. const onClose = jest.fn();
  10. const onSuccess = jest.fn();
  11. beforeEach(function() {
  12. onClose.mockReset();
  13. onSuccess.mockReset();
  14. });
  15. afterEach(function() {
  16. browserHistory.push.mockReset();
  17. });
  18. it('creates and redirects to newly created incident', async function() {
  19. const mock = MockApiClient.addMockResponse({
  20. url: '/organizations/org-slug/incidents/',
  21. method: 'POST',
  22. body: {
  23. identifier: '11111',
  24. },
  25. });
  26. const wrapper = mount(
  27. <CreateIncidentModal
  28. Body={Modal.Body}
  29. Header={Modal.Header}
  30. organization={org}
  31. closeModal={closeModal}
  32. onClose={onClose}
  33. issues={['123', '456']}
  34. />,
  35. TestStubs.routerContext()
  36. );
  37. wrapper.find('Input[name="title"]').simulate('change', {target: {value: 'Oh no'}});
  38. wrapper.find('Form').simulate('submit');
  39. expect(mock).toHaveBeenCalledWith(
  40. '/organizations/org-slug/incidents/',
  41. expect.objectContaining({
  42. data: {
  43. dateStarted: new Date(),
  44. groups: ['123', '456'],
  45. query: '',
  46. title: 'Oh no',
  47. },
  48. method: 'POST',
  49. })
  50. );
  51. await tick();
  52. expect(onClose).toHaveBeenCalled();
  53. expect(closeModal).toHaveBeenCalled();
  54. expect(browserHistory.push).toHaveBeenCalledWith(
  55. '/organizations/org-slug/incidents/11111/'
  56. );
  57. });
  58. });