trace.spec.tsx 2.8 KB

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