2020-09-25 04:46:33 -05:00
|
|
|
jest.mock('electron-log');
|
|
|
|
|
2019-03-01 07:39:49 -06:00
|
|
|
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,
|
2019-08-20 04:00:13 -05:00
|
|
|
isLinux: false,
|
2019-03-06 10:30:55 -06:00
|
|
|
isMac: true,
|
2019-03-01 07:39:49 -06:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-09-25 04:46:33 -05:00
|
|
|
jest.mock('../src/common/logger', () => {
|
|
|
|
return {
|
|
|
|
logger: {
|
|
|
|
setLoggerWindow: jest.fn(),
|
|
|
|
error: jest.fn(),
|
|
|
|
warn: jest.fn(),
|
|
|
|
info: jest.fn(),
|
|
|
|
verbose: jest.fn(),
|
|
|
|
debug: jest.fn(),
|
|
|
|
silly: jest.fn(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2019-03-01 07:39:49 -06:00
|
|
|
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', () => {
|
2019-04-03 07:55:27 -05:00
|
|
|
expect(protocolHandlerInstance.protocolUri).toBe('symphony://?userId=22222');
|
2019-03-01 07:39:49 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2019-03-01 11:13:50 -06:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2019-03-01 07:39:49 -06:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2019-03-01 09:43:08 -06:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2019-03-01 07:39:49 -06:00
|
|
|
});
|