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 checkDropdownVariableOptionsFailed = () => {
|
||||||
const failedErrorMsgElement = fixture.debugElement.query(By.css('.adf-dropdown-failed-message'));
|
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'));
|
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);
|
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 () => {
|
it('should display options persisted from process variable', async () => {
|
||||||
widget.field = getVariableDropdownWidget(
|
widget.field = getVariableDropdownWidget(
|
||||||
'variables.json-variable',
|
'variables.json-variable',
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
FormFieldTypes,
|
FormFieldTypes,
|
||||||
FormService,
|
FormService,
|
||||||
RuleEntry,
|
RuleEntry,
|
||||||
|
VariableConfig,
|
||||||
WidgetComponent
|
WidgetComponent
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { FormCloudService } from '../../../services/form-cloud.service';
|
import { FormCloudService } from '../../../services/form-cloud.service';
|
||||||
@ -66,6 +67,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
|||||||
list$: Observable<FormFieldOption[]>;
|
list$: Observable<FormFieldOption[]>;
|
||||||
filter$ = new BehaviorSubject<string>('');
|
filter$ = new BehaviorSubject<string>('');
|
||||||
|
|
||||||
|
private readonly defaultVariableName = '';
|
||||||
private readonly defaultVariableOptionId = 'id';
|
private readonly defaultVariableOptionId = 'id';
|
||||||
private readonly defaultVariableOptionLabel = 'name';
|
private readonly defaultVariableOptionLabel = 'name';
|
||||||
private readonly defaultVariableOptionPath = 'data';
|
private readonly defaultVariableOptionPath = 'data';
|
||||||
@ -80,6 +82,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
|
|||||||
this.setPreviewState();
|
this.setPreviewState();
|
||||||
this.checkFieldOptionsSource();
|
this.checkFieldOptionsSource();
|
||||||
this.updateOptions();
|
this.updateOptions();
|
||||||
|
this.setDefaultVariableConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkFieldOptionsSource(): void {
|
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 {
|
private persistFieldOptionsFromVariable(): void {
|
||||||
const optionsPath = this.field?.variableConfig?.optionsPath ?? this.defaultVariableOptionPath;
|
const optionsPath = this.field?.variableConfig?.optionsPath ?? this.defaultVariableOptionPath;
|
||||||
const variableName = this.field?.variableConfig?.variableName;
|
const variableName = this.field?.variableConfig?.variableName;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user