quickContextHovercard.spec.tsx 5.8 KB

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