mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
C2-25226: OpenFin disconnection handler (#2274)
- `openfin.init` allows to provide a disconnection handler - this disconnection handler is stored on SSF side - the openfin handler forward the disconnection event through a new `openfin-disconnection` event - SSF calls the disconnection handler when a new `openfin-disconnection` event is received Minor: - in the openfin handler, a call to reset is now done before trying to connect to OpenFin - removed the timeout log in the timeout promise, the log will be shown if the timeout promise rejects first (or in case of error)
This commit is contained in:
@@ -35,10 +35,13 @@ jest.mock('../src/app/config-handler', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const mockSend = jest.fn();
|
||||
jest.mock('../src/app/window-handler', () => {
|
||||
return {
|
||||
windowHandler: {
|
||||
getMainWebContents: jest.fn(),
|
||||
getMainWebContents: jest.fn(() => ({
|
||||
send: mockSend,
|
||||
})),
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -163,17 +166,23 @@ describe('Openfin', () => {
|
||||
expect(fireIntentSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should register an intent handler', async () => {
|
||||
it('should register an intent handler and trigger intent handler on intent received', async () => {
|
||||
const intentName = 'my-intent';
|
||||
const connectSyncMock = await connectMock.Interop.connectSync();
|
||||
const intentHandlerRegistrationSpy = jest.spyOn(
|
||||
connectSyncMock,
|
||||
'registerIntentHandler',
|
||||
);
|
||||
|
||||
await openfinHandler.connect();
|
||||
await openfinHandler.registerIntentHandler('my-intent');
|
||||
await openfinHandler.registerIntentHandler(intentName);
|
||||
|
||||
expect(intentHandlerRegistrationSpy).toHaveBeenCalledTimes(1);
|
||||
expect(connectSyncMock.registerIntentHandler).toHaveBeenCalledTimes(1);
|
||||
|
||||
const intentHandler =
|
||||
connectSyncMock.registerIntentHandler.mock.calls[0][0];
|
||||
intentHandler('intent-data');
|
||||
|
||||
expect(mockSend).toHaveBeenCalledWith(
|
||||
'openfin-intent-received',
|
||||
'intent-data',
|
||||
);
|
||||
});
|
||||
|
||||
it('should join a context group', async () => {
|
||||
@@ -253,4 +262,25 @@ describe('Openfin', () => {
|
||||
|
||||
expect(removeFromContextGroupSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should trigger disconnection handler when disconnected', async () => {
|
||||
const disconnectionEvent = {
|
||||
type: 'type',
|
||||
topic: 'topic',
|
||||
brokerName: 'broken-name',
|
||||
};
|
||||
|
||||
const connectSyncMock = await connectMock.Interop.connectSync();
|
||||
|
||||
await openfinHandler.connect();
|
||||
|
||||
const disconnectionHandler =
|
||||
connectSyncMock.onDisconnection.mock.calls[0][0];
|
||||
disconnectionHandler(disconnectionEvent);
|
||||
|
||||
expect(mockSend).toHaveBeenCalledWith(
|
||||
'openfin-disconnection',
|
||||
disconnectionEvent,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user