Skip to content

Commit 2e5a362

Browse files
jrichter1dgolovin
authored andcommitted
Add tests
1 parent 244d9b5 commit 2e5a362

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

test/unit/pages/install/controller-test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe('Install controller', function() {
222222
expect(progress.current).equals(10);
223223
});
224224
it('lable value', function() {
225-
expect(progress.label).equals(
225+
expect(progress.label).to.have.string(
226226
progress.sizeInKB(progress.currentAmount) + ' / ' + progress.sizeInKB(progress.totalSize) + ' KB (' + progress.current + '%)'
227227
);
228228
});
@@ -278,6 +278,29 @@ describe('Install controller', function() {
278278
expect(progress.current).equals(100);
279279
});
280280
});
281+
describe('calculateTime', function() {
282+
let progress;
283+
beforeEach(function() {
284+
progress = new ProgressState();
285+
progress.lastTime = 100000;
286+
progress.totalSize = 9000000;
287+
progress.currentAmount = 400000;
288+
sandbox.stub(Date.prototype, 'getTime').returns(101000);
289+
});
290+
291+
it('returns time estimate based on average speed', function() {
292+
expect(progress.calculateTime()).to.equal((9000000 - 400000) / 400);
293+
});
294+
295+
it('uses exponential moving average speed', function() {
296+
progress.averageSpeed = 800;
297+
298+
//average speed moves with a smoothing factor
299+
let result = progress.calculateTime();
300+
expect(progress.averageSpeed).to.equal(0.15 * 400 + 0.85 * 800);
301+
expect(result).to.equal((9000000 - 400000) / (0.15 * 400 + 0.85 * 800));
302+
});
303+
});
281304
});
282305

283306
it('downloadAgain closes dialog with error and start download for failed installers', function() {

0 commit comments

Comments
 (0)