mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
ELECTRON-928 - migrate presence to the Power Monitor API (#530)
This commit is contained in:
committed by
Vishwas Shashidhar
parent
8ca8db65ed
commit
81ac612552
@@ -72,7 +72,7 @@ const ipcRenderer = {
|
||||
module.exports = {
|
||||
require: jest.fn(),
|
||||
match: jest.fn(),
|
||||
app: jest.fn(),
|
||||
app: app,
|
||||
ipcMain: ipcMain,
|
||||
ipcRenderer: ipcRenderer,
|
||||
remote: jest.fn(),
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
const electron = require('./__mocks__/electron');
|
||||
const activityDetection = require('../js/activityDetection');
|
||||
|
||||
describe('Tests for Activity Detection', function() {
|
||||
|
||||
const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
||||
|
||||
beforeAll(function(done) {
|
||||
activityDetection.setActivityWindow(900000, electron.ipcRenderer);
|
||||
done();
|
||||
});
|
||||
beforeAll(function(done) {
|
||||
electron.app.isReady = jest.fn().mockReturnValue(true);
|
||||
electron.powerMonitor = { querySystemIdleTime: jest.fn() }
|
||||
done();
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
jest.clearAllMocks()
|
||||
@@ -20,17 +20,8 @@ describe('Tests for Activity Detection', function() {
|
||||
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 });
|
||||
@@ -49,6 +40,14 @@ describe('Tests for Activity Detection', function() {
|
||||
|
||||
});
|
||||
|
||||
it('should start `activityDetection()`', () => {
|
||||
const spy = jest.spyOn(activityDetection, 'activityDetection');
|
||||
expect(spy).not.toBeCalled();
|
||||
|
||||
activityDetection.activityDetection();
|
||||
expect(spy).toBeCalled();
|
||||
});
|
||||
|
||||
it('should not send activity event as data is undefined', function() {
|
||||
const spy = jest.spyOn(activityDetection, 'send');
|
||||
|
||||
@@ -59,4 +58,27 @@ describe('Tests for Activity Detection', function() {
|
||||
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user