eventCause.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {Client} from 'app/api';
  4. import EventCause from 'app/components/events/eventCause';
  5. describe('EventCause', function() {
  6. let wrapper, organization, project, event;
  7. afterEach(function() {
  8. Client.clearMockResponses();
  9. });
  10. beforeEach(function() {
  11. event = TestStubs.Event();
  12. organization = TestStubs.Organization();
  13. project = TestStubs.Project();
  14. Client.addMockResponse({
  15. method: 'GET',
  16. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  17. body: {
  18. committers: [
  19. {
  20. author: {name: 'Max Bittker', id: '1'},
  21. commits: [
  22. {
  23. message:
  24. 'feat: Enhance suggested commits and add to alerts\n\n- Refactor components to use new shared CommitRow\n- Add Suspect Commits to alert emails\n- Refactor committers scanning code to handle various edge cases.',
  25. score: 4,
  26. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  27. repository: TestStubs.Repository(),
  28. dateCreated: '2018-03-02T18:30:26Z',
  29. },
  30. {
  31. message:
  32. 'feat: Enhance suggested commits and add to alerts\n\n- Refactor components to use new shared CommitRow\n- Add Suspect Commits to alert emails\n- Refactor committers scanning code to handle various edge cases.',
  33. score: 4,
  34. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  35. repository: TestStubs.Repository(),
  36. dateCreated: '2018-03-02T18:30:26Z',
  37. },
  38. ],
  39. },
  40. {
  41. author: {name: 'Somebody else', id: '2'},
  42. commits: [
  43. {
  44. message: 'fix: Make things less broken',
  45. score: 2,
  46. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  47. repository: TestStubs.Repository(),
  48. dateCreated: '2018-03-02T16:30:26Z',
  49. },
  50. ],
  51. },
  52. ],
  53. },
  54. });
  55. wrapper = mount(
  56. <EventCause event={event} orgId={organization.slug} projectId={project.slug} />,
  57. {
  58. context: {
  59. organization,
  60. project,
  61. group: TestStubs.Group(),
  62. },
  63. }
  64. );
  65. });
  66. it('renders', function(done) {
  67. wrapper.update();
  68. setTimeout(() => {
  69. expect(wrapper.find('CommitRow')).toHaveLength(1);
  70. done();
  71. });
  72. });
  73. it('expands', async function(done) {
  74. wrapper.update();
  75. wrapper.find('ExpandButton').simulate('click');
  76. await tick();
  77. expect(wrapper.find('CommitRow')).toHaveLength(2);
  78. //and hides
  79. wrapper.find('ExpandButton').simulate('click');
  80. await tick();
  81. expect(wrapper.find('CommitRow')).toHaveLength(1);
  82. done();
  83. });
  84. });