2016-04-27 18:42:59 +00:00
|
|
|
// render, renderOption, and addFooterLink are already covered in the browser tests
|
|
|
|
|
|
|
|
( function ( $, mw ) {
|
|
|
|
QUnit.module( 'ext.popups.settings' );
|
|
|
|
|
|
|
|
QUnit.test( 'save', function ( assert ) {
|
|
|
|
var jQueryInit = this.sandbox.stub( jQuery.fn, 'init' ),
|
|
|
|
radioButtonValue;
|
|
|
|
|
|
|
|
QUnit.expect( 2 );
|
|
|
|
|
|
|
|
this.sandbox.stub( mw.popups.settings, 'reloadPage' );
|
|
|
|
this.sandbox.stub( mw.popups.settings, 'close' );
|
|
|
|
jQueryInit.withArgs( 'input[name=mwe-popups-setting]:checked', '#mwe-popups-settings' )
|
|
|
|
.returns( {
|
|
|
|
val: function () {
|
|
|
|
return radioButtonValue;
|
|
|
|
}
|
|
|
|
} );
|
2016-06-24 16:25:20 +00:00
|
|
|
jQueryInit.withArgs( '#mwe-popups-settings-form, #mwe-popups-settings .save' )
|
2016-04-27 18:42:59 +00:00
|
|
|
.returns( {
|
|
|
|
hide: $.noop
|
|
|
|
} );
|
2016-06-24 16:25:20 +00:00
|
|
|
jQueryInit.withArgs( '#mwe-popups-settings-help, #mwe-popups-settings .okay' )
|
2016-04-27 18:42:59 +00:00
|
|
|
.returns( {
|
|
|
|
show: $.noop
|
|
|
|
} );
|
|
|
|
|
|
|
|
radioButtonValue = 'simple';
|
|
|
|
mw.popups.settings.save();
|
|
|
|
assert.equal(
|
2016-05-13 20:15:36 +00:00
|
|
|
mw.storage.get( 'mwe-popups-enabled' ),
|
|
|
|
'1',
|
2016-04-27 18:42:59 +00:00
|
|
|
'Popups are enabled when the `simple` radio button is checked.'
|
|
|
|
);
|
|
|
|
|
|
|
|
radioButtonValue = 'off';
|
|
|
|
mw.popups.settings.save();
|
|
|
|
assert.equal(
|
2016-05-13 20:15:36 +00:00
|
|
|
mw.storage.get( 'mwe-popups-enabled' ),
|
|
|
|
'0',
|
2016-04-27 18:42:59 +00:00
|
|
|
'Popups are disabled when the `off` radio button is checked.'
|
|
|
|
);
|
|
|
|
|
|
|
|
jQueryInit.restore();
|
|
|
|
mw.popups.settings.reloadPage.restore();
|
|
|
|
mw.popups.settings.close.restore();
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'open', function ( assert ) {
|
|
|
|
QUnit.expect( 2 );
|
|
|
|
|
|
|
|
mw.popups.settings.open();
|
|
|
|
assert.equal(
|
2016-06-24 16:25:20 +00:00
|
|
|
( $( window ).width() - mw.popups.settings.$element.outerWidth( true ) ) / 2 + 'px',
|
2016-04-27 18:42:59 +00:00
|
|
|
mw.popups.settings.$element.css( 'left' ),
|
|
|
|
'Settings dialog is horizontally aligned in the middle.'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
( $( window ).height() - mw.popups.settings.$element.outerHeight( true ) ) / 2 + 'px',
|
|
|
|
mw.popups.settings.$element.css( 'top' ),
|
|
|
|
'Settings dialog is vertically aligned in the middle.'
|
|
|
|
);
|
|
|
|
mw.popups.settings.close();
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'close', function ( assert ) {
|
|
|
|
QUnit.expect( 2 );
|
|
|
|
|
|
|
|
mw.popups.settings.open();
|
|
|
|
assert.equal(
|
|
|
|
mw.popups.settings.$element.is( ':visible' ),
|
|
|
|
true,
|
|
|
|
'Settings dialog is visible when settings are opened.'
|
|
|
|
);
|
|
|
|
mw.popups.settings.close();
|
|
|
|
assert.equal(
|
|
|
|
mw.popups.settings.$element.is( ':visible' ),
|
|
|
|
false,
|
|
|
|
'Settings dialog is not visible when settings are closed.'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} )( jQuery, mediaWiki );
|