mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-28 01:20:07 +00:00
Merge "search: Remove unused generateUrl() function"
This commit is contained in:
commit
aafd9eabaf
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
{
|
||||
"resourceModule": "skins.vector.search",
|
||||
"maxSize": "3.3 kB"
|
||||
"maxSize": "3.2 kB"
|
||||
},
|
||||
{
|
||||
"resourceModule": "skins.vector.icons",
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* @see https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/skins/Vector/+/refs/heads/master/includes/Constants.php
|
||||
*/
|
||||
const INPUT_LOCATION_MOVED = 'header-moved',
|
||||
wgScript = mw.config.get( 'wgScript' ),
|
||||
// T251544: Collect search performance metrics to compare Vue search with
|
||||
// mediawiki.searchSuggest performance. Marks and Measures will only be
|
||||
// recorded on the Vector skin and only if browser supported.
|
||||
|
@ -122,35 +121,6 @@ function getWprovFromResultIndex( index ) {
|
|||
* @property {string} [url]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} GenerateUrlMeta
|
||||
* @property {number} index
|
||||
*/
|
||||
|
||||
/**
|
||||
* Used by the Vue-enhanced search component to generate URLs for the search results. Adds a
|
||||
* `wprov` paramater to the URL to satisfy the SearchSatisfaction instrumentation.
|
||||
*
|
||||
* @see getWprovFromResultIndex
|
||||
*
|
||||
* @param {SearchResultPartial|string} suggestion
|
||||
* @param {GenerateUrlMeta} meta
|
||||
* @return {string}
|
||||
*/
|
||||
function generateUrl( suggestion, meta ) {
|
||||
const result = new mw.Uri( wgScript );
|
||||
|
||||
if ( typeof suggestion !== 'string' ) {
|
||||
suggestion = suggestion.title;
|
||||
}
|
||||
|
||||
result.query.title = 'Special:Search';
|
||||
result.query.suggestion = suggestion;
|
||||
result.query.wprov = getWprovFromResultIndex( meta.index );
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new list of search results,
|
||||
* with the `wprov` parameter added to each result's url (if any).
|
||||
|
@ -174,7 +144,6 @@ function addWprovToSearchResultUrls( results, offset ) {
|
|||
* @typedef {Object} Instrumentation
|
||||
* @property {Object} listeners
|
||||
* @property {Function} getWprovFromResultIndex
|
||||
* @property {Function} generateUrl
|
||||
* @property {Function} addWprovToSearchResultUrls
|
||||
*/
|
||||
|
||||
|
@ -203,6 +172,5 @@ module.exports = {
|
|||
onSubmit: onSuggestionClick
|
||||
},
|
||||
getWprovFromResultIndex,
|
||||
generateUrl,
|
||||
addWprovToSearchResultUrls
|
||||
};
|
||||
|
|
|
@ -10,17 +10,6 @@ describe( 'instrumentation', () => {
|
|||
.toBe( expected );
|
||||
} );
|
||||
|
||||
describe( 'generateUrl', () => {
|
||||
test.each( [
|
||||
[ 'string', 'title' ],
|
||||
[ 'object', { title: 'title' } ]
|
||||
] )( 'should generate URL from %s', ( _name, suggestion ) => {
|
||||
const meta = { index: 1 };
|
||||
expect( instrumentation.generateUrl( suggestion, meta ) )
|
||||
.toBe( 'https://host/?title=Special%3ASearch&suggestion=title&wprov=acrw1_1' );
|
||||
} );
|
||||
} );
|
||||
|
||||
test( 'addWprovToSearchResultUrls without offset', () => {
|
||||
const url1 = 'https://host/?title=Special%3ASearch&search=Aa',
|
||||
url2Base = 'https://host/?title=Special%3ASearch&search=Ab',
|
||||
|
|
53
tests/jest/urlGenerator.test.js
Normal file
53
tests/jest/urlGenerator.test.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
const urlGenerator = require( '../../resources/skins.vector.search/urlGenerator.js' );
|
||||
|
||||
describe( 'urlGenerator', () => {
|
||||
describe( 'default', () => {
|
||||
test.each( [
|
||||
[ 'string', 'title', '&fulltext=1' ],
|
||||
[ 'object', { title: 'title', id: 0, key: '' } ]
|
||||
] )( 'suggestion as %s', ( _name, suggestion, extraParams = '' ) => {
|
||||
const config = {
|
||||
get: jest.fn().mockImplementation( ( key, fallback ) => {
|
||||
if ( key === 'wgScript' ) {
|
||||
return '/w/index.php';
|
||||
}
|
||||
return fallback;
|
||||
} ),
|
||||
set: jest.fn()
|
||||
};
|
||||
|
||||
expect( urlGenerator( config ).generateUrl( suggestion ) )
|
||||
.toBe( `/w/index.php?title=Special%3ASearch${extraParams}&search=title` );
|
||||
} );
|
||||
|
||||
test( 'custom params, articlePath', () => {
|
||||
const config = {
|
||||
get: jest.fn().mockImplementation( ( _key, fallback ) => {
|
||||
return fallback;
|
||||
} ),
|
||||
set: jest.fn()
|
||||
};
|
||||
|
||||
expect( urlGenerator( config ).generateUrl(
|
||||
{ title: 'title', id: 0, key: '' },
|
||||
{ TITLE: 'SPECIAL:SEARCH' },
|
||||
'/W/INDEX.PHP'
|
||||
) ).toBe( '/W/INDEX.PHP?TITLE=SPECIAL%3ASEARCH&search=title' );
|
||||
} );
|
||||
} );
|
||||
|
||||
test( 'custom', () => {
|
||||
const customGenerator = {};
|
||||
const config = {
|
||||
get: jest.fn().mockImplementation( ( key, fallback ) => {
|
||||
if ( key === 'wgVectorSearchUrlGenerator' ) {
|
||||
return customGenerator;
|
||||
}
|
||||
return fallback;
|
||||
} ),
|
||||
set: jest.fn()
|
||||
};
|
||||
|
||||
expect( urlGenerator( config ) ).toBe( customGenerator );
|
||||
} );
|
||||
} );
|
Loading…
Reference in a new issue