issueContext.spec.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  6. import {GroupStatus} from 'sentry/types/group';
  7. import type {EventData} from 'sentry/utils/discover/eventView';
  8. import IssueContext from './issueContext';
  9. import {defaultRow} from './testUtils';
  10. const mockedGroup = GroupFixture({
  11. id: '3512441874',
  12. project: ProjectFixture({
  13. id: '1',
  14. slug: 'cool-team',
  15. }),
  16. status: GroupStatus.IGNORED,
  17. assignedTo: {
  18. id: '12312',
  19. name: 'ingest',
  20. type: 'team',
  21. },
  22. count: '2500000',
  23. userCount: 64000,
  24. title: 'typeError: error description',
  25. });
  26. const renderIssueContext = (dataRow: EventData = defaultRow) => {
  27. const organization = OrganizationFixture();
  28. render(<IssueContext dataRow={dataRow} organization={organization} />, {organization});
  29. };
  30. describe('Quick Context Content Issue Column', function () {
  31. beforeEach(() => {
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/users/',
  34. body: [],
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  38. body: [],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/issues/3512441874/events/oldest/',
  42. method: 'GET',
  43. body: [],
  44. });
  45. MockApiClient.addMockResponse({
  46. url: '/issues/3512441874/',
  47. method: 'GET',
  48. body: mockedGroup,
  49. });
  50. MockApiClient.addMockResponse({
  51. url: `/organizations/org-slug/projects/`,
  52. body: [ProjectFixture()],
  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. const group = {...mockedGroup, status: GroupStatus.RESOLVED};
  66. MockApiClient.addMockResponse({
  67. url: '/issues/3512441874/',
  68. method: 'GET',
  69. body: group,
  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. const group = {...mockedGroup, status: GroupStatus.UNRESOLVED};
  78. MockApiClient.addMockResponse({
  79. url: '/issues/3512441874/',
  80. method: 'GET',
  81. body: group,
  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: RepositoryFixture(),
  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: RepositoryFixture(),
  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. });