From 0150a0cb26f74ea0d162254631afe1d190cd339f Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Fri, 30 Sep 2022 19:00:03 +0200 Subject: [PATCH] search: Add some tests for instrumentation.js Change I45dda26cb5 removes some code, and in the process reduces the branch coverage of the skins.vector.search module below the threshold of 25% that CI requires; add some tests for instrumentation.js to bring the branch coverage up again. Change-Id: I5d7ae019b3219b410c658583a6d72cf56d0cc1c5 --- tests/jest/instrumentation.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/jest/instrumentation.test.js diff --git a/tests/jest/instrumentation.test.js b/tests/jest/instrumentation.test.js new file mode 100644 index 00000000..334d6c47 --- /dev/null +++ b/tests/jest/instrumentation.test.js @@ -0,0 +1,24 @@ +const instrumentation = require( '../../resources/skins.vector.search/instrumentation.js' ); + +describe( 'instrumentation', () => { + test.each( [ + [ 0, 'acrw10' ], + [ 1, 'acrw11' ], + [ -1, 'acrw1' ] + ] )( 'getWprovFromResultIndex( %d ) = %s', ( index, expected ) => { + expect( instrumentation.getWprovFromResultIndex( index ) ) + .toBe( expected ); + } ); + + describe( 'generateUrl', () => { + test.each( [ + [ 'string', 'title' ], + [ 'object', { title: 'title' } ] + ] )( 'should generate URL from %s', ( _name, suggestion ) => { + const meta = { index: 1 }; + expect( instrumentation.generateUrl( suggestion, meta ) ) + // mw-node-qunit provides a pretty weird mw.Uri.toString()... + .toBe( 'https://host?title=suggestion=wprov' ); + } ); + } ); +} );