forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtocolHandler.test.js
118 lines (74 loc) · 3.27 KB
/
ProtocolHandler.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* 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 nonProtocolUrl = 'sy://abc=123';
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('protocol handler open url should be called', function(done) {
const spy = jest.spyOn(mainProcess, 'send');
mainProcess.send('open-url', nonProtocolUrl);
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();
});
it('check protocol action should be called when we have an incorrect protocol url', function (done) {
const spy = jest.spyOn(protocolHandler, 'checkProtocolAction');
const setSpy = jest.spyOn(protocolHandler, 'setProtocolUrl');
protocolHandler.setProtocolUrl(nonProtocolUrl);
expect(setSpy).toHaveBeenCalledWith(nonProtocolUrl);
protocolHandler.checkProtocolAction();
expect(spy).toHaveBeenCalled();
expect(protocolHandler.getProtocolUrl()).toBeUndefined();
done();
});
it('check protocol action should be called when the protocol url is undefined', function(done) {
const spy = jest.spyOn(protocolHandler, 'checkProtocolAction');
const setSpy = jest.spyOn(protocolHandler, 'setProtocolUrl');
protocolHandler.setProtocolUrl(undefined);
expect(setSpy).toHaveBeenCalledWith(undefined);
protocolHandler.checkProtocolAction();
expect(spy).toHaveBeenCalled();
expect(protocolHandler.getProtocolUrl()).toBeUndefined();
done();
});
it('should cache the protocol url if the protocol window is not defined yet', (done) => {
protocolHandler.setProtocolWindow(null);
const setSpy = jest.spyOn(protocolHandler, 'setProtocolUrl');
protocolHandler.setProtocolUrl(url);
protocolHandler.checkProtocolAction();
expect(setSpy).toHaveBeenCalled();
done();
});
});