mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-12-02 05:29:15 -06:00
6aca522a1e
* Typescript - Optimize loading styles and register global shortcuts * Typescript - Update version info logic to support BC * Typescript - Implement memory refresh logic * Typescript - Optimize memory refresh, devtools & appBridge code * Typescript - Mock window-handler to fix unit tests * Typescript - Change logic to remove if else and early exit
74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
jest.mock('electron-log');
|
|
|
|
jest.mock('../src/app/window-handler', () => {
|
|
return {
|
|
windowHandler: {
|
|
setIsAutoReload: jest.fn(() => true),
|
|
},
|
|
};
|
|
});
|
|
|
|
describe('activity detection', () => {
|
|
const originalTimeout: number = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
|
let activityDetectionInstance;
|
|
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
jest.useFakeTimers();
|
|
// I did it for reset module imported between tests
|
|
const { activityDetection } = require('../src/app/activity-detection');
|
|
activityDetectionInstance = activityDetection;
|
|
});
|
|
|
|
afterAll((done) => {
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
done();
|
|
});
|
|
|
|
it('should call `setWindowAndThreshold` correctly', () => {
|
|
// mocking startActivityMonitor
|
|
const spy: jest.SpyInstance = jest.spyOn(activityDetectionInstance, 'setWindowAndThreshold');
|
|
const idleThresholdMock: number = 1000;
|
|
|
|
jest.spyOn(activityDetectionInstance, 'startActivityMonitor')
|
|
.mockImplementation(() => jest.fn());
|
|
|
|
activityDetectionInstance.setWindowAndThreshold({}, idleThresholdMock);
|
|
|
|
expect(spy).toBeCalledWith({}, 1000);
|
|
});
|
|
|
|
it('should start activity monitor when `setWindowAndThreshold` is called', () => {
|
|
const idleThresholdMock: number = 1000;
|
|
const spy: jest.SpyInstance = jest.spyOn(activityDetectionInstance, 'startActivityMonitor')
|
|
.mockImplementation(() => jest.fn());
|
|
|
|
activityDetectionInstance.setWindowAndThreshold({}, idleThresholdMock);
|
|
|
|
expect(spy).toBeCalled();
|
|
});
|
|
|
|
it('should call `activity` when `startActivityMonitor` is called', () => {
|
|
const spy: jest.SpyInstance = jest.spyOn(activityDetectionInstance, 'activity');
|
|
|
|
activityDetectionInstance.startActivityMonitor();
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
expect(spy).toBeCalled();
|
|
});
|
|
|
|
it('should call `sendActivity` when period was greater than idleTime', () => {
|
|
// period is this.idleThreshold = 60 * 60 * 1000;
|
|
const mockIdleTime: number = 50;
|
|
const spy: jest.SpyInstance = jest.spyOn(activityDetectionInstance, 'sendActivity');
|
|
const mockIdleTimeinMillis: number = mockIdleTime * 1000;
|
|
|
|
activityDetectionInstance.activity(mockIdleTime);
|
|
|
|
expect(spy).toBeCalledWith(mockIdleTimeinMillis);
|
|
});
|
|
|
|
});
|