diff --git a/lib/gui/models/store.js b/lib/gui/models/store.js index 2914407f..bb4193e0 100644 --- a/lib/gui/models/store.js +++ b/lib/gui/models/store.js @@ -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}` }); diff --git a/tests/gui/models/flash-state.spec.js b/tests/gui/models/flash-state.spec.js index 39df0340..43753924 100644 --- a/tests/gui/models/flash-state.spec.js +++ b/tests/gui/models/flash-state.spec.js @@ -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() {