[ADF-5013] Dropdown does not display the default value (#5275)

* [ADF-5013] Dropdown does not display the default value

* Revert "[ADF-5013] Dropdown does not display the default value"

This reverts commit a18d2161

* * fixed e2e

* unit test added
This commit is contained in:
dhrn 2019-11-22 15:29:40 +05:30 committed by Eugenio Romano
parent 5068cbf539
commit e0f00dd7ae
2 changed files with 40 additions and 4 deletions

View File

@ -159,7 +159,7 @@ describe('DropdownCloudWidgetComponent', () => {
});
}));
it('shoud map properties if restResponsePath is set', (done) => {
it('should map properties if restResponsePath is set', (done) => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'dropdown-id',
name: 'date-name',
@ -188,7 +188,7 @@ describe('DropdownCloudWidgetComponent', () => {
});
});
it('shoud preselect dropdown widget value set as id ', (done) => {
it('should preselect dropdown widget value when Json (rest call) passed', (done) => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'dropdown-id',
name: 'date-name',
@ -228,6 +228,42 @@ describe('DropdownCloudWidgetComponent', () => {
});
});
it('should preselect dropdown widget value when String (defined value) passed ', (done) => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'dropdown-id',
name: 'date-name',
type: 'dropdown-cloud',
readOnly: 'false',
restUrl: 'fake-rest-url',
optionType: 'rest',
value: 'opt1'
});
const dropdownSpy = spyOn(formCloudService, 'getDropDownJsonData').and.returnValue(of(<FormFieldOption[]> [
{
id: 'opt1',
name: 'default1_value'
},
{
id: 2,
name: 'default2_value'
}
]));
widget.ngOnInit();
fixture.detectChanges();
const dropDownElement: any = element.querySelector('#dropdown-id');
dropDownElement.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
const optOne: any = fixture.debugElement.queryAll(By.css('[id="opt1"]'));
expect(dropdownSpy).toHaveBeenCalled();
expect(optOne[0].nativeElement.className).toBe('mat-option ng-star-inserted mat-active');
done();
});
});
});
});
});

View File

@ -82,8 +82,8 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
});
}
compareDropdownValues(opt1: string, opt2: FormFieldOption): boolean {
return opt1 && opt2 && ( opt1 === opt2.id || opt1 === opt2.name);
compareDropdownValues(opt1: string, opt2: FormFieldOption | string): boolean {
return opt1 && opt2 && typeof opt2 !== 'string' ? ( opt1 === opt2.id || opt1 === opt2.name ) : opt1 === opt2;
}
getOptionValue(option: FormFieldOption, fieldValue: string): string {