-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* SDA-4770 Adaptations on openfin integration * SDA-4770 Adaptations on openfin integration
- Loading branch information
1 parent
c9326fd
commit 72be5a4
Showing
7 changed files
with
182 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ jest.mock('@openfin/node-adapter', () => ({ | |
getAllClientsInContextGroup: jest.fn(), | ||
joinContextGroup: jest.fn(), | ||
getContextGroups: jest.fn(), | ||
fireIntentForContext: jest.fn(), | ||
removeClientFromContextGroup: jest.fn(), | ||
}), | ||
}, | ||
}); | ||
|
@@ -50,24 +52,57 @@ describe('Openfin', () => { | |
}); | ||
|
||
it('should not be connected', () => { | ||
const info = openfinHandler.getInfo(); | ||
const connectionStatus = openfinHandler.getConnectionStatus(); | ||
|
||
expect(info.isConnected).toBeFalsy(); | ||
expect(connectionStatus.isConnected).toBeFalsy(); | ||
}); | ||
|
||
it('should connect', async () => { | ||
const connectSyncSpy = jest.spyOn(connectMock.Interop, 'connectSync'); | ||
|
||
await openfinHandler.connect(); | ||
const info = openfinHandler.getInfo(); | ||
const isConnected = openfinHandler.getConnectionStatus(); | ||
const connectionStatus = openfinHandler.getConnectionStatus(); | ||
|
||
expect(connect).toHaveBeenCalled(); | ||
expect(connectSyncSpy).toHaveBeenCalledTimes(1); | ||
expect(info.isConnected).toBeTruthy(); | ||
expect(isConnected).toBeTruthy(); | ||
expect(connectionStatus.isConnected).toBeTruthy(); | ||
}); | ||
|
||
it('should reject and return false if connection times out', async () => { | ||
jest.useFakeTimers(); | ||
const connectSyncSpy = jest | ||
.spyOn(connectMock.Interop, 'connectSync') | ||
.mockImplementationOnce((_channelName) => { | ||
return new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
resolve(); | ||
}, 12000); | ||
}); | ||
}); | ||
|
||
const connectionTimeoutSpy = jest.spyOn(global, 'setTimeout'); | ||
|
||
let connectionStatus; | ||
|
||
const connectPromise = openfinHandler.connect(); | ||
const resultPromise = connectPromise.then((res) => { | ||
connectionStatus = res; | ||
}); | ||
|
||
jest.advanceTimersByTime(10000); | ||
|
||
expect(connectionStatus).toBeUndefined(); | ||
|
||
await resultPromise; | ||
|
||
expect(connectionStatus.isConnected).toBe(false); | ||
|
||
expect(connectionTimeoutSpy).toHaveBeenCalledTimes(2); | ||
expect(connectionTimeoutSpy.mock.calls[0][1]).toBeGreaterThanOrEqual(10000); | ||
|
||
expect(connectSyncSpy).toHaveBeenCalledTimes(1); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should reject and return false if connection times out', async () => { | ||
|
@@ -113,10 +148,13 @@ describe('Openfin', () => { | |
|
||
await openfinHandler.connect(); | ||
const customIntent = { | ||
type: 'fdc3.contact', | ||
name: 'Andy Young', | ||
id: { | ||
email: '[email protected]', | ||
name: 'ViewContact', | ||
context: { | ||
type: 'fdc3.contact', | ||
name: 'Andy Young', | ||
id: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
}; | ||
await openfinHandler.fireIntent(customIntent); | ||
|
@@ -169,4 +207,33 @@ describe('Openfin', () => { | |
|
||
expect(getAllClientsInContextGroupSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should fire an intent for a given context', async () => { | ||
const connectSyncMock = await connectMock.Interop.connectSync(); | ||
const fireIntentSpy = jest.spyOn(connectSyncMock, 'fireIntentForContext'); | ||
|
||
await openfinHandler.connect(); | ||
const context = { | ||
type: 'fdc3.contact', | ||
name: 'Andy Young', | ||
id: { | ||
email: '[email protected]', | ||
}, | ||
}; | ||
await openfinHandler.fireIntentForContext(context); | ||
|
||
expect(fireIntentSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should remove client from context group', async () => { | ||
const connectSyncMock = await connectMock.Interop.connectSync(); | ||
const fireIntentSpy = jest.spyOn( | ||
connectSyncMock, | ||
'removeClientFromContextGroup', | ||
); | ||
|
||
await openfinHandler.removeClientFromContextGroup(); | ||
|
||
expect(fireIntentSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
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