Skip to content

Commit

Permalink
feat(headless): restore range facet state after refresh (#4599)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenKandelaars authored Oct 29, 2024
1 parent 91a2538 commit f304b63
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function restoreFromParameters(
if (action.payload.nf) {
restoreRangeFacets(state, action.payload.nf, 'numericalRange');
}
if (action.payload.mnf) {
restoreRangeFacets(state, action.payload.mnf, 'numericalRange');
}
if (action.payload.df) {
restoreRangeFacets(state, action.payload.df, 'dateRange');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3024,6 +3024,67 @@ describe('commerceFacetSetReducer', () => {
);
});

it('populates manual numeric facet requests', () => {
const finalState = commerceFacetSetReducer(
state,
action({
mnf: {
manual_numeric_facet_1: [
{
start: 1,
end: 10,
endInclusive: false,
},
{
start: 15,
end: 20,
endInclusive: true,
},
],
manual_numeric_facet_2: [
{
start: 11,
end: 20,
endInclusive: true,
},
],
},
})
);

const firstRequest = finalState['manual_numeric_facet_1'].request;
expect(firstRequest.type).toEqual('numericalRange');
expect(firstRequest.values).toEqual(
expect.arrayContaining([
expect.objectContaining({
start: 1,
end: 10,
endInclusive: false,
state: 'selected',
}),
expect.objectContaining({
start: 15,
end: 20,
endInclusive: true,
state: 'selected',
}),
])
);

const secondRequest = finalState['manual_numeric_facet_2'].request;
expect(secondRequest.type).toEqual('numericalRange');
expect(secondRequest.values).toEqual(
expect.arrayContaining([
expect.objectContaining({
start: 11,
end: 20,
endInclusive: true,
state: 'selected',
}),
])
);
});

it('populates date facet requests', () => {
const finalState = commerceFacetSetReducer(
state,
Expand Down

0 comments on commit f304b63

Please sign in to comment.