This commit is contained in:
eromano
2025-05-15 18:39:08 +02:00
parent 001f0dc1a2
commit 95716ae50f
5 changed files with 16 additions and 36 deletions
@@ -1008,7 +1008,7 @@ describe('DropdownCloudWidgetComponent', () => {
widget['setFormControlValue']();
expect(widget.dropdownControl.setValue).toHaveBeenCalledWith({ id: 'testValueObj', name: 'testValueObjName' }, { emitEvent: false });
expect(widget.dropdownControl.value).toEqual({ id: 'testValue', name: '' });
expect(widget.dropdownControl.value).toEqual({ id: 'testValueObj', name: 'testValueObjName' });
});
it('should display options persisted from process variable', async () => {
@@ -195,8 +195,12 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
}
private setFormControlValue(): void {
if (this.field?.value && typeof this.field?.value === 'object') {
if (Array.isArray(this.field.value)) {
this.dropdownControl.setValue(this.field?.value, { emitEvent: false });
} else if (this.field?.value && typeof this.field?.value === 'object') {
this.dropdownControl.setValue({ id: this.field?.value.id, name: this.field?.value.name }, { emitEvent: false });
} else if (this.field.value === null) {
this.dropdownControl.setValue(this.field?.value, { emitEvent: false });
} else {
this.dropdownControl.setValue({ id: this.field?.value, name: '' }, { emitEvent: false });
}
@@ -35,7 +35,7 @@ describe('defaultValueValidator', () => {
it('should return null when a valid option is selected', () => {
const validator = defaultValueValidator(mockField);
const control = new FormControl('opt_1');
const control = new FormControl({ id: 'opt_1' });
const result = validator(control);
@@ -59,14 +59,4 @@ describe('defaultValueValidator', () => {
expect(result).toEqual({ required: true });
});
it('should return null when the field has no options', () => {
mockField.options = [];
const validator = defaultValueValidator(mockField);
const control = new FormControl('opt_1');
const result = validator(control);
expect(result).toBeNull();
});
});