mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 07:17:18 +00:00
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:
parent
df74a2763c
commit
efa7f986a4
@ -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}`
|
||||
});
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user