SDA-4770 Adaptations on openfin integration (#2268) (#2269)

* SDA-4770 Adaptations on openfin integration

* SDA-4770 Adaptations on openfin integration
This commit is contained in:
Salah Benmoussati 2025-01-22 19:45:35 +01:00 committed by GitHub
parent c9326fd5f8
commit 72be5a43cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 182 additions and 14 deletions

View File

@ -27,6 +27,8 @@ jest.mock('../src/app/openfin-handler', () => {
getAllClientsInContextGroup: jest.fn(), getAllClientsInContextGroup: jest.fn(),
registerIntentHandler: jest.fn(), registerIntentHandler: jest.fn(),
unregisterIntentHandler: jest.fn(), unregisterIntentHandler: jest.fn(),
fireIntentForContext: jest.fn(),
removeClientFromContextGroup: jest.fn(),
}, },
}; };
}); });
@ -712,5 +714,27 @@ describe('main api handler', () => {
expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledTimes(1);
}); });
it('should call `fireIntentForContext`', () => {
const spy = jest.spyOn(openfinHandler, 'fireIntentForContext');
const value = {
cmd: apiCmds.openfinFireIntentForContext,
};
ipcMain.send(apiName.symphonyApi, value);
expect(spy).toHaveBeenCalledTimes(1);
});
it('should call `removeClientFromContextGroup`', () => {
const spy = jest.spyOn(openfinHandler, 'removeClientFromContextGroup');
const value = {
cmd: apiCmds.openfinRemoveClientFromContextGroup,
};
ipcMain.send(apiName.symphonyApi, value);
expect(spy).toHaveBeenCalledTimes(1);
});
}); });
}); });

View File

@ -14,6 +14,8 @@ jest.mock('@openfin/node-adapter', () => ({
getAllClientsInContextGroup: jest.fn(), getAllClientsInContextGroup: jest.fn(),
joinContextGroup: jest.fn(), joinContextGroup: jest.fn(),
getContextGroups: jest.fn(), getContextGroups: jest.fn(),
fireIntentForContext: jest.fn(),
removeClientFromContextGroup: jest.fn(),
}), }),
}, },
}); });
@ -50,10 +52,8 @@ describe('Openfin', () => {
}); });
it('should not be connected', () => { it('should not be connected', () => {
const info = openfinHandler.getInfo();
const connectionStatus = openfinHandler.getConnectionStatus(); const connectionStatus = openfinHandler.getConnectionStatus();
expect(info.isConnected).toBeFalsy();
expect(connectionStatus.isConnected).toBeFalsy(); expect(connectionStatus.isConnected).toBeFalsy();
}); });
@ -61,13 +61,48 @@ describe('Openfin', () => {
const connectSyncSpy = jest.spyOn(connectMock.Interop, 'connectSync'); const connectSyncSpy = jest.spyOn(connectMock.Interop, 'connectSync');
await openfinHandler.connect(); await openfinHandler.connect();
const info = openfinHandler.getInfo(); const connectionStatus = openfinHandler.getConnectionStatus();
const isConnected = openfinHandler.getConnectionStatus();
expect(connect).toHaveBeenCalled(); expect(connect).toHaveBeenCalled();
expect(connectSyncSpy).toHaveBeenCalledTimes(1); expect(connectSyncSpy).toHaveBeenCalledTimes(1);
expect(info.isConnected).toBeTruthy(); expect(connectionStatus.isConnected).toBeTruthy();
expect(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 () => { it('should reject and return false if connection times out', async () => {
@ -113,11 +148,14 @@ describe('Openfin', () => {
await openfinHandler.connect(); await openfinHandler.connect();
const customIntent = { const customIntent = {
name: 'ViewContact',
context: {
type: 'fdc3.contact', type: 'fdc3.contact',
name: 'Andy Young', name: 'Andy Young',
id: { id: {
email: 'andy.young@example.com', email: 'andy.young@example.com',
}, },
},
}; };
await openfinHandler.fireIntent(customIntent); await openfinHandler.fireIntent(customIntent);
@ -169,4 +207,33 @@ describe('Openfin', () => {
expect(getAllClientsInContextGroupSpy).toHaveBeenCalledTimes(1); 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: 'andy.young@example.com',
},
};
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);
});
}); });

View File

@ -569,6 +569,12 @@ ipcMain.on(
case apiCmds.openfinUnregisterIntentHandler: case apiCmds.openfinUnregisterIntentHandler:
openfinHandler.unregisterIntentHandler(arg.intentName); openfinHandler.unregisterIntentHandler(arg.intentName);
break; break;
case apiCmds.openfinFireIntentForContext:
openfinHandler.fireIntentForContext(arg.context);
break;
case apiCmds.openfinRemoveClientFromContextGroup:
openfinHandler.removeClientFromContextGroup();
break;
default: default:
break; break;
} }
@ -649,6 +655,8 @@ ipcMain.handle(
return openfinHandler.getContextGroups(); return openfinHandler.getContextGroups();
case apiCmds.openfinGetAllClientsInContextGroup: case apiCmds.openfinGetAllClientsInContextGroup:
return openfinHandler.getAllClientsInContextGroup(arg.contextGroupId); return openfinHandler.getAllClientsInContextGroup(arg.contextGroupId);
case apiCmds.openfinGetClientInfo:
return openfinHandler.getClientInfo();
default: default:
break; break;
} }

View File

@ -30,8 +30,7 @@ export class OpenfinHandler {
const connectionTimeoutPromise = new Promise((_, reject) => const connectionTimeoutPromise = new Promise((_, reject) =>
setTimeout(() => { setTimeout(() => {
logger.error( logger.error(
`openfin-handler: Connection timeout after ${ `openfin-handler: Connection timeout after ${timeoutValue / 1000
timeoutValue / 1000
} seconds`, } seconds`,
); );
return reject( return reject(
@ -174,12 +173,45 @@ export class OpenfinHandler {
} }
/** /**
* Returns connection status and provider name * Returns provider name
*/ */
public getInfo() { public getInfo() {
return { return {
provider: OPENFIN_PROVIDER, provider: OPENFIN_PROVIDER,
isConnected: this.getConnectionStatus().isConnected, fdc3Version: '',
optionalFeatures: {
OriginatingAppMetadata: false,
UserChannelMembershipAPIs: false,
DesktopAgentBridging: false,
},
appMetadata: null,
};
}
/**
* Fires an intent for a given context
* @param context
*/
public fireIntentForContext(context: any) {
this.interopClient.fireIntentForContext(context);
}
/**
* Removes a client from current context group
*/
public removeClientFromContextGroup() {
this.interopClient.removeClientFromContextGroup();
}
/**
* Returns client name
*
*/
public getClientInfo(): unknown {
const { openfin }: IConfig = config.getConfigFields(['openfin']);
return {
name: openfin?.uuid || '',
}; };
} }

View File

@ -93,6 +93,9 @@ export enum apiCmds {
openfinJoinContextGroup = 'openfin-join-context-group', openfinJoinContextGroup = 'openfin-join-context-group',
openfinGetContextGroups = 'openfin-get-context-groups', openfinGetContextGroups = 'openfin-get-context-groups',
openfinGetAllClientsInContextGroup = 'openfin-get-all-clients-in-context-group', openfinGetAllClientsInContextGroup = 'openfin-get-all-clients-in-context-group',
openfinFireIntentForContext = 'openfin-fire-intent-for-context',
openfinRemoveClientFromContextGroup = 'openfin-remove-client-from-context-group',
openfinGetClientInfo = 'openfin-get-client-info',
} }
export enum apiName { export enum apiName {

View File

@ -117,6 +117,10 @@ if (ssfWindow.ssf) {
joinContextGroup: ssfWindow.ssf.openfinJoinContextGroup, joinContextGroup: ssfWindow.ssf.openfinJoinContextGroup,
getAllClientsInContextGroup: getAllClientsInContextGroup:
ssfWindow.ssf.openfinGetAllClientsInContextGroup, ssfWindow.ssf.openfinGetAllClientsInContextGroup,
fireIntentForContext: ssfWindow.ssf.openfinFireIntentForContext,
removeClientFromContextGroup:
ssfWindow.ssf.openfinRemoveClientFromContextGroup,
getClientInfo: ssfWindow.ssf.openfinGetClientInfo,
}); });
} }

View File

@ -988,6 +988,36 @@ export class SSFApi {
}); });
} }
/**
* Fires an intent for a given context
* @param context
*/
public openfinFireIntentForContext(context: any): void {
local.ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openfinFireIntentForContext,
context,
});
}
/**
* Removes client from current context group
*/
public openfinRemoveClientFromContextGroup() {
local.ipcRenderer.send(apiName.symphonyApi, {
cmd: apiCmds.openfinRemoveClientFromContextGroup,
});
}
/**
* Returns client info
*/
public async openfinGetClientInfo() {
const info = await local.ipcRenderer.invoke(apiName.symphonyApi, {
cmd: apiCmds.openfinGetClientInfo,
});
return info;
}
/** /**
* *
* Returns Openfin connection status * Returns Openfin connection status