mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4038] People/GroupCloudDemo - add appName filter (#4283)
* [ADF-4038] - People/Group Cloud Component add app name filter * [ADF-4038] add unit test, modify ngOnChange appName condition * [ADF-4038] People/GroupCloudDemo - add radio button to filter application name or roles
This commit is contained in:
committed by
Eugenio Romano
parent
8901261ec9
commit
898d62477e
@@ -26,6 +26,7 @@ import { GroupCloudService } from '../services/group-cloud.service';
|
||||
import { setupTestBed, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||
import { mockGroups } from '../mock/group-cloud.mock';
|
||||
import { GroupModel } from '../models/group.model';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
|
||||
describe('GroupCloudComponent', () => {
|
||||
let component: GroupCloudComponent;
|
||||
@@ -59,6 +60,9 @@ describe('GroupCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should be able to fetch client id', async(() => {
|
||||
component.ngOnChanges( {
|
||||
appName: new SimpleChange(null, component.appName, true)
|
||||
});
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(getClientIdByApplicationNameSpy).toHaveBeenCalled();
|
||||
@@ -291,4 +295,22 @@ describe('GroupCloudComponent', () => {
|
||||
expect(checkGroupHasAccessSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should load the clients if appName change', async( () => {
|
||||
component.appName = 'ADF';
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(getClientIdByApplicationNameSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should filter users if appName change', async(() => {
|
||||
component.appName = 'ADF';
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(checkGroupHasAccessSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
@@ -107,19 +107,24 @@ export class GroupCloudComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
this.initSearch();
|
||||
|
||||
if (this.appName) {
|
||||
this.disableSearch();
|
||||
this.loadClientId();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes.preSelectGroups && this.hasPreSelectGroups()) {
|
||||
this.loadPreSelectGroups();
|
||||
}
|
||||
|
||||
if (changes.appName && this.isAppNameChanged(changes.appName)) {
|
||||
this.disableSearch();
|
||||
this.loadClientId();
|
||||
} else {
|
||||
this.enableSearch();
|
||||
}
|
||||
}
|
||||
|
||||
private isAppNameChanged(change) {
|
||||
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
||||
}
|
||||
|
||||
private async loadClientId() {
|
||||
|
@@ -31,6 +31,7 @@ describe('PeopleCloudComponent', () => {
|
||||
let identityService: IdentityUserService;
|
||||
let findUsersSpy: jasmine.Spy;
|
||||
let checkUserHasAccessSpy: jasmine.Spy;
|
||||
let loadClientsByApplicationNameSpy: jasmine.Spy;
|
||||
|
||||
setupTestBed({
|
||||
imports: [ProcessServiceCloudTestingModule, StartTaskCloudTestingModule],
|
||||
@@ -44,7 +45,7 @@ describe('PeopleCloudComponent', () => {
|
||||
identityService = TestBed.get(IdentityUserService);
|
||||
findUsersSpy = spyOn(identityService, 'findUsersByName').and.returnValue(of(mockUsers));
|
||||
checkUserHasAccessSpy = spyOn(identityService, 'checkUserHasClientApp').and.returnValue(of(true));
|
||||
spyOn(identityService, 'getClientIdByApplicationName').and.returnValue(of('mock-client-id'));
|
||||
loadClientsByApplicationNameSpy = spyOn(identityService, 'getClientIdByApplicationName').and.returnValue(of('mock-client-id'));
|
||||
});
|
||||
|
||||
it('should create PeopleCloudComponent', () => {
|
||||
@@ -294,4 +295,24 @@ describe('PeopleCloudComponent', () => {
|
||||
expect(checkUserHasRoleSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should load the clients if appName change', async( () => {
|
||||
component.appName = 'ADF';
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(loadClientsByApplicationNameSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should filter users if appName change', async(() => {
|
||||
component.appName = '';
|
||||
fixture.detectChanges();
|
||||
component.appName = 'ADF';
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(checkUserHasAccessSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
@@ -102,17 +102,23 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
||||
this.selectedUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this.preSelectUsers);
|
||||
this.selectedUsers$ = this.selectedUsersSubject.asObservable();
|
||||
this.initSearch();
|
||||
|
||||
if (this.appName) {
|
||||
this.disableSearch();
|
||||
this.loadClientId();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes.preSelectUsers && this.hasPreSelectUsers()) {
|
||||
this.loadPreSelectUsers();
|
||||
}
|
||||
|
||||
if (changes.appName && this.isAppNameChanged(changes.appName)) {
|
||||
this.disableSearch();
|
||||
this.loadClientId();
|
||||
} else {
|
||||
this.enableSearch();
|
||||
}
|
||||
}
|
||||
|
||||
private isAppNameChanged(change) {
|
||||
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
||||
}
|
||||
|
||||
private initSearch() {
|
||||
@@ -202,6 +208,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
||||
}
|
||||
|
||||
private async loadClientId() {
|
||||
|
||||
this.clientId = await this.identityUserService.getClientIdByApplicationName(this.appName).toPromise();
|
||||
|
||||
if (this.clientId) {
|
||||
|
Reference in New Issue
Block a user