From 28d74d70685e0824b5895979d7603587c87b651b Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 29 Jan 2017 23:21:14 -0500 Subject: [PATCH] ValidStateMonitor: handle empty diff on past failure See the description in the test case. This is a bug fix. * src/validate/ValidStateMonitor.js (_checkCauseFix): Do not consider an empty diff on a past failure to be a fix. * test/validate/ValidStateMonitorTest.js: Add test. DEV-2296 --- src/validate/ValidStateMonitor.js | 5 ++--- test/validate/ValidStateMonitorTest.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/validate/ValidStateMonitor.js b/src/validate/ValidStateMonitor.js index 59d4b66..9fb6ef5 100644 --- a/src/validate/ValidStateMonitor.js +++ b/src/validate/ValidStateMonitor.js @@ -298,9 +298,8 @@ module.exports = Class( 'ValidStateMonitor' ) // and there must be data for this index for the field // in question (if the field wasn't touched, then of // course there's no failure!) - if ( ( fail === undefined ) - || ( !( fail[ cause_index ] ) - && ( field[ cause_index ] !== undefined ) ) + if ( ( ( fail === undefined ) || !( fail[ cause_index ] ) ) + && ( field[ cause_index ] !== undefined ) ) { found( field[ cause_index ] ); diff --git a/test/validate/ValidStateMonitorTest.js b/test/validate/ValidStateMonitorTest.js index 75dab73..52dc272 100644 --- a/test/validate/ValidStateMonitorTest.js +++ b/test/validate/ValidStateMonitorTest.js @@ -318,6 +318,25 @@ describe( 'ValidStateMonitor', function() } ); + // if a diff is present for a previously failed key (e.g. foo), + // but contains no changes (e.g. [ undefined ]), and doesn't + // include the failure on the second call, then it should not be + // considered to be a fix (this is a bugfix) + it( 'keeps past failures on key if failure does not reoccur', () => + { + const fail_past = mkfail( 'foo', [ 'bar', 'baz' ] ); + + return mkstore( { foo: [ undefined, undefined ] } ) + .then( data => + Sut() + .update( data, { foo: fail_past } ) + // no failure or fix (foo has no updates) + .then( sut => sut.update( data, {} ) ) + .then( sut => expect( sut.hasFailures() ).to.be.true ) + ); + } ); + + it( 'does not trigger failure event for existing', function() { var called = 0;