trace.spec.tsx 3.1 KB

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