Skip to content

Commit f20490e

Browse files
fix(combo): efetua disparo do getObjectByValue caso alterar valor
Ao alterar o valor do model do campo, que contenha serviço, e o mesmo estiver selecionado, é efetuada a busca novamente pelo "id" via getObjectByValue. Fixes DTHFUI-4312
1 parent cd000dd commit f20490e

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,14 +1688,33 @@ describe('PoComboComponent - with service:', () => {
16881688
expect(component.controlComboVisibility).toHaveBeenCalledWith(false);
16891689
});
16901690

1691-
it('shouldn`t call updateOptionByFilteredValue if not exists selectedValue', () => {
1691+
it('should call updateOptionByFilteredValue if selectedValue is different of value parameter', () => {
16921692
component.service = getFakeService([{ label: 'label', value: 1 }]);
16931693
component.selectedValue = 'po';
16941694

16951695
spyOn(component, 'updateOptionByFilteredValue');
1696-
16971696
component.getObjectByValue('value');
16981697

1698+
expect(component.updateOptionByFilteredValue).toHaveBeenCalled();
1699+
});
1700+
1701+
it('shouldn`t call updateOptionByFilteredValue if selectedValue exists and is equal to the value', () => {
1702+
component.service = getFakeService([{ label: 'label', value: 1 }]);
1703+
component.selectedValue = 1;
1704+
1705+
spyOn(component, 'updateOptionByFilteredValue');
1706+
1707+
component.getObjectByValue(1);
1708+
expect(component.updateOptionByFilteredValue).not.toHaveBeenCalled();
1709+
});
1710+
1711+
it('should not call updateOptionByFilteredValue if the selectedOption label exists and is equal to the value', () => {
1712+
component.service = getFakeService([{ label: 'label', value: 1 }]);
1713+
component.selectedValue = 1;
1714+
component.selectedOption = { label: 'label', value: 1 };
1715+
1716+
spyOn(component, 'updateOptionByFilteredValue');
1717+
component.getObjectByValue('label');
16991718
expect(component.updateOptionByFilteredValue).not.toHaveBeenCalled();
17001719
});
17011720

@@ -1789,22 +1808,6 @@ describe('PoComboComponent - with service:', () => {
17891808
expect(fakeThis.service.getObjectByValue).toHaveBeenCalledWith(param, filterParams);
17901809
});
17911810

1792-
it('getObjectByValue: should not call PoComboFilterService.getObjectByValue() if selectedValue is valid', () => {
1793-
const param = 'value';
1794-
const fakeThis = {
1795-
service: {
1796-
getObjectByValue: () => {}
1797-
},
1798-
selectedValue: 'valid'
1799-
};
1800-
1801-
spyOn(fakeThis.service, 'getObjectByValue');
1802-
1803-
component.getObjectByValue.apply(fakeThis, [param]);
1804-
1805-
expect(fakeThis.service.getObjectByValue).not.toHaveBeenCalled();
1806-
});
1807-
18081811
it('ngAfterViewInit: should call `focus` if `autoFocus` is true.', () => {
18091812
component.autoFocus = true;
18101813

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class PoComboComponent extends PoComboBaseComponent implements AfterViewI
368368
}
369369

370370
getObjectByValue(value) {
371-
if (!this.selectedValue) {
371+
if (this.selectedValue !== value && this.selectedOption?.label !== value) {
372372
this.isProcessingGetObjectByValue = true;
373373

374374
this.getSubscription = this.service.getObjectByValue(value, this.filterParams).subscribe(

0 commit comments

Comments
 (0)