From a3060ca818712830d3f6def708da2e3449dd4041 Mon Sep 17 00:00:00 2001 From: aprudhomme-coveo <132079077+aprudhomme-coveo@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:41:08 -0400 Subject: [PATCH] feat(atomic): change default label to the field for automatic facets (#3090) https://coveord.atlassian.net/browse/KIT-2631 --- .../automatic-facet-assertions.ts | 10 +++++ .../automatic-facet.cypress.ts | 45 +++++++++++++++++++ .../atomic-breadbox/atomic-breadbox.tsx | 2 +- .../atomic-automatic-facet.tsx | 2 +- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet-assertions.ts b/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet-assertions.ts index 38941e7fff7..1575d2dc990 100644 --- a/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet-assertions.ts +++ b/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet-assertions.ts @@ -53,3 +53,13 @@ export function assertLogClearFacetValues() { }); }); } + +export function assertLabel( + BaseFacetSelector: BaseFacetSelector, + labelValue: string, + fieldOrLabel: string +) { + it(`should have the ${fieldOrLabel} value as the value`, () => { + BaseFacetSelector.labelButton().contains(labelValue); + }); +} diff --git a/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet.cypress.ts b/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet.cypress.ts index d0007bb6345..859bb654b2c 100644 --- a/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet.cypress.ts +++ b/packages/atomic/cypress/e2e/facets/automatic-facet/automatic-facet.cypress.ts @@ -45,6 +45,51 @@ describe('Automatic Facet Test Suites', () => { ); }); + describe('verify label', () => { + const fieldName = 'field'; + function setupForLabelLogic(responseLabel: string | undefined) { + new TestFixture() + .with( + addAutomaticFacetGenerator({ + 'desired-count': '1', + 'are-collapsed': 'false', + }) + ) + .withCustomResponse((r) => { + r.generateAutomaticFacets = { + facets: [ + { + field: fieldName, + label: responseLabel, + values: [], + }, + ], + }; + }) + .init(); + } + + describe('when it is defined in the response', () => { + beforeEach(() => setupForLabelLogic('label')); + + AutomaticFacetAssertions.assertLabel( + AutomaticFacetSelectors, + 'label', + 'label' + ); + }); + + describe('when it is undefined in the response', () => { + beforeEach(() => setupForLabelLogic(undefined)); + + AutomaticFacetAssertions.assertLabel( + AutomaticFacetSelectors, + fieldName, + 'field' + ); + }); + }); + describe('when selecting a value', () => { const index = 1; function setupSelectValue() { diff --git a/packages/atomic/src/components/search/atomic-breadbox/atomic-breadbox.tsx b/packages/atomic/src/components/search/atomic-breadbox/atomic-breadbox.tsx index 44d68d1271b..901a644db20 100644 --- a/packages/atomic/src/components/search/atomic-breadbox/atomic-breadbox.tsx +++ b/packages/atomic/src/components/search/atomic-breadbox/atomic-breadbox.tsx @@ -389,7 +389,7 @@ export class AtomicBreadbox implements InitializableComponent { ) .map(({value, facetId, field, label}) => ({ facetId, - label: this.bindings.i18n.t(label ? label : 'no-label'), + label: label ? label : field, deselect: value.deselect, formattedValue: [ getFieldValueCaption(field, value.value.value, this.bindings.i18n), diff --git a/packages/atomic/src/components/search/facets/atomic-automatic-facet/atomic-automatic-facet.tsx b/packages/atomic/src/components/search/facets/atomic-automatic-facet/atomic-automatic-facet.tsx index d65c5caa176..a1edca5c609 100644 --- a/packages/atomic/src/components/search/facets/atomic-automatic-facet/atomic-automatic-facet.tsx +++ b/packages/atomic/src/components/search/facets/atomic-automatic-facet/atomic-automatic-facet.tsx @@ -117,7 +117,7 @@ export class AtomicAutomaticFacet implements InitializableComponent { private get label() { return isNullOrUndefined(this.facet.state.label) - ? 'no-label' + ? this.facet.state.field : this.facet.state.label; }