Skip to content

Commit

Permalink
fix(lookup): resolve disclaimer do lookup para o filtro booleano
Browse files Browse the repository at this point in the history
Ajusta label do filtro booleano no disclaimer do lookup

fixes DTHFUI-7511
  • Loading branch information
CSimoesJr committed Aug 29, 2023
1 parent 8df2611 commit bdbfd4d
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -600,17 +605,18 @@ describe('PoLookupModalBaseComponent:', () => {
component.advancedFilters = [
{
property: 'company',
label: 'The company',
optionsMulti: true,
options: [
{ label: 'Totvs', value: 1 },
{ label: 'PO UI', value: 2 }
]
}
];
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');
Expand All @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = <any>{ 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];
}

Expand Down Expand Up @@ -402,15 +414,26 @@ export abstract class PoLookupModalBaseComponent implements OnDestroy, OnInit {
});

if (labels.join()) {
this.disclaimer.label = labels.join(', ');
this.disclaimerLabel = labels.join(', ');
}
}

private formatValueToCurrency(field: PoLookupAdvancedFilter, filterValue: any) {
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() {
Expand Down

0 comments on commit bdbfd4d

Please sign in to comment.