2022-11-30 16:25:59 +00:00
|
|
|
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 ) )
|
2024-01-11 19:08:25 +00:00
|
|
|
.toBe( `/w/index.php?title=Special%3ASearch${ extraParams }&search=title` );
|
2022-11-30 16:25:59 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
test( 'custom params, articlePath', () => {
|
|
|
|
const config = {
|
2024-06-06 15:22:05 +00:00
|
|
|
get: jest.fn().mockImplementation( ( _key, fallback ) => fallback ),
|
2022-11-30 16:25:59 +00:00
|
|
|
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 );
|
|
|
|
} );
|
|
|
|
} );
|