mediawiki-extensions-Visual.../modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterSearchWidget.test.js
Svantje Lilienthal ee98622076 Change style for adding an "Unknown field" in the parameter search
Bug: T286236
Change-Id: Ibb3df034c9b423dd4130d8242bd7bf0dc742ee2f
2021-07-08 09:20:25 +02:00

51 lines
1.4 KiB
JavaScript

( function () {
/**
* @param {string[]} [knownParameters]
* @return {ve.dm.MWTemplateModel} but it's a mock
*/
function makeTemplateMock( knownParameters ) {
const spec = {
getKnownParameterNames: () => knownParameters || [],
getParameterLabel: () => '',
getParameterAliases: () => [],
getParameterDescription: () => '',
isParameterDeprecated: () => false
};
return {
connect: () => {},
getSpec: () => spec,
hasParameter: () => false
};
}
QUnit.module( 've.ui.MWParameterSearchWidget' );
QUnit.test( 'Forbidden characters in parameter names', ( assert ) => {
const template = makeTemplateMock(),
widget = new ve.ui.MWParameterSearchWidget( template );
widget.query.setValue( '{{|p=}}' );
widget.addResults();
const items = widget.results.getItems();
assert.strictEqual( items.length, 1 );
assert.strictEqual( items[ 0 ].getData().name, 'p' );
} );
QUnit.test( 'Unknown parameter partly matches a known parameter', ( assert ) => {
const template = makeTemplateMock( [ 'abbreviation' ] ),
widget = new ve.ui.MWParameterSearchWidget( template );
widget.query.setValue( 'abbr' );
widget.addResults();
const items = widget.results.getItems();
assert.strictEqual( items.length, 2 );
assert.strictEqual( items[ 0 ].getData().name, 'abbr' );
assert.strictEqual( items[ 0 ].getData().isUnknown, true );
assert.strictEqual( items[ 1 ].getData().name, 'abbreviation' );
} );
}() );