Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitm@lovullo.com>2016-04-21 16:23:41 -0400
committerMike Gerwitz <gerwitm@lovullo.com>2016-04-21 16:23:41 -0400
commit0a8329b405370e81b759e1e79906270d5e0a7371 (patch)
treef7a9f501903ea464b5a72884ee0475867944d626 /test/validate
parent98fefd537eefc5d221e749a021e9c9311bf3c525 (diff)
downloadliza-0a8329b405370e81b759e1e79906270d5e0a7371.tar.gz
liza-0a8329b405370e81b759e1e79906270d5e0a7371.tar.bz2
liza-0a8329b405370e81b759e1e79906270d5e0a7371.zip
Support multiple validation failure causes
* src/validate/Failure.js (__construct): Takes an array of causes. (getCauses): Now returns an array of causes. * src/validate/ValidStateMonitor.js: Recognize fixes on array of causes. * test/validate/FailureTest.js: Updated * test/validate/ValidStateMonitorTest.js: Updated
Diffstat (limited to 'test/validate')
-rw-r--r--test/validate/FailureTest.js32
-rw-r--r--test/validate/ValidStateMonitorTest.js43
2 files changed, 61 insertions, 14 deletions
diff --git a/test/validate/FailureTest.js b/test/validate/FailureTest.js
index e9abd3f..9b97e1a 100644
--- a/test/validate/FailureTest.js
+++ b/test/validate/FailureTest.js
@@ -43,12 +43,28 @@ describe( 'Failure', function()
} );
- it( 'throws error when not given a Field for cause', function()
+ it( 'throws error when not given a Field for causes', function()
{
expect( function()
{
+ // not an array
Sut( DummyField(), '', {} );
} ).to.throw( TypeError );
+
+ expect( function()
+ {
+ // one not a Field
+ Sut( DummyField(), '', [ DummyField(), {} ] );
+ } ).to.throw( TypeError );
+ } );
+
+
+ it( 'does not throw error for empty clause list', function()
+ {
+ expect( function()
+ {
+ Sut( DummyField(), '', [] );
+ } ).to.not.throw( TypeError );
} );
@@ -83,14 +99,14 @@ describe( 'Failure', function()
} );
- describe( '#getCause', function()
+ describe( '#getCauses', function()
{
- it( 'returns original cause field', function()
+ it( 'returns original cause fields', function()
{
- var cause = DummyField();
+ var causes = [ DummyField(), DummyField() ];
- expect( Sut( DummyField(), '', cause ).getCause() )
- .to.equal( cause );
+ expect( Sut( DummyField(), '', causes ).getCauses() )
+ .to.equal( causes );
} );
@@ -99,8 +115,8 @@ describe( 'Failure', function()
{
var field = DummyField();
- expect( Sut( field ).getCause() )
- .to.equal( field );
+ expect( Sut( field ).getCauses() )
+ .to.deep.equal( [ field ] );
} );
} );
diff --git a/test/validate/ValidStateMonitorTest.js b/test/validate/ValidStateMonitorTest.js
index 084adf7..52f3705 100644
--- a/test/validate/ValidStateMonitorTest.js
+++ b/test/validate/ValidStateMonitorTest.js
@@ -214,7 +214,7 @@ describe( 'ValidStateMonitor', function()
var data = { cause: [ 'bar' ] },
field = Field( 'foo', 0 ),
cause = Field( 'cause', 0 ),
- fail = Failure( field, 'reason', cause );
+ fail = Failure( field, 'reason', [ cause ] );
Sut()
.on( 'fix', function( fixed )
@@ -235,7 +235,33 @@ describe( 'ValidStateMonitor', function()
var data = { cause: [ undefined, 'bar' ] },
field = Field( 'foo', 0 ),
cause = Field( 'cause', 1 ),
- fail = Failure( field, 'reason', cause );
+ 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 any number of causes', function( done )
+ {
+ // different index
+ var data = { cause_fix: [ undefined, 'bar' ] },
+ field = Field( 'foo', 0 ),
+ cause1 = Field( 'cause_no', 1 ),
+ cause2 = Field( 'cause_fix', 1 ),
+ fail = Failure(
+ field,
+ 'reason',
+ [ cause1, cause2 ]
+ );
Sut()
.on( 'fix', function( fixed )
@@ -253,10 +279,15 @@ describe( 'ValidStateMonitor', function()
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 );
+ var data = { noncause: [ undefined, 'bar' ] },
+ field = Field( 'foo', 0 ),
+ cause1 = Field( 'cause', 1 ),
+ cause2 = Field( 'cause', 2 ),
+ fail = Failure(
+ field,
+ 'reason',
+ [ cause1, cause2 ]
+ );
Sut()
.on( 'fix', nocall )