quickContextHovercard.spec.tsx 5.7 KB

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