quickContextHovercard.spec.tsx 5.1 KB

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