-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
typescript: activityDetection unit test
- Loading branch information
Victor R. Braga de Sales Mascarenhasm
committed
Jan 25, 2019
1 parent
efe914d
commit e3f124f
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
describe('activity detection', () => { | ||
|
||
const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterAll((done) => { | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; | ||
done(); | ||
}); | ||
|
||
it('should call `setWindowAndThreshold` correctly', () => { | ||
const { activityDetection } = require('../src/app/activity-detection'); | ||
|
||
// mocking startActivityMonitor | ||
jest.spyOn(activityDetection, 'startActivityMonitor') | ||
.mockImplementation(() => jest.fn()); | ||
|
||
const spy = jest.spyOn(activityDetection, 'setWindowAndThreshold'); | ||
|
||
activityDetection.setWindowAndThreshold({}, 1000); | ||
|
||
expect(spy).toBeCalledWith({}, 1000); | ||
}); | ||
|
||
it('should start activity monitor when `setWindowAndThreshold` is called', () => { | ||
const { activityDetection } = require('../src/app/activity-detection'); | ||
|
||
const spy = jest.spyOn(activityDetection, 'startActivityMonitor') | ||
.mockImplementation(() => jest.fn()); | ||
|
||
activityDetection.setWindowAndThreshold({}, 1000); | ||
|
||
expect(spy).toBeCalled(); | ||
}); | ||
|
||
it('should call `activity` when `startActivityMonitor` is called', () => { | ||
const { activityDetection } = require('../src/app/activity-detection'); | ||
const electron = require('./__mocks__/electron'); | ||
|
||
electron.powerMonitor = { querySystemIdleTime: jest.fn().mockImplementation((cb) => cb(15)) }; | ||
|
||
const spy = jest.spyOn(activityDetection, 'activity'); | ||
|
||
activityDetection.startActivityMonitor(); | ||
|
||
jest.runOnlyPendingTimers(); | ||
|
||
expect(spy).toBeCalledWith(15); | ||
}); | ||
|
||
it('should call `sendActivity` when period was greater than idleTime', () => { | ||
const { activityDetection } = require('../src/app/activity-detection'); | ||
// period is this.idleThreshold = 60 * 60 * 1000; | ||
const spy = jest.spyOn(activityDetection, 'sendActivity'); | ||
|
||
activityDetection.activity(50); | ||
|
||
expect(spy).toBeCalledWith(50 * 1000); | ||
}); | ||
|
||
}); |