eventCause.spec.jsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  3. import {EventCause} from 'sentry/components/events/eventCause';
  4. import {CommitRow} from '../commitRow';
  5. import {QuickContextCommitRow} from '../discover/quickContextCommitRow';
  6. describe('EventCause', function () {
  7. const organization = TestStubs.Organization();
  8. const project = TestStubs.Project();
  9. const event = TestStubs.Event();
  10. const group = TestStubs.Group({firstRelease: {}});
  11. const committers = [
  12. {
  13. author: {name: 'Max Bittker', id: '1'},
  14. commits: [
  15. {
  16. message:
  17. '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.',
  18. score: 4,
  19. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  20. repository: TestStubs.Repository(),
  21. dateCreated: '2018-03-02T18:30:26Z',
  22. },
  23. {
  24. message:
  25. '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.',
  26. score: 4,
  27. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  28. repository: TestStubs.Repository(),
  29. dateCreated: '2018-03-02T18:30:26Z',
  30. },
  31. ],
  32. },
  33. {
  34. author: {name: 'Somebody else', id: '2'},
  35. commits: [
  36. {
  37. message: 'fix: Make things less broken',
  38. score: 2,
  39. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  40. repository: TestStubs.Repository(),
  41. dateCreated: '2018-03-02T16:30:26Z',
  42. },
  43. ],
  44. },
  45. ];
  46. afterEach(function () {
  47. Client.clearMockResponses();
  48. });
  49. beforeEach(function () {
  50. Client.addMockResponse({
  51. method: 'GET',
  52. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  53. body: {
  54. committers,
  55. },
  56. });
  57. });
  58. it('Renders base commit row', async function () {
  59. render(
  60. <EventCause
  61. project={project}
  62. commitRow={CommitRow}
  63. eventId={event.id}
  64. group={group}
  65. />,
  66. {
  67. organization,
  68. }
  69. );
  70. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  71. expect(screen.queryByTestId('quick-context-commit-row')).not.toBeInTheDocument();
  72. expect(screen.queryByTestId('email-warning')).not.toBeInTheDocument();
  73. });
  74. it('Renders quick context commit row', async function () {
  75. render(
  76. <EventCause
  77. project={project}
  78. commitRow={QuickContextCommitRow}
  79. eventId={event.id}
  80. group={group}
  81. />,
  82. {
  83. organization,
  84. }
  85. );
  86. expect(await screen.findByTestId('quick-context-commit-row')).toBeInTheDocument();
  87. expect(screen.queryByTestId('commit-row')).not.toBeInTheDocument();
  88. });
  89. it('renders correct heading for single commit', async () => {
  90. // For this one test, undo the `beforeEach` so that we can respond with just a single commit
  91. Client.clearMockResponses();
  92. Client.addMockResponse({
  93. method: 'GET',
  94. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  95. body: {
  96. committers: [committers[0]],
  97. },
  98. });
  99. render(
  100. <EventCause
  101. project={project}
  102. commitRow={CommitRow}
  103. eventId={event.id}
  104. group={group}
  105. />,
  106. {
  107. organization,
  108. }
  109. );
  110. expect(await screen.findByText(/Suspect Commit/i)).toBeInTheDocument();
  111. expect(screen.queryByText(/Suspect Commits/i)).not.toBeInTheDocument();
  112. });
  113. it('renders correct heading for multiple commits (and filters to unique commits)', async () => {
  114. render(
  115. <EventCause
  116. project={project}
  117. commitRow={CommitRow}
  118. eventId={event.id}
  119. group={group}
  120. />,
  121. {
  122. organization,
  123. }
  124. );
  125. // There are two commits rather than three because two of the mock commits above are the same
  126. expect(await screen.findByText(/Suspect Commits \(2\)/i)).toBeInTheDocument();
  127. });
  128. it('expands', async function () {
  129. render(
  130. <EventCause
  131. project={project}
  132. commitRow={CommitRow}
  133. eventId={event.id}
  134. group={group}
  135. />,
  136. {
  137. organization,
  138. }
  139. );
  140. await userEvent.click(await screen.findByText('Show more'));
  141. expect(screen.getAllByTestId('commit-row')).toHaveLength(2);
  142. // and hides
  143. await userEvent.click(screen.getByText('Show less'));
  144. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  145. });
  146. it('shows unassociated email warning', async function () {
  147. Client.addMockResponse({
  148. method: 'GET',
  149. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  150. body: {
  151. committers: [
  152. {
  153. author: {name: 'Somebody else', email: 'somebodyelse@email.com'},
  154. commits: [
  155. {
  156. message: 'fix: Make things less broken',
  157. score: 2,
  158. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  159. repository: TestStubs.Repository(),
  160. dateCreated: '2018-03-02T16:30:26Z',
  161. },
  162. ],
  163. },
  164. ],
  165. },
  166. });
  167. render(
  168. <EventCause
  169. project={project}
  170. commitRow={CommitRow}
  171. eventId={event.id}
  172. group={group}
  173. />,
  174. {
  175. organization,
  176. }
  177. );
  178. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  179. expect(screen.getByTestId('email-warning')).toBeInTheDocument();
  180. });
  181. });