2021-10-13 13:21:04 +00:00
|
|
|
{
|
2021-07-01 12:26:38 +00:00
|
|
|
|
|
|
|
/**
|
2021-07-02 12:13:25 +00:00
|
|
|
* @param {string[]} [knownParameters]
|
2021-07-01 12:26:38 +00:00
|
|
|
* @return {ve.dm.MWTemplateModel} but it's a mock
|
|
|
|
*/
|
2021-10-13 13:21:04 +00:00
|
|
|
const makeTemplateMock = function ( knownParameters ) {
|
2021-07-01 12:26:38 +00:00
|
|
|
const spec = {
|
2021-07-02 12:13:25 +00:00
|
|
|
getKnownParameterNames: () => knownParameters || [],
|
2021-07-01 12:26:38 +00:00
|
|
|
getParameterLabel: () => '',
|
|
|
|
getParameterAliases: () => [],
|
|
|
|
getParameterDescription: () => '',
|
|
|
|
isParameterDeprecated: () => false
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
connect: () => {},
|
|
|
|
getSpec: () => spec,
|
|
|
|
hasParameter: () => false
|
|
|
|
};
|
2021-10-13 13:21:04 +00:00
|
|
|
};
|
2021-07-01 12:26:38 +00:00
|
|
|
|
|
|
|
QUnit.module( 've.ui.MWParameterSearchWidget' );
|
|
|
|
|
2021-07-02 12:13:25 +00:00
|
|
|
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' );
|
|
|
|
} );
|
|
|
|
|
2021-07-01 12:26:38 +00:00
|
|
|
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' );
|
2021-08-25 15:08:34 +00:00
|
|
|
assert.ok( items[ 0 ].getData().isUnknown );
|
2021-07-01 12:26:38 +00:00
|
|
|
assert.strictEqual( items[ 1 ].getData().name, 'abbreviation' );
|
|
|
|
} );
|
|
|
|
|
2021-10-13 13:21:04 +00:00
|
|
|
}
|