This repository was archived by the owner on Dec 30, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -238,8 +238,34 @@ describe('Store', () => {
238
238
distinct : null ,
239
239
attributesToRetrieve : [ 'objectID' ] ,
240
240
} ;
241
+ store . addFacet ( 'price' ) ;
241
242
242
243
// Make sure distinct parameter is gone when overrided with null.
243
244
expect ( store . queryParameters ) . not . toHaveProperty ( 'distinct' ) ;
244
245
} ) ;
246
+
247
+ test ( 'should allow to retrieve all the searchParameters' , ( ) => {
248
+ const client = algoliaClient ( 'app_id' , 'api_key' ) ;
249
+ const helper = algoliaHelper ( client ) ;
250
+
251
+ const store = new Store ( helper ) ;
252
+
253
+ const searchParameters = helper . getState ( ) ;
254
+ expect ( store . searchParameters ) . toEqual ( searchParameters ) ;
255
+ } ) ;
256
+
257
+ test ( 'should allow to accept new search parameters' , ( ) => {
258
+ const client = algoliaClient ( 'app_id' , 'api_key' ) ;
259
+ const helper = algoliaHelper ( client ) ;
260
+
261
+ const store = new Store ( helper ) ;
262
+
263
+ const searchParameters = helper . getState ( ) ;
264
+ const newSearchParameters = Object . assign ( { } , searchParameters , {
265
+ page : 3 ,
266
+ } ) ;
267
+
268
+ store . searchParameters = newSearchParameters ;
269
+ expect ( store . searchParameters ) . toEqual ( newSearchParameters ) ;
270
+ } ) ;
245
271
} ) ;
Original file line number Diff line number Diff line change 1
1
import algolia from 'algoliasearch' ;
2
- import algoliaHelper from 'algoliasearch-helper' ;
2
+ import algoliaHelper , { SearchParameters } from 'algoliasearch-helper' ;
3
3
import { version } from '../package.json' ;
4
4
5
5
export const FACET_AND = 'and' ;
@@ -306,6 +306,15 @@ export class Store {
306
306
return parameters ;
307
307
}
308
308
309
+ get searchParameters ( ) {
310
+ return Object . assign ( { } , this . _helper . state ) ;
311
+ }
312
+
313
+ set searchParameters ( searchParameters ) {
314
+ const newSearchParameters = SearchParameters . make ( searchParameters ) ;
315
+ this . _helper . setState ( newSearchParameters ) ;
316
+ }
317
+
309
318
// Todo: find a better name for this function.
310
319
refresh ( ) {
311
320
this . _helper . search ( ) ;
You can’t perform that action at this time.
0 commit comments