Typescript - Remove unwanted checks in protocol handler and add test cases

This commit is contained in:
Kiran Niranjan 2019-03-01 21:13:08 +05:30
parent 05b52380ed
commit 7ee09ab787
2 changed files with 20 additions and 6 deletions

View File

@ -72,4 +72,24 @@ describe('protocol handler', () => {
expect(spy).toBeCalled();
});
it('should invoke `sendProtocol` when `setPreloadWebContents` is called and protocolUri is valid', () => {
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };
protocolHandlerInstance.protocolUri = 'symphony://?userId=123456';
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance, 'sendProtocol');
protocolHandlerInstance.setPreloadWebContents({ send: jest.fn() });
expect(spy).toBeCalledWith('symphony://?userId=123456');
});
it('should not invoke `sendProtocol` when `setPreloadWebContents` is called and protocolUri is invalid', () => {
protocolHandlerInstance.preloadWebContents = { send: jest.fn() };
protocolHandlerInstance.protocolUri = null;
const spy: jest.SpyInstance = jest.spyOn(protocolHandlerInstance, 'sendProtocol');
protocolHandlerInstance.setPreloadWebContents({ send: jest.fn() });
expect(spy).not.toBeCalled();
});
});

View File

@ -1,5 +1,3 @@
import * as url from 'url';
import { apiName } from '../common/api-interface';
import { isMac, isWindowsOS } from '../common/env';
import { getCommandLineArgs } from '../common/utils';
@ -62,10 +60,6 @@ class ProtocolHandler {
public processArgv(argv?: string[]): void {
const protocolUriFromArgv = getCommandLineArgs(argv || process.argv, protocol.SymphonyProtocol, false);
if (isWindowsOS && protocolUriFromArgv) {
const parsedURL = url.parse(protocolUriFromArgv);
if (!parsedURL.protocol || !parsedURL.slashes) {
return;
}
this.sendProtocol(protocolUriFromArgv, false);
}
}