Skip to content

Commit 5905b79

Browse files
authored
Merge pull request #1010 from Vlad0n20/fix/ENG-11333
feat(ENG-11333): fix selected filters from overriding default filters
2 parents 23b9cae + cff3b4e commit 5905b79

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/app/shared/stores/global-search/global-search.state.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import {
2020
FetchResources,
2121
LoadFilterOptions,
2222
LoadFilterOptionsAndSetValues,
23+
SetDefaultFilterValue,
2324
SetExtraFilters,
25+
UpdateSelectedFilterOption,
2426
} from './global-search.actions';
2527
import { GlobalSearchSelectors } from './global-search.selectors';
2628
import { 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
});

src/app/shared/stores/global-search/global-search.state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ export class GlobalSearchState {
327327
let hasCedarFilters = state.extraFilters.length > 0;
328328

329329
Object.entries(state.selectedFilterOptions).forEach(([key, options]) => {
330+
if (key in state.defaultFilterOptions) return;
330331
const filter = state.filters.find((f) => f.key === key) ?? state.extraFilters.find((f) => f.key === key);
331332

332333
if (filter?.cedarPropertyIri) {

0 commit comments

Comments
 (0)