2017-06-02 11:29:31 -05:00
|
|
|
const electron = require('./__mocks__/electron');
|
2018-03-13 05:20:32 -05:00
|
|
|
const activityDetection = require('../js/activityDetection');
|
2017-08-23 11:38:33 -05:00
|
|
|
describe('Tests for Activity Detection', function() {
|
2017-06-02 11:29:31 -05:00
|
|
|
|
2017-08-24 02:51:02 -05:00
|
|
|
const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
2018-03-13 05:20:32 -05:00
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
2017-06-02 11:29:31 -05:00
|
|
|
|
2018-12-20 08:11:06 -06:00
|
|
|
beforeAll(function(done) {
|
|
|
|
electron.app.isReady = jest.fn().mockReturnValue(true);
|
|
|
|
electron.powerMonitor = { querySystemIdleTime: jest.fn() }
|
|
|
|
done();
|
|
|
|
});
|
2017-06-02 11:29:31 -05:00
|
|
|
|
2017-08-23 11:38:33 -05:00
|
|
|
beforeEach(function() {
|
2017-06-02 11:29:31 -05:00
|
|
|
jest.clearAllMocks()
|
|
|
|
});
|
|
|
|
|
2017-08-23 11:38:33 -05:00
|
|
|
afterAll(function(done) {
|
2017-07-20 06:57:48 -05:00
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
|
done();
|
2017-05-10 11:12:00 -05:00
|
|
|
});
|
|
|
|
|
2017-08-23 11:38:33 -05:00
|
|
|
it('should send activity event', function() {
|
2017-05-10 11:12:00 -05:00
|
|
|
const spy = jest.spyOn(activityDetection, 'send');
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
2017-08-23 11:38:33 -05:00
|
|
|
activityDetection.send({ systemIdleTime: 120000 });
|
|
|
|
expect(spy).toHaveBeenCalledWith({ systemIdleTime: 120000 });
|
2017-05-10 11:12:00 -05:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-08-23 11:38:33 -05:00
|
|
|
it('should monitor user activity', function() {
|
2017-06-02 11:29:31 -05:00
|
|
|
activityDetection.setActivityWindow(500000, electron.ipcRenderer);
|
|
|
|
const spy = jest.spyOn(activityDetection, 'monitorUserActivity');
|
|
|
|
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
|
|
|
activityDetection.monitorUserActivity();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-12-20 08:11:06 -06:00
|
|
|
it('should start `activityDetection()`', () => {
|
|
|
|
const spy = jest.spyOn(activityDetection, 'activityDetection');
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
|
|
|
activityDetection.activityDetection();
|
|
|
|
expect(spy).toBeCalled();
|
|
|
|
});
|
|
|
|
|
2017-08-23 11:38:33 -05:00
|
|
|
it('should not send activity event as data is undefined', function() {
|
2017-06-02 11:29:31 -05:00
|
|
|
const spy = jest.spyOn(activityDetection, 'send');
|
|
|
|
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
|
|
|
activityDetection.send(undefined);
|
|
|
|
expect(spy).toHaveBeenCalledWith(undefined);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-12-20 08:11:06 -06:00
|
|
|
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();
|
|
|
|
|
|
|
|
});
|
2018-03-13 05:20:32 -05:00
|
|
|
});
|