jenkins-bot has submitted this change and it was merged.

Change subject: core: Add tests for throttle
......................................................................


core: Add tests for throttle

Change-Id: Ifaae9899b020848afa07d455347c8b06f114ba14
---
M tests/core.test.js
M tests/index.php
2 files changed, 51 insertions(+), 0 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/core.test.js b/tests/core.test.js
index a3f517c..ed0eb8f 100644
--- a/tests/core.test.js
+++ b/tests/core.test.js
@@ -177,3 +177,53 @@
                window.clearTimeout = clearTimeoutReal;
        }
 } );
+
+QUnit.test( 'throttle', 2, function ( assert ) {
+       var f,
+               log = [],
+               testTimer = new OO.ui.TestTimer(),
+               setTimeoutReal = window.setTimeout,
+               clearTimeoutReal = window.clearTimeout;
+       window.setTimeout = testTimer.setTimeout.bind( testTimer );
+       window.clearTimeout = testTimer.clearTimeout.bind( testTimer );
+       try {
+               f = OO.ui.throttle( log.push.bind( log ), 50 );
+               f( 1 ); // runs
+               testTimer.runPending( 20 );
+               log.push( 'a' );
+               f( 2 ); // throttled
+               testTimer.runPending( 30 );
+               log.push( 'b' );
+               f( 3 ); // throttled
+               log.push( 'c' );
+               testTimer.runPending( 30 ); // call happens
+               log.push( 'd' );
+               f( 4 ); // throttled
+               testTimer.runPending( 20 );
+               log.push( 'e' );
+               testTimer.runPending( 20 );
+               log.push( 'f' );
+               testTimer.runPending( 20 ); // call happens
+               log.push( 'g' );
+               testTimer.runPending( 20 );
+               assert.deepEqual( log, [ 1, 'a', 'b', 'c', 3, 'd', 'e', 'f', 4, 
'g' ], 'throttle 50 ms' );
+
+               log = [];
+               f = OO.ui.throttle( log.push.bind( log ), 0 );
+               f( 1 );
+               log.push( 'a' );
+               f( 2 );
+               log.push( 'b' );
+               testTimer.runPending();
+               f( 3 );
+               log.push( 'c' );
+               testTimer.runPending();
+               log.push( 'd' );
+               assert.deepEqual( log, [ 1, 'a', 2, 'b', 3, 'c', 'd' ], 
'throttle 0 ms' );
+               testTimer.runPending();
+
+       } finally {
+               window.setTimeout = setTimeoutReal;
+               window.clearTimeout = clearTimeoutReal;
+       }
+} );
diff --git a/tests/index.php b/tests/index.php
index bcf9366..8a22673 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -33,6 +33,7 @@
        <script src="../dist/oojs-ui.js"></script>
        <script src="../dist/oojs-ui-apex.js"></script>
        <script src="../dist/oojs-ui-mediawiki.js"></script>
+       <script src="./TestTimer.js"></script>
        <!-- Test suites -->
        <script src="./core.test.js"></script>
        <script src="./Element.test.js"></script>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifaae9899b020848afa07d455347c8b06f114ba14
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: DLynch <dly...@wikimedia.org>
Gerrit-Reviewer: Divec <da...@troi.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to