Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2016-04-20 12:11:17 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2016-04-20 12:11:17 -0400
commitf624710451b5955ee6d96fcc2fdf351dc491cc82 (patch)
tree2da3d69dd9cc52bac84197a2dd678047349d5652 /test
parentf784db5f2bafe3200c1130478f91317c0ff97ffb (diff)
downloadliza-f624710451b5955ee6d96fcc2fdf351dc491cc82.tar.gz
liza-f624710451b5955ee6d96fcc2fdf351dc491cc82.tar.bz2
liza-f624710451b5955ee6d96fcc2fdf351dc491cc82.zip
Consider field failure cause when checking fixes
This maintains BC with the old string-based system. * src/validate/ValidStateMonitor.js (_getCause): Added. (detectFixes): Consider failure cause if available when checking for fixes.
Diffstat (limited to 'test')
-rw-r--r--test/validate/ValidStateMonitorTest.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/validate/ValidStateMonitorTest.js b/test/validate/ValidStateMonitorTest.js
index 6ce9dcd..084adf7 100644
--- a/test/validate/ValidStateMonitorTest.js
+++ b/test/validate/ValidStateMonitorTest.js
@@ -204,6 +204,66 @@ describe( 'ValidStateMonitor', function()
expect( called ).to.equal( 1 );
} );
+
+
+ describe( 'given a cause', function()
+ {
+ it( 'considers when recognizing fix', function( done )
+ {
+ // same index
+ var data = { cause: [ 'bar' ] },
+ field = Field( 'foo', 0 ),
+ cause = Field( 'cause', 0 ),
+ fail = Failure( field, 'reason', cause );
+
+ Sut()
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'bar' ] } );
+
+ done();
+ } )
+ .update( data, { foo: [ fail ] } )
+ .update( data, {} );
+ } );
+
+
+ it( 'considers different cause index', function( done )
+ {
+ // different index
+ var data = { cause: [ undefined, 'bar' ] },
+ field = Field( 'foo', 0 ),
+ cause = Field( 'cause', 1 ),
+ fail = Failure( field, 'reason', cause );
+
+ Sut()
+ .on( 'fix', function( fixed )
+ {
+ expect( fixed )
+ .to.deep.equal( { foo: [ 'bar' ] } );
+
+ done();
+ } )
+ .update( data, { foo: [ fail ] } )
+ .update( data, {} );
+ } );
+
+
+ it( 'recognizes non-fix', function()
+ {
+ // no cause data
+ var data = { noncause: [ undefined, 'bar' ] },
+ field = Field( 'foo', 0 ),
+ cause = Field( 'cause', 1 ),
+ fail = Failure( field, 'reason', cause );
+
+ Sut()
+ .on( 'fix', nocall )
+ .update( data, { foo: [ fail ] } )
+ .update( data, {} );
+ } );
+ } );
} );