mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-03 10:16:22 +00:00
b05da8d49d
When the print button is clicked, load all images from the page before calling window.print Add a timeout to make sure the user doesnt wait too long. Change-Id: Ie922d239f9c5b5757237dc10b673fb500ff203ad Depends-on: Id7f21606be3db22fe8dfde2db675f9905547cfea Bug: T180058
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
( function ( M ) {
|
|
var Skin = M.require( 'mobile.startup/Skin' ),
|
|
Deferred = $.Deferred,
|
|
DownloadIcon = M.require( 'skins.minerva.scripts/DownloadIcon' );
|
|
|
|
QUnit.module( 'Minerva DownloadIcon', {
|
|
setup: function () {
|
|
this.skin = new Skin( {} );
|
|
}
|
|
} );
|
|
|
|
QUnit.test( '#DownloadIcon (print after image download)', function ( assert ) {
|
|
var icon = new DownloadIcon( this.skin ),
|
|
d = Deferred(),
|
|
spy = this.sandbox.stub( window, 'print' );
|
|
|
|
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d.resolve() );
|
|
|
|
icon.onClick();
|
|
d.then( function () {
|
|
assert.ok( spy.calledOnce, 'Print occurred.' );
|
|
} );
|
|
|
|
return d;
|
|
} );
|
|
|
|
QUnit.test( '#DownloadIcon (print via timeout)', function ( assert ) {
|
|
var icon = new DownloadIcon( this.skin ),
|
|
d = Deferred(),
|
|
spy = this.sandbox.stub( window, 'print' );
|
|
|
|
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d );
|
|
|
|
window.setTimeout( function () {
|
|
d.resolve();
|
|
}, 3400 );
|
|
|
|
icon.onClick();
|
|
d.then( function () {
|
|
assert.ok( spy.calledOnce,
|
|
'Print was called once despite loadImagesList resolving after MAX_PRINT_TIMEOUT' );
|
|
} );
|
|
|
|
return d;
|
|
} );
|
|
|
|
QUnit.test( '#DownloadIcon (multiple clicks)', function ( assert ) {
|
|
var icon = new DownloadIcon( this.skin ),
|
|
d = Deferred(),
|
|
spy = this.sandbox.stub( window, 'print' );
|
|
|
|
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d );
|
|
|
|
window.setTimeout( function () {
|
|
d.resolve();
|
|
}, 3400 );
|
|
|
|
icon.onClick();
|
|
icon.onClick();
|
|
d.then( function () {
|
|
assert.ok( spy.calledOnce,
|
|
'Print was called once despite multiple clicks' );
|
|
} );
|
|
|
|
return d;
|
|
} );
|
|
}( mw.mobileFrontend ) );
|