Skip to content

Commit fc98d72

Browse files
committed
feat(es2): CR followup
1 parent 70a3871 commit fc98d72

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ describe('GlobalSearchState', () => {
9292
expect(mockGetFilterOptions).not.toHaveBeenCalled();
9393
});
9494

95+
it('should set isLoaded to true for a CEDAR filter when short-circuiting', () => {
96+
const { store } = setup();
97+
98+
store.dispatch(new SetExtraFilters([CEDAR_FILTER]));
99+
store.dispatch(new FetchResources());
100+
store.dispatch(new LoadFilterOptions(CEDAR_FILTER.key));
101+
102+
const filters = store.selectSnapshot(GlobalSearchSelectors.getFilters);
103+
const cedarFilterState = filters.find((f) => f.key === CEDAR_FILTER.key);
104+
expect(cedarFilterState?.isLoaded).toBe(true);
105+
});
106+
95107
it('should call the API for a regular filter', () => {
96108
const { store, mockGetFilterOptions } = setup();
97109

@@ -180,10 +192,35 @@ describe('GlobalSearchState', () => {
180192
store.dispatch(new FetchResources());
181193

182194
const params = mockGetResources.mock.calls[0][0];
183-
expect(params[`cardSearchText[osf:hasCedarRecord.cedar:${CEDAR_FILTER.cedarPropertyIri}]`]).toBe('"High School"');
195+
expect(params[`cardSearchText[osf:hasCedarRecord.cedar:${CEDAR_FILTER.cedarPropertyIri}][]`]).toEqual([
196+
'"High School"',
197+
]);
184198
expect(params[`cardSearchFilter[${CEDAR_FILTER.key}][]`]).toBeUndefined();
185199
});
186200

201+
it('should include all selected values for a CEDAR filter', () => {
202+
const { store, mockGetResources } = setup();
203+
store.dispatch(new SetExtraFilters([CEDAR_FILTER]));
204+
store.dispatch(new FetchResources());
205+
mockGetResources.mockClear();
206+
207+
store.dispatch(
208+
new LoadFilterOptionsAndSetValues({
209+
[CEDAR_FILTER.key]: [
210+
{ label: 'High School', value: 'High School', cardSearchResultCount: null },
211+
{ label: 'Middle School', value: 'Middle School', cardSearchResultCount: null },
212+
],
213+
})
214+
);
215+
store.dispatch(new FetchResources());
216+
217+
const params = mockGetResources.mock.calls[0][0];
218+
expect(params[`cardSearchText[osf:hasCedarRecord.cedar:${CEDAR_FILTER.cedarPropertyIri}][]`]).toEqual([
219+
'"High School"',
220+
'"Middle School"',
221+
]);
222+
});
223+
187224
it('should use extraFilters as fallback for CEDAR lookup before state.filters is populated', () => {
188225
const { store, mockGetResources } = setup();
189226
store.dispatch(new SetExtraFilters([CEDAR_FILTER]));
@@ -197,7 +234,9 @@ describe('GlobalSearchState', () => {
197234
store.dispatch(new FetchResources());
198235

199236
const params = mockGetResources.mock.calls[0][0];
200-
expect(params[`cardSearchText[osf:hasCedarRecord.cedar:${CEDAR_FILTER.cedarPropertyIri}]`]).toBe('"High School"');
237+
expect(params[`cardSearchText[osf:hasCedarRecord.cedar:${CEDAR_FILTER.cedarPropertyIri}][]`]).toEqual([
238+
'"High School"',
239+
]);
201240
});
202241
});
203242
});

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export class GlobalSearchState {
6565

6666
const filter = state.filters.find((f) => f.key === filterKey);
6767
if (filter?.cedarPropertyIri) {
68+
ctx.patchState({
69+
filters: state.filters.map((f) => (f.key === filterKey ? { ...f, isLoaded: true } : f)),
70+
});
6871
return EMPTY;
6972
}
7073

@@ -328,9 +331,9 @@ export class GlobalSearchState {
328331

329332
if (filter?.cedarPropertyIri) {
330333
hasCedarFilters = true;
331-
const value = options[0]?.value;
332-
if (value) {
333-
filtersParams[`cardSearchText[osf:hasCedarRecord.cedar:${filter.cedarPropertyIri}]`] = `"${value}"`;
334+
const values = options.map((o) => `"${o.value}"`);
335+
if (values.length) {
336+
filtersParams[`cardSearchText[osf:hasCedarRecord.cedar:${filter.cedarPropertyIri}][]`] = values;
334337
}
335338
} else {
336339
const firstOptionValue = options[0]?.value;

0 commit comments

Comments
 (0)