trace.spec.tsx 2.9 KB

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