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', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2017-02-22 10:37:18 +00:00
|
|
|
function newFromText( title ) {
|
2018-12-13 03:09:26 +00:00
|
|
|
return {
|
2019-08-05 12:42:21 +00:00
|
|
|
getUrl() { return `url/${title}`; }
|
2018-12-13 03:09:26 +00:00
|
|
|
};
|
2017-02-22 10:37:18 +00:00
|
|
|
}
|
|
|
|
|
2018-03-14 19:44:22 +00:00
|
|
|
mediaWiki.Title = { newFromText };
|
2017-04-25 11:56:22 +00:00
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
afterEach() {
|
2017-04-25 11:56:22 +00:00
|
|
|
mediaWiki.Title = null;
|
2017-02-22 10:37:18 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2018-04-26 20:43:05 +00:00
|
|
|
QUnit.test( 'it should set the settingsUrl', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = createStubUser( /* isAnon = */ false ),
|
|
|
|
actions = {};
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-04-26 20:43:05 +00:00
|
|
|
const behavior = createPreviewBehavior( user, actions );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-04-26 20:43:05 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
behavior.settingsUrl,
|
|
|
|
'url/Special:Preferences#mw-prefsection-rendering'
|
|
|
|
);
|
2017-02-22 10:37:18 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it shouldn\'t set the settingsUrl if the user is logged out', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = createStubUser( /* isAnon = */ true ),
|
2017-02-22 10:37:18 +00:00
|
|
|
actions = {},
|
2018-04-26 20:43:05 +00:00
|
|
|
behavior = createPreviewBehavior( user, actions );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
behavior.settingsUrl,
|
|
|
|
undefined,
|
|
|
|
'No settings URL is set.'
|
|
|
|
);
|
2017-02-22 10:37:18 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it shouldn\'t set a showSettings handler if the user is logged in', function ( assert ) {
|
2018-10-29 01:48:38 +00:00
|
|
|
const
|
|
|
|
user = createStubUser( /* isAnon = */ false ),
|
|
|
|
event = {
|
|
|
|
preventDefault: this.sandbox.spy()
|
|
|
|
},
|
|
|
|
actions = {
|
|
|
|
showSettings: () => assert.ok( false, 'No show settings handler is set.' )
|
|
|
|
},
|
2018-04-26 20:43:05 +00:00
|
|
|
behavior = createPreviewBehavior( user, actions );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-10-29 01:48:38 +00:00
|
|
|
behavior.showSettings( event );
|
|
|
|
assert.ok( true );
|
2017-02-22 10:37:18 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'it should set a showSettings handler if the user is logged out', function ( assert ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = createStubUser( /* isAnon = */ true ),
|
2017-02-22 10:37:18 +00:00
|
|
|
event = {
|
|
|
|
preventDefault: this.sandbox.spy()
|
|
|
|
},
|
|
|
|
actions = {
|
|
|
|
showSettings: this.sandbox.spy()
|
|
|
|
},
|
2018-04-26 20:43:05 +00:00
|
|
|
behavior = createPreviewBehavior( user, actions );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
|
|
|
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 ) {
|
2018-03-19 19:39:41 +00:00
|
|
|
const user = createStubUser( /* isAnon = */ true ),
|
|
|
|
actions = {};
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
actions.previewDwell = () => {};
|
|
|
|
actions.abandon = () => {};
|
|
|
|
actions.previewShow = () => {};
|
|
|
|
actions.linkClick = () => {};
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-04-26 20:43:05 +00:00
|
|
|
const behavior = createPreviewBehavior( user, actions );
|
2017-02-22 10:37:18 +00:00
|
|
|
|
2018-05-08 19:48:17 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
behavior.previewDwell,
|
|
|
|
actions.previewDwell,
|
|
|
|
'Preview dwelled action is mixed.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
behavior.previewAbandon,
|
|
|
|
actions.abandon,
|
|
|
|
'Preview action is mixed.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
behavior.previewShow,
|
|
|
|
actions.previewShow,
|
|
|
|
'Preview shown action is mixed.'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
behavior.click,
|
|
|
|
actions.linkClick,
|
|
|
|
'Link click action is mixed.'
|
|
|
|
);
|
2017-02-22 10:37:18 +00:00
|
|
|
} );
|