-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a6704b
commit b27faed
Showing
20 changed files
with
730 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { activityDetection } from '../src/app/activity-detection'; | |
import * as c9PipeHandler from '../src/app/c9-pipe-handler'; | ||
import { downloadHandler } from '../src/app/download-handler'; | ||
import '../src/app/main-api-handler'; | ||
import { openfinHandler } from '../src/app/openfin-handler'; | ||
import { protocolHandler } from '../src/app/protocol-handler'; | ||
import { screenSnippet } from '../src/app/screen-snippet-handler'; | ||
import * as windowActions from '../src/app/window-actions'; | ||
|
@@ -10,9 +11,56 @@ import * as utils from '../src/app/window-utils'; | |
import { apiCmds, apiName } from '../src/common/api-interface'; | ||
import { logger } from '../src/common/logger'; | ||
import { BrowserWindow, ipcMain } from './__mocks__/electron'; | ||
import { connect } from '@openfin/node-adapter'; | ||
|
||
jest.mock('electron-log'); | ||
|
||
jest.mock('../src/app/openfin-handler', () => { | ||
return { | ||
openfinHandler: { | ||
connect: jest.fn(), | ||
fireIntent: jest.fn(), | ||
joinContextGroup: jest.fn(), | ||
getContextGroups: jest.fn(), | ||
getConnectionStatus: jest.fn(), | ||
getInfo: jest.fn(), | ||
getAllClientsInContextGroup: jest.fn(), | ||
registerIntentHandler: jest.fn(), | ||
unregisterIntentHandler: jest.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
jest.mock('@openfin/node-adapter', () => ({ | ||
connect: jest.fn(), | ||
})); | ||
|
||
(connect as jest.Mock).mockResolvedValue({ | ||
Interop: { | ||
connectSync: jest.fn().mockReturnValue({ | ||
onDisconnection: jest.fn(), | ||
fireIntent: jest.fn(), | ||
registerIntentHandler: jest.fn(), | ||
}), | ||
}, | ||
}); | ||
|
||
jest.mock('../src/app/config-handler', () => { | ||
return { | ||
config: { | ||
getConfigFields: jest.fn(() => { | ||
return { | ||
openfin: { | ||
uuid: 'some-uuid', | ||
licenseKey: 'some-license-key', | ||
runtimeVersion: 'some-runtime-version', | ||
}, | ||
}; | ||
}), | ||
}, | ||
}; | ||
}); | ||
|
||
jest.mock('../src/app/protocol-handler', () => { | ||
return { | ||
protocolHandler: { | ||
|
@@ -553,4 +601,114 @@ describe('main api handler', () => { | |
expect(spy).toBeCalledWith(...expectedValue); | ||
}); | ||
}); | ||
|
||
describe('openfin api events', () => { | ||
beforeEach(() => { | ||
(connect as jest.Mock).mockResolvedValue({ | ||
Interop: { | ||
connectSync: jest.fn().mockReturnValue({ | ||
onDisconnection: jest.fn(), | ||
}), | ||
}, | ||
}); | ||
(windowHandler.getMainWebContents as jest.Mock).mockReturnValue({ | ||
send: jest.fn(), | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call `connect` correctly', () => { | ||
const spy = jest.spyOn(openfinHandler, 'connect'); | ||
const value = { | ||
cmd: apiCmds.openfinConnect, | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call `fireIntent`', () => { | ||
const spy = jest.spyOn(openfinHandler, 'fireIntent'); | ||
const value = { | ||
cmd: apiCmds.openfinFireIntent, | ||
intent: { | ||
name: 'ViewContact', | ||
context: { | ||
type: 'fdc3.contact', | ||
name: 'Andy Young', | ||
id: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call `registerIntentHandler`', () => { | ||
const spy = jest.spyOn(openfinHandler, 'registerIntentHandler'); | ||
const value = { | ||
cmd: apiCmds.openfinRegisterIntentHandler, | ||
intentName: 'ViewContact', | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call `unregisterIntentHandler`', () => { | ||
const spy = jest.spyOn(openfinHandler, 'unregisterIntentHandler'); | ||
const value = { | ||
cmd: apiCmds.openfinUnregisterIntentHandler, | ||
intentName: 'ViewContact', | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call `joinContextGroup`', () => { | ||
const spy = jest.spyOn(openfinHandler, 'joinContextGroup'); | ||
const value = { | ||
cmd: apiCmds.openfinJoinContextGroup, | ||
contextGroupId: 'group-id', | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call `getContextGroups`', () => { | ||
const spy = jest.spyOn(openfinHandler, 'getContextGroups'); | ||
const value = { | ||
cmd: apiCmds.openfinGetContextGroups, | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call `getAllClientsInContextGroup`', () => { | ||
const spy = jest.spyOn(openfinHandler, 'getAllClientsInContextGroup'); | ||
const value = { | ||
cmd: apiCmds.openfinGetAllClientsInContextGroup, | ||
contextGroupId: 'group-id', | ||
}; | ||
|
||
ipcMain.send(apiName.symphonyApi, value); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.