2023-05-12 20:44:30 +00:00
|
|
|
import createSettingsDialogRenderer, { toggleHelp } from '../../../src/ui/settingsDialogRenderer';
|
2017-02-22 10:22:58 +00:00
|
|
|
|
2018-03-08 20:57:22 +00:00
|
|
|
QUnit.module( 'ext.popups/settingsDialogRenderer', {
|
2018-03-14 22:04:59 +00:00
|
|
|
beforeEach() {
|
2018-12-13 03:09:26 +00:00
|
|
|
function render() {
|
|
|
|
return $( '<div>' );
|
|
|
|
}
|
|
|
|
function getTemplate() {
|
|
|
|
return { render };
|
|
|
|
}
|
2017-02-22 10:22:58 +00:00
|
|
|
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.html = { escape: ( str ) => str };
|
|
|
|
mw.template = { get: getTemplate };
|
2021-04-15 07:20:00 +00:00
|
|
|
mw.config = { get() {} };
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.msg = () => {};
|
2017-02-22 10:22:58 +00:00
|
|
|
},
|
2018-03-14 22:04:59 +00:00
|
|
|
afterEach() {
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.msg = null;
|
2021-04-15 07:20:00 +00:00
|
|
|
mw.config = null;
|
2019-10-17 08:51:49 +00:00
|
|
|
mw.template = null;
|
|
|
|
mw.html = null;
|
2017-02-22 10:22:58 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2023-05-12 20:44:30 +00:00
|
|
|
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' );
|
|
|
|
} );
|
|
|
|
|
2018-03-14 23:50:09 +00:00
|
|
|
QUnit.test( '#render', ( assert ) => {
|
2024-01-15 18:03:22 +00:00
|
|
|
const main = document.createElement( 'main' );
|
2018-03-19 19:39:41 +00:00
|
|
|
const boundActions = {
|
2018-03-14 22:04:59 +00:00
|
|
|
saveSettings() {},
|
|
|
|
hideSettings() {}
|
2017-02-22 10:22:58 +00:00
|
|
|
},
|
|
|
|
expected = {
|
2023-10-19 21:12:09 +00:00
|
|
|
refresh() {},
|
2018-03-14 22:04:59 +00:00
|
|
|
appendTo() {},
|
|
|
|
show() {},
|
|
|
|
hide() {},
|
|
|
|
toggleHelp() {},
|
|
|
|
setEnabled() {}
|
2017-02-22 10:22:58 +00:00
|
|
|
},
|
2024-01-15 18:03:22 +00:00
|
|
|
dialogRenderer = createSettingsDialogRenderer( mw.config )( boundActions, {} );
|
2017-02-22 10:22:58 +00:00
|
|
|
|
|
|
|
// Specifically NOT a deep equal. Only structure.
|
|
|
|
assert.propEqual(
|
2024-01-15 18:03:22 +00:00
|
|
|
dialogRenderer,
|
2017-02-22 10:22:58 +00:00
|
|
|
expected,
|
|
|
|
'Interface exposed has the expected methods'
|
|
|
|
);
|
2024-01-15 18:03:22 +00:00
|
|
|
|
|
|
|
// Sanity checks for some methods
|
|
|
|
assert.strictEqual( main.childElementCount, 0 );
|
|
|
|
dialogRenderer.appendTo( main );
|
|
|
|
assert.strictEqual( main.childElementCount, 1 );
|
|
|
|
|
|
|
|
assert.strictEqual( $( main.children[ 0 ] ).css( 'display' ), 'block' );
|
|
|
|
dialogRenderer.hide();
|
|
|
|
assert.strictEqual( $( main.children[ 0 ] ).css( 'display' ), 'none' );
|
2017-02-22 10:22:58 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// FIXME: Add Qunit integration tests about the rendering and the behavior of
|
|
|
|
// the settings dialog.
|