fix: don't allow to set the flashing state if not flashing (#519)

Currently, we allow updating the flashing state independently on the
value of the `flashing` property.

In order to maintain the application state coherent, we deny updating
the flashing state if we're not currently flashing, which lets us safely
assume that the state will be in a reset state if we're not flashing.

Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-06-23 15:38:40 -04:00 committed by GitHub
parent 2ecf9d32a7
commit 5ac5f3a423
2 changed files with 20 additions and 0 deletions

View File

@ -86,6 +86,10 @@ const store = function(state, action) {
}
case 'SET_FLASH_STATE': {
if (!state.getIn([ 'flash', 'flashing' ])) {
throw new Error('Can\'t set the flashing state when not flashing');
}
return state.setIn([ 'flash', 'state' ], Immutable.fromJS(action.data));
}

View File

@ -67,6 +67,22 @@ describe('Browser: ImageWriter', function() {
});
describe('.setProgressState()', function() {
it('should not allow setting the state if flashing is false', function() {
ImageWriterService.setFlashing(false);
m.chai.expect(function() {
ImageWriterService.setProgressState({
type: 'write',
percentage: 50,
eta: 15,
speed: 100000000000
});
}).to.throw('Can\'t set the flashing state when not flashing');
});
});
describe('.setFlashing()', function() {
it('should be able to set flashing to true', function() {