Electron-66 (Unit tests) (#120)

* Electron-66 - Added more unit tests for config, getRegistry & throttle

* Electron-66 - Added some more unit tests and enabled activity detection unit test
This commit is contained in:
Kiran Niranjan
2017-06-02 21:59:31 +05:30
committed by Lynn
parent 4a02beeb86
commit a839c86d83
7 changed files with 277 additions and 10 deletions

View File

@@ -1,10 +1,30 @@
// const activityDetection = require('../js/activityDetection/activityDetection.js');
// const electron = require('./__mocks__/electron');
const electron = require('./__mocks__/electron');
const childProcess = require('child_process');
xdescribe('Tests for Activity Detection', function() {
let activityDetection;
beforeAll(function () {
activityDetection.setActivityWindow(120000, electron.ipcRenderer);
describe('Tests for Activity Detection', function() {
var originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
beforeAll(function (done) {
childProcess.exec('npm rebuild --runtime=electron --target=1.2.2 --disturl=https://atom.io/download/atom-shell --build-from-source', function (err) {
activityDetection = require('../js/activityDetection/activityDetection.js');
activityDetection.setActivityWindow(120000, electron.ipcRenderer);
done();
});
});
beforeEach(function () {
jest.clearAllMocks()
});
afterAll(function (done) {
childProcess.exec('npm run rebuild', function (err, stdout) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done();
});
});
it('should get user activity where user is not idle', function() {
@@ -37,4 +57,25 @@ xdescribe('Tests for Activity Detection', function() {
});
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 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);
});
});