mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-12 15:55:19 +00:00
4afa1958a0
Use schema revision 16163887. Add the 'checkin' action, which is accompanied by the 'checkin' property. The action is logged at the following seconds (Fibonacci numbers) after the page loads: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765. The `checkin` property contains the values listed above. Bug: T147314 Change-Id: Ib9ec7bd0e60aa34a04e32222b025347f6ee31794
109 lines
3.4 KiB
JavaScript
109 lines
3.4 KiB
JavaScript
( function ( mw, $ ) {
|
|
var pageVisibility = mw.popups.pageVisibility,
|
|
checkin = mw.popups.checkin,
|
|
// remember the original chechkin times
|
|
CHECKIN_TIMES = checkin.CHECKIN_TIMES;
|
|
|
|
QUnit.module( 'ext.popups/checkin', {
|
|
setup: function () {
|
|
checkin.CHECKIN_TIMES = CHECKIN_TIMES;
|
|
checkin.haveCheckinActionsBeenSetup = false;
|
|
this.CHECKIN_TIMES = [ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,
|
|
377, 610, 987, 1597, 2584, 4181, 6765 ];
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'checkin times are correct', function ( assert ) {
|
|
assert.expect( 1 );
|
|
assert.deepEqual( checkin.CHECKIN_TIMES, this.CHECKIN_TIMES );
|
|
} );
|
|
|
|
QUnit.test( 'visible timeout will not fire the callback if the' +
|
|
' browser does not support the visibility API', function ( assert ) {
|
|
var delay = 1000,
|
|
spy = this.sandbox.spy(),
|
|
done = assert.async();
|
|
|
|
assert.expect( 1 );
|
|
|
|
this.sandbox.stub( pageVisibility, 'getDocumentHiddenPropertyName' ).returns( undefined );
|
|
|
|
checkin.setVisibleTimeout( spy, delay );
|
|
setTimeout( function () {
|
|
assert.ok( spy.notCalled );
|
|
done();
|
|
}, 2 * delay ); // wait a little more in case the the event loop is busy
|
|
|
|
} );
|
|
|
|
QUnit.test( 'visible timeout pause works correctly', function ( assert ) {
|
|
var delay = 5000,
|
|
pause = 2000,
|
|
// error margin in milliseconds
|
|
delta = 50,
|
|
spy = this.sandbox.spy(),
|
|
done = assert.async();
|
|
|
|
assert.expect( 2 );
|
|
|
|
this.sandbox.stub( pageVisibility, 'getDocumentHiddenPropertyName' ).returns( 'customHidden' );
|
|
this.sandbox.stub( pageVisibility, 'getDocumentVisibilitychangeEventName' ).returns( 'customvisibilitychange' );
|
|
|
|
checkin.setVisibleTimeout( spy, delay );
|
|
|
|
// pause immediately, after making sure the document is hidden
|
|
this.sandbox.stub( pageVisibility, 'isDocumentHidden' ).returns( true );
|
|
$( document ).trigger( 'customvisibilitychange' );
|
|
|
|
// resume after `pause` milliseconds
|
|
pageVisibility.isDocumentHidden.restore();
|
|
this.sandbox.stub( pageVisibility, 'isDocumentHidden' ).returns( false );
|
|
setTimeout( function () {
|
|
$( document ).trigger( 'customvisibilitychange' );
|
|
pageVisibility.isDocumentHidden.restore();
|
|
}, pause );
|
|
|
|
setTimeout( function () {
|
|
// make sure the spy is not called after `delay` as we've paused
|
|
assert.ok( spy.notCalled );
|
|
|
|
setTimeout( function () {
|
|
// make sure the spy is called after `delay` + `pause` as we've resumed
|
|
assert.ok( spy.called );
|
|
done();
|
|
}, pause + delta );
|
|
}, delay + delta );
|
|
|
|
} );
|
|
|
|
QUnit.test( 'checkin actions will not be set up if they already have been', function ( assert ) {
|
|
var spy = this.sandbox.spy( checkin, 'setVisibleTimeout' ),
|
|
actionSpy = this.sandbox.spy();
|
|
|
|
assert.expect( 1 );
|
|
|
|
checkin.haveCheckinActionsBeenSetup = true;
|
|
checkin.setupActions( actionSpy );
|
|
assert.ok( spy.notCalled, 'setVisibleTimeout has not been called.' );
|
|
} );
|
|
|
|
QUnit.test( 'checkin actions are setup correctly', function ( assert ) {
|
|
var actionSpy = this.sandbox.spy(),
|
|
done = assert.async();
|
|
|
|
checkin.CHECKIN_TIMES = [ 1, 2, 3 ];
|
|
|
|
assert.expect( checkin.CHECKIN_TIMES.length );
|
|
|
|
checkin.setupActions( actionSpy );
|
|
setTimeout( function () {
|
|
$.each( checkin.CHECKIN_TIMES, function ( i, time ) {
|
|
assert.ok( actionSpy.calledWith( time ),
|
|
'`action` has been called the correct checkin time: ' + time + '.' );
|
|
} );
|
|
done();
|
|
// give two more seconds to catch up
|
|
}, ( checkin.CHECKIN_TIMES[ checkin.CHECKIN_TIMES.length - 1 ] + 2 ) * 1000 );
|
|
} );
|
|
}( mediaWiki, jQuery ) );
|