2021-10-13 13:21:04 +00:00
|
|
|
{
|
|
|
|
const enableCirrusSearchLookup = function ( enabled ) {
|
2021-03-01 17:02:38 +00:00
|
|
|
const config = mw.config.get( 'wgVisualEditorConfig' );
|
2021-05-19 16:51:48 +00:00
|
|
|
config.cirrusSearchLookup = enabled !== false;
|
2021-03-01 17:02:38 +00:00
|
|
|
mw.config.set( 'wgVisualEditorConfig', config );
|
2021-10-13 13:21:04 +00:00
|
|
|
};
|
2021-03-01 17:02:38 +00:00
|
|
|
|
|
|
|
QUnit.module( 've.ui.MWTemplateTitleInputWidget', QUnit.newMwEnvironment( {
|
2021-06-21 09:17:37 +00:00
|
|
|
beforeEach: function () {
|
|
|
|
enableCirrusSearchLookup( false );
|
|
|
|
},
|
2021-03-01 17:02:38 +00:00
|
|
|
afterEach() {
|
|
|
|
enableCirrusSearchLookup( false );
|
|
|
|
}
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
QUnit.test( 'default prefixsearch', ( assert ) => {
|
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget(),
|
|
|
|
query = 'a',
|
|
|
|
apiParams = widget.getApiParams( query );
|
|
|
|
|
|
|
|
assert.deepEqual( apiParams, {
|
|
|
|
action: 'query',
|
|
|
|
generator: 'prefixsearch',
|
|
|
|
gpslimit: 10,
|
|
|
|
gpsnamespace: 10,
|
|
|
|
gpssearch: 'a',
|
|
|
|
ppprop: 'disambiguation',
|
|
|
|
prop: [ 'info', 'pageprops' ],
|
|
|
|
redirects: true
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'CirrusSearch: all API parameters', ( assert ) => {
|
2021-05-19 16:51:48 +00:00
|
|
|
enableCirrusSearchLookup();
|
2021-03-01 17:02:38 +00:00
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget(),
|
|
|
|
query = 'a',
|
|
|
|
apiParams = widget.getApiParams( query );
|
|
|
|
|
|
|
|
assert.deepEqual( apiParams, {
|
|
|
|
action: 'query',
|
|
|
|
generator: 'search',
|
|
|
|
gsrlimit: 10,
|
|
|
|
gsrnamespace: 10,
|
2021-05-19 16:51:48 +00:00
|
|
|
gsrprop: 'redirecttitle',
|
2021-03-01 17:02:38 +00:00
|
|
|
gsrsearch: 'a*',
|
|
|
|
ppprop: 'disambiguation',
|
|
|
|
prop: [ 'info', 'pageprops' ],
|
|
|
|
redirects: true
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2021-05-19 16:51:48 +00:00
|
|
|
QUnit.test( 'CirrusSearch: showRedirectTargets disabled', ( assert ) => {
|
|
|
|
enableCirrusSearchLookup();
|
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget( { showRedirectTargets: false } ),
|
|
|
|
apiParams = widget.getApiParams();
|
|
|
|
|
|
|
|
assert.notOk( 'gsrprop' in apiParams );
|
|
|
|
} );
|
|
|
|
|
2021-03-01 17:02:38 +00:00
|
|
|
QUnit.test( 'CirrusSearch: prefixsearch behavior', ( assert ) => {
|
2021-05-19 16:51:48 +00:00
|
|
|
enableCirrusSearchLookup();
|
2021-03-01 17:02:38 +00:00
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget();
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
query: 'a',
|
|
|
|
expected: 'a*'
|
|
|
|
},
|
2021-06-21 09:17:37 +00:00
|
|
|
{
|
|
|
|
query: 'a ',
|
|
|
|
expected: 'a '
|
|
|
|
},
|
2021-03-01 17:02:38 +00:00
|
|
|
{
|
|
|
|
query: 'ü',
|
|
|
|
expected: 'ü*'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '3',
|
|
|
|
expected: '3*'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '!!',
|
2021-06-21 09:17:37 +00:00
|
|
|
expected: '!!'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'Foo:',
|
|
|
|
expected: 'Foo:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'Foo:Bar',
|
|
|
|
expected: 'Foo:Bar*'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foo_',
|
|
|
|
expected: 'foo_'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foo-',
|
|
|
|
expected: 'foo-'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foo+',
|
|
|
|
expected: 'foo+'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foo/',
|
|
|
|
expected: 'foo/'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foo~',
|
|
|
|
expected: 'foo~'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foo*',
|
|
|
|
expected: 'foo*'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '(foo)',
|
|
|
|
expected: '(foo)'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '[foo]',
|
|
|
|
expected: '[foo]'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '{foo}',
|
|
|
|
expected: '{foo}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '"foo"',
|
|
|
|
expected: '"foo"'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'foß',
|
|
|
|
expected: 'foß*'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: '中文字',
|
|
|
|
expected: '中文字*'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
query: 'zhōngwénzì',
|
|
|
|
expected: 'zhōngwénzì*'
|
2021-03-01 17:02:38 +00:00
|
|
|
}
|
|
|
|
].forEach( ( data ) => {
|
|
|
|
const apiParams = widget.getApiParams( data.query );
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
apiParams.gsrsearch,
|
|
|
|
data.expected,
|
|
|
|
'Searching for ' + data.query
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|
2021-05-19 16:51:48 +00:00
|
|
|
|
|
|
|
QUnit.test( 'CirrusSearch: redirect is forwarded to the TitleOptionWidget', ( assert ) => {
|
|
|
|
enableCirrusSearchLookup();
|
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget(),
|
|
|
|
originalData = { redirecttitle: 'Template:From' },
|
|
|
|
data = widget.getOptionWidgetData( 'Template:To', { originalData } );
|
|
|
|
|
|
|
|
assert.strictEqual( data.redirecttitle, 'Template:From' );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'CirrusSearch: redirect appears in the description', ( assert ) => {
|
|
|
|
enableCirrusSearchLookup();
|
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget();
|
|
|
|
|
|
|
|
let option = widget.createOptionWidget( { redirecttitle: 'Template:From' } );
|
|
|
|
assert.strictEqual(
|
|
|
|
option.$element.find( '.ve-ui-mwTemplateTitleInputWidget-redirectedfrom' ).text(),
|
|
|
|
'(redirectedfrom: From)'
|
|
|
|
);
|
|
|
|
|
|
|
|
widget.relative = false;
|
|
|
|
option = widget.createOptionWidget( { redirecttitle: 'Template:From' } );
|
|
|
|
assert.strictEqual(
|
|
|
|
option.$element.find( '.ve-ui-mwTemplateTitleInputWidget-redirectedfrom' ).text(),
|
|
|
|
'(redirectedfrom: Template:From)'
|
|
|
|
);
|
|
|
|
} );
|
2021-10-13 13:21:04 +00:00
|
|
|
}
|