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 { mockUsers } from '../../mock/user-cloud.mock';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
|
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
|
||||||
|
import { SimpleChange } from '@angular/core';
|
||||||
|
|
||||||
describe('PeopleCloudComponent', () => {
|
describe('PeopleCloudComponent', () => {
|
||||||
let component: PeopleCloudComponent;
|
let component: PeopleCloudComponent;
|
||||||
@ -318,9 +319,9 @@ describe('PeopleCloudComponent', () => {
|
|||||||
|
|
||||||
it('should not validate preselect values if preselectValidation flag is set to false', () => {
|
it('should not validate preselect values if preselectValidation flag is set to false', () => {
|
||||||
component.mode = 'multiple';
|
component.mode = 'multiple';
|
||||||
component.validate = false;
|
|
||||||
component.preSelectUsers = <any> [{ id: mockUsers[1].id }, { id: mockUsers[2].id }];
|
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.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(component.validatePreselectUsers).not.toHaveBeenCalled();
|
expect(component.validatePreselectUsers).not.toHaveBeenCalled();
|
||||||
|
@ -103,13 +103,10 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
|||||||
invalidUsers: IdentityUserModel[];
|
invalidUsers: IdentityUserModel[];
|
||||||
|
|
||||||
constructor(private identityUserService: IdentityUserService, private logService: LogService) {
|
constructor(private identityUserService: IdentityUserService, private logService: LogService) {
|
||||||
this.searchUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this._searchUsers);
|
|
||||||
this.searchUsers$ = this.searchUsersSubject.asObservable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.selectedUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this.preSelectUsers);
|
this.initSubjects();
|
||||||
this.selectedUsers$ = this.selectedUsersSubject.asObservable();
|
|
||||||
this.initSearch();
|
this.initSearch();
|
||||||
|
|
||||||
if (this.appName) {
|
if (this.appName) {
|
||||||
@ -119,6 +116,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
this.initSubjects();
|
||||||
|
|
||||||
if (this.isPreselectedUserChanged(changes) && this.isValidationEnabled()) {
|
if (this.isPreselectedUserChanged(changes) && this.isValidationEnabled()) {
|
||||||
this.loadPreSelectUsers();
|
this.loadPreSelectUsers();
|
||||||
} else {
|
} 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) {
|
private isAppNameChanged(change) {
|
||||||
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user