From d16d5469fd8785dc06ccb0cc599585f96f219f62 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 24 Jun 2016 09:47:24 -0400 Subject: [PATCH] fix: don't throw missing eta if eta is zero (#528) The commit 0f8136f, which enforced validation for the state object, introduced a subtle bug where `Missing state eta` would be thrown if `eta === 0`, since `!0` evaluates to `true`. This would cause the flashing to stop right at the end (when eta is zero). Signed-off-by: Juan Cruz Viotti --- lib/gui/models/store.js | 2 +- tests/gui/modules/image-writer.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/gui/models/store.js b/lib/gui/models/store.js index f0d58b12..b6811809 100644 --- a/lib/gui/models/store.js +++ b/lib/gui/models/store.js @@ -123,7 +123,7 @@ const storeReducer = (state, action) => { throw new Error(`Invalid state percentage: ${action.data.percentage}`); } - if (!action.data.eta) { + if (!action.data.eta && action.data.eta !== 0) { throw new Error('Missing state eta'); } diff --git a/tests/gui/modules/image-writer.spec.js b/tests/gui/modules/image-writer.spec.js index 4d74b72e..3fbb4c97 100644 --- a/tests/gui/modules/image-writer.spec.js +++ b/tests/gui/modules/image-writer.spec.js @@ -138,6 +138,18 @@ describe('Browser: ImageWriter', function() { }).to.throw('Missing state eta'); }); + it('should not throw if eta is equal to zero', function() { + ImageWriterService.setFlashing(true); + m.chai.expect(function() { + ImageWriterService.setProgressState({ + type: 'write', + percentage: 50, + eta: 0, + speed: 100000000000 + }); + }).to.not.throw('Missing state eta'); + }); + it('should throw if eta is not a number', function() { ImageWriterService.setFlashing(true); m.chai.expect(function() {