issueContext.spec.tsx 6.7 KB

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