quickContextHovercard.spec.tsx 5.7 KB

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