mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-25 04:06:42 +00:00
Trigger drive scans after slight delays
This allows unit tests to easily capture the first run, as otherwise happens too fast.
This commit is contained in:
parent
b7da4dfeda
commit
491a0ae9c9
@ -131,7 +131,7 @@ if (window.mocha) {
|
|||||||
|
|
||||||
var driveScanner = angular.module('ResinEtcher.drive-scanner', []);
|
var driveScanner = angular.module('ResinEtcher.drive-scanner', []);
|
||||||
|
|
||||||
driveScanner.service('DriveScannerRefreshService', function($interval) {
|
driveScanner.service('DriveScannerRefreshService', function($interval, $timeout) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var interval = null;
|
var interval = null;
|
||||||
@ -150,8 +150,15 @@ driveScanner.service('DriveScannerRefreshService', function($interval) {
|
|||||||
* }, 2000);
|
* }, 2000);
|
||||||
*/
|
*/
|
||||||
this.every = function(fn, ms) {
|
this.every = function(fn, ms) {
|
||||||
fn();
|
|
||||||
interval = $interval(fn, ms);
|
// Call fn after in the next process tick
|
||||||
|
// to be able to capture the first run
|
||||||
|
// in unit tests.
|
||||||
|
$timeout(function() {
|
||||||
|
fn();
|
||||||
|
interval = $interval(fn, ms);
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@ if (window.mocha) {
|
|||||||
|
|
||||||
var driveScanner = angular.module('ResinEtcher.drive-scanner', []);
|
var driveScanner = angular.module('ResinEtcher.drive-scanner', []);
|
||||||
|
|
||||||
driveScanner.service('DriveScannerRefreshService', function($interval) {
|
driveScanner.service('DriveScannerRefreshService', function($interval, $timeout) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var interval = null;
|
var interval = null;
|
||||||
@ -53,8 +53,15 @@ driveScanner.service('DriveScannerRefreshService', function($interval) {
|
|||||||
* }, 2000);
|
* }, 2000);
|
||||||
*/
|
*/
|
||||||
this.every = function(fn, ms) {
|
this.every = function(fn, ms) {
|
||||||
fn();
|
|
||||||
interval = $interval(fn, ms);
|
// Call fn after in the next process tick
|
||||||
|
// to be able to capture the first run
|
||||||
|
// in unit tests.
|
||||||
|
$timeout(function() {
|
||||||
|
fn();
|
||||||
|
interval = $interval(fn, ms);
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,9 +12,11 @@ describe('Browser: DriveScanner', function() {
|
|||||||
|
|
||||||
var DriveScannerRefreshService;
|
var DriveScannerRefreshService;
|
||||||
var $interval;
|
var $interval;
|
||||||
|
var $timeout;
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(function(_$interval_, _DriveScannerRefreshService_) {
|
beforeEach(angular.mock.inject(function(_$interval_, _$timeout_, _DriveScannerRefreshService_) {
|
||||||
$interval = _$interval_;
|
$interval = _$interval_;
|
||||||
|
$timeout = _$timeout_;
|
||||||
DriveScannerRefreshService = _DriveScannerRefreshService_;
|
DriveScannerRefreshService = _DriveScannerRefreshService_;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -23,6 +25,7 @@ describe('Browser: DriveScanner', function() {
|
|||||||
it('should call the function right away', function() {
|
it('should call the function right away', function() {
|
||||||
var spy = m.sinon.spy();
|
var spy = m.sinon.spy();
|
||||||
DriveScannerRefreshService.every(spy, 1000);
|
DriveScannerRefreshService.every(spy, 1000);
|
||||||
|
$timeout.flush();
|
||||||
DriveScannerRefreshService.stop();
|
DriveScannerRefreshService.stop();
|
||||||
m.chai.expect(spy).to.have.been.calledOnce;
|
m.chai.expect(spy).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
@ -30,6 +33,7 @@ describe('Browser: DriveScanner', function() {
|
|||||||
it('should call the function in an interval', function() {
|
it('should call the function in an interval', function() {
|
||||||
var spy = m.sinon.spy();
|
var spy = m.sinon.spy();
|
||||||
DriveScannerRefreshService.every(spy, 100);
|
DriveScannerRefreshService.every(spy, 100);
|
||||||
|
$timeout.flush();
|
||||||
|
|
||||||
// 400ms = 100ms / 4 + 1 (the initial call)
|
// 400ms = 100ms / 4 + 1 (the initial call)
|
||||||
$interval.flush(400);
|
$interval.flush(400);
|
||||||
@ -45,11 +49,13 @@ describe('Browser: DriveScanner', function() {
|
|||||||
describe('DriveScannerService', function() {
|
describe('DriveScannerService', function() {
|
||||||
|
|
||||||
var $interval;
|
var $interval;
|
||||||
|
var $timeout;
|
||||||
var $q;
|
var $q;
|
||||||
var DriveScannerService;
|
var DriveScannerService;
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(function(_$interval_, _$q_, _DriveScannerService_) {
|
beforeEach(angular.mock.inject(function(_$interval_, _$timeout_, _$q_, _DriveScannerService_) {
|
||||||
$interval = _$interval_;
|
$interval = _$interval_;
|
||||||
|
$timeout = _$timeout_;
|
||||||
$q = _$q_;
|
$q = _$q_;
|
||||||
DriveScannerService = _DriveScannerService_;
|
DriveScannerService = _DriveScannerService_;
|
||||||
}));
|
}));
|
||||||
@ -169,6 +175,7 @@ describe('Browser: DriveScanner', function() {
|
|||||||
|
|
||||||
it('should set the drives to the scanned ones', function() {
|
it('should set the drives to the scanned ones', function() {
|
||||||
DriveScannerService.start(200);
|
DriveScannerService.start(200);
|
||||||
|
$timeout.flush();
|
||||||
$interval.flush(400);
|
$interval.flush(400);
|
||||||
m.chai.expect(DriveScannerService.drives).to.deep.equal(this.drives);
|
m.chai.expect(DriveScannerService.drives).to.deep.equal(this.drives);
|
||||||
DriveScannerService.stop();
|
DriveScannerService.stop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user