mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
AAE-22847 Fill out input fields with default values (#9930)
* AAE-22847 Fill out input fields with default values * AAE-22847 Add tests * AAE-22847 Fix lint issue
This commit is contained in:
parent
0b3101698a
commit
d91fba7259
@ -808,6 +808,14 @@ describe('DropdownCloudWidgetComponent', () => {
|
||||
}
|
||||
});
|
||||
|
||||
const getVariableDropdownWidgetWithoutConfig = () =>
|
||||
new FormFieldModel(new FormModel({ taskId: 'fake-task-id', readOnly: 'false' }), {
|
||||
id: 'variable-dropdown-id',
|
||||
name: 'variable-options-dropdown',
|
||||
type: 'dropdown',
|
||||
optionType: 'variable'
|
||||
});
|
||||
|
||||
const checkDropdownVariableOptionsFailed = () => {
|
||||
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-dropdown-failed-message'));
|
||||
expect(failedErrorMsgElement.nativeElement.textContent.trim()).toBe(errorIcon.concat('FORM.FIELD.VARIABLE_DROPDOWN_OPTIONS_FAILED'));
|
||||
@ -815,6 +823,16 @@ describe('DropdownCloudWidgetComponent', () => {
|
||||
expect(widget.field.options.length).toEqual(0);
|
||||
};
|
||||
|
||||
it('should add default variable config when variable config property is not provided', () => {
|
||||
widget.field = getVariableDropdownWidgetWithoutConfig();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(widget.field.json.variableConfig.variableName).toBe('');
|
||||
expect(widget.field.json.variableConfig.optionsPath).toBe('data');
|
||||
expect(widget.field.json.variableConfig.optionsId).toBe('id');
|
||||
expect(widget.field.json.variableConfig.optionsLabel).toBe('name');
|
||||
});
|
||||
|
||||
it('should display options persisted from process variable', async () => {
|
||||
widget.field = getVariableDropdownWidget(
|
||||
'variables.json-variable',
|
||||
|
@ -24,6 +24,7 @@ import {
|
||||
FormFieldTypes,
|
||||
FormService,
|
||||
RuleEntry,
|
||||
VariableConfig,
|
||||
WidgetComponent
|
||||
} from '@alfresco/adf-core';
|
||||
import { FormCloudService } from '../../../services/form-cloud.service';
|
||||
@ -66,6 +67,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
||||
list$: Observable<FormFieldOption[]>;
|
||||
filter$ = new BehaviorSubject<string>('');
|
||||
|
||||
private readonly defaultVariableName = '';
|
||||
private readonly defaultVariableOptionId = 'id';
|
||||
private readonly defaultVariableOptionLabel = 'name';
|
||||
private readonly defaultVariableOptionPath = 'data';
|
||||
@ -80,6 +82,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
||||
this.setPreviewState();
|
||||
this.checkFieldOptionsSource();
|
||||
this.updateOptions();
|
||||
this.setDefaultVariableConfig();
|
||||
}
|
||||
|
||||
private checkFieldOptionsSource(): void {
|
||||
@ -103,6 +106,19 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
||||
}
|
||||
}
|
||||
|
||||
private setDefaultVariableConfig(): void {
|
||||
if (!this.field.json) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.field.json.variableConfig = {
|
||||
variableName: this.field.json?.variableConfig?.variableName || this.defaultVariableName,
|
||||
optionsPath: this.field.json?.variableConfig?.optionsPath || this.defaultVariableOptionPath,
|
||||
optionsId: this.field.json?.variableConfig?.optionsId || this.defaultVariableOptionId,
|
||||
optionsLabel: this.field.json?.variableConfig?.optionsLabel || this.defaultVariableOptionLabel
|
||||
} as VariableConfig;
|
||||
}
|
||||
|
||||
private persistFieldOptionsFromVariable(): void {
|
||||
const optionsPath = this.field?.variableConfig?.optionsPath ?? this.defaultVariableOptionPath;
|
||||
const variableName = this.field?.variableConfig?.variableName;
|
||||
|
Loading…
x
Reference in New Issue
Block a user