mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Cloud people component - Fix the unit test related to the subject initialization (#4456)
* Fix the unit test related to the cloud people component * Fix init subject and add unit test
This commit is contained in:
parent
997c53b47b
commit
355e97ef39
@ -23,6 +23,7 @@ import { LogService, setupTestBed, IdentityUserService, IdentityUserModel } from
|
||||
import { mockUsers } from '../../mock/user-cloud.mock';
|
||||
import { of } from 'rxjs';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
|
||||
describe('PeopleCloudComponent', () => {
|
||||
let component: PeopleCloudComponent;
|
||||
@ -318,9 +319,9 @@ describe('PeopleCloudComponent', () => {
|
||||
|
||||
it('should not validate preselect values if preselectValidation flag is set to false', () => {
|
||||
component.mode = 'multiple';
|
||||
component.validate = false;
|
||||
component.preSelectUsers = <any> [{ id: mockUsers[1].id }, { id: mockUsers[2].id }];
|
||||
fixture.detectChanges();
|
||||
let change = new SimpleChange(null, 'validate', false);
|
||||
component.ngOnChanges({'validate': change});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(component.validatePreselectUsers).not.toHaveBeenCalled();
|
||||
|
@ -103,13 +103,10 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
||||
invalidUsers: IdentityUserModel[];
|
||||
|
||||
constructor(private identityUserService: IdentityUserService, private logService: LogService) {
|
||||
this.searchUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this._searchUsers);
|
||||
this.searchUsers$ = this.searchUsersSubject.asObservable();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.selectedUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this.preSelectUsers);
|
||||
this.selectedUsers$ = this.selectedUsersSubject.asObservable();
|
||||
this.initSubjects();
|
||||
this.initSearch();
|
||||
|
||||
if (this.appName) {
|
||||
@ -119,6 +116,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
this.initSubjects();
|
||||
|
||||
if (this.isPreselectedUserChanged(changes) && this.isValidationEnabled()) {
|
||||
this.loadPreSelectUsers();
|
||||
} else {
|
||||
@ -133,6 +132,18 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
initSubjects() {
|
||||
if (this.selectedUsersSubject === undefined) {
|
||||
this.selectedUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this.preSelectUsers);
|
||||
this.selectedUsers$ = this.selectedUsersSubject.asObservable();
|
||||
}
|
||||
|
||||
if (this.searchUsersSubject === undefined) {
|
||||
this.searchUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this._searchUsers);
|
||||
this.searchUsers$ = this.searchUsersSubject.asObservable();
|
||||
}
|
||||
}
|
||||
|
||||
private isAppNameChanged(change) {
|
||||
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user