mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
search: Remove unused generateUrl() function
As far as I can tell, this has been dead code ever since it was
introduced in change Ica040cd18d (commit aa10668e6d
), and was never
called; the effective search URL was initially constructed via inputs to
the search form (e.g. a hidden input for wprov), and later the separate
urlGenerator.js was added. (Also, “suggestion” is not a valid
Special:Search paramater as far as I can tell.)
Also add some tests for the separate urlGenerator.js, to make up for the
other tests being removed.
This reduces the module size of skins.vector.search enough that we can
decrease the bundle size test config to 3.2 kB [KiB].
Change-Id: I6be5ba362402c2c2ec582d9a0192c80f46e7a7ce
This commit is contained in:
parent
820c173644
commit
6fc25f87b9
|
@ -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