content.spec.tsx 3.5 KB

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