issueContext.spec.tsx 6.7 KB

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