import { configureProductAnalytics, start } from '../../core/csqCore'; import { ContentsquareModule } from '../../core/nativeModules'; import { ProductAnalyticsOptions } from '../../types/types'; jest.mock('../../core/nativeModules', () => ({ ContentsquareModule: { start: jest.fn(), configureProductAnalytics: jest.fn(), initComponents: jest.fn(), }, })); describe('CSQ Core Functions', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('start', () => { it('should call ContentsquareModule.start with true', () => { start(); expect(ContentsquareModule.start).toHaveBeenCalledWith(true); expect(ContentsquareModule.start).toHaveBeenCalledTimes(1); }); }); describe('configureProductAnalytics', () => { const envId = 'test-env-id'; it('should call ContentsquareModule.configureProductAnalytics with envId, default options and no other options provided', () => { configureProductAnalytics(envId); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledWith(envId, {}); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledTimes(1); }); it('should call ContentsquareModule.configureProductAnalytics with envId and merged options', () => { const options: ProductAnalyticsOptions = { enableViewAutocapture: true, disablePageviewAutocapture: false, resumePreviousSession: true, }; configureProductAnalytics(envId, options); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledWith(envId, options); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledTimes(1); }); it('should call ContentsquareModule.configureProductAnalytics with all possible options', () => { const options: ProductAnalyticsOptions = { enableViewAutocapture: true, disablePageviewAutocapture: false, resumePreviousSession: true, enablePushNotificationAutocapture: true, enablePushNotificationTitleAutocapture: false, enablePushNotificationBodyAutocapture: true, baseUrl: 'https://api.example.com', uploadInterval: 5000, captureAdvertiserId: true, captureVendorId: false, messageBatchMessageLimit: 100, clearEventPropertiesOnNewUser: true, pruningLookBackWindow: 7, maximumDatabaseSize: 50000, maximumBatchCountPerUpload: 10, disableScreenviewForwardToDXA: false, disableScreenviewForwardToPA: true, // iOS specific options disablePageviewTitleAutocapture: true, disableInteractionAutocapture: false, }; configureProductAnalytics(envId, options); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledWith(envId, options); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledTimes(1); }); it('should handle empty string envId', () => { configureProductAnalytics(''); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledWith('', {}); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledTimes(1); }); it('should handle empty options object', () => { const emptyOptions: ProductAnalyticsOptions = {}; configureProductAnalytics(envId, emptyOptions); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledWith(envId, {}); expect( ContentsquareModule.configureProductAnalytics ).toHaveBeenCalledTimes(1); }); }); });