added more tests to increase coverage to 100 for protocol handler

This commit is contained in:
Vishwas Shashidhar 2019-03-01 22:43:50 +05:30 committed by Kiran Niranjan
parent 7ee09ab787
commit 68efbfa0e8
2 changed files with 29 additions and 1 deletions

View File

@ -13,6 +13,7 @@ jest.mock('../src/common/utils', () => {
jest.mock('../src/common/env', () => {
return {
isWindowsOS: false,
isMac: true
};
});
@ -41,6 +42,31 @@ describe('protocol handler', () => {
expect(spy).toBeCalledWith(protocolAction, 'symphony://?userId=123456');
});
it('protocol activate should be called when uri is correct on macOS', () => {
const { activate } = require('../src/app/window-actions');
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };
const uri: string = 'symphony://?userId=123456';
protocolHandlerInstance.sendProtocol(uri);
expect(activate).toBeCalledWith('main');
});
it('protocol activate should not be called when uri is correct on non macOS', () => {
const env = require('../src/common/env');
env.isMac = false;
const { activate } = require('../src/app/window-actions');
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };
const uri: string = 'symphony://?userId=123456';
protocolHandlerInstance.sendProtocol(uri);
expect(activate).not.toBeCalled();
});
it('protocol action not should be called when uri is incorrect', () => {
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };

View File

@ -45,7 +45,9 @@ class ProtocolHandler {
}
// This is needed for mac OS as it brings pop-outs to foreground
// (if it has been previously focused) instead of main window
if (isMac) activate(apiName.mainWindowName);
if (isMac) {
activate(apiName.mainWindowName);
}
if (ProtocolHandler.isValidProtocolUri(uri)) {
this.preloadWebContents.send('protocol-action', uri);