eventCause.spec.tsx 5.7 KB

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