mediawiki-extensions-Visual.../modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterSearchWidget.test.js
Thiemo Kreuz fecded9f70 Fix parameter search being to relaxed on unknown params
When what you type is a partial match, you can't add it as an
unknown parameter, even if that would be the correct action. The
reason for this unexpected edge-case is a mistake in the code
where a variable called "exactMatch" is set when a *partial*
"nameMatch" was found.

Bug: T285940
Change-Id: I6d12e2d7251a19d7d5f8be544c3c32a3ac14fcf0
2021-07-01 20:09:51 +02:00

39 lines
1.1 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( '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().description, 'visualeditor-parameter-search-unknown' );
assert.strictEqual( items[ 1 ].getData().name, 'abbreviation' );
} );
}() );