Skip to content

Commit

Permalink
fix(commerce): only expose breadcrumbs with values (#4132)
Browse files Browse the repository at this point in the history
By only exposing breadcrumbs with values, breadcrumbs without facet
values will not be included. Since we also filter out breadcrumbs
without values, the `hasBreadcrumbs` check will be `false` instead of
`true` when there are facets with no values, which is the desired state.

[CAPI-1089]

[CAPI-1089]:
https://coveord.atlassian.net/browse/CAPI-1089?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
Spuffynism authored Jul 3, 2024
1 parent 60a384d commit d3d57e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ describe('core breadcrumb manager', () => {
expect(breadcrumbManager.subscribe).toBeTruthy();
});

it('#hasBreadcrumbs is false when there are no facet values', () => {
setFacetsState(
buildMockCommerceRegularFacetResponse({
facetId,
values: [],
})
);
setFacetsState(
buildMockCommerceNumericFacetResponse({
facetId,
values: [],
})
);

expect(breadcrumbManager.state.hasBreadcrumbs).toEqual(false);
});

describe('#deselectAll', () => {
it('deselects all breadcrumbs', () => {
breadcrumbManager.deselectAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ export function buildCoreBreadcrumbManager(
.map((facetId) =>
options.facetResponseSelector(engine[stateKey], facetId)
)
.filter((facet): facet is AnyFacetResponse => facet !== undefined)
.filter(
(facet): facet is AnyFacetResponse =>
facet !== undefined && facet.values.length > 0
)
.map(createBreadcrumb) ?? [];
return {
facetBreadcrumbs: breadcrumbs,
Expand Down

0 comments on commit d3d57e8

Please sign in to comment.