From 67785cba54d31798fe70d9fea123335274b7d20d Mon Sep 17 00:00:00 2001 From: davidcanonieto Date: Thu, 4 Oct 2018 11:33:07 +0100 Subject: [PATCH] [ADF-3629] Fix involved user bug on People Widget (#3858) --- .../components/widgets/people/people.widget.html | 7 +++++-- .../widgets/people/people.widget.spec.ts | 16 ++++++++++++++++ .../components/widgets/people/people.widget.ts | 14 ++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/core/form/components/widgets/people/people.widget.html b/lib/core/form/components/widgets/people/people.widget.html index 71356436a3..6a7f67c1a6 100644 --- a/lib/core/form/components/widgets/people/people.widget.html +++ b/lib/core/form/components/widgets/people/people.widget.html @@ -13,8 +13,11 @@ [formControl]="searchTerm" placeholder="{{field.placeholder}}" [matAutocomplete]="auto"> - - + +
diff --git a/lib/core/form/components/widgets/people/people.widget.spec.ts b/lib/core/form/components/widgets/people/people.widget.spec.ts index 3ec6b63a65..3f7b49af12 100644 --- a/lib/core/form/components/widgets/people/people.widget.spec.ts +++ b/lib/core/form/components/widgets/people/people.widget.spec.ts @@ -143,6 +143,22 @@ describe('PeopleWidgetComponent', () => { expect(widget.groupId).toBe(''); }); + it('should display involved user in task form', async() => { + widget.field.value = new UserProcessModel({ + id: 'people-id', + firstName: 'John', + lastName: 'Doe', + email: 'john@test.com' + }); + widget.ngOnInit(); + + const involvedUser = fixture.debugElement.nativeElement.querySelector('input[data-automation-id="adf-people-search-input"]'); + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(involvedUser.value).toBe('John Doe'); + }); + }); + describe('when template is ready', () => { let fakeUserResult = [ diff --git a/lib/core/form/components/widgets/people/people.widget.ts b/lib/core/form/components/widgets/people/people.widget.ts index 15e06ad3cc..8b279ec883 100644 --- a/lib/core/form/components/widgets/people/people.widget.ts +++ b/lib/core/form/components/widgets/people/people.widget.ts @@ -53,7 +53,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit { searchTerm = new FormControl(); errorMsg = ''; - searchTerms$: Observable = this.searchTerm.valueChanges; + searchTerms$: Observable = this.searchTerm.valueChanges; users$ = this.searchTerms$.pipe( tap(() => { @@ -61,7 +61,8 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit { }), distinctUntilChanged(), switchMap((searchTerm) => { - return this.formService.getWorkflowUsers(searchTerm, this.groupId) + let value = searchTerm.email ? this.getDisplayName(searchTerm) : searchTerm; + return this.formService.getWorkflowUsers(value, this.groupId) .pipe( catchError(err => { this.errorMsg = err.message; @@ -70,7 +71,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit { ); }), map((list: UserProcessModel[]) => { - let value = this.searchTerm.value; + let value = this.searchTerm.value.email ? this.getDisplayName(this.searchTerm.value) : this.searchTerm.value; this.checkUserAndValidateForm(list, value); return list; }) @@ -83,7 +84,9 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit { ngOnInit() { if (this.field) { - this.searchTerm.setValue(this.getDisplayName(this.field.value)); + if (this.field.value) { + this.searchTerm.setValue(this.field.value); + } if (this.field.readOnly) { this.searchTerm.disable(); } @@ -128,10 +131,9 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit { return ''; } - onItemSelect(item) { + onItemSelect(item: UserProcessModel) { if (item) { this.field.value = item; - this.searchTerm.setValue(item); } } }