content.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. transactiontoSpanChildrenCount: {},
  41. };
  42. render(
  43. <TraceDetailsContent
  44. location={initialData.location}
  45. organization={initialData.organization}
  46. traceSlug="123"
  47. params={{traceSlug: '123'}}
  48. traceEventView={eventView}
  49. dateSelected
  50. isLoading={false}
  51. error={null}
  52. traces={null}
  53. meta={meta}
  54. />
  55. );
  56. const errorList = await screen.findByTestId('trace-view-errors');
  57. expect(
  58. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[0].title)
  59. ).toBeInTheDocument();
  60. expect(
  61. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[1].title)
  62. ).toBeInTheDocument();
  63. expect(
  64. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[0].level)
  65. ).toBeInTheDocument();
  66. expect(
  67. await within(errorList).findByText(SAMPLE_ERROR_DATA.data[1].level)
  68. ).toBeInTheDocument();
  69. });
  70. it('should should display an error if the error events could not be fetched', async () => {
  71. MockApiClient.addMockResponse({
  72. url: '/organizations/org-slug/events/',
  73. statusCode: 404,
  74. body: {detail: 'This is a test error'},
  75. });
  76. const initialData = initializeData();
  77. const eventView = EventView.fromSavedQuery(DEFAULT_EVENT_VIEW);
  78. const meta = {
  79. errors: 2,
  80. projects: 1,
  81. transactions: 0,
  82. performance_issues: 0,
  83. transactiontoSpanChildrenCount: {},
  84. };
  85. render(
  86. <TraceDetailsContent
  87. location={initialData.location}
  88. organization={initialData.organization}
  89. traceSlug="123"
  90. params={{traceSlug: '123'}}
  91. traceEventView={eventView}
  92. dateSelected
  93. isLoading={false}
  94. error={null}
  95. traces={null}
  96. meta={meta}
  97. />
  98. );
  99. const errorText = await screen.findByText(
  100. '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'
  101. );
  102. const errorContainer = errorText.parentElement;
  103. expect(errorContainer).toBeInTheDocument();
  104. });
  105. });
  106. });