eventContext.spec.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import type {Location} from 'history';
  2. import {EventFixture} from 'sentry-fixture/event';
  3. import {LocationFixture} from 'sentry-fixture/locationFixture';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {makeTestQueryClient} from 'sentry-test/queryClient';
  6. import {render, screen} from 'sentry-test/reactTestingLibrary';
  7. import ConfigStore from 'sentry/stores/configStore';
  8. import {
  9. EntryType,
  10. Event,
  11. EventError,
  12. EventOrGroupType,
  13. ExceptionType,
  14. ExceptionValue,
  15. Frame,
  16. } from 'sentry/types/event';
  17. import EventView, {EventData} from 'sentry/utils/discover/eventView';
  18. import {QueryClientProvider} from 'sentry/utils/queryClient';
  19. import EventContext from './eventContext';
  20. const mockedLocation = LocationFixture({
  21. query: {
  22. field: ['issue', 'transaction.duration'],
  23. },
  24. });
  25. const dataRow: EventData = {
  26. id: '6b43e285de834ec5b5fe30d62d549b20',
  27. issue: 'SENTRY-VVY',
  28. release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
  29. 'issue.id': 3512441874,
  30. 'project.name': 'sentry',
  31. };
  32. const renderEventContext = (location?: Location, eventView?: EventView) => {
  33. const organization = OrganizationFixture();
  34. render(
  35. <QueryClientProvider client={makeTestQueryClient()}>
  36. <EventContext
  37. dataRow={dataRow}
  38. organization={organization}
  39. location={location}
  40. eventView={eventView}
  41. />
  42. </QueryClientProvider>,
  43. {organization}
  44. );
  45. };
  46. describe('Quick Context Content: Event ID Column', function () {
  47. afterEach(() => {
  48. MockApiClient.clearMockResponses();
  49. });
  50. it('Renders transaction duration context', async () => {
  51. const currentTime = Date.now();
  52. MockApiClient.addMockResponse({
  53. url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
  54. body: EventFixture({
  55. type: EventOrGroupType.TRANSACTION,
  56. entries: [],
  57. endTimestamp: currentTime,
  58. startTimestamp: currentTime - 2,
  59. }),
  60. });
  61. renderEventContext(mockedLocation);
  62. expect(await screen.findByText(/Transaction Duration/i)).toBeInTheDocument();
  63. expect(screen.getByText(/2.00s/i)).toBeInTheDocument();
  64. });
  65. it('Renders transaction status context', async () => {
  66. const currentTime = Date.now();
  67. MockApiClient.addMockResponse({
  68. url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
  69. body: EventFixture({
  70. type: EventOrGroupType.TRANSACTION,
  71. entries: [],
  72. endTimestamp: currentTime,
  73. startTimestamp: currentTime - 2,
  74. contexts: {
  75. trace: {
  76. status: 'ok',
  77. },
  78. },
  79. tags: [
  80. {
  81. key: 'http.status_code',
  82. value: '200',
  83. },
  84. ],
  85. }),
  86. });
  87. renderEventContext(mockedLocation);
  88. expect(await screen.findByText(/Status/i)).toBeInTheDocument();
  89. expect(screen.getByText(/ok/i)).toBeInTheDocument();
  90. expect(screen.getByText(/HTTP 200/i)).toBeInTheDocument();
  91. });
  92. it('Renders NO stack trace message for error events without stackTraces', async () => {
  93. jest.spyOn(ConfigStore, 'get').mockImplementation(() => null);
  94. MockApiClient.addMockResponse({
  95. url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
  96. body: EventFixture({type: EventOrGroupType.ERROR, entries: []}),
  97. });
  98. renderEventContext();
  99. expect(
  100. await screen.findByText(/There is no stack trace available for this event./i)
  101. ).toBeInTheDocument();
  102. });
  103. it('Renders stack trace as context', async () => {
  104. const frame: Frame = {
  105. colNo: 0,
  106. filename: 'file.js',
  107. function: 'throwError',
  108. lineNo: 0,
  109. absPath: null,
  110. context: [],
  111. inApp: false,
  112. instructionAddr: null,
  113. module: null,
  114. package: null,
  115. platform: null,
  116. rawFunction: null,
  117. symbol: null,
  118. symbolAddr: null,
  119. trust: undefined,
  120. vars: null,
  121. };
  122. const thread: ExceptionValue = {
  123. stacktrace: {
  124. hasSystemFrames: false,
  125. registers: {},
  126. framesOmitted: 0,
  127. frames: [frame],
  128. },
  129. mechanism: null,
  130. module: null,
  131. rawStacktrace: null,
  132. threadId: null,
  133. type: '',
  134. value: '',
  135. };
  136. const exceptionValue: ExceptionType = {
  137. values: [thread],
  138. excOmitted: undefined,
  139. hasSystemFrames: false,
  140. };
  141. const errorEvent: Event = {
  142. id: '6b43e285de834ec5b5fe30d62d549b20',
  143. type: EventOrGroupType.ERROR,
  144. entries: [
  145. {
  146. type: EntryType.EXCEPTION,
  147. data: exceptionValue,
  148. },
  149. ],
  150. } as EventError;
  151. MockApiClient.addMockResponse({
  152. url: '/organizations/org-slug/events/sentry:6b43e285de834ec5b5fe30d62d549b20/',
  153. body: EventFixture(errorEvent),
  154. });
  155. renderEventContext(mockedLocation);
  156. expect(await screen.findByTestId('stack-trace-content')).toBeInTheDocument();
  157. });
  158. });