quickContextWrapper.spec.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import ConfigStore from 'sentry/stores/configStore';
  3. import {Event, EventOrGroupType} from 'sentry/types/event';
  4. import EventView, {EventData} from 'sentry/utils/discover/eventView';
  5. import {QueryClient, QueryClientProvider} from 'sentry/utils/queryClient';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import {QuickContextHoverWrapper} from './quickContextWrapper';
  8. import {defaultRow, mockedCommit, mockedUser1, mockedUser2} from './testUtils';
  9. import {ContextType} from './utils';
  10. const queryClient = new QueryClient({
  11. defaultOptions: {
  12. queries: {
  13. retry: false,
  14. },
  15. },
  16. });
  17. const renderQuickContextContent = (
  18. dataRow: EventData = defaultRow,
  19. contextType: ContextType = ContextType.ISSUE,
  20. eventView?: EventView
  21. ) => {
  22. const organization = TestStubs.Organization();
  23. render(
  24. <QueryClientProvider client={queryClient}>
  25. <QuickContextHoverWrapper
  26. dataRow={dataRow}
  27. contextType={contextType}
  28. organization={organization}
  29. eventView={eventView}
  30. >
  31. Text from Child
  32. </QuickContextHoverWrapper>
  33. </QueryClientProvider>,
  34. {organization}
  35. );
  36. };
  37. const makeEvent = (event: Partial<Event> = {}): Event => {
  38. const evt: Event = {
  39. ...TestStubs.Event(),
  40. ...event,
  41. };
  42. return evt;
  43. };
  44. jest.mock('sentry/utils/useLocation');
  45. const mockUseLocation = useLocation as jest.MockedFunction<typeof useLocation>;
  46. describe('Quick Context', function () {
  47. describe('Quick Context default behaviour', function () {
  48. beforeEach(() => {
  49. MockApiClient.addMockResponse({
  50. url: '/issues/3512441874/events/oldest/',
  51. method: 'GET',
  52. body: [],
  53. });
  54. });
  55. afterEach(() => {
  56. queryClient.clear();
  57. MockApiClient.clearMockResponses();
  58. mockUseLocation.mockReset();
  59. });
  60. it('Renders child', async () => {
  61. renderQuickContextContent();
  62. expect(await screen.findByText(/Text from Child/i)).toBeInTheDocument();
  63. });
  64. it('Renders quick context hover body', async () => {
  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. MockApiClient.addMockResponse({
  74. url: '/issues/3512441874/',
  75. method: 'GET',
  76. body: {},
  77. });
  78. renderQuickContextContent();
  79. await userEvent.hover(screen.getByText('Text from Child'));
  80. expect(await screen.findByTestId('quick-context-hover-body')).toBeInTheDocument();
  81. });
  82. it('Renders quick context failure message', async () => {
  83. MockApiClient.addMockResponse({
  84. url: '/organizations/org-slug/users/',
  85. body: [],
  86. });
  87. MockApiClient.addMockResponse({
  88. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  89. body: [],
  90. });
  91. MockApiClient.addMockResponse({
  92. url: '/issues/3512441874/',
  93. statusCode: 400,
  94. });
  95. renderQuickContextContent();
  96. await userEvent.hover(screen.getByText('Text from Child'));
  97. // Error is expected, do not fail when calling console.error
  98. jest.spyOn(console, 'error').mockImplementation();
  99. expect(
  100. await screen.findByText(/Failed to load context for column./i)
  101. ).toBeInTheDocument();
  102. });
  103. it('Renders issue context header with copy button', async () => {
  104. MockApiClient.addMockResponse({
  105. url: '/issues/3512441874/',
  106. method: 'GET',
  107. body: {},
  108. });
  109. renderQuickContextContent();
  110. await userEvent.hover(screen.getByText('Text from Child'));
  111. expect(await screen.findByText(/Issue/i)).toBeInTheDocument();
  112. expect(screen.getByText(/SENTRY-VVY/i)).toBeInTheDocument();
  113. expect(
  114. screen.getByTestId('quick-context-hover-header-copy-button')
  115. ).toBeInTheDocument();
  116. });
  117. it('Renders release header with copy button', async () => {
  118. MockApiClient.addMockResponse({
  119. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  120. body: TestStubs.Release({
  121. id: '1',
  122. shortVersion: 'sentry-android-shop@1.2.0',
  123. version: 'sentry-android-shop@1.2.0',
  124. dateCreated: '2010-05-17T02:41:20Z',
  125. lastEvent: '2011-10-17T02:41:20Z',
  126. firstEvent: '2010-05-17T02:41:20Z',
  127. status: 'open',
  128. commitCount: 4,
  129. lastCommit: mockedCommit,
  130. newGroups: 21,
  131. authors: [mockedUser1, mockedUser2],
  132. }),
  133. });
  134. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  135. await userEvent.hover(screen.getByText('Text from Child'));
  136. expect(await screen.findByText(/Release/i)).toBeInTheDocument();
  137. expect(screen.getByText(/22.10.0/i)).toBeInTheDocument();
  138. expect(screen.getByText(/(aaf33944f93d)/i)).toBeInTheDocument();
  139. expect(
  140. screen.getByTestId('quick-context-hover-header-copy-button')
  141. ).toBeInTheDocument();
  142. });
  143. it('Renders event id header', async () => {
  144. jest.spyOn(ConfigStore, 'get').mockImplementation(() => null);
  145. MockApiClient.addMockResponse({
  146. url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
  147. body: makeEvent({type: EventOrGroupType.ERROR, entries: []}),
  148. });
  149. renderQuickContextContent(defaultRow, ContextType.EVENT);
  150. await userEvent.hover(screen.getByText('Text from Child'));
  151. expect(await screen.findByText(/Event ID/i)).toBeInTheDocument();
  152. expect(screen.getByText(/6b43e285/i)).toBeInTheDocument();
  153. expect(
  154. screen.getByTestId('quick-context-hover-header-copy-button')
  155. ).toBeInTheDocument();
  156. });
  157. });
  158. });