quickContextHovercard.spec.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. describe('Quick Context', function () {
  46. describe('Quick Context default behaviour', function () {
  47. beforeEach(() => {
  48. MockApiClient.addMockResponse({
  49. url: '/issues/3512441874/events/oldest/',
  50. method: 'GET',
  51. body: [],
  52. });
  53. });
  54. afterEach(() => {
  55. queryClient.clear();
  56. MockApiClient.clearMockResponses();
  57. jest.mocked(useLocation).mockReset();
  58. });
  59. it('Renders child', async () => {
  60. renderQuickContextContent();
  61. expect(await screen.findByText(/Text from Child/i)).toBeInTheDocument();
  62. });
  63. it('Renders quick context hover body', async () => {
  64. MockApiClient.addMockResponse({
  65. url: '/organizations/org-slug/users/',
  66. body: [],
  67. });
  68. MockApiClient.addMockResponse({
  69. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  70. body: [],
  71. });
  72. MockApiClient.addMockResponse({
  73. url: '/issues/3512441874/',
  74. method: 'GET',
  75. body: {},
  76. });
  77. renderQuickContextContent();
  78. await userEvent.hover(screen.getByText('Text from Child'));
  79. expect(await screen.findByTestId('quick-context-hover-body')).toBeInTheDocument();
  80. });
  81. it('Renders quick context failure message', async () => {
  82. MockApiClient.addMockResponse({
  83. url: '/organizations/org-slug/users/',
  84. body: [],
  85. });
  86. MockApiClient.addMockResponse({
  87. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  88. body: [],
  89. });
  90. MockApiClient.addMockResponse({
  91. url: '/issues/3512441874/',
  92. statusCode: 400,
  93. });
  94. renderQuickContextContent();
  95. await userEvent.hover(screen.getByText('Text from Child'));
  96. // Error is expected, do not fail when calling console.error
  97. jest.spyOn(console, 'error').mockImplementation();
  98. expect(
  99. await screen.findByText(/Failed to load context for column./i)
  100. ).toBeInTheDocument();
  101. });
  102. it('Renders issue context header with copy button', async () => {
  103. MockApiClient.addMockResponse({
  104. url: '/issues/3512441874/',
  105. method: 'GET',
  106. body: {},
  107. });
  108. renderQuickContextContent();
  109. await userEvent.hover(screen.getByText('Text from Child'));
  110. expect(await screen.findByText(/Issue/i)).toBeInTheDocument();
  111. expect(screen.getByText(/SENTRY-VVY/i)).toBeInTheDocument();
  112. expect(
  113. screen.getByTestId('quick-context-hover-header-copy-button')
  114. ).toBeInTheDocument();
  115. });
  116. it('Renders release header with copy button', async () => {
  117. MockApiClient.addMockResponse({
  118. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  119. body: TestStubs.Release({
  120. id: '1',
  121. shortVersion: 'sentry-android-shop@1.2.0',
  122. version: 'sentry-android-shop@1.2.0',
  123. dateCreated: '2010-05-17T02:41:20Z',
  124. lastEvent: '2011-10-17T02:41:20Z',
  125. firstEvent: '2010-05-17T02:41:20Z',
  126. status: 'open',
  127. commitCount: 4,
  128. lastCommit: mockedCommit,
  129. newGroups: 21,
  130. authors: [mockedUser1, mockedUser2],
  131. }),
  132. });
  133. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  134. await userEvent.hover(screen.getByText('Text from Child'));
  135. expect(await screen.findByText(/Release/i)).toBeInTheDocument();
  136. expect(screen.getByText(/22.10.0/i)).toBeInTheDocument();
  137. expect(screen.getByText(/(aaf33944f93d)/i)).toBeInTheDocument();
  138. expect(
  139. screen.getByTestId('quick-context-hover-header-copy-button')
  140. ).toBeInTheDocument();
  141. });
  142. it('Renders event id header', async () => {
  143. jest.spyOn(ConfigStore, 'get').mockImplementation(() => null);
  144. MockApiClient.addMockResponse({
  145. url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
  146. body: makeEvent({type: EventOrGroupType.ERROR, entries: []}),
  147. });
  148. renderQuickContextContent(defaultRow, ContextType.EVENT);
  149. await userEvent.hover(screen.getByText('Text from Child'));
  150. expect(await screen.findByText(/Event ID/i)).toBeInTheDocument();
  151. expect(screen.getByText(/6b43e285/i)).toBeInTheDocument();
  152. expect(
  153. screen.getByTestId('quick-context-hover-header-copy-button')
  154. ).toBeInTheDocument();
  155. });
  156. });
  157. });