quickContext.spec.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import GroupStore from 'sentry/stores/groupStore';
  3. import {Group} from 'sentry/types';
  4. import {EventData} from 'sentry/utils/discover/eventView';
  5. import QuickContext, {ContextType, QuickContextHoverWrapper} from './quickContext';
  6. const defaultRow: EventData = {
  7. id: '6b43e285de834ec5b5fe30d62d549b20',
  8. issue: 'SENTRY-VVY',
  9. release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
  10. title: 'error: Error -3 while decompressing data: invalid stored block lengths',
  11. 'issue.id': 3512441874,
  12. 'project.name': 'sentry',
  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. });
  27. const renderQuickContextContent = (
  28. data: Group | null = null,
  29. dataRow: EventData = defaultRow,
  30. contextType: ContextType = ContextType.ISSUE,
  31. loading: boolean = false,
  32. error: boolean = false
  33. ) => {
  34. const organization = TestStubs.Organization();
  35. render(
  36. <QuickContext
  37. dataRow={dataRow}
  38. contextType={contextType}
  39. error={error}
  40. loading={loading}
  41. data={data}
  42. />,
  43. {organization}
  44. );
  45. };
  46. describe('Quick Context', function () {
  47. describe('Quick Context Content', function () {
  48. describe('Quick Context Content default behaviour', function () {
  49. it('Loading state renders for Quick Context.', () => {
  50. renderQuickContextContent(null, defaultRow, ContextType.ISSUE, true);
  51. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  52. });
  53. it('Error state renders for Quick Context.', () => {
  54. renderQuickContextContent(null, defaultRow, ContextType.ISSUE, false, true);
  55. expect(
  56. screen.getByText(/Failed to load context for column./i)
  57. ).toBeInTheDocument();
  58. expect(
  59. screen.queryByTestId('quick-context-loading-indicator')
  60. ).not.toBeInTheDocument();
  61. });
  62. });
  63. describe('Quick Context Content Issue Column', function () {
  64. beforeEach(() => {
  65. MockApiClient.addMockResponse({
  66. url: '/organizations/org-slug/users/',
  67. body: [],
  68. });
  69. MockApiClient.addMockResponse({
  70. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  71. body: [],
  72. });
  73. jest.spyOn(GroupStore, 'get').mockImplementation(() => mockedGroup);
  74. });
  75. afterEach(function () {
  76. GroupStore.reset();
  77. MockApiClient.clearMockResponses();
  78. });
  79. describe('Quick Context for Issue Column - Status', function () {
  80. it('Render Ignored Issue status context when data is loaded', async () => {
  81. renderQuickContextContent(mockedGroup);
  82. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  83. expect(screen.getByText(/Ignored/i)).toBeInTheDocument();
  84. expect(screen.getByTestId('quick-context-ignored-icon')).toBeInTheDocument();
  85. });
  86. it('Render Resolved Issue status context when data is loaded', async () => {
  87. mockedGroup = {...mockedGroup, status: 'resolved'};
  88. renderQuickContextContent(mockedGroup);
  89. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  90. expect(screen.getByText(/Resolved/i)).toBeInTheDocument();
  91. expect(screen.getByTestId('icon-check-mark')).toBeInTheDocument();
  92. });
  93. it('Render Unresolved Issue status context when data is loaded', async () => {
  94. mockedGroup = {...mockedGroup, status: 'unresolved'};
  95. renderQuickContextContent(mockedGroup);
  96. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  97. expect(screen.getByText(/Unresolved/i)).toBeInTheDocument();
  98. expect(screen.getByTestId('quick-context-unresolved-icon')).toBeInTheDocument();
  99. });
  100. });
  101. describe('Quick Context for Issue Column - Assignee', function () {
  102. it('Render Assigned To context when data is loaded', async () => {
  103. renderQuickContextContent(mockedGroup);
  104. expect(await screen.findByText(/Assigned To/i)).toBeInTheDocument();
  105. expect(screen.getByText(/#ingest/i)).toBeInTheDocument();
  106. });
  107. });
  108. describe('Quick Context for Issue Column - Suspect Commits', function () {
  109. it('Does not render suspect commit to context when row lacks event id', async () => {
  110. const dataRowWithoutId: unknown = {
  111. issue: 'SENTRY-VVY',
  112. release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
  113. title:
  114. 'error: Error -3 while decompressing data: invalid stored block lengths',
  115. 'issue.id': 3512441874,
  116. 'project.name': 'sentry',
  117. };
  118. renderQuickContextContent(mockedGroup, dataRowWithoutId as EventData);
  119. await waitFor(() => {
  120. expect(
  121. screen.queryByTestId('quick-context-suspect-commits-container')
  122. ).not.toBeInTheDocument();
  123. });
  124. });
  125. it('Renders Suspect Commits', async () => {
  126. MockApiClient.addMockResponse({
  127. method: 'GET',
  128. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  129. body: {
  130. committers: [
  131. {
  132. author: {name: 'Max Bittker', id: '1'},
  133. commits: [
  134. {
  135. message: 'feat: Added new feature',
  136. score: 4,
  137. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  138. repository: TestStubs.Repository(),
  139. dateCreated: '2018-03-02T18:30:26Z',
  140. pullRequest: {
  141. externalUrl: 'url',
  142. },
  143. },
  144. ],
  145. },
  146. ],
  147. },
  148. });
  149. renderQuickContextContent(mockedGroup);
  150. expect(await screen.findByText(/Suspect Commits/i)).toBeInTheDocument();
  151. expect(screen.getByText(/MB/i)).toBeInTheDocument();
  152. expect(screen.getByText(/View commit/i)).toBeInTheDocument();
  153. expect(screen.getByText(/by/i)).toBeInTheDocument();
  154. expect(screen.getByText(/You/i)).toBeInTheDocument();
  155. });
  156. });
  157. });
  158. });
  159. describe('Quick Context Hover', function () {
  160. afterEach(() => {
  161. GroupStore.reset();
  162. MockApiClient.clearMockResponses();
  163. });
  164. beforeEach(() => {
  165. MockApiClient.addMockResponse({
  166. url: '/organizations/org-slug/users/',
  167. body: [],
  168. });
  169. });
  170. it('Renders Child and Info Icon', async () => {
  171. render(
  172. <QuickContextHoverWrapper contextType={ContextType.ISSUE} dataRow={defaultRow}>
  173. Text from Child
  174. </QuickContextHoverWrapper>
  175. );
  176. expect(await screen.findByText(/Text from Child/i)).toBeInTheDocument();
  177. expect(screen.getByTestId('quick-context-hover-trigger')).toBeInTheDocument();
  178. });
  179. it('Renders HoverCard with Issue Context', async () => {
  180. MockApiClient.addMockResponse({
  181. url: '/issues/3512441874/',
  182. body: mockedGroup,
  183. });
  184. render(
  185. <QuickContextHoverWrapper contextType={ContextType.ISSUE} dataRow={defaultRow}>
  186. Text from Child
  187. </QuickContextHoverWrapper>
  188. );
  189. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  190. expect(
  191. await screen.findByTestId('quick-context-issue-status-container')
  192. ).toBeInTheDocument();
  193. expect(
  194. screen.getByTestId('quick-context-suspect-commits-container')
  195. ).toBeInTheDocument();
  196. expect(
  197. screen.getByTestId('quick-context-assigned-to-container')
  198. ).toBeInTheDocument();
  199. });
  200. });
  201. });