mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-19 05:15:52 +00:00
765aa40cc1
Use the standardised MediaWiki storage system for the simple use case of disabling/enabling Popups. The jStorage library is 12kb uncompressed and cannot be justified for this usage (and if it becomes the standardised library mw.storage will begin using it) This means that browsers with full localStorage or no localStorage support will not be able to disable Popups. Given the current ecosystem of the web - localStorage is widely supported - and the fact that grade A browsers enjoy localStorage support - this is not a problem. See https://github.com/wikimedia/mediawiki/blob/REL1_27/resources/src/startup.js#L59 Changes: * Stop using jStorage * Cleanup and migrate previous values in jStorage with plan for removing this in a month. Bug: T136241 Change-Id: I6dac2911e84d6cb20731be34add01576cf407c46
85 lines
2.2 KiB
JavaScript
85 lines
2.2 KiB
JavaScript
// 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;
|
|
}
|
|
} );
|
|
jQueryInit.withArgs( '#mwe-popups-settings-form' )
|
|
.returns( {
|
|
hide: $.noop
|
|
} );
|
|
jQueryInit.withArgs( '#mwe-popups-settings-help' )
|
|
.returns( {
|
|
show: $.noop
|
|
} );
|
|
|
|
radioButtonValue = 'simple';
|
|
mw.popups.settings.save();
|
|
assert.equal(
|
|
mw.storage.get( 'mwe-popups-enabled' ),
|
|
'1',
|
|
'Popups are enabled when the `simple` radio button is checked.'
|
|
);
|
|
|
|
radioButtonValue = 'off';
|
|
mw.popups.settings.save();
|
|
assert.equal(
|
|
mw.storage.get( 'mwe-popups-enabled' ),
|
|
'0',
|
|
'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(
|
|
// 600 is defined in styles
|
|
( $( window ).width() - 600 ) / 2 + 'px',
|
|
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 );
|