mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-21 10:33:05 +00:00
58e27f56d6
These are only needed when we need to access a specific `this` from within another `function () {}` context. This is not the case in the situations here. This is split from Ibf25d7e to make it smaller and easier to argue about. Change-Id: Ide1476de91fc343aa992ad92a1321d3a38b06dd0
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
{
|
|
/**
|
|
* @param {string[]} [knownParameters]
|
|
* @return {ve.dm.MWTemplateModel} but it's a mock
|
|
*/
|
|
const makeTemplateMock = function ( 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.true( items[ 0 ].getData().isUnknown );
|
|
assert.strictEqual( items[ 1 ].getData().name, 'abbreviation' );
|
|
} );
|
|
|
|
}
|