SymphonyElectron/tests/ProtocolHandler.test.js
Vishwas Shashidhar cda34b1d70 Electron 24 - protocol handler (#85)
* added idea and coverage directories under gitignore

* electron-24: implemented handlers to process protocol actions

* electron-17: implemented use case for opening app if it is not open and handle the protocol url

* electron-24: added code and documentation comments

* electron-24: added unit tests for the protocol handler

* added npm-debug log to gitignore

* electron-24: added protocol handler support for windows

* electron-24: made changes as per comments on the PR

* electron-16: added more comments and further refactoring
2017-05-13 11:23:44 -07:00

61 lines
1.5 KiB
JavaScript

/**
* Created by vishwas on 10/05/17.
*/
const protocolHandler = require('../js/protocolHandler');
const electron = require('./__mocks__/electron');
describe('protocol handler', function () {
const url = 'symphony://?userId=100001';
const mainProcess = electron.ipcMain;
const protocolWindow = electron.ipcRenderer;
beforeAll(function () {
protocolHandler.setProtocolWindow(protocolWindow);
});
it('process a protocol action', function (done) {
const spy = jest.spyOn(protocolHandler, 'processProtocolAction');
protocolHandler.processProtocolAction(url);
expect(spy).toHaveBeenCalledWith(url);
done();
});
it('protocol url should be undefined by default', function (done) {
expect(protocolHandler.getProtocolUrl()).toBeUndefined();
done();
});
it('protocol handler open url should be called', function (done) {
const spy = jest.spyOn(mainProcess, 'send');
mainProcess.send('open-url', url);
expect(spy).toHaveBeenCalled();
done();
});
it('check protocol action should be called', function (done) {
const spy = jest.spyOn(protocolHandler, 'checkProtocolAction');
const setSpy = jest.spyOn(protocolHandler, 'setProtocolUrl');
protocolHandler.setProtocolUrl(url);
expect(setSpy).toHaveBeenCalledWith(url);
protocolHandler.checkProtocolAction();
expect(spy).toHaveBeenCalled();
expect(protocolHandler.getProtocolUrl()).toBeUndefined();
done();
});
});