eventContext.spec.tsx 4.8 KB

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