eventContext.spec.tsx 4.8 KB

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