eventContext.spec.tsx 4.9 KB

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