fix(GUI): bound flash progress percentage within 0-100 (#1258)

We limit the Store state flashing percentage to be within 0-100,
throwing errors otherwise. Comes with tests.

Changelog-Type: Bound flash progress percentage within 0-100 range.
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Benedict Aas 2017-05-10 00:24:44 +01:00 committed by Juan Cruz Viotti
parent df74a2763c
commit efa7f986a4
2 changed files with 26 additions and 1 deletions

View File

@ -26,6 +26,7 @@ const supportedFormats = require('../../shared/supported-formats');
const errors = require('../../shared/errors');
const release = require('../../shared/release');
const fileExtensions = require('../../shared/file-extensions');
const utils = require('../../shared/utils');
const packageJSON = require('../../../package.json');
/**
@ -203,7 +204,7 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
});
}
if (!_.isNumber(action.data.percentage)) {
if (!utils.isValidPercentage(action.data.percentage)) {
throw errors.createError({
title: `Invalid state percentage: ${action.data.percentage}`
});

View File

@ -143,6 +143,30 @@ describe('Browser: flashState', function() {
}).to.throw('Invalid state percentage: 50');
});
it('should throw if percentage is outside maximum bound', function() {
flashState.setFlashingFlag();
m.chai.expect(function() {
flashState.setProgressState({
type: 'write',
percentage: 101,
eta: 15,
speed: 0
});
}).to.throw('Invalid state percentage: 101');
});
it('should throw if percentage is outside minimum bound', function() {
flashState.setFlashingFlag();
m.chai.expect(function() {
flashState.setProgressState({
type: 'write',
percentage: -1,
eta: 15,
speed: 0
});
}).to.throw('Invalid state percentage: -1');
});
it('should throw if eta is missing', function() {
flashState.setFlashingFlag();
m.chai.expect(function() {