2017-07-28 17:32:46 +00:00
|
|
|
import createPreviewBehavior from '../../src/previewBehavior';
|
|
|
|
import { createStubUser } from './stubs';
|
2017-02-22 10:37:18 +00:00
|
|
|
|
|
|
|
QUnit.module( 'ext.popups.preview.settingsBehavior', {
|
2017-04-25 15:10:11 +00:00
|
|
|
beforeEach: function () {
|
2017-02-22 10:37:18 +00:00
|
|
|
function newFromText( title ) {
|
|
|
|
return { getUrl: function () { return 'url/' + title; } };
|
|
|
|
}
|
|
|
|
|
2018-03-14 19:44:22 +00:00
|
|
|
mediaWiki.Title = { newFromText };
|
2017-02-22 10:37:18 +00:00
|
|
|
/* global Map */ this.config = new Map();
|
2017-04-25 11:56:22 +00:00
|
|
|
},
|
|
|
|
afterEach: function () {
|
|
|
|
mediaWiki.Title = null;
|
2017-02-22 10:37:18 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it should set the settingsUrl on wgPopupsBetaFeature', function ( assert ) {
|
2018-02-16 12:52:56 +00:00
|
|
|
var user = createStubUser( /* isAnon = */ false ),
|
2017-02-22 10:37:18 +00:00
|
|
|
actions = {},
|
|
|
|
cases;
|
|
|
|
|
|
|
|
cases = [
|
|
|
|
[ true, 'Special:Preferences#mw-prefsection-betafeatures' ],
|
|
|
|
[ false, 'Special:Preferences#mw-prefsection-rendering' ]
|
|
|
|
];
|
|
|
|
|
2018-02-16 12:52:56 +00:00
|
|
|
cases.forEach( ( testCase ) => {
|
2017-02-22 10:37:18 +00:00
|
|
|
var behavior;
|
|
|
|
|
2018-02-16 12:52:56 +00:00
|
|
|
this.config.set( 'wgPopupsBetaFeature', testCase[ 0 ] );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-02-16 12:52:56 +00:00
|
|
|
behavior = createPreviewBehavior( this.config, user, actions );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
behavior.settingsUrl,
|
|
|
|
'url/' + testCase[ 1 ]
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', function ( assert ) {
|
|
|
|
var user = 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 = 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 = 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 = createStubUser( /* isAnon = */ true ),
|
|
|
|
actions = {},
|
|
|
|
behavior;
|
|
|
|
|
|
|
|
actions.previewDwell = function () {};
|
|
|
|
actions.abandon = function () {};
|
|
|
|
actions.previewShow = function () {};
|
2017-03-22 14:54:04 +00:00
|
|
|
actions.linkClick = function () {};
|
2017-02-22 10:37:18 +00:00
|
|
|
|
|
|
|
behavior = createPreviewBehavior( this.config, user, actions );
|
|
|
|
|
|
|
|
assert.strictEqual( behavior.previewDwell, actions.previewDwell );
|
|
|
|
assert.strictEqual( behavior.previewAbandon, actions.abandon );
|
|
|
|
assert.strictEqual( behavior.previewShow, actions.previewShow );
|
2017-03-22 14:54:04 +00:00
|
|
|
assert.strictEqual( behavior.click, actions.linkClick );
|
2017-02-22 10:37:18 +00:00
|
|
|
} );
|