Phuedx has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/331339 )

Change subject: actions: Conditionally dispatch LINK_DWELL
......................................................................

actions: Conditionally dispatch LINK_DWELL

Change-Id: I9046296f061677674f9ad991ec6dacd1dd9db65c
---
M resources/ext.popups/actions.js
M tests/qunit/ext.popups/actions.test.js
2 files changed, 51 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/39/331339/1

diff --git a/resources/ext.popups/actions.js b/resources/ext.popups/actions.js
index 996eadb..aa26148 100644
--- a/resources/ext.popups/actions.js
+++ b/resources/ext.popups/actions.js
@@ -160,7 +160,7 @@
                                .then( function () {
                                        var previewState = getState().preview;
 
-                                       if ( previewState.enabled && 
previewState.activeLink === el ) {
+                                       if ( previewState.enabled && 
previewState.activeToken === token ) {
                                                dispatch( fetch( gateway, el ) 
);
                                        }
                                } );
diff --git a/tests/qunit/ext.popups/actions.test.js 
b/tests/qunit/ext.popups/actions.test.js
index 8519adf..c162823 100644
--- a/tests/qunit/ext.popups/actions.test.js
+++ b/tests/qunit/ext.popups/actions.test.js
@@ -118,7 +118,8 @@
                // Stub the state tree being updated.
                this.state.preview = {
                        enabled: true,
-                       activeLink: el
+                       activeLink: el,
+                       activeToken: generateToken()
                };
 
                // ---
@@ -156,43 +157,59 @@
                this.waitDeferred.resolve();
        } );
 
-       QUnit.test( '#linkDwell doesn\'t dispatch under certain conditions', 
function ( assert ) {
-               var cases,
-                       done,
-                       that = this,
-                       event = {};
+       QUnit.test( '#linkDwell doesn\'t continue when previews are disabled', 
function ( assert ) {
+               var done = assert.async(),
+                       event = {},
+                       dispatch = this.sandbox.spy();
 
-               cases = [
-                       {
-                               enabled: false
-                       },
-                       {
-                               enabled: true,
-                               activeLink: undefined // Any value other than 
this.el.
-                       }
-               ];
+               mw.popups.actions.linkDwell( this.el, event, /* gateway = */ 
null, generateToken )(
+                       dispatch,
+                       this.getState
+               );
 
-               done = assert.async( cases.length );
+               this.state.preview = {
+                       enabled: false
+               };
 
-               $.each( cases, function ( testCase ) {
-                       var dispatch = that.sandbox.spy();
+               this.waitPromise.then( function () {
+                       assert.strictEqual( dispatch.callCount, 1 );
 
-                       mw.popups.actions.linkDwell( that.el, event, /* gateway 
= */ null, generateToken )(
-                               dispatch,
-                               that.getState
-                       );
-
-                       that.state.preview = testCase;
-
-                       that.waitPromise.then( function () {
-                               assert.strictEqual( dispatch.callCount, 1 );
-
-                               done();
-                       } );
-
-                       // After 500 ms...
-                       that.waitDeferred.resolve();
+                       done();
                } );
+
+               // After 500 ms...
+               this.waitDeferred.resolve();
+       } );
+
+       QUnit.test( '#linkDwell doesn\'t continue if the token has changed', 
function ( assert ) {
+               var done = assert.async(),
+                       event = {},
+                       dispatch = this.sandbox.spy();
+
+               mw.popups.actions.linkDwell( this.el, event, /* gateway = */ 
null, generateToken )(
+                       dispatch,
+                       this.getState
+               );
+
+               this.state.preview = {
+                       enabled: true,
+
+                       // Consider the user tabbing back and forth between two 
links in the time
+                       // it takes to start fetching data via the gateway: the 
active link hasn't
+                       // changed, but the active token has.
+                       activeLink: this.el,
+
+                       activeToken: '0123456789'
+               };
+
+               this.waitPromise.then( function () {
+                       assert.strictEqual( dispatch.callCount, 1 );
+
+                       done();
+               } );
+
+               // After 500 ms...
+               this.waitDeferred.resolve();
        } );
 
        QUnit.module( 'ext.popups/actions#linkAbandon', {

-- 
To view, visit https://gerrit.wikimedia.org/r/331339
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9046296f061677674f9ad991ec6dacd1dd9db65c
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

Reply via email to