2022-09-30 17:00:03 +00:00
|
|
|
const instrumentation = require( '../../resources/skins.vector.search/instrumentation.js' );
|
|
|
|
|
|
|
|
describe( 'instrumentation', () => {
|
|
|
|
test.each( [
|
2022-10-21 09:30:18 +00:00
|
|
|
[ 0, 'acrw1_0' ],
|
|
|
|
[ 1, 'acrw1_1' ],
|
|
|
|
[ -1, 'acrw1_-1' ]
|
2022-09-30 17:00:03 +00:00
|
|
|
] )( 'getWprovFromResultIndex( %d ) = %s', ( index, expected ) => {
|
|
|
|
expect( instrumentation.getWprovFromResultIndex( index ) )
|
|
|
|
.toBe( expected );
|
|
|
|
} );
|
|
|
|
|
2022-10-24 12:10:46 +00:00
|
|
|
test( 'addWprovToSearchResultUrls without offset', () => {
|
2022-09-30 14:45:38 +00:00
|
|
|
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',
|
2024-01-11 19:08:25 +00:00
|
|
|
url: `${ url2Base }&wprov=xyz`
|
2022-09-30 14:45:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Ac',
|
|
|
|
url: url3
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Ad'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-10-24 12:10:46 +00:00
|
|
|
expect( instrumentation.addWprovToSearchResultUrls( results, 0 ) )
|
2022-09-30 14:45:38 +00:00
|
|
|
.toStrictEqual( [
|
|
|
|
{
|
|
|
|
title: 'Aa',
|
2024-01-11 19:08:25 +00:00
|
|
|
url: `${ url1 }&wprov=acrw1_0`
|
2022-09-30 14:45:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Ab',
|
2024-01-11 19:08:25 +00:00
|
|
|
url: `${ url2Base }&wprov=acrw1_1`
|
2022-09-30 14:45:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Ac',
|
2024-01-11 19:08:25 +00:00
|
|
|
url: `${ url3 }?wprov=acrw1_2`
|
2022-09-30 14:45:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Ad'
|
|
|
|
}
|
|
|
|
] );
|
|
|
|
expect( results[ 0 ].url ).toStrictEqual( url1 );
|
|
|
|
} );
|
2022-10-24 12:10:46 +00:00
|
|
|
|
|
|
|
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',
|
2024-01-11 19:08:25 +00:00
|
|
|
url: `${ url1 }&wprov=acrw1_4`
|
2022-10-24 12:10:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Af',
|
2024-01-11 19:08:25 +00:00
|
|
|
url: `${ url2 }&wprov=acrw1_5`
|
2022-10-24 12:10:46 +00:00
|
|
|
}
|
|
|
|
] );
|
|
|
|
} );
|
2022-09-30 17:00:03 +00:00
|
|
|
} );
|