content.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {initializeData as _initializeData} from 'sentry-test/performance/initializePerformanceData';
  2. import {act, render, screen, within} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import {DEFAULT_EVENT_VIEW} from 'sentry/views/discover/data';
  6. import TraceDetailsContent from 'sentry/views/performance/traceDetails/content';
  7. const SAMPLE_ERROR_DATA = {
  8. data: [
  9. {id: '1', level: 'error', title: 'Test error 1', project: 'sentry'},
  10. {id: '2', level: 'fatal', title: 'Test error 2', project: 'sentry'},
  11. ],
  12. };
  13. const initializeData = () => {
  14. const data = _initializeData({
  15. features: ['performance-view', 'trace-view'],
  16. });
  17. act(() => ProjectsStore.loadInitialData(data.projects));
  18. return data;
  19. };
  20. describe('TraceDetailsContent', () => {
  21. describe('Without Transactions', () => {
  22. beforeEach(() => {
  23. MockApiClient.addMockResponse({
  24. url: '/organizations/org-slug/events/',
  25. body: SAMPLE_ERROR_DATA,
  26. });
  27. });
  28. afterEach(function () {
  29. MockApiClient.clearMockResponses();
  30. ProjectsStore.reset();
  31. });
  32. it('should render a list of errors when a trace contains only error events', async () => {
  33. const initialData = initializeData();
  34. const eventView = EventView.fromSavedQuery(DEFAULT_EVENT_VIEW);
  35. const meta = {
  36. errors: 2,
  37. projects: 1,
  38. transactions: 0,
  39. performance_issues: 1,
  40. transaction_child_count_map: {},
  41. span_count: 0,
  42. span_count_map: {},
  43. };
  44. render(
  45. <TraceDetailsContent
  46. location={initialData.location}
  47. organization={initialData.organization}
  48. traceSlug="123"
  49. params={{traceSlug: '123'}}
  50. traceEventView={eventView}
  51. dateSelected
  52. isLoading={false}
  53. error={null}
  54. traces={null}
  55. meta={meta}
  56. />
  57. );
  58. const errorList = await screen.findByTestId('trace-view-errors');
  59. expect(
  60. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[0]!.title)
  61. ).toBeInTheDocument();
  62. expect(
  63. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[1]!.title)
  64. ).toBeInTheDocument();
  65. expect(
  66. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[0]!.level)
  67. ).toBeInTheDocument();
  68. expect(
  69. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[1]!.level)
  70. ).toBeInTheDocument();
  71. });
  72. it('should should display an error if the error events could not be fetched', async () => {
  73. MockApiClient.addMockResponse({
  74. url: '/organizations/org-slug/events/',
  75. statusCode: 404,
  76. body: {detail: 'This is a test error'},
  77. });
  78. const initialData = initializeData();
  79. const eventView = EventView.fromSavedQuery(DEFAULT_EVENT_VIEW);
  80. const meta = {
  81. errors: 2,
  82. projects: 1,
  83. transactions: 0,
  84. performance_issues: 0,
  85. transaction_child_count_map: {},
  86. span_count: 0,
  87. span_count_map: {},
  88. };
  89. render(
  90. <TraceDetailsContent
  91. location={initialData.location}
  92. organization={initialData.organization}
  93. traceSlug="123"
  94. params={{traceSlug: '123'}}
  95. traceEventView={eventView}
  96. dateSelected
  97. isLoading={false}
  98. error={null}
  99. traces={null}
  100. meta={meta}
  101. />
  102. );
  103. const errorText = await screen.findByText(
  104. 'The trace cannot be shown when all events are errors. An error occurred when attempting to fetch these error events: This is a test error'
  105. );
  106. const errorContainer = errorText.parentElement;
  107. expect(errorContainer).toBeInTheDocument();
  108. });
  109. });
  110. });