Skip to content

Commit 8457001

Browse files
micgro42lucaswerkmeister
authored andcommitted
Support loading more results in Vector search client
This lets users scroll to load additional search results. To match the old search more closely, we’ll also want to reduce the number of results initially shown (should be fewer than the number of loaded results), but that can be done separately. Bug: T322333 Change-Id: I67fac3b209d6a1ab2661e1e1c0681edd8472ac6c Depends-On: Iadade9cbf48457cfeabc78439624602ec3f98782
1 parent 95036aa commit 8457001

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

repo/resources/wikibase.vector.searchClient.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
const vectorSearchClient = {
5656
fetchByTitle: ( q, limit = 10, _showDescription = true ) => {
5757
return fetchResults( q, limit );
58+
},
59+
loadMore: ( q, offset, limit = 10, _showDescription = true ) => {
60+
return fetchResults( q, limit, offset );
5861
}
5962
};
6063

repo/tests/jest/wikibase.vector.searchClient.spec.js

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ describe( 'Vector Search Client', () => {
4242
]
4343
} ];
4444

45-
it( 'test construction and fetchByTitle behavior', async () => {
45+
beforeEach( () => {
46+
// ensure that require( searchClient.js ) has the side-effect we want to test each time
47+
jest.resetModules();
48+
} );
49+
50+
it.each( [
51+
[ 'fetchByTitle' ],
52+
[ 'loadMore' ]
53+
] )( 'test construction and %s behavior', async ( name ) => {
4654
const fakeApiInstance = {
4755
get: jest.fn().mockResolvedValue( {
4856
search: mockApiResults
@@ -62,14 +70,10 @@ describe( 'Vector Search Client', () => {
6270
const vectorSearchClient = global.mw.config.set.mock.calls[ 0 ][ 1 ];
6371

6472
const exampleSearchString = 'abc';
73+
const vectorOffset = 20;
6574
const vectorLimit = 10;
6675

67-
const apiController = vectorSearchClient.fetchByTitle(
68-
exampleSearchString,
69-
vectorLimit,
70-
true
71-
);
72-
expect( fakeApiInstance.get ).toHaveBeenCalledWith( {
76+
const expectedParams = {
7377
action: 'wbsearchentities',
7478
search: exampleSearchString,
7579
limit: vectorLimit,
@@ -78,7 +82,26 @@ describe( 'Vector Search Client', () => {
7882
type: 'item',
7983
format: 'json',
8084
errorformat: 'plaintext'
81-
} );
85+
};
86+
let apiController;
87+
if ( name === 'fetchByTitle' ) {
88+
apiController = vectorSearchClient.fetchByTitle(
89+
exampleSearchString,
90+
vectorLimit,
91+
true
92+
);
93+
} else if ( name === 'loadMore' ) {
94+
apiController = vectorSearchClient.loadMore(
95+
exampleSearchString,
96+
vectorOffset,
97+
vectorLimit,
98+
true
99+
);
100+
expectedParams.continue = vectorOffset;
101+
} else {
102+
throw new Error( `Unexpected test name ${name}` );
103+
}
104+
expect( fakeApiInstance.get ).toHaveBeenCalledWith( expectedParams );
82105

83106
const actualTransformedResult = await apiController.fetch;
84107
expect( actualTransformedResult ).toStrictEqual( {

0 commit comments

Comments
 (0)