actions: Dispatch FETCH_END

... when the gateway request ends, per I62c9cb04.

Change-Id: Ifbed65d6b97877e859e81f256fa44344a64fc64f
This commit is contained in:
Sam Smith 2017-03-26 12:13:56 -07:00 committed by jdlrobson
parent 8b311aa159
commit 3646b04876
4 changed files with 28 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View file

@ -112,6 +112,11 @@ actions.fetch = function ( gateway, el, started ) {
var now = mw.now(),
delay;
dispatch( timedAction( {
type: types.FETCH_END,
el: el
} ) );
// If the API request has taken longer than the target delay, then
// don't delay any further.
delay = Math.max(

View file

@ -293,7 +293,7 @@ QUnit.test( 'it should delay dispatching the FETCH_COMPLETE action', function (
result = {},
done = assert.async( 2 );
assert.expect( 3 );
assert.expect( 4 );
this.fetch();
@ -309,18 +309,31 @@ QUnit.test( 'it should delay dispatching the FETCH_COMPLETE action', function (
done();
} );
this.waitPromise.then( function () {
// Let the wait.then execute to run the dispatch before asserting
setTimeout( function () {
assert.equal( that.dispatch.callCount, 2, 'dispatch called for start and end' );
assert.deepEqual( that.dispatch.getCall( 1 ).args[ 0 ], {
assert.equal( that.dispatch.callCount, 3, 'dispatch called for start and end' );
assert.deepEqual(
that.dispatch.getCall( 1 ).args[ 0 ],
{
type: 'FETCH_END',
el: that.el,
timestamp: 250
},
'It should dispatch the FETCH_END action when the gateway request ends.'
);
assert.deepEqual(
that.dispatch.getCall( 2 ).args[ 0 ],
{
type: 'FETCH_COMPLETE',
el: that.el,
result: result,
delay: 250,
timestamp: 250
} );
},
'It should dispatch the FETCH_COMPLETE action when the preview model is resolved.'
);
done();
} );