issueContext.spec.tsx 6.9 KB

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