ELECTRON-32 Added unit test cases for activity detection (#84)

This commit is contained in:
Kiran Niranjan 2017-05-10 21:42:00 +05:30 committed by Lynn
parent c0908e64ef
commit d6031dd440
2 changed files with 41 additions and 0 deletions

View File

@ -89,5 +89,6 @@ function setActivityWindow(period, win) {
module.exports = {
send: send,
setActivityWindow: setActivityWindow,
activityDetection: activityDetection,
initiateActivityDetection: initiateActivityDetection
};

View File

@ -0,0 +1,40 @@
const activityDetection = require('../js/activityDetection/activityDetection.js');
const electron = require('./__mocks__/electron');
describe('Tests for Activity Detection', function() {
beforeAll(function () {
activityDetection.setActivityWindow(120000, electron.ipcRenderer);
});
it('should get user activity where user is not idle', function() {
const data = activityDetection.activityDetection();
expect(data.isUserIdle).toBe(false);
expect(data.systemIdleTime).toBeLessThan(120000);
});
it('should return null', function() {
const spy = jest.spyOn(activityDetection, 'activityDetection');
const data = activityDetection.activityDetection();
expect(spy).toHaveBeenCalled();
expect(data.isUserIdle).toBe(false);
activityDetection.setActivityWindow(0, electron.ipcRenderer);
const noData = activityDetection.activityDetection();
expect(noData).toBeNull();
});
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});
});
});