forked from finos/SymphonyElectron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivityDetection.test.js
84 lines (56 loc) · 2.55 KB
/
activityDetection.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
const electron = require('./__mocks__/electron');
const activityDetection = require('../js/activityDetection');
describe('Tests for Activity Detection', function() {
const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
beforeAll(function(done) {
electron.app.isReady = jest.fn().mockReturnValue(true);
electron.powerMonitor = { querySystemIdleTime: jest.fn() }
done();
});
beforeEach(function() {
jest.clearAllMocks()
});
afterAll(function(done) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done();
});
it('should send activity event', function() {
const spy = jest.spyOn(activityDetection, 'send');
expect(spy).not.toBeCalled();
activityDetection.send({ systemIdleTime: 120000 });
expect(spy).toHaveBeenCalledWith({ systemIdleTime: 120000 });
});
it('should monitor user activity', function() {
activityDetection.setActivityWindow(500000, electron.ipcRenderer);
const spy = jest.spyOn(activityDetection, 'monitorUserActivity');
expect(spy).not.toBeCalled();
activityDetection.monitorUserActivity();
expect(spy).toHaveBeenCalled();
});
it('should start `activityDetection()`', () => {
const spy = jest.spyOn(activityDetection, 'activityDetection');
expect(spy).not.toBeCalled();
activityDetection.activityDetection();
expect(spy).toBeCalled();
});
it('should not send activity event as data is undefined', function() {
const spy = jest.spyOn(activityDetection, 'send');
expect(spy).not.toBeCalled();
activityDetection.send(undefined);
expect(spy).toHaveBeenCalledWith(undefined);
});
it('should call `send()` when period was greater than idleTime', () => {
const spy = jest.spyOn(activityDetection, 'send');
expect(spy).not.toBeCalled();
electron.powerMonitor = { querySystemIdleTime: jest.fn().mockImplementationOnce(cb => cb(1)) };
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
expect(spy).toBeCalled();
});
it('should start `activityDetection()` when `setActivityWindow()` was called', () => {
const spy = jest.spyOn(activityDetection, 'activityDetection');
expect(spy).not.toBeCalled();
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
expect(spy).toBeCalled();
});
});