actions: Add token to LINK_ABANDON_*

Change-Id: I7f6187f6c0249c112a08163a343d35ee75cf85e8
This commit is contained in:
Sam Smith 2017-01-08 13:32:03 +00:00
parent 46cd38849e
commit 4d736b9a78
2 changed files with 25 additions and 8 deletions

View file

@ -200,17 +200,21 @@
* @return {Object} * @return {Object}
*/ */
actions.linkAbandon = function ( el ) { actions.linkAbandon = function ( el ) {
return function ( dispatch ) { return function ( dispatch, getState ) {
var token = getState().preview.activeToken;
dispatch( timedAction( { dispatch( timedAction( {
type: types.LINK_ABANDON_START, type: types.LINK_ABANDON_START,
el: el el: el,
token: token
} ) ); } ) );
mw.popups.wait( ABANDON_END_DELAY ) mw.popups.wait( ABANDON_END_DELAY )
.then( function () { .then( function () {
dispatch( { dispatch( {
type: types.LINK_ABANDON_END, type: types.LINK_ABANDON_END,
el: el el: el,
token: token
} ); } );
} ); } );
}; };

View file

@ -276,16 +276,25 @@
QUnit.test( 'it should dispatch start and end actions', function ( assert ) { QUnit.test( 'it should dispatch start and end actions', function ( assert ) {
var that = this, var that = this,
dispatch = that.sandbox.spy(), dispatch = that.sandbox.spy(),
token = '0123456789',
getState = function () {
return {
preview: {
activeToken: token
}
};
},
done = assert.async(); done = assert.async();
this.sandbox.stub( mw, 'now' ).returns( new Date() ); this.sandbox.stub( mw, 'now' ).returns( new Date() );
mw.popups.actions.linkAbandon( that.el )( dispatch ); mw.popups.actions.linkAbandon( that.el )( dispatch, getState );
assert.ok( dispatch.calledWith( { assert.ok( dispatch.calledWith( {
type: 'LINK_ABANDON_START', type: 'LINK_ABANDON_START',
el: that.el, el: that.el,
timestamp: mw.now() timestamp: mw.now(),
token: token
} ) ); } ) );
// --- // ---
@ -296,10 +305,14 @@
); );
that.waitPromise.then( function () { that.waitPromise.then( function () {
assert.ok( dispatch.calledWith( { assert.ok(
dispatch.calledWith( {
type: 'LINK_ABANDON_END', type: 'LINK_ABANDON_END',
el: that.el el: that.el,
} ) ); token: token
} ),
'LINK_ABANDON_* share the same token.'
);
done(); done();
} ); } );