Phuedx has uploaded a new change for review.
https://gerrit.wikimedia.org/r/322634
Change subject: actions: Include event in LINK_DWELL action
......................................................................
actions: Include event in LINK_DWELL action
Also include the time at which the interaction started.
Change-Id: Ie46562a2641e8bd26fc687e16e4e7ef3760824b1
---
M resources/ext.popups/actions.js
M resources/ext.popups/boot.js
M resources/ext.popups/reducers.js
M tests/qunit/ext.popups/actions.test.js
M tests/qunit/ext.popups/reducers.test.js
5 files changed, 52 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups
refs/changes/34/322634/1
diff --git a/resources/ext.popups/actions.js b/resources/ext.popups/actions.js
index c6c4a51..cacbad4 100644
--- a/resources/ext.popups/actions.js
+++ b/resources/ext.popups/actions.js
@@ -78,14 +78,17 @@
* their mouse or by focussing it using their keyboard or an assistive
device.
*
* @param {Element} el
- * @param {Function} gateway
+ * @param {Event} event
+ * @param {ext.popups.Gateway} gateway
* @return {Redux.Thunk}
*/
- actions.linkDwell = function ( el, gateway ) {
+ actions.linkDwell = function ( el, event, gateway ) {
return function ( dispatch, getState ) {
dispatch( {
type: types.LINK_DWELL,
- el: el
+ el: el,
+ event: event,
+ interactionStarted: mw.now()
} );
setTimeout( function () {
diff --git a/resources/ext.popups/boot.js b/resources/ext.popups/boot.js
index db54fdc..cdc2844 100644
--- a/resources/ext.popups/boot.js
+++ b/resources/ext.popups/boot.js
@@ -111,8 +111,8 @@
);
previewLinks
- .on( 'mouseover focus', function () {
- actions.linkDwell( this, gateway );
+ .on( 'mouseover focus', function ( event ) {
+ actions.linkDwell( this, event, gateway
);
} )
.on( 'mouseout blur', function () {
actions.linkAbandon( this );
diff --git a/resources/ext.popups/reducers.js b/resources/ext.popups/reducers.js
index 080bc25..442aee7 100644
--- a/resources/ext.popups/reducers.js
+++ b/resources/ext.popups/reducers.js
@@ -43,6 +43,7 @@
pageToken: undefined,
linkInteractionToken: undefined,
activeLink: undefined,
+ activeEvent: undefined,
interactionStarted: undefined,
isDelayingFetch: false,
isFetching: false
@@ -59,6 +60,7 @@
case mw.popups.actionTypes.LINK_DWELL:
return nextState( state, {
activeLink: action.el,
+ activeEvent: action.event,
interactionStarted:
action.interactionStarted,
isDelayingFetch: true,
linkInteractionToken:
action.linkInteractionToken
diff --git a/tests/qunit/ext.popups/actions.test.js
b/tests/qunit/ext.popups/actions.test.js
index e46b92d..72a2fb4 100644
--- a/tests/qunit/ext.popups/actions.test.js
+++ b/tests/qunit/ext.popups/actions.test.js
@@ -28,7 +28,7 @@
setup: function () {
var that = this;
- this.el = $( '<a>' )
+ that.el = $( '<a>' )
.data( 'page-previews-title', 'Foo' )
.eq( 0 );
@@ -41,19 +41,24 @@
QUnit.test( '#linkDwell', function ( assert ) {
var done,
+ event = {},
dispatch = this.sandbox.spy(),
gatewayDeferred = $.Deferred(),
gateway = function () {
return gatewayDeferred;
};
+ this.sandbox.stub( mw, 'now' ).returns( new Date() );
+
done = assert.async();
- mw.popups.actions.linkDwell( this.el, gateway )( dispatch,
this.getState );
+ mw.popups.actions.linkDwell( this.el, event, gateway )(
dispatch, this.getState );
assert.ok( dispatch.calledWith( {
type: 'LINK_DWELL',
- el: this.el
+ el: this.el,
+ event: event,
+ interactionStarted: mw.now()
} ) );
// Stub the state tree being updated.
diff --git a/tests/qunit/ext.popups/reducers.test.js
b/tests/qunit/ext.popups/reducers.test.js
index 5959c4b..a6d2145 100644
--- a/tests/qunit/ext.popups/reducers.test.js
+++ b/tests/qunit/ext.popups/reducers.test.js
@@ -1,4 +1,4 @@
-( function ( mw ) {
+( function ( mw, $ ) {
QUnit.module( 'ext.popups/reducers' );
@@ -16,6 +16,7 @@
pageToken: undefined,
linkInteractionToken: undefined,
activeLink: undefined,
+ activeEvent: undefined,
interactionStarted: undefined,
isDelayingFetch: false,
isFetching: false
@@ -32,14 +33,16 @@
QUnit.test( '#preview', function ( assert ) {
var state = mw.popups.reducers.preview( undefined, { type:
'@@INIT' } ),
- action = {
- type: 'BOOT',
- isUserInCondition: true,
- sessionToken: '0123456789',
- pageToken: '9876543210'
- };
+ action;
- assert.expect( 1 );
+ assert.expect( 2 );
+
+ action = {
+ type: 'BOOT',
+ isUserInCondition: true,
+ sessionToken: '0123456789',
+ pageToken: '9876543210'
+ };
assert.deepEqual(
mw.popups.reducers.preview( state, action ),
@@ -51,6 +54,28 @@
isFetching: false
},
'It should set enabled and the session tokens on the
BOOT action'
+ );
+
+ // ---
+ action = {
+ type: 'LINK_DWELL',
+ el: $( '<a>' ),
+ event: {},
+ interactionStarted: mw.now(),
+ linkInteractionToken: '0123456789'
+ };
+
+ assert.deepEqual(
+ mw.popups.reducers.preview( state, action ),
+ {
+ activeLink: action.el,
+ activeEvent: action.event,
+ isDelayingFetch: true,
+ isFetching: false,
+ interactionStarted: action.interactionStarted,
+ linkInteractionToken:
action.linkInteractionToken
+ },
+ 'It should set active link and event as well as
interaction info on the LINK_DWELL action'
);
} );
@@ -67,5 +92,5 @@
'It should set isAnimating to true on the
PREVIEW_ANIMATING action'
);
} );
-}( mediaWiki ) );
+}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/322634
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie46562a2641e8bd26fc687e16e4e7ef3760824b1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: mpga
Gerrit-Owner: Phuedx <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits