Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/app/shared/stores/global-search/global-search.state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
FetchResources,
LoadFilterOptions,
LoadFilterOptionsAndSetValues,
SetDefaultFilterValue,
SetExtraFilters,
UpdateSelectedFilterOption,
} from './global-search.actions';
import { GlobalSearchSelectors } from './global-search.selectors';
import { GlobalSearchState } from './global-search.state';
Expand Down Expand Up @@ -239,4 +241,27 @@ describe('GlobalSearchState', () => {
]);
});
});

describe('SetDefaultFilterValue', () => {
it('should include the default filter in the API call', () => {
const { store, mockGetResources } = setup();

store.dispatch(new SetDefaultFilterValue('defaultKey', 'default-value'));
store.dispatch(new FetchResources());

const params = mockGetResources.mock.calls[0][0];
expect(params['cardSearchFilter[defaultKey][]']).toBe('default-value');
});

it('should not be overridden when a selected filter for the same key is cleared', () => {
const { store, mockGetResources } = setup();

store.dispatch(new SetDefaultFilterValue('defaultKey', 'default-value'));
store.dispatch(new UpdateSelectedFilterOption('defaultKey', []));
store.dispatch(new FetchResources());

const params = mockGetResources.mock.calls[0][0];
expect(params['cardSearchFilter[defaultKey][]']).toBe('default-value');
});
});
});
1 change: 1 addition & 0 deletions src/app/shared/stores/global-search/global-search.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export class GlobalSearchState {
let hasCedarFilters = state.extraFilters.length > 0;

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

if (filter?.cedarPropertyIri) {
Expand Down
Loading