Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2016-04-28 11:53:14 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2016-04-28 11:53:14 -0400
commite6ede4ad3aa58baea85fa69938fd83e73963728a (patch)
tree5630ac18874bcdd11f174873033e9ce051c4a807 /test/validate
parente406c198d2a8004fec6d031481e01d862cdda2dd (diff)
downloadliza-e6ede4ad3aa58baea85fa69938fd83e73963728a.tar.gz
liza-e6ede4ad3aa58baea85fa69938fd83e73963728a.tar.bz2
liza-e6ede4ad3aa58baea85fa69938fd83e73963728a.zip
ValidStateMonitor: merge subsequent failures before fixes
* src/validate/ValidStateMonitor.js (mergeFailures): Another error on a field that previously failed will no longer overwrite the previous failure, which caused issue when the causes changed (leaving fields potentially unfixed). * test/validate/ValidStateMonitorTest.js: Respective tests added.
Diffstat (limited to 'test/validate')
-rw-r--r--test/validate/ValidStateMonitorTest.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/validate/ValidStateMonitorTest.js b/test/validate/ValidStateMonitorTest.js
index 52f3705..fa3db01 100644
--- a/test/validate/ValidStateMonitorTest.js
+++ b/test/validate/ValidStateMonitorTest.js
@@ -147,6 +147,50 @@ describe( 'ValidStateMonitor', function()
.on( 'fix', nocall( 'fix' ) )
.update( {}, { foo: fail } );
} );
+
+
+ it( 'does not discard existing failures', function( done )
+ {
+ var sut = Sut();
+
+ // has both failures
+ var fail1 = Failure(
+ Field( 'foo', 0 ),
+ '',
+ [ Field( 'cause1', 0 ), Field( 'cause2', 0 ) ]
+ );
+
+ // has only one of the two failures
+ var fail2 = Failure(
+ Field( 'foo', 1 ),
+ '',
+ [ Field( 'cause2', 1 ) ]
+ );
+
+ // the second failure has fewer causes than the first;
+ // we need to make sure that it doesn't overwrite,
+ // leading to fewer caues
+ sut
+ .update( {}, { foo: [ fail1 ] } )
+ .update( {}, { foo: [ fail2 ] } );
+
+ // if cause1 wasn't removed, then this will fix it
+ sut
+ .once( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'causefix1' ] } );
+
+ // and then we should have no failures
+ expect( sut.hasFailures() ).to.be.false;
+
+ done();
+ } )
+ .update(
+ { foo: [ 'moo' ], cause1: [ 'causefix1' ] },
+ {}
+ );
+ } );
} );