quickContextHovercard.spec.tsx 5.8 KB

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