2016-11-16 19:45:10 +00:00
|
|
|
( function ( mw, $ ) {
|
2016-11-14 19:37:11 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups/actions' );
|
|
|
|
|
2016-11-16 19:45:10 +00:00
|
|
|
QUnit.test( '#boot', function ( assert ) {
|
2016-11-14 19:37:11 +00:00
|
|
|
var isUserInCondition = function () {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
sessionID = '0123456789',
|
|
|
|
generateToken = function () {
|
|
|
|
return '9876543210';
|
|
|
|
};
|
|
|
|
|
2016-11-16 19:45:10 +00:00
|
|
|
assert.expect( 1 );
|
|
|
|
|
2016-11-14 19:37:11 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
mw.popups.actions.boot( isUserInCondition, sessionID, generateToken ),
|
|
|
|
{
|
|
|
|
type: 'BOOT',
|
|
|
|
isUserInCondition: false,
|
|
|
|
sessionToken: '0123456789',
|
|
|
|
pageToken: '9876543210'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2016-11-16 19:45:10 +00:00
|
|
|
QUnit.module( 'ext.popups/actions#linkDwell @integration', {
|
|
|
|
setup: function () {
|
|
|
|
var that = this;
|
|
|
|
|
2016-11-21 11:08:06 +00:00
|
|
|
that.el = $( '<a>' )
|
2016-11-16 19:45:10 +00:00
|
|
|
.data( 'page-previews-title', 'Foo' )
|
|
|
|
.eq( 0 );
|
|
|
|
|
|
|
|
that.state = {};
|
|
|
|
that.getState = function () {
|
|
|
|
return that.state;
|
|
|
|
};
|
2016-11-25 10:40:33 +00:00
|
|
|
|
|
|
|
that.waitDeferred = $.Deferred();
|
|
|
|
that.waitPromise = that.waitDeferred.promise();
|
|
|
|
|
|
|
|
that.sandbox.stub( mw.popups, 'wait', function () {
|
|
|
|
return that.waitPromise;
|
|
|
|
} );
|
2016-11-16 19:45:10 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( '#linkDwell', function ( assert ) {
|
2016-11-25 10:40:33 +00:00
|
|
|
var done = assert.async(),
|
2016-11-21 11:08:06 +00:00
|
|
|
event = {},
|
2016-11-16 19:45:10 +00:00
|
|
|
dispatch = this.sandbox.spy(),
|
|
|
|
gatewayDeferred = $.Deferred(),
|
|
|
|
gateway = function () {
|
|
|
|
return gatewayDeferred;
|
2016-11-25 10:40:33 +00:00
|
|
|
},
|
|
|
|
fetchThunk,
|
|
|
|
result = {};
|
2016-11-16 19:45:10 +00:00
|
|
|
|
2016-11-21 11:08:06 +00:00
|
|
|
this.sandbox.stub( mw, 'now' ).returns( new Date() );
|
|
|
|
|
|
|
|
mw.popups.actions.linkDwell( this.el, event, gateway )( dispatch, this.getState );
|
2016-11-16 19:45:10 +00:00
|
|
|
|
|
|
|
assert.ok( dispatch.calledWith( {
|
|
|
|
type: 'LINK_DWELL',
|
2016-11-21 11:08:06 +00:00
|
|
|
el: this.el,
|
|
|
|
event: event,
|
|
|
|
interactionStarted: mw.now()
|
2016-11-16 19:45:10 +00:00
|
|
|
} ) );
|
|
|
|
|
|
|
|
// Stub the state tree being updated.
|
|
|
|
this.state.preview = {
|
|
|
|
activeLink: this.el
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2016-11-25 10:40:33 +00:00
|
|
|
this.waitPromise.then( function () {
|
2016-11-16 19:45:10 +00:00
|
|
|
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',
|
|
|
|
title: 'Foo'
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
gatewayDeferred.resolve( result );
|
|
|
|
|
|
|
|
assert.ok( dispatch.calledWith( {
|
|
|
|
type: 'FETCH_END',
|
|
|
|
result: result
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
done();
|
2016-11-25 10:40:33 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// After 500 ms...
|
|
|
|
this.waitDeferred.resolve();
|
2016-11-16 19:45:10 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
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.
|
|
|
|
};
|
|
|
|
|
2016-11-25 10:40:33 +00:00
|
|
|
this.waitPromise.then( function () {
|
2016-11-16 19:45:10 +00:00
|
|
|
assert.strictEqual( dispatch.callCount, 1 );
|
|
|
|
|
|
|
|
done();
|
2016-11-25 10:40:33 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// After 500 ms...
|
|
|
|
this.waitDeferred.resolve();
|
2016-11-16 19:45:10 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
}( mediaWiki, jQuery ) );
|