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.master
parent
e406c198d2
commit
e6ede4ad3a
|
@ -146,10 +146,18 @@ module.exports = Class( 'ValidStateMonitor' )
|
||||||
{
|
{
|
||||||
past[ name ] = past[ name ] || [];
|
past[ name ] = past[ name ] || [];
|
||||||
|
|
||||||
|
var cur_past = past[ name ];
|
||||||
|
|
||||||
// copy each failure into the past failures table
|
// copy each failure into the past failures table
|
||||||
for ( var i in failures[ name ] )
|
for ( var i in failures[ name ] )
|
||||||
{
|
{
|
||||||
past[ name ][ i ] = failures[ name ][ i ];
|
var new_failure = failures[ name ][ i ];
|
||||||
|
|
||||||
|
// merge with past failure if present
|
||||||
|
cur_past[ i ] = ( cur_past[ i ] !== undefined )
|
||||||
|
? cur_past[ i ].merge( new_failure )
|
||||||
|
: new_failure;
|
||||||
|
|
||||||
count_new++;
|
count_new++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,50 @@ describe( 'ValidStateMonitor', function()
|
||||||
.on( 'fix', nocall( 'fix' ) )
|
.on( 'fix', nocall( 'fix' ) )
|
||||||
.update( {}, { foo: fail } );
|
.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' ] },
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue