Skip to content

Commit

Permalink
feat(atomic): change default label to the field for automatic facets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aprudhomme-coveo authored Aug 9, 2023
1 parent 31bb6c7 commit a3060ca
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a3060ca

Please sign in to comment.