@@ -20,7 +20,9 @@ import {
2020 FetchResources ,
2121 LoadFilterOptions ,
2222 LoadFilterOptionsAndSetValues ,
23+ SetDefaultFilterValue ,
2324 SetExtraFilters ,
25+ UpdateSelectedFilterOption ,
2426} from './global-search.actions' ;
2527import { GlobalSearchSelectors } from './global-search.selectors' ;
2628import { GlobalSearchState } from './global-search.state' ;
@@ -239,4 +241,27 @@ describe('GlobalSearchState', () => {
239241 ] ) ;
240242 } ) ;
241243 } ) ;
244+
245+ describe ( 'SetDefaultFilterValue' , ( ) => {
246+ it ( 'should include the default filter in the API call' , ( ) => {
247+ const { store, mockGetResources } = setup ( ) ;
248+
249+ store . dispatch ( new SetDefaultFilterValue ( 'defaultKey' , 'default-value' ) ) ;
250+ store . dispatch ( new FetchResources ( ) ) ;
251+
252+ const params = mockGetResources . mock . calls [ 0 ] [ 0 ] ;
253+ expect ( params [ 'cardSearchFilter[defaultKey][]' ] ) . toBe ( 'default-value' ) ;
254+ } ) ;
255+
256+ it ( 'should not be overridden when a selected filter for the same key is cleared' , ( ) => {
257+ const { store, mockGetResources } = setup ( ) ;
258+
259+ store . dispatch ( new SetDefaultFilterValue ( 'defaultKey' , 'default-value' ) ) ;
260+ store . dispatch ( new UpdateSelectedFilterOption ( 'defaultKey' , [ ] ) ) ;
261+ store . dispatch ( new FetchResources ( ) ) ;
262+
263+ const params = mockGetResources . mock . calls [ 0 ] [ 0 ] ;
264+ expect ( params [ 'cardSearchFilter[defaultKey][]' ] ) . toBe ( 'default-value' ) ;
265+ } ) ;
266+ } ) ;
242267} ) ;
0 commit comments