2017-06-02 21:59:31 +05:30
|
|
|
const electron = require('./__mocks__/electron');
|
2018-03-13 15:50:32 +05:30
|
|
|
const activityDetection = require('../js/activityDetection');
|
2017-05-10 21:42:00 +05:30
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
describe('Tests for Activity Detection', function() {
|
2017-06-02 21:59:31 +05:30
|
|
|
|
2017-08-24 13:21:02 +05:30
|
|
|
const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
2018-03-13 15:50:32 +05:30
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
2017-06-02 21:59:31 +05:30
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
beforeAll(function(done) {
|
2018-03-13 15:50:32 +05:30
|
|
|
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
|
|
|
|
done();
|
2017-06-02 21:59:31 +05:30
|
|
|
});
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
beforeEach(function() {
|
2017-06-02 21:59:31 +05:30
|
|
|
jest.clearAllMocks()
|
|
|
|
});
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
afterAll(function(done) {
|
2017-07-20 17:27:48 +05:30
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
|
done();
|
2017-05-10 21:42:00 +05:30
|
|
|
});
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
it('should return null', function() {
|
2017-05-10 21:42:00 +05:30
|
|
|
|
|
|
|
activityDetection.setActivityWindow(0, electron.ipcRenderer);
|
|
|
|
const noData = activityDetection.activityDetection();
|
|
|
|
expect(noData).toBeNull();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
it('should send activity event', function() {
|
2017-05-10 21:42:00 +05:30
|
|
|
const spy = jest.spyOn(activityDetection, 'send');
|
|
|
|
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
activityDetection.send({ systemIdleTime: 120000 });
|
|
|
|
expect(spy).toHaveBeenCalledWith({ systemIdleTime: 120000 });
|
2017-05-10 21:42:00 +05:30
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
it('should monitor user activity', function() {
|
2017-06-02 21:59:31 +05:30
|
|
|
activityDetection.setActivityWindow(500000, electron.ipcRenderer);
|
|
|
|
const spy = jest.spyOn(activityDetection, 'monitorUserActivity');
|
|
|
|
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
|
|
|
activityDetection.monitorUserActivity();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-08-23 22:08:33 +05:30
|
|
|
it('should not send activity event as data is undefined', function() {
|
2017-06-02 21:59:31 +05:30
|
|
|
const spy = jest.spyOn(activityDetection, 'send');
|
|
|
|
|
|
|
|
expect(spy).not.toBeCalled();
|
|
|
|
|
|
|
|
activityDetection.send(undefined);
|
|
|
|
expect(spy).toHaveBeenCalledWith(undefined);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-13 15:50:32 +05:30
|
|
|
});
|