2021-10-13 13:21:04 +00:00
|
|
|
{
|
2022-05-03 19:01:18 +00:00
|
|
|
const toggleCirrusSearchLookup = ( enabled ) =>
|
2022-03-04 13:48:14 +00:00
|
|
|
mw.config.set( 'wgVisualEditorConfig', ve.extendObject( {}, mw.config.get( 'wgVisualEditorConfig' ), {
|
2022-05-03 19:01:18 +00:00
|
|
|
cirrusSearchLookup: enabled !== false
|
2022-03-04 13:48:14 +00:00
|
|
|
} ) );
|
2022-05-03 19:01:18 +00:00
|
|
|
|
|
|
|
const makeFakeApi = () => {
|
|
|
|
return {
|
|
|
|
defaults: { parameters: {} },
|
|
|
|
get: () => {
|
|
|
|
return {
|
|
|
|
abort: { bind: () => {} },
|
|
|
|
then: () => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2021-10-13 13:21:04 +00:00
|
|
|
};
|
2021-03-01 17:02:38 +00:00
|
|
|
|
2022-05-03 19:01:18 +00:00
|
|
|
QUnit.module( 've.ui.MWTemplateTitleInputWidget', ve.test.utils.newMwEnvironment( {
|
|
|
|
// Config will be reset by newMwEnvironment's teardown
|
|
|
|
beforeEach: toggleCirrusSearchLookup
|
|
|
|
} ) );
|
2021-03-01 17:02:38 +00:00
|
|
|
|
|
|
|
QUnit.test( 'default prefixsearch', ( assert ) => {
|
2022-05-03 19:01:18 +00:00
|
|
|
toggleCirrusSearchLookup( false );
|
|
|
|
|
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: 'prefixsearch',
|
|
|
|
gpslimit: 10,
|
|
|
|
gpsnamespace: 10,
|
|
|
|
gpssearch: 'a',
|
|
|
|
ppprop: 'disambiguation',
|
|
|
|
prop: [ 'info', 'pageprops' ],
|
|
|
|
redirects: true
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
QUnit.test( 'CirrusSearch: all API parameters', ( assert ) => {
|
|
|
|
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 ) => {
|
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget( { showRedirectTargets: false } ),
|
|
|
|
apiParams = widget.getApiParams();
|
|
|
|
|
2021-11-02 01:27:09 +00:00
|
|
|
assert.false( 'gsrprop' in apiParams );
|
2021-05-19 16:51:48 +00:00
|
|
|
} );
|
|
|
|
|
2021-03-01 17:02:38 +00:00
|
|
|
QUnit.test( 'CirrusSearch: prefixsearch behavior', ( assert ) => {
|
|
|
|
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
|
|
|
|
2022-05-03 19:01:18 +00:00
|
|
|
QUnit.test( 'CirrusSearch with prefixsearch fallback', function ( assert ) {
|
|
|
|
const done = assert.async(),
|
|
|
|
api = makeFakeApi();
|
|
|
|
this.sandbox.stub( api, 'get' )
|
|
|
|
.onFirstCall().returns( ve.createDeferred()
|
|
|
|
.resolve( { query: {
|
|
|
|
pages: [
|
|
|
|
{ pageid: 101, title: 'B' },
|
|
|
|
{ pageid: 102, title: 'A' },
|
|
|
|
// Documentation subpage, expected to be stripped
|
|
|
|
{ pageid: 103, title: 'A/(templatedata-doc-subpage)' }
|
|
|
|
],
|
|
|
|
redirects: [
|
|
|
|
// Alternative source for indexes, expected to be copied to the pages array
|
|
|
|
{ from: '', to: 'B', index: 1 },
|
|
|
|
{ from: '', to: 'A', index: 0 }
|
|
|
|
]
|
|
|
|
} } )
|
|
|
|
.promise( { abort: function () {} } )
|
|
|
|
)
|
|
|
|
.onSecondCall().returns( ve.createDeferred()
|
|
|
|
.resolve( { query: { pages: [
|
|
|
|
// Duplicate found by CirrusSearch (above) and prefixsearch
|
|
|
|
{ pageid: 102, title: 'A', index: 2 },
|
|
|
|
// New prefixsearch matches, expected to be prepended, in order of relevance
|
|
|
|
{ pageid: 201, title: 'D', index: 1 },
|
|
|
|
{ pageid: 202, title: 'C', index: 0 }
|
|
|
|
] } } )
|
|
|
|
)
|
|
|
|
.onThirdCall().returns( ve.createDeferred()
|
|
|
|
.resolve( /* we can skip the templatedata request for this test */ )
|
|
|
|
);
|
|
|
|
|
|
|
|
const widget = new ve.ui.MWTemplateTitleInputWidget( { api, showDescriptions: true } );
|
|
|
|
widget.setValue( 'something' );
|
|
|
|
widget.getLookupRequest()
|
|
|
|
.done( ( response ) => {
|
|
|
|
assert.deepEqual( response.query.pages, [
|
|
|
|
{ pageid: 202, title: 'C', index: -10 },
|
|
|
|
{ pageid: 201, title: 'D', index: -9 },
|
|
|
|
{ pageid: 102, title: 'A', index: 0 },
|
|
|
|
{ pageid: 101, title: 'B', index: 1 }
|
|
|
|
] );
|
|
|
|
} )
|
|
|
|
.always( () => done() );
|
|
|
|
} );
|
|
|
|
|
2021-05-19 16:51:48 +00:00
|
|
|
QUnit.test( 'CirrusSearch: redirect is forwarded to the TitleOptionWidget', ( assert ) => {
|
|
|
|
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 ) => {
|
|
|
|
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
|
|
|
}
|