mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-15 03:34:03 +00:00
c6a502954d
The behavior of the cog varies when: * The user is logged in/out. * Page Previews is enabled as a beta feature. Since the behavior of the cog doesn't vary per-preview, it can be determined at boot time and passed to the renderer. However, in order to keep the renderer stateless, we pass the behavior to it when a preview is added to the DOM. Changes: * Add the mw.popups.createPreviewBehavior factory function, which returns an object that encapsulates how a preview responds to the user dwelling on it, abandoning it, and clicking on the cog. * Invoke mw.popups.createPreviewBehavior at boot time and pass it to the mw.popups.changeListeners.render change listener, which then passes it to mw.popups.Preview#show. * Make mw.popups.Preview#show responsible for binding event handlers and configuring the cog based on the behavior. Bug: T146889 Change-Id: I39d7d0afd7b1fe896019a1b3a82ee907bfb20edd
92 lines
2.7 KiB
JavaScript
92 lines
2.7 KiB
JavaScript
( function ( mw, $ ) {
|
|
|
|
var createPreviewBehavior = mw.popups.createPreviewBehavior;
|
|
|
|
QUnit.module( 'ext.popups.preview.settingsBehavior', {
|
|
setup: function () {
|
|
this.config = new mw.Map();
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should set the settingsUrl on wgPopupsBetaFeature', function ( assert ) {
|
|
var that = this,
|
|
user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
|
|
actions = {},
|
|
cases;
|
|
|
|
cases = [
|
|
[ true, 'Special:Preferences#mw-prefsection-betafeatures' ],
|
|
[ false, 'Special:Preferences#mw-prefsection-rendering' ]
|
|
];
|
|
|
|
$.each( cases, function ( i, testCase ) {
|
|
var behavior;
|
|
|
|
that.config.set( 'wgPopupsBetaFeature', testCase[ 0 ] );
|
|
|
|
behavior = createPreviewBehavior( that.config, user, actions );
|
|
|
|
assert.deepEqual(
|
|
behavior.settingsUrl,
|
|
mw.Title.newFromText( testCase[ 1 ] ).getUrl()
|
|
);
|
|
} );
|
|
} );
|
|
|
|
QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', function ( assert ) {
|
|
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
|
|
actions = {},
|
|
behavior = createPreviewBehavior( this.config, user, actions );
|
|
|
|
assert.strictEqual( behavior.settingsUrl, undefined );
|
|
} );
|
|
|
|
QUnit.test( 'it shouldn\'t set a showSettings handler if the user is logged in', function ( assert ) {
|
|
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ false ),
|
|
actions = {},
|
|
behavior = createPreviewBehavior( this.config, user, actions );
|
|
|
|
assert.strictEqual( behavior.showSettings, $.noop );
|
|
} );
|
|
|
|
QUnit.test( 'it should set a showSettings handler if the user is logged out', function ( assert ) {
|
|
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
|
|
event = {
|
|
preventDefault: this.sandbox.spy()
|
|
},
|
|
actions = {
|
|
showSettings: this.sandbox.spy()
|
|
},
|
|
behavior = createPreviewBehavior( this.config, user, actions );
|
|
|
|
behavior.showSettings( event );
|
|
|
|
assert.ok(
|
|
event.preventDefault.called,
|
|
'It should prevent the default action of the event.'
|
|
);
|
|
|
|
assert.ok(
|
|
actions.showSettings.called,
|
|
'It should dispatch the SETTINGS_SHOW action.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'it should mix in default actions', function ( assert ) {
|
|
var user = mw.popups.tests.stubs.createStubUser( /* isAnon = */ true ),
|
|
actions = {},
|
|
behavior;
|
|
|
|
actions.previewDwell = function () {};
|
|
actions.abandon = function () {};
|
|
actions.previewShow = function () {};
|
|
|
|
behavior = createPreviewBehavior( this.config, user, actions );
|
|
|
|
assert.strictEqual( behavior.previewDwell, actions.previewDwell );
|
|
assert.strictEqual( behavior.previewAbandon, actions.abandon );
|
|
assert.strictEqual( behavior.previewShow, actions.previewShow );
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|