mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-27 17:10:19 +00:00
6fc25f87b9
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
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
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 );
|
|
} );
|
|
} );
|