suspectCommits.spec.tsx 5.7 KB

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