mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-02 19:26:24 +00:00
e6081106f1
Why: Because they are the approved standard by TC39 and Ecma for JavaScript modules. Changes: * Wrap mw-node-qunit in run.js to register babel to transpile modules for node v6 * Change all sources in src/ to use ES modules * Change constants.js to be able to run without jQuery.bracketedDevicePixelRatio given ES modules are hoisted to the top by spec so we can't patch globals before importing it * Change all tests in tests/node-qunit/ to use ES modules * Drop usage of mock-require given ES modules are easy to stub with sinon Additional changes: * Rename tests/node-qunit/renderer.js to renderer.test.js to follow the convention of all the other files * Make npm run test:node run only .test.js test files so that it doesn't run the stubs.js or run.js file. Bug: T171951 Change-Id: I17a0b76041d5e2fd18e2d54950d9d7c0db99a941
99 lines
2.8 KiB
JavaScript
99 lines
2.8 KiB
JavaScript
import createPreviewBehavior from '../../src/previewBehavior';
|
|
import { createStubUser } from './stubs';
|
|
|
|
QUnit.module( 'ext.popups.preview.settingsBehavior', {
|
|
beforeEach: function () {
|
|
function newFromText( title ) {
|
|
return { getUrl: function () { return 'url/' + title; } };
|
|
}
|
|
|
|
mediaWiki.Title = { newFromText: newFromText };
|
|
/* global Map */ this.config = new Map();
|
|
},
|
|
afterEach: function () {
|
|
mediaWiki.Title = null;
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'it should set the settingsUrl on wgPopupsBetaFeature', function ( assert ) {
|
|
var that = this,
|
|
user = 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,
|
|
'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 () {};
|
|
actions.linkClick = 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 );
|
|
assert.strictEqual( behavior.click, actions.linkClick );
|
|
} );
|