issueContext.spec.tsx 6.6 KB

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