suspectCommits.spec.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {LocationFixture} from 'sentry-fixture/locationFixture';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {ProjectFixture} from 'sentry-fixture/project';
  6. import {RepositoryFixture} from 'sentry-fixture/repository';
  7. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  8. import {QuickContextCommitRow} from 'sentry/components/discover/quickContextCommitRow';
  9. import {CommitRow} from '../commitRow';
  10. import {SuspectCommits} from './suspectCommits';
  11. describe('SuspectCommits', function () {
  12. describe('SuspectCommits', function () {
  13. const organization = OrganizationFixture();
  14. const project = ProjectFixture();
  15. const event = EventFixture();
  16. const group = GroupFixture({firstRelease: {}} as any);
  17. const committers = [
  18. {
  19. author: {name: 'Max Bittker', id: '1'},
  20. commits: [
  21. {
  22. message:
  23. '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.',
  24. score: 4,
  25. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  26. repository: RepositoryFixture(),
  27. dateCreated: '2018-03-02T18:30:26Z',
  28. },
  29. {
  30. message:
  31. '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.',
  32. score: 4,
  33. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  34. repository: RepositoryFixture(),
  35. dateCreated: '2018-03-02T18:30:26Z',
  36. },
  37. ],
  38. },
  39. {
  40. author: {name: 'Somebody else', id: '2'},
  41. commits: [
  42. {
  43. message: 'fix: Make things less broken',
  44. score: 2,
  45. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  46. repository: RepositoryFixture(),
  47. dateCreated: '2018-03-02T16:30:26Z',
  48. },
  49. ],
  50. },
  51. ];
  52. afterEach(function () {
  53. MockApiClient.clearMockResponses();
  54. });
  55. beforeEach(function () {
  56. MockApiClient.addMockResponse({
  57. method: 'GET',
  58. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  59. body: {
  60. committers,
  61. },
  62. });
  63. MockApiClient.addMockResponse({
  64. url: `/organizations/${organization.slug}/projects/`,
  65. body: [project],
  66. });
  67. });
  68. it('Renders base commit row', async function () {
  69. render(
  70. <SuspectCommits
  71. projectSlug={project.slug}
  72. commitRow={CommitRow}
  73. eventId={event.id}
  74. group={group}
  75. />
  76. );
  77. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  78. expect(screen.queryByTestId('quick-context-commit-row')).not.toBeInTheDocument();
  79. expect(screen.queryByTestId('email-warning')).not.toBeInTheDocument();
  80. });
  81. it('Renders quick context commit row', async function () {
  82. render(
  83. <SuspectCommits
  84. projectSlug={project.slug}
  85. commitRow={QuickContextCommitRow}
  86. eventId={event.id}
  87. group={group}
  88. />
  89. );
  90. expect(await screen.findByTestId('quick-context-commit-row')).toBeInTheDocument();
  91. expect(screen.queryByTestId('commit-row')).not.toBeInTheDocument();
  92. });
  93. it('renders correct heading for single commit', async () => {
  94. // For this one test, undo the `beforeEach` so that we can respond with just a single commit
  95. MockApiClient.clearMockResponses();
  96. MockApiClient.addMockResponse({
  97. method: 'GET',
  98. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  99. body: {
  100. committers: [committers[0]],
  101. },
  102. });
  103. render(
  104. <SuspectCommits
  105. projectSlug={project.slug}
  106. commitRow={CommitRow}
  107. eventId={event.id}
  108. group={group}
  109. />
  110. );
  111. expect(await screen.findByText(/Suspect Commit/i)).toBeInTheDocument();
  112. expect(screen.queryByText(/Suspect Commits/i)).not.toBeInTheDocument();
  113. });
  114. it('expands', async function () {
  115. render(
  116. <SuspectCommits
  117. projectSlug={project.slug}
  118. commitRow={CommitRow}
  119. eventId={event.id}
  120. group={group}
  121. />
  122. );
  123. await userEvent.click(await screen.findByText('Show more'));
  124. expect(screen.getAllByTestId('commit-row')).toHaveLength(2);
  125. // and hides
  126. await userEvent.click(screen.getByText('Show less'));
  127. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  128. });
  129. it('shows unassociated email warning', async function () {
  130. MockApiClient.addMockResponse({
  131. method: 'GET',
  132. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  133. body: {
  134. committers: [
  135. {
  136. author: {name: 'Somebody else', email: 'somebodyelse@email.com'},
  137. commits: [
  138. {
  139. message: 'fix: Make things less broken',
  140. score: 2,
  141. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  142. repository: RepositoryFixture(),
  143. dateCreated: '2018-03-02T16:30:26Z',
  144. },
  145. ],
  146. },
  147. ],
  148. },
  149. });
  150. render(
  151. <SuspectCommits
  152. projectSlug={project.slug}
  153. commitRow={CommitRow}
  154. eventId={event.id}
  155. group={group}
  156. />
  157. );
  158. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  159. expect(screen.getByTestId('email-warning')).toBeInTheDocument();
  160. });
  161. });
  162. describe('StreamlinedSuspectCommits', function () {
  163. const organization = OrganizationFixture({features: ['issue-details-streamline']});
  164. const project = ProjectFixture();
  165. const event = EventFixture();
  166. const group = GroupFixture({firstRelease: {}} as any);
  167. const location = LocationFixture({query: {streamline: '1'}});
  168. const committers = [
  169. {
  170. author: {name: 'Max Bittker', id: '1'},
  171. commits: [
  172. {
  173. message:
  174. '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.',
  175. score: 4,
  176. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  177. repository: RepositoryFixture(),
  178. dateCreated: '2018-03-02T18:30:26Z',
  179. },
  180. {
  181. message:
  182. '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.',
  183. score: 4,
  184. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  185. repository: RepositoryFixture(),
  186. dateCreated: '2018-03-02T18:30:26Z',
  187. },
  188. ],
  189. },
  190. {
  191. author: {name: 'Somebody else', id: '2'},
  192. commits: [
  193. {
  194. message: 'fix: Make things less broken',
  195. score: 2,
  196. id: 'zzzzzz3d0c9000829084ac7b1c9221fb18437c',
  197. repository: RepositoryFixture(),
  198. dateCreated: '2018-03-02T16:30:26Z',
  199. },
  200. ],
  201. },
  202. ];
  203. afterEach(function () {
  204. MockApiClient.clearMockResponses();
  205. });
  206. beforeEach(function () {
  207. MockApiClient.addMockResponse({
  208. method: 'GET',
  209. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  210. body: {
  211. committers: [committers[0]],
  212. },
  213. });
  214. });
  215. it('Renders base commit row', async function () {
  216. render(
  217. <SuspectCommits
  218. projectSlug={project.slug}
  219. commitRow={CommitRow}
  220. eventId={event.id}
  221. group={group}
  222. />,
  223. {router: {location}}
  224. );
  225. expect(await screen.findByTestId('commit-row')).toBeInTheDocument();
  226. expect(screen.queryByTestId('quick-context-commit-row')).not.toBeInTheDocument();
  227. expect(screen.queryByTestId('email-warning')).not.toBeInTheDocument();
  228. });
  229. it('Renders quick context commit row', async function () {
  230. render(
  231. <SuspectCommits
  232. projectSlug={project.slug}
  233. commitRow={QuickContextCommitRow}
  234. eventId={event.id}
  235. group={group}
  236. />,
  237. {router: {location}}
  238. );
  239. expect(await screen.findByTestId('quick-context-commit-row')).toBeInTheDocument();
  240. expect(screen.queryByTestId('commit-row')).not.toBeInTheDocument();
  241. });
  242. it('renders multiple suspect commits', async () => {
  243. MockApiClient.addMockResponse({
  244. method: 'GET',
  245. url: `/projects/${organization.slug}/${project.slug}/events/${event.id}/committers/`,
  246. body: {
  247. committers,
  248. },
  249. });
  250. render(
  251. <SuspectCommits
  252. projectSlug={project.slug}
  253. commitRow={CommitRow}
  254. eventId={event.id}
  255. group={group}
  256. />,
  257. {router: {location}}
  258. );
  259. expect(
  260. await screen.findByText('feat: Enhance suggested commits and add to alerts')
  261. ).toBeInTheDocument();
  262. expect(await screen.findByText('fix: Make things less broken')).toBeInTheDocument();
  263. expect(await screen.findAllByTestId('commit-row')).toHaveLength(2);
  264. });
  265. });
  266. });