Debian Codegraph @

skins/Vector/tests/jest/urlGenerator.test.js

raw symbols SCIP
1 const urlGenerator = require( '../../resources/skins.vector.search/urlGenerator.js' );
2
3 describe( 'urlGenerator', () => {
4 describe( 'default', () => {
5 test.each( [
6 [ 'string', 'title', '&fulltext=1' ],
7 [ 'object', { title: 'title', id: 0, key: '' } ]
8 ] )( 'suggestion as %s', ( _name, suggestion, extraParams = '' ) => {
9 const config = {
10 get: jest.fn().mockImplementation( ( key, fallback ) => {
11 if ( key === 'wgScript' ) {
12 return '/w/index.php';
13 }
14 return fallback;
15 } ),
16 set: jest.fn()
17 };
18
19 expect( urlGenerator( config ).generateUrl( suggestion ) )
20 .toBe( `/w/index.php?title=Special%3ASearch${ extraParams }&search=title` );
21 } );
22
23 test( 'custom params, articlePath', () => {
24 const config = {
25 get: jest.fn().mockImplementation( ( _key, fallback ) => fallback ),
26 set: jest.fn()
27 };
28
29 expect( urlGenerator( config ).generateUrl(
30 { title: 'title', id: 0, key: '' },
31 { TITLE: 'SPECIAL:SEARCH' },
32 '/W/INDEX.PHP'
33 ) ).toBe( '/W/INDEX.PHP?TITLE=SPECIAL%3ASEARCH&search=title' );
34 } );
35 } );
36
37 test( 'custom', () => {
38 const customGenerator = {};
39 const config = {
40 get: jest.fn().mockImplementation( ( key, fallback ) => {
41 if ( key === 'wgVectorSearchUrlGenerator' ) {
42 return customGenerator;
43 }
44 return fallback;
45 } ),
46 set: jest.fn()
47 };
48
49 expect( urlGenerator( config ) ).toBe( customGenerator );
50 } );
51 } );