mediawiki-extensions-Popups/tests/node-qunit/ui/settingsDialogRenderer.test.js
Jon Robson 6924a89b07 Generalize settings code
A new REGISTER_SETTING action replaces the BOOT action for
registering settings. This allows custom preview types to be
associated with a setting. They do this by adding the enabled
property to the module they provide to mw.popups.register

Every time the new action is called, we refresh the settings
dialog UI with the new settings.

Previously the settings dialog was hardcoded, but now it is generated
from the registered preview types by deriving associated messages
and checking they exist, so by default custom types will not show
up in the settings.

Benefits:
* This change empowers us to add a setting for Math previews to allow
them to be enabled or disabled.
* Allows us to separate references as its own module

Additional notes:
* The syncUserSettings.js changeListener is no longer needed as the logic
for this is handled inside the "userSettings" change listener in response to
the "settings" reducer which is responding to
SETTINGS_CHANGE and REGISTER_SETTING actions.

Upon merging:
* https://www.mediawiki.org/wiki/Extension:Popups#Extensibility will be
updated to detail how a setting can be registered.

Bug: T334261
Bug: T326692
Change-Id: Ie11057052fb9035944f2b79a17fb486f97102994
2023-10-17 15:08:15 +00:00

65 lines
1.6 KiB
JavaScript

import createSettingsDialogRenderer, { toggleHelp } from '../../../src/ui/settingsDialogRenderer';
QUnit.module( 'ext.popups/settingsDialogRenderer', {
beforeEach() {
function render() {
return $( '<div>' );
}
function getTemplate() {
return { render };
}
mw.html = { escape: ( str ) => str };
mw.template = { get: getTemplate };
mw.config = { get() {} };
mw.msg = () => {};
},
afterEach() {
mw.msg = null;
mw.config = null;
mw.template = null;
mw.html = null;
}
} );
QUnit.test( '#toggleHelp', ( assert ) => {
const dialog = document.createElement( 'div' );
const main = document.createElement( 'main' );
const save = document.createElement( 'button' );
save.classList.add( 'mwe-popups-settings-help' );
dialog.appendChild( main );
dialog.appendChild( save );
toggleHelp( dialog, true );
assert.strictEqual( main.style.display, 'none' );
assert.strictEqual( save.style.display, '' );
toggleHelp( dialog, false );
assert.strictEqual( main.style.display, '' );
assert.strictEqual( save.style.display, 'none' );
} );
QUnit.test( '#render', ( assert ) => {
const boundActions = {
saveSettings() {},
hideSettings() {}
},
expected = {
refresh() {},
appendTo() {},
show() {},
hide() {},
toggleHelp() {},
setEnabled() {}
},
result = createSettingsDialogRenderer( mw.config )( boundActions, {} );
// Specifically NOT a deep equal. Only structure.
assert.propEqual(
result,
expected,
'Interface exposed has the expected methods'
);
} );
// FIXME: Add Qunit integration tests about the rendering and the behavior of
// the settings dialog.