mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-27 01:11:13 -06:00
protocol handle unit test (#576)
This commit is contained in:
parent
58956e1b32
commit
05b52380ed
75
spec/protocolHandler.spec.ts
Normal file
75
spec/protocolHandler.spec.ts
Normal file
@ -0,0 +1,75 @@
|
||||
jest.mock('../src/app/window-actions', () => {
|
||||
return {
|
||||
activate: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('../src/common/utils', () => {
|
||||
return {
|
||||
getCommandLineArgs: jest.fn(() => 'symphony://?userId=22222'),
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('../src/common/env', () => {
|
||||
return {
|
||||
isWindowsOS: false,
|
||||
};
|
||||
});
|
||||
|
||||
describe('protocol handler', () => {
|
||||
let protocolHandlerInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
const { protocolHandler } = require('../src/app/protocol-handler');
|
||||
protocolHandlerInstance = protocolHandler;
|
||||
});
|
||||
|
||||
it('protocol uri should be null by default', () => {
|
||||
expect(protocolHandlerInstance.protocolUri).toBeNull();
|
||||
});
|
||||
|
||||
it('protocol action should be called when uri is correct', () => {
|
||||
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };
|
||||
|
||||
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance.preloadWebContents, 'send');
|
||||
const uri: string = 'symphony://?userId=123456';
|
||||
const protocolAction: string = 'protocol-action';
|
||||
|
||||
protocolHandlerInstance.sendProtocol(uri);
|
||||
|
||||
expect(spy).toBeCalledWith(protocolAction, 'symphony://?userId=123456');
|
||||
});
|
||||
|
||||
it('protocol action not should be called when uri is incorrect', () => {
|
||||
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };
|
||||
|
||||
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance.preloadWebContents, 'send');
|
||||
const uri: string = 'symphony---://?userId=123456';
|
||||
const protocolAction: string = 'protocol-action';
|
||||
|
||||
protocolHandlerInstance.sendProtocol(uri);
|
||||
|
||||
expect(spy).not.toBeCalledWith(protocolAction, 'symphony://?userId=123456');
|
||||
});
|
||||
|
||||
it('protocol should get uri from `processArgv` when `getCommandLineArgs` is called', () => {
|
||||
const { getCommandLineArgs } = require('../src/common/utils');
|
||||
|
||||
protocolHandlerInstance.processArgv('');
|
||||
|
||||
expect(getCommandLineArgs).toBeCalled();
|
||||
});
|
||||
|
||||
it('should be called `sendProtocol` when is windowsOS on `processArgs`', () => {
|
||||
const env = require('../src/common/env');
|
||||
env.isWindowsOS = true;
|
||||
|
||||
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance, 'sendProtocol');
|
||||
|
||||
protocolHandlerInstance.processArgv('');
|
||||
|
||||
expect(spy).toBeCalled();
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user