mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-18 10:51:10 +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
83 lines
1.7 KiB
JavaScript
83 lines
1.7 KiB
JavaScript
const instrumentation = require( '../../resources/skins.vector.search/instrumentation.js' );
|
|
|
|
describe( 'instrumentation', () => {
|
|
test.each( [
|
|
[ 0, 'acrw1_0' ],
|
|
[ 1, 'acrw1_1' ],
|
|
[ -1, 'acrw1_-1' ]
|
|
] )( 'getWprovFromResultIndex( %d ) = %s', ( index, expected ) => {
|
|
expect( instrumentation.getWprovFromResultIndex( index ) )
|
|
.toBe( expected );
|
|
} );
|
|
|
|
test( 'addWprovToSearchResultUrls without offset', () => {
|
|
const url1 = 'https://host/?title=Special%3ASearch&search=Aa',
|
|
url2Base = 'https://host/?title=Special%3ASearch&search=Ab',
|
|
url3 = 'https://host/Ac';
|
|
const results = [
|
|
{
|
|
title: 'Aa',
|
|
url: url1
|
|
},
|
|
{
|
|
title: 'Ab',
|
|
url: `${url2Base}&wprov=xyz`
|
|
},
|
|
{
|
|
title: 'Ac',
|
|
url: url3
|
|
},
|
|
{
|
|
title: 'Ad'
|
|
}
|
|
];
|
|
|
|
expect( instrumentation.addWprovToSearchResultUrls( results, 0 ) )
|
|
.toStrictEqual( [
|
|
{
|
|
title: 'Aa',
|
|
url: `${url1}&wprov=acrw1_0`
|
|
},
|
|
{
|
|
title: 'Ab',
|
|
url: `${url2Base}&wprov=acrw1_1`
|
|
},
|
|
{
|
|
title: 'Ac',
|
|
url: `${url3}?wprov=acrw1_2`
|
|
},
|
|
{
|
|
title: 'Ad'
|
|
}
|
|
] );
|
|
expect( results[ 0 ].url ).toStrictEqual( url1 );
|
|
} );
|
|
|
|
test( 'addWprovToSearchResultUrls with offset', () => {
|
|
const url1 = 'https://host/?title=Special%3ASearch&search=Ae',
|
|
url2 = 'https://host/?title=Special%3ASearch&search=Af';
|
|
const results = [
|
|
{
|
|
title: 'Ae',
|
|
url: url1
|
|
},
|
|
{
|
|
title: 'Af',
|
|
url: url2
|
|
}
|
|
];
|
|
|
|
expect( instrumentation.addWprovToSearchResultUrls( results, 4 ) )
|
|
.toStrictEqual( [
|
|
{
|
|
title: 'Ae',
|
|
url: `${url1}&wprov=acrw1_4`
|
|
},
|
|
{
|
|
title: 'Af',
|
|
url: `${url2}&wprov=acrw1_5`
|
|
}
|
|
] );
|
|
} );
|
|
} );
|