issueContext.spec.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {Repository} from 'sentry-fixture/repository';
  3. import {makeTestQueryClient} from 'sentry-test/queryClient';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import {EventData} from 'sentry/utils/discover/eventView';
  6. import {QueryClientProvider} from 'sentry/utils/queryClient';
  7. import IssueContext from './issueContext';
  8. import {defaultRow} from './testUtils';
  9. let mockedGroup = TestStubs.Group({
  10. id: '3512441874',
  11. project: {
  12. id: '1',
  13. slug: 'cool-team',
  14. },
  15. status: 'ignored',
  16. assignedTo: {
  17. id: '12312',
  18. name: 'ingest',
  19. type: 'team',
  20. },
  21. count: 2500000,
  22. userCount: 64000,
  23. title: 'typeError: error description',
  24. });
  25. const renderIssueContext = (dataRow: EventData = defaultRow) => {
  26. const organization = Organization();
  27. render(
  28. <QueryClientProvider client={makeTestQueryClient()}>
  29. <IssueContext dataRow={dataRow} organization={organization} />
  30. </QueryClientProvider>,
  31. {organization}
  32. );
  33. };
  34. describe('Quick Context Content Issue Column', function () {
  35. beforeEach(() => {
  36. MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/users/',
  38. body: [],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/issues/3512441874/events/oldest/',
  46. method: 'GET',
  47. body: [],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: '/issues/3512441874/',
  51. method: 'GET',
  52. body: mockedGroup,
  53. });
  54. });
  55. afterEach(function () {
  56. MockApiClient.clearMockResponses();
  57. });
  58. it('Renders ignored issue status context', async () => {
  59. renderIssueContext();
  60. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  61. expect(screen.getByText(/Ignored/i)).toBeInTheDocument();
  62. expect(screen.getByTestId('quick-context-ignored-icon')).toBeInTheDocument();
  63. });
  64. it('Renders resolved issue status context', async () => {
  65. mockedGroup = {...mockedGroup, status: 'resolved'};
  66. MockApiClient.addMockResponse({
  67. url: '/issues/3512441874/',
  68. method: 'GET',
  69. body: mockedGroup,
  70. });
  71. renderIssueContext();
  72. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  73. expect(screen.getByText(/Resolved/i)).toBeInTheDocument();
  74. expect(screen.getByTestId('icon-check-mark')).toBeInTheDocument();
  75. });
  76. it('Renders unresolved issue status context', async () => {
  77. mockedGroup = {...mockedGroup, status: 'unresolved'};
  78. MockApiClient.addMockResponse({
  79. url: '/issues/3512441874/',
  80. method: 'GET',
  81. body: mockedGroup,
  82. });
  83. renderIssueContext();
  84. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  85. expect(screen.getByText(/Unresolved/i)).toBeInTheDocument();
  86. expect(screen.getByTestId('quick-context-unresolved-icon')).toBeInTheDocument();
  87. });
  88. it('Renders event and user counts', async () => {
  89. renderIssueContext();
  90. expect(await screen.findByText(/Events/i)).toBeInTheDocument();
  91. expect(screen.getByText(/2.5m/i)).toBeInTheDocument();
  92. expect(screen.getByText(/Users/i)).toBeInTheDocument();
  93. expect(screen.getByText(/64k/i)).toBeInTheDocument();
  94. });
  95. it('Renders assigned to context', async () => {
  96. renderIssueContext();
  97. expect(await screen.findByText(/Assigned To/i)).toBeInTheDocument();
  98. expect(screen.getByText(/#ingest/i)).toBeInTheDocument();
  99. });
  100. it('Renders title', async () => {
  101. renderIssueContext();
  102. expect(await screen.findByText(/Title/i)).toBeInTheDocument();
  103. expect(screen.getByText(/typeError: error description/i)).toBeInTheDocument();
  104. });
  105. describe('Suspect commits', () => {
  106. const maiseyCommitter = {
  107. author: {name: 'Maisey the Dog', id: '1231'},
  108. commits: [
  109. {
  110. message: 'feat(simulator): Add option for multiple squirrels (#1121)',
  111. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  112. dateCreated: '2012-09-08T04:15:12',
  113. repository: Repository(),
  114. },
  115. ],
  116. };
  117. const charlieCommitter = {
  118. author: {name: 'Charlie Bear', id: '1121'},
  119. commits: [
  120. {
  121. message:
  122. 'ref(simulator): Split leaderboard calculations into separate functions (#1231)',
  123. id: 'fe29668b24cea6faad8afb8f6d9417f402ef9c18',
  124. dateCreated: '2012-04-15T09:09:12',
  125. repository: Repository(),
  126. },
  127. ],
  128. };
  129. beforeEach(() => {
  130. MockApiClient.addMockResponse({
  131. url: '/issues/3512441874/events/oldest/',
  132. method: 'GET',
  133. body: {
  134. eventID: '6b43e285de834ec5b5fe30d62d549b20',
  135. },
  136. });
  137. });
  138. afterEach(() => {
  139. MockApiClient.clearMockResponses();
  140. });
  141. it('Renders a single suspect commit', async () => {
  142. MockApiClient.addMockResponse({
  143. method: 'GET',
  144. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  145. body: {
  146. committers: [maiseyCommitter],
  147. },
  148. });
  149. renderIssueContext();
  150. // Make sure the title renders in the singular, since there's only one commit
  151. expect(await screen.findByText(/Suspect Commit/i)).toBeInTheDocument();
  152. expect(screen.queryByText(/Suspect Commits/i)).not.toBeInTheDocument();
  153. // Ensure all commit data is present
  154. expect(screen.getByText(/MD/i)).toBeInTheDocument();
  155. expect(screen.getByTestId('quick-context-commit-row')).toHaveTextContent(
  156. /View commit ab27092 by Maisey the Dog/
  157. );
  158. });
  159. it('Renders multiple suspect commits', async () => {
  160. MockApiClient.addMockResponse({
  161. method: 'GET',
  162. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  163. body: {
  164. committers: [maiseyCommitter, charlieCommitter],
  165. },
  166. });
  167. renderIssueContext();
  168. // Make sure the title renders in the plural
  169. expect(await screen.findByText(/Suspect Commits \(2\)/i)).toBeInTheDocument();
  170. // When there's more than one commit, any past the first start out hidden
  171. const expandButton = await screen.findByTestId('expand-commit-list');
  172. await userEvent.click(expandButton);
  173. // Check that they're both there
  174. expect(screen.getByText(/MD/i)).toBeInTheDocument();
  175. expect(screen.getByText(/CB/i)).toBeInTheDocument();
  176. expect(screen.getAllByTestId('quick-context-commit-row')[0]).toHaveTextContent(
  177. /View commit ab27092 by Maisey the Dog/
  178. );
  179. expect(screen.getAllByTestId('quick-context-commit-row')[1]).toHaveTextContent(
  180. /View commit fe29668 by Charlie Bear/
  181. );
  182. });
  183. });
  184. });