mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-19 05:15:52 +00:00
eabb7011fb
If the user abandons the link after the API request delay (500 ms) but before the it resolves (~10e3 ms), then the preview shouldn't be rendered. Changes: * actions: Include the link in the FETCH_START, FETCH_FAILED, and FETCH_END actions. * reducers: If the active link has changed, then FETCH_END is a NOOP. Supporting changes: * reducers: Signal that a preview should be rendered and shown with preview.shouldShow. Change-Id: I3dd1c0c566ec63de515174c14845d7927583ce93
135 lines
2.7 KiB
JavaScript
135 lines
2.7 KiB
JavaScript
( function ( mw, $ ) {
|
|
|
|
QUnit.module( 'ext.popups/actions' );
|
|
|
|
QUnit.test( '#boot', function ( assert ) {
|
|
var isUserInCondition = function () {
|
|
return false;
|
|
},
|
|
sessionID = '0123456789',
|
|
generateToken = function () {
|
|
return '9876543210';
|
|
};
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.actions.boot( isUserInCondition, sessionID, generateToken ),
|
|
{
|
|
type: 'BOOT',
|
|
isUserInCondition: false,
|
|
sessionToken: '0123456789',
|
|
pageToken: '9876543210'
|
|
}
|
|
);
|
|
} );
|
|
|
|
QUnit.module( 'ext.popups/actions#linkDwell @integration', {
|
|
setup: function () {
|
|
var that = this;
|
|
|
|
that.el = $( '<a>' )
|
|
.data( 'page-previews-title', 'Foo' )
|
|
.eq( 0 );
|
|
|
|
that.state = {};
|
|
that.getState = function () {
|
|
return that.state;
|
|
};
|
|
|
|
that.waitDeferred = $.Deferred();
|
|
that.waitPromise = that.waitDeferred.promise();
|
|
|
|
that.sandbox.stub( mw.popups, 'wait', function () {
|
|
return that.waitPromise;
|
|
} );
|
|
}
|
|
} );
|
|
|
|
QUnit.test( '#linkDwell', function ( assert ) {
|
|
var done = assert.async(),
|
|
event = {},
|
|
dispatch = this.sandbox.spy(),
|
|
gatewayDeferred = $.Deferred(),
|
|
gateway = function () {
|
|
return gatewayDeferred;
|
|
},
|
|
el = this.el,
|
|
fetchThunk,
|
|
result = {};
|
|
|
|
this.sandbox.stub( mw, 'now' ).returns( new Date() );
|
|
|
|
mw.popups.actions.linkDwell( el, event, gateway )( dispatch, this.getState );
|
|
|
|
assert.ok( dispatch.calledWith( {
|
|
type: 'LINK_DWELL',
|
|
el: el,
|
|
event: event,
|
|
interactionStarted: mw.now()
|
|
} ) );
|
|
|
|
// Stub the state tree being updated.
|
|
this.state.preview = {
|
|
activeLink: el
|
|
};
|
|
|
|
// ---
|
|
|
|
this.waitPromise.then( function () {
|
|
assert.strictEqual(
|
|
dispatch.callCount,
|
|
2,
|
|
'The fetch action is dispatched after 500 ms'
|
|
);
|
|
|
|
fetchThunk = dispatch.secondCall.args[0];
|
|
fetchThunk( dispatch );
|
|
|
|
assert.ok( dispatch.calledWith( {
|
|
type: 'FETCH_START',
|
|
el: el,
|
|
title: 'Foo'
|
|
} ) );
|
|
|
|
// ---
|
|
|
|
gatewayDeferred.resolve( result );
|
|
|
|
assert.ok( dispatch.calledWith( {
|
|
type: 'FETCH_END',
|
|
el: el,
|
|
result: result
|
|
} ) );
|
|
|
|
done();
|
|
} );
|
|
|
|
// After 500 ms...
|
|
this.waitDeferred.resolve();
|
|
} );
|
|
|
|
QUnit.test( '#linkDwell doesn\'t dispatch the fetch action if the active link has changed', function ( assert ) {
|
|
var done,
|
|
dispatch = this.sandbox.spy();
|
|
|
|
done = assert.async();
|
|
|
|
mw.popups.actions.linkDwell( this.el /*, gateway */ )( dispatch, this.getState );
|
|
|
|
this.state.preview = {
|
|
activeLink: undefined // Any value other than this.el.
|
|
};
|
|
|
|
this.waitPromise.then( function () {
|
|
assert.strictEqual( dispatch.callCount, 1 );
|
|
|
|
done();
|
|
} );
|
|
|
|
// After 500 ms...
|
|
this.waitDeferred.resolve();
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|