Files
SymphonyElectron/tests/activityDetection.test.js
T

62 lines
1.7 KiB
JavaScript
Raw Normal View History

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');
describe('Tests for Activity Detection', function() {
2017-06-02 21:59:31 +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
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
});
beforeEach(function() {
2017-06-02 21:59:31 +05:30
jest.clearAllMocks()
});
afterAll(function(done) {
2017-07-20 17:27:48 +05:30
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
done();
});
it('should return null', function() {
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 });
});
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();
});
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
});