[ADF-4274] - Fix users filtering on single selection mode (#4476)

* [ADF-4274] - fix  users filtering on single selection mode

* [ADF-4274] - add unit test
This commit is contained in:
Silviu Popa
2019-03-30 13:12:10 +02:00
committed by Eugenio Romano
parent f422fa30d2
commit d8321b977a
2 changed files with 20 additions and 1 deletions

View File

@@ -398,4 +398,23 @@ describe('PeopleCloudComponent', () => {
});
});
}));
it('should not filter the preselect user in single selection mode', async ((done) => {
spyOn(identityService, 'findUserByUsername').and.returnValue(Promise.resolve(mockUsers));
component.mode = 'single';
component.validate = true;
component.preSelectUsers = <any> [{ username: mockUsers[1].username }];
fixture.detectChanges();
let inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
inputHTMLElement.focus();
inputHTMLElement.dispatchEvent(new Event('input'));
inputHTMLElement.dispatchEvent(new Event('keyup'));
inputHTMLElement.dispatchEvent(new Event('keydown'));
inputHTMLElement.value = mockUsers[1].username;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.queryAll(By.css('mat-option')).length).toBe(3);
});
}));
});

View File

@@ -278,7 +278,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
}
private isUserAlreadySelected(user: IdentityUserModel): boolean {
if (this.preSelectUsers && this.preSelectUsers.length > 0) {
if (this.preSelectUsers && this.preSelectUsers.length > 0 && this.isMultipleMode()) {
const result = this.preSelectUsers.find((selectedUser) => {
return selectedUser.id === user.id || selectedUser.email === user.email || selectedUser.username === user.username;
});