jest.mock('./../Commons/Logger/Logger'); jest.mock('../HelperFunctions', () => { const result: { [key: string]: any } = jest.genMockFromModule('../HelperFunctions'); result.sendRequestToFramework = jest.fn().mockImplementation(() => Promise.resolve()); result.sendRegisterRequestToFramework = jest.fn().mockImplementation((callback: Function, operation: Operations) => { setTimeout(() => { callback('hello'); }, 1); return Promise.resolve(); }); return result; }); import * as App from './ApplicationAPI'; import * as helper from './HelperFunctions'; import { Operations } from './models/Commons'; import { ChannelTypes, InteractionDirectionTypes, SearchRecords, Field, SearchLayouts, Activity } from './ApplicationAPI'; describe('ApplicationAPI', () => { test('registerScreenpopControlChanged', async () => { const callback: (screenPopEnabled: boolean) => Promise = jest.fn(); const promise = App.registerScreenpopControlChanged(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.SCREENPOP_CONTROL_CHANGED); }); test('registerScreenpop', async () => { const callback: (channel: ChannelTypes, direction: InteractionDirectionTypes, objectId: string, objectType: string) => Promise = jest.fn(); const promise = App.registerScreenpop(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.SCREEN_POP); }); test('registerGlobalSearch', async () => { // TODO: update so that cad param is of a better format. map of string->string?? const callback: (channel: ChannelTypes, direction: InteractionDirectionTypes, cad: string, query: string, maxRecords?: number) => Promise = jest.fn(); const promise = App.registerGlobalSearch(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.GLOBAL_SEARCH); }); test('registerSearch', async () => { const callback: ( channel: ChannelTypes, direction: InteractionDirectionTypes, cadValue: string, objectFields: Field[], objectType: string, maxRecords?: number ) => Promise = jest.fn(); const promise = App.registerSearch(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.SEARCH); }); test('registerGlobalSearchAndScreenpop', async () => { // TODO: update so that cad param is of a better format. map of string->string?? const callback: (channel: ChannelTypes, direction: InteractionDirectionTypes, cad: string, query: string, maxRecords?: number) => Promise = jest.fn(); const promise = App.registerGlobalSearchAndScreenpop(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.GLOBAL_SEARCH_AND_SCREENPOP); }); test('registerEnableClickToDial', async () => { const callback: (enabled: boolean) => Promise = jest.fn(); const promise = App.registerEnableClickToDial(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.ENABLE_CLICK_TO_DIAL); }); test('registerSetSoftphoneHeight', async () => { const callback: (height: number) => Promise = jest.fn(); const promise = App.registerSetSoftphoneHeight(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.SET_SOFTPHONE_HEIGHT); }); test('registerSetSoftphoneWidth', async () => { const callback: (height: number) => Promise = jest.fn(); const promise = App.registerSetSoftphoneWidth(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.SET_SOFTPHONE_WIDTH); }); test('registerGetSearchLayout', async () => { const callback: () => Promise = jest.fn(); const promise = App.registerGetSearchLayout(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.GET_SEARCH_LAYOUT); }); test('registerGetPageInfo', async () => { const callback: () => Promise = jest.fn(); const promise = App.registerGetPageInfo(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.GET_PAGE_INFO); }); test('click-to-dial', async () => { const promise = App.clickToDial('555-555-5555', new SearchRecords()); await expect(promise).resolves.toBeUndefined(); }); test('onFocus', async () => { const promise = App.onFocus(new SearchRecords()); await expect(promise).resolves.toBeUndefined(); }); test('registerSaveActivity', async () => { const callback: (avtivity: Activity) => Promise = jest.fn(); const promise = App.registerSaveActivity(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.SAVE_ACTIVITY); }); test('registerIsToolbarVisible', async () => { const callback: () => Promise = jest.fn(); const promise = App.registerIsToolbarVisible(callback); await expect(promise).resolves.toBeUndefined(); expect(helper.sendRegisterRequestToFramework).toHaveBeenLastCalledWith(callback, Operations.IS_TOOLBAR_VISIBLE); }); test('loadBridgeScript', async () => { const promise = App.loadBridgeScripts(['http://example.com/jquery.js']); await expect(promise).resolves.toBeUndefined(); }); });