diff --git a/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.spec.ts b/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.spec.ts index 8610ab0d18..18e8e83f74 100644 --- a/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.spec.ts +++ b/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.spec.ts @@ -514,10 +514,15 @@ describe('PoLookupModalBaseComponent:', () => { }); it('addDisclaimer: should create disclaimer and disclaimerGroup.disclaimer with parameters', () => { - const expectedValueDisclaimer = { property: 'propertyTest', value: 'valueTest' }; + component.advancedFilters = [{ property: 'propertyTest' }]; + const expectedValueDisclaimer = { + property: 'propertyTest', + value: 'valueTest', + label: 'PropertyTest: valueTest' + }; const expectedValueDisclaimerGroup = { title: 'titleTest', - disclaimers: [{ property: 'propertyTest', value: 'valueTest' }] + disclaimers: [{ property: 'propertyTest', value: 'valueTest', label: 'PropertyTest: valueTest' }] }; component.addDisclaimer('valueTest', 'propertyTest'); @@ -529,10 +534,10 @@ describe('PoLookupModalBaseComponent:', () => { it("addDisclaimer: should return formated currency in locale default if field type is 'currency'", () => { component['language'] = 'pt'; component.advancedFilters = [{ property: 'value', type: 'currency' }]; - const expectedValueDisclaimer = { property: 'value', value: 321, label: '321,00' }; + const expectedValueDisclaimer = { property: 'value', value: 321, label: 'Value: 321,00' }; const expectedValueDisclaimerGroup = { title: 'titleTest', - disclaimers: [{ property: 'value', value: 321, label: '321,00' }] + disclaimers: [{ property: 'value', value: 321, label: 'Value: 321,00' }] }; component.addDisclaimer(321, 'value'); @@ -543,10 +548,10 @@ describe('PoLookupModalBaseComponent:', () => { it("addDisclaimer: should return formated currency in locale 'En' if field type is 'currency' and locale is 'en'", () => { component.advancedFilters = [{ property: 'value', type: 'currency', locale: 'en' }]; - const expectedValueDisclaimer = { property: 'value', value: 321, label: '321.00' }; + const expectedValueDisclaimer = { property: 'value', value: 321, label: 'Value: 321.00' }; const expectedValueDisclaimerGroup = { title: 'titleTest', - disclaimers: [{ property: 'value', value: 321, label: '321.00' }] + disclaimers: [{ property: 'value', value: 321, label: 'Value: 321.00' }] }; component.addDisclaimer(321, 'value'); @@ -565,10 +570,10 @@ describe('PoLookupModalBaseComponent:', () => { ] } ]; - const expectedValueDisclaimer = { property: 'company', value: 1, label: 'Totvs' }; + const expectedValueDisclaimer = { property: 'company', value: 1, label: 'Company: Totvs' }; const expectedValueDisclaimerGroup = { title: 'titleTest', - disclaimers: [{ property: 'company', value: 1, label: 'Totvs' }] + disclaimers: [{ property: 'company', value: 1, label: 'Company: Totvs' }] }; component.addDisclaimer(1, 'company'); @@ -584,10 +589,10 @@ describe('PoLookupModalBaseComponent:', () => { options: [{ value: 1 }, { value: 2 }] } ]; - const expectedValueDisclaimer = { property: 'company', value: 1 }; + const expectedValueDisclaimer = { property: 'company', value: 1, label: 'Company: 1' }; const expectedValueDisclaimerGroup = { title: 'titleTest', - disclaimers: [{ property: 'company', value: 1 }] + disclaimers: [{ property: 'company', value: 1, label: 'Company: 1' }] }; component.addDisclaimer(1, 'company'); @@ -600,6 +605,7 @@ describe('PoLookupModalBaseComponent:', () => { component.advancedFilters = [ { property: 'company', + label: 'The company', optionsMulti: true, options: [ { label: 'Totvs', value: 1 }, @@ -607,10 +613,10 @@ describe('PoLookupModalBaseComponent:', () => { ] } ]; - const expectedValueDisclaimer = { property: 'company', value: [1, 2], label: 'Totvs, PO UI' }; + const expectedValueDisclaimer = { property: 'company', value: [1, 2], label: 'The company: Totvs, PO UI' }; const expectedValueDisclaimerGroup = { title: 'titleTest', - disclaimers: [{ property: 'company', value: [1, 2], label: 'Totvs, PO UI' }] + disclaimers: [{ property: 'company', value: [1, 2], label: 'The company: Totvs, PO UI' }] }; component.addDisclaimer([1, 2], 'company'); @@ -619,6 +625,59 @@ describe('PoLookupModalBaseComponent:', () => { expect(component.disclaimerGroup.disclaimers).toEqual(expectedValueDisclaimerGroup.disclaimers); }); + it('addDisclaimer: should add disclaimer for boolean property when value is true', () => { + component.advancedFilters = [{ property: 'isApproved', type: 'boolean', label: 'Is Approved' }]; + + component.addDisclaimer(true, 'isApproved'); + + expect(component.disclaimer.label).toBe('Is Approved: true'); + }); + + it('addDisclaimer: should add disclaimer for boolean property when value is false', () => { + component.advancedFilters = [{ property: 'isActive', type: 'boolean', label: 'Is Active' }]; + + component.addDisclaimer(false, 'isActive'); + + expect(component.disclaimer.label).toBe('Is Active: false'); + }); + + it('formatValueToBoolean: should format value to boolean when filterValue is truthy', () => { + const filterValue = true; + const field = { + label: 'Field Label', + booleanTrue: 'Yes', + property: 'fieldProperty' + }; + + component['formatValueToBoolean'](field, filterValue); + + expect(component['disclaimerLabel']).toBe('Yes'); + }); + + it('formatValueToBoolean: should format value to boolean when filterValue is falsy', () => { + const filterValue = false; + const field = { + label: 'Field Label', + booleanFalse: 'No', + property: 'fieldProperty' + }; + + component['formatValueToBoolean'](field, filterValue); + + expect(component['disclaimerLabel']).toBe('No'); + }); + + it('formatValueToBoolean: should format value to property when label is not provided', () => { + const filterValue = true; + const field = { + property: 'fieldProperty' + }; + + component['formatValueToBoolean'](field, filterValue); + + expect(component['disclaimerLabel']).toBe('true'); + }); + xit('p-infinite-scroll: should update property `p-infinite-scroll`', () => { const booleanValidTrueValues = [true, 'true', 1, '']; const booleanInvalidValues = [undefined, null, NaN, 2, 'string']; diff --git a/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.ts b/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.ts index ef396a8be7..c74c346775 100644 --- a/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.ts +++ b/projects/ui/src/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.ts @@ -5,7 +5,7 @@ import { catchError } from 'rxjs/operators'; import { InputBoolean } from '../../../../decorators'; -import { isTypeof } from '../../../../utils/util'; +import { capitalizeFirstLetter, isTypeof } from '../../../../utils/util'; import { poLocaleDefault } from '../../../../services/po-language/po-language.constant'; import { PoModalAction } from '../../../../components/po-modal'; import { PoModalComponent } from '../../../../components/po-modal/po-modal.component'; @@ -193,6 +193,7 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit { private filterSubscription: Subscription; private searchSubscription: Subscription; private showMoreSubscription: Subscription; + private disclaimerLabel: string; private _literals: PoLookupLiterals; private _title: string; @@ -296,18 +297,29 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit { } addDisclaimer(value: any, property: string) { - const fieldFilter = this.advancedFilters?.find(filter => filter.property === property); + this.disclaimerLabel = ''; + const fieldFilter = this.advancedFilters.find(filter => filter.property === property); this.disclaimer = { property: property }; this.disclaimer.value = value; + const labelProperty = fieldFilter.label || capitalizeFirstLetter(fieldFilter.property); - if (fieldFilter?.type === 'currency' && value) { + if (fieldFilter.type === 'currency' && value) { this.formatValueToCurrency(fieldFilter, value); } - if (fieldFilter?.options && value) { + if (fieldFilter.type === 'boolean' && (value === true || value === false)) { + this.formatValueToBoolean(fieldFilter, value); + } + + if (fieldFilter.options && value) { this.applyDisclaimerLabelValue(fieldFilter, value); } + if (!this.disclaimerLabel) { + this.disclaimerLabel = this.disclaimer.value; + } + + this.disclaimer.label = `${labelProperty}: ${this.disclaimerLabel}`; this.disclaimerGroup.disclaimers = [...this.disclaimerGroup.disclaimers, this.disclaimer]; } @@ -402,7 +414,7 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit { }); if (labels.join()) { - this.disclaimer.label = labels.join(', '); + this.disclaimerLabel = labels.join(', '); } } @@ -410,7 +422,18 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit { const currencyLabel = new Intl.NumberFormat(field.locale ? field.locale : this.language, { minimumFractionDigits: 2 }).format(filterValue); - this.disclaimer.label = currencyLabel; + this.disclaimerLabel = currencyLabel; + } + + private formatValueToBoolean(field: PoLookupAdvancedFilter, filterValue: any) { + let labelBoolean: string; + + if (filterValue) { + labelBoolean = field.booleanTrue ? field.booleanTrue : filterValue; + } else { + labelBoolean = field.booleanFalse ? field.booleanFalse : filterValue; + } + this.disclaimerLabel = `${labelBoolean}`; } private setAdvancedFilterModalProperties() {