Phuedx has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/323523

Change subject: actions: window.setTimeout -> mw.popups.wait
......................................................................

actions: window.setTimeout -> mw.popups.wait

The QUnit test suite now completes in ~10e2 ms rather than ~10e3 ms.

Changes:
* Make mw.popups.actions#linkDwell to use mw.popups.wait.
* Make the tests for mw.popups.actions#linkDwell complete faster, but
  still asynchronously, by stubbing mw.popups.wait.

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


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

diff --git a/resources/ext.popups/actions.js b/resources/ext.popups/actions.js
index 44a4bf8..e51c4b3 100644
--- a/resources/ext.popups/actions.js
+++ b/resources/ext.popups/actions.js
@@ -91,12 +91,12 @@
                                interactionStarted: mw.now()
                        } );
 
-                       // TODO: Use mw.popups.wait.
-                       setTimeout( function () {
-                               if ( getState().preview.activeLink === el ) {
-                                       dispatch( fetch( gateway, $( el ).data( 
'page-previews-title' ) ) );
-                               }
-                       }, FETCH_START_DELAY );
+                       mw.popups.wait( FETCH_START_DELAY )
+                               .then( function () {
+                                       if ( getState().preview.activeLink === 
el ) {
+                                               dispatch( fetch( gateway, $( el 
).data( 'page-previews-title' ) ) );
+                                       }
+                               } );
                };
        };
 
diff --git a/tests/qunit/ext.popups/actions.test.js 
b/tests/qunit/ext.popups/actions.test.js
index 72a2fb4..45b80f0 100644
--- a/tests/qunit/ext.popups/actions.test.js
+++ b/tests/qunit/ext.popups/actions.test.js
@@ -36,21 +36,28 @@
                        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,
+               var done = assert.async(),
                        event = {},
                        dispatch = this.sandbox.spy(),
                        gatewayDeferred = $.Deferred(),
                        gateway = function () {
                                return gatewayDeferred;
-                       };
+                       },
+                       fetchThunk,
+                       result = {};
 
                this.sandbox.stub( mw, 'now' ).returns( new Date() );
-
-               done = assert.async();
 
                mw.popups.actions.linkDwell( this.el, event, gateway )( 
dispatch, this.getState );
 
@@ -68,10 +75,7 @@
 
                // ---
 
-               setTimeout( function () {
-                       var fetchThunk,
-                               result = {};
-
+               this.waitPromise.then( function () {
                        assert.strictEqual(
                                dispatch.callCount,
                                2,
@@ -94,7 +98,10 @@
                        } ) );
 
                        done();
-               }, 500 );
+               } );
+
+               // After 500 ms...
+               this.waitDeferred.resolve();
        } );
 
        QUnit.test( '#linkDwell doesn\'t dispatch the fetch action if the 
active link has changed', function ( assert ) {
@@ -109,11 +116,14 @@
                        activeLink: undefined // Any value other than this.el.
                };
 
-               setTimeout( function () {
+               this.waitPromise.then( function () {
                        assert.strictEqual( dispatch.callCount, 1 );
 
                        done();
-               }, 500 );
+               } );
+
+               // After 500 ms...
+               this.waitDeferred.resolve();
        } );
 
 }( mediaWiki, jQuery ) );

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

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