import { csEventSubscriber } from '../../core/csEventSubscriber'; import { ContentsquareModule } from '../../core/nativeModules'; import { onSessionReplayLinkChange, setDefaultMasking, } from '../../replay/sessionReplay'; import { EventSubscriberType } from '../../types/types'; jest.mock('../../core/logging/logger', () => ({ warn: jest.fn(), })); jest.mock('../../core/nativeModules', () => ({ ContentsquareModule: { setOnSessionReplayLinkChange: jest.fn(), setDefaultMasking: jest.fn(), }, })); jest.mock('../../core/csEventSubscriber', () => ({ csEventSubscriber: jest.fn(), })); describe('sessionReplay', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('onSessionReplayLinkChange', () => { it('should set the session replay link change handler and return a CSEventSubscriber', () => { const mockCallback = jest.fn(); const mockSubscriber = { unsubscribe: jest.fn() }; (csEventSubscriber as jest.Mock).mockReturnValue(mockSubscriber); const result = onSessionReplayLinkChange(mockCallback); expect( ContentsquareModule.setOnSessionReplayLinkChange ).toHaveBeenCalled(); expect(csEventSubscriber).toHaveBeenCalledWith( EventSubscriberType.ON_SESSION_REPLAY_LINK_CHANGE, expect.any(Function) ); const payload = 'http://example.com/session-replay'; const subscriberCallback = (csEventSubscriber as jest.Mock).mock .calls[0][1]; subscriberCallback(payload); expect(mockCallback).toHaveBeenCalledWith(payload); expect(result).toBe(mockSubscriber); }); }); describe('setDefaultMasking', () => { it('should set the default masking value in ContentsquareModule', () => { setDefaultMasking(true); expect(ContentsquareModule.setDefaultMasking).toHaveBeenCalledWith(true); setDefaultMasking(false); expect(ContentsquareModule.setDefaultMasking).toHaveBeenCalledWith(false); }); }); });