diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts index 7335b4bb96..4bb92b9483 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.spec.ts @@ -983,6 +983,20 @@ describe('DropdownCloudWidgetComponent', () => { expect(widget.field.options.length).toEqual(0); }; + it('should set dropdownControl value without emitting events', () => { + widget.field = { + value: 'testValue', + options: [], + isVisible: true + } as any; // Mock field + spyOn(widget.dropdownControl, 'setValue').and.callThrough(); + + widget['setFormControlValue'](); + + expect(widget.dropdownControl.setValue).toHaveBeenCalledWith({ id: 'testValue', name: '' }, { emitEvent: false }); + expect(widget.dropdownControl.value).toEqual({ id: 'testValue', name: '' }); + }); + it('should display options persisted from process variable', async () => { widget.field = getVariableDropdownWidget( 'variables.json-variable', diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts index df3b5eadca..1ff67c8a4e 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts @@ -195,7 +195,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI } private setFormControlValue(): void { - this.dropdownControl.setValue(this.field?.value, { emitEvent: false }); + this.dropdownControl.setValue({ id: this.field?.value, name: '' }, { emitEvent: false }); } private updateFormControlState(): void { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validator.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validator.spec.ts new file mode 100644 index 0000000000..1544243b59 --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validator.spec.ts @@ -0,0 +1,72 @@ +/*! + * @license + * Copyright © 2005-2025 Hyland Software, Inc. and its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { FormFieldModel } from '@alfresco/adf-core'; +import { FormControl } from '@angular/forms'; +import { defaultValueValidator } from './validators'; +import { DEFAULT_OPTION } from './dropdown-cloud.widget'; + +describe('defaultValueValidator', () => { + let mockField: FormFieldModel; + + beforeEach(() => { + mockField = new FormFieldModel(null, { + options: [ + { id: DEFAULT_OPTION.id, name: DEFAULT_OPTION.name }, + { id: 'opt_1', name: 'Option 1' }, + { id: 'opt_2', name: 'Option 2' } + ] + }); + }); + + it('should return null when a valid option is selected', () => { + const validator = defaultValueValidator(mockField); + const control = new FormControl('opt_1'); + + const result = validator(control); + + expect(result).toBeNull(); + }); + + it('should return a required error when no valid option is selected', () => { + const validator = defaultValueValidator(mockField); + const control = new FormControl(null); + + const result = validator(control); + + expect(result).toEqual({ required: true }); + }); + + it('should return a required error when the default option is selected', () => { + const validator = defaultValueValidator(mockField); + const control = new FormControl(DEFAULT_OPTION.id); + + const result = validator(control); + + 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(); + }); +});