trace.spec.tsx 2.8 KB

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