Skip to content

Commit

Permalink
protocol handle unit test (finos#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
VICTOR RAPHAEL BRAGA DE SALES MASCARENHAS authored and KiranNiranjan committed Mar 19, 2019
1 parent 83b6a6c commit cab3576
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions spec/protocolHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});

});

0 comments on commit cab3576

Please sign in to comment.