replayPlayerEventsContext.spec.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type {ReactNode} from 'react';
  2. import {ReplayRecordFixture} from 'sentry-fixture/replayRecord';
  3. import {renderHook} from 'sentry-test/reactTestingLibrary';
  4. import {
  5. ReplayPlayerEventsContextProvider,
  6. useReplayPlayerEvents,
  7. } from 'sentry/utils/replays/playback/providers/replayPlayerEventsContext';
  8. import ReplayReader from 'sentry/utils/replays/replayReader';
  9. function makeWrapper(replay: ReplayReader) {
  10. return function ({children}: {children?: ReactNode}) {
  11. return (
  12. <ReplayPlayerEventsContextProvider replay={replay}>
  13. {children}
  14. </ReplayPlayerEventsContextProvider>
  15. );
  16. };
  17. }
  18. describe('replayPlayerEventsContext', () => {
  19. it('should have a stable to the list of rrweb event frames', () => {
  20. const mockReplay = ReplayReader.factory({
  21. attachments: [],
  22. errors: [],
  23. fetching: false,
  24. replayRecord: ReplayRecordFixture(),
  25. });
  26. const {result, rerender} = renderHook(useReplayPlayerEvents, {
  27. wrapper: makeWrapper(mockReplay!),
  28. });
  29. const initialRef = result.current;
  30. rerender();
  31. expect(result.current).toEqual(initialRef);
  32. });
  33. it('should return the rrweb frames for the replay', () => {
  34. const mockReplay = ReplayReader.factory({
  35. attachments: [],
  36. errors: [],
  37. fetching: false,
  38. replayRecord: ReplayRecordFixture(),
  39. });
  40. const mockRRwebFrames: any[] = [];
  41. mockReplay!.getRRWebFrames = jest.fn().mockReturnValue(mockRRwebFrames);
  42. const {result} = renderHook(useReplayPlayerEvents, {
  43. wrapper: makeWrapper(mockReplay!),
  44. });
  45. expect(result.current).toStrictEqual(mockRRwebFrames);
  46. });
  47. });