import { Platform } from 'react-native'; import { handleUrl, start } from '../../core/core'; import { ContentsquareModule } from '../../core/nativeModules'; jest.mock('../../core/nativeModules', () => ({ ContentsquareModule: { start: jest.fn(), handleUrl: jest.fn(), initComponents: jest.fn(), }, })); jest.mock('react-native', () => ({ Platform: { OS: 'ios', }, })); describe('sdkFunctions', () => { beforeEach(() => { jest.clearAllMocks(); }); describe('start', () => { it('should call ContentsquareModule.start', () => { start(); expect(ContentsquareModule.start).toHaveBeenCalledTimes(1); }); }); describe('handleUrl', () => { it('should call ContentsquareModule.handleUrl on iOS', () => { Platform.OS = 'ios'; const testUrl = 'myapp://some-path'; handleUrl(testUrl); expect(ContentsquareModule.handleUrl).toHaveBeenCalledWith(testUrl); expect(ContentsquareModule.handleUrl).toHaveBeenCalledTimes(1); }); it('should not call ContentsquareModule.handleUrl on Android', () => { Platform.OS = 'android'; const testUrl = 'myapp://some-path'; handleUrl(testUrl); expect(ContentsquareModule.handleUrl).not.toHaveBeenCalled(); }); it('should handle null or undefined URL gracefully on iOS', () => { Platform.OS = 'ios'; handleUrl(null); handleUrl(undefined); expect(ContentsquareModule.handleUrl).toHaveBeenCalledWith(null); expect(ContentsquareModule.handleUrl).toHaveBeenCalledWith(undefined); expect(ContentsquareModule.handleUrl).toHaveBeenCalledTimes(2); }); }); });