Skip to content

Commit ac0ef53

Browse files
committed
Feature: Clear facets
1 parent a154a26 commit ac0ef53

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

packages/client/src/builders/search/facetBuilder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,12 @@ export class FacetBuilder {
651651
}
652652
//#endregion
653653

654+
public clear(): this {
655+
this.facets = [];
656+
657+
return this;
658+
}
659+
654660
build(): ProductFacetQuery | null {
655661
return this.facets.length === 0
656662
? null

packages/client/tests/integration-tests/productSearch.integration.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ test('Product search - data object facets', async () => {
5050
expect(result?.hits).toBeGreaterThan(0);
5151
});
5252

53+
test('Product search - with cleared facets', async () => {
54+
const request = baseProductBuilder()
55+
.facets(f => f.addBrandFacet());
56+
57+
request.facets(builder => builder.clear());
58+
59+
const result = await searcher.searchProducts(request.build());
60+
61+
expect(result?.facets).toBeUndefined();
62+
});
63+
5364
test('Retail Media search', async () => {
5465
const request: ProductSearchRequest = baseProductBuilder()
5566
.setRetailMedia({

packages/client/tests/unit-tests/builders/facetBuilder.unit.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,15 @@ test('brand to be added as facet and to have its value set', () => {
4141
expect(subject?.items).toHaveLength(2);
4242
const brandFacet = subject!.items![0] as BrandFacet;
4343
expect(brandFacet.selected).toBe(null);
44+
});
45+
46+
test('clear', () => {
47+
const builder: FacetBuilder = baseBuilder();
48+
builder.addBrandFacet(['HP']);
49+
50+
builder.clear();
51+
52+
const subject: ProductFacetQuery | null = builder.build();
53+
54+
expect(subject).toBe(null);
4455
});

0 commit comments

Comments
 (0)