trace.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {ReplayRecordFixture} from 'sentry-fixture/replayRecord';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import type {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  4. import {useTransactionData} from 'sentry/views/replays/detail/trace/replayTransactionContext';
  5. import Trace from 'sentry/views/replays/detail/trace/trace';
  6. jest.mock('sentry/views/replays/detail/trace/replayTransactionContext');
  7. const mockUseTransactionData = jest.mocked(useTransactionData);
  8. const mockTraceFullDetailed = {} as TraceFullDetailed;
  9. function setMockTransactionState({
  10. didInit = false,
  11. errors = [],
  12. isFetching = false,
  13. traces = undefined,
  14. }: Partial<ReturnType<typeof useTransactionData>['state']>) {
  15. const eventView = null;
  16. mockUseTransactionData.mockReturnValue({
  17. state: {didInit, errors, isFetching, traces},
  18. eventView,
  19. });
  20. }
  21. describe('trace', () => {
  22. beforeEach(() => {
  23. mockUseTransactionData.mockReset();
  24. });
  25. it('should show the blank screen if there is no replayRecord', () => {
  26. setMockTransactionState({});
  27. render(<Trace replayRecord={undefined} />);
  28. const placeholder = screen.getByTestId('loading-placeholder');
  29. expect(placeholder).toBeInTheDocument();
  30. expect(placeholder).toBeEmptyDOMElement();
  31. });
  32. it('should show the blank screen if the hook has not initialized yet', () => {
  33. setMockTransactionState({});
  34. render(<Trace replayRecord={ReplayRecordFixture()} />);
  35. const placeholder = screen.getByTestId('loading-placeholder');
  36. expect(placeholder).toBeInTheDocument();
  37. expect(placeholder).toBeEmptyDOMElement();
  38. });
  39. it('should show a loading spinner if the hook is fetching, but there are no traces returned yet', () => {
  40. setMockTransactionState({didInit: true, isFetching: true});
  41. render(<Trace replayRecord={ReplayRecordFixture()} />);
  42. const placeholder = screen.getByTestId('loading-placeholder');
  43. expect(placeholder).toBeInTheDocument();
  44. expect(placeholder).not.toBeEmptyDOMElement();
  45. });
  46. it('should show errors if there are any', () => {
  47. setMockTransactionState({
  48. didInit: true,
  49. isFetching: true,
  50. traces: [mockTraceFullDetailed],
  51. errors: [new Error('Something went wrong')],
  52. });
  53. render(<Trace replayRecord={ReplayRecordFixture()} />);
  54. const emptyState = screen.getByTestId('empty-state');
  55. expect(emptyState).toHaveTextContent('Unable to retrieve traces');
  56. });
  57. it('should show a `no traces found` message if fetching is done, and there are no traces returned', () => {
  58. setMockTransactionState({
  59. didInit: true,
  60. isFetching: false,
  61. traces: [],
  62. errors: [],
  63. });
  64. render(<Trace replayRecord={ReplayRecordFixture()} />);
  65. const emptyState = screen.getByTestId('empty-state');
  66. expect(emptyState).toHaveTextContent('No traces found');
  67. });
  68. });