mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[AAE-1344] [FE] - Removed all pre-selected users on removing of single pre-selected user. (#5350)
* [AAE-1344] [FE] - Removed all preselected users on removing of single pre-selected user. * * Fixed Search problem on admin manage permision dialog * * Fixed failing unit test. * * Fixed failing unit test on group component
This commit is contained in:
parent
9c83c35e61
commit
12d068c228
@ -1,6 +1,6 @@
|
||||
<div class="adf-cloud-group">
|
||||
<mat-form-field>
|
||||
<mat-label>{{ (title || 'ADF_CLOUD_GROUPS.SEARCH-GROUP') | translate }}</mat-label>
|
||||
<mat-label id="adf-group-cloud-title-id">{{ (title || 'ADF_CLOUD_GROUPS.SEARCH-GROUP') | translate }}</mat-label>
|
||||
<mat-chip-list #groupChipList *ngIf="isMultipleMode()" [disabled]="isDisabled" data-automation-id="adf-cloud-group-chip-list" class="apa-group-chip-list">
|
||||
<mat-chip
|
||||
*ngFor="let group of selectedGroups$ | async"
|
||||
|
@ -68,6 +68,16 @@ describe('GroupCloudComponent', () => {
|
||||
expect(component instanceof GroupCloudComponent).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', async(() => {
|
||||
component.title = 'TITLE_KEY';
|
||||
fixture.detectChanges();
|
||||
const matLabel: HTMLInputElement = <HTMLInputElement> element.querySelector('#adf-group-cloud-title-id');
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(matLabel.textContent).toEqual('TITLE_KEY');
|
||||
});
|
||||
}));
|
||||
|
||||
describe('Search group', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
@ -135,17 +145,6 @@ describe('GroupCloudComponent', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', (done) => {
|
||||
component.title = 'TITLE_KEY';
|
||||
fixture.detectChanges();
|
||||
const matLabel: HTMLInputElement = <HTMLInputElement> element.querySelector('mat-label');
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(matLabel.textContent).toEqual('TITLE_KEY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when application name defined', () => {
|
||||
|
@ -26,7 +26,8 @@ import {
|
||||
Input,
|
||||
SimpleChanges,
|
||||
OnChanges,
|
||||
OnDestroy
|
||||
OnDestroy,
|
||||
ChangeDetectionStrategy
|
||||
} from '@angular/core';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { trigger, state, style, transition, animate } from '@angular/animations';
|
||||
@ -48,6 +49,7 @@ import { IdentityGroupModel, IdentityGroupSearchParam, IdentityGroupService } fr
|
||||
])
|
||||
])
|
||||
],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class GroupCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<form>
|
||||
<mat-form-field class="adf-people-cloud">
|
||||
<mat-label id="title-id">{{ title | translate }}</mat-label>
|
||||
<mat-label id="adf-people-cloud-title-id">{{ title | translate }}</mat-label>
|
||||
<mat-chip-list #userChipList *ngIf="isMultipleMode(); else singleSelection">
|
||||
<mat-chip
|
||||
*ngFor="let user of selectedUsers$ | async"
|
||||
|
@ -69,6 +69,26 @@ describe('PeopleCloudComponent', () => {
|
||||
expect(component instanceof PeopleCloudComponent).toBe(true, 'should create PeopleCloudComponent');
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', async(() => {
|
||||
component.title = 'TITLE_KEY';
|
||||
fixture.detectChanges();
|
||||
const matLabel: HTMLInputElement = <HTMLInputElement> fixture.nativeElement.querySelector('#adf-people-cloud-title-id');
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(matLabel.textContent).toEqual('TITLE_KEY');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not populate placeholder when title is not present', async(() => {
|
||||
fixture.detectChanges();
|
||||
const matLabel: HTMLInputElement = <HTMLInputElement> fixture.nativeElement.querySelector('#adf-people-cloud-title-id');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(matLabel.textContent).toEqual('');
|
||||
});
|
||||
}));
|
||||
|
||||
describe('Search user', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
@ -136,27 +156,6 @@ describe('PeopleCloudComponent', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', (done) => {
|
||||
component.title = 'TITLE_KEY';
|
||||
fixture.detectChanges();
|
||||
const matLabel: HTMLInputElement = <HTMLInputElement> element.querySelector('mat-label');
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(matLabel.textContent).toEqual('TITLE_KEY');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not populate placeholder when title is present', (done) => {
|
||||
const matLabel: HTMLInputElement = <HTMLInputElement> element.querySelector('mat-label');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then( () => {
|
||||
fixture.detectChanges();
|
||||
expect(matLabel.textContent).toEqual('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when application name defined', () => {
|
||||
@ -654,21 +653,6 @@ describe('PeopleCloudComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should populate placeholder when title is present', () => {
|
||||
fixture.detectChanges();
|
||||
component.title = 'ADF_TASK_LIST.START_TASK.FORM.LABEL.ASSIGNEE';
|
||||
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('mat-label');
|
||||
fixture.detectChanges();
|
||||
expect(inputHTMLElement.textContent).toEqual('ADF_TASK_LIST.START_TASK.FORM.LABEL.ASSIGNEE');
|
||||
});
|
||||
|
||||
it('should not populate placeholder when title is present', () => {
|
||||
fixture.detectChanges();
|
||||
const inputHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('mat-label');
|
||||
fixture.detectChanges();
|
||||
expect(inputHTMLElement.textContent).toEqual('');
|
||||
});
|
||||
|
||||
it('should remove duplicated preselcted users when a user is duplicated', () => {
|
||||
spyOn(identityService, 'findUserById').and.returnValue(of(mockUsers[0]));
|
||||
component.mode = 'multiple';
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { Component, OnInit, Output, EventEmitter, ViewEncapsulation, Input, ViewChild, ElementRef, SimpleChanges, OnChanges, OnDestroy } from '@angular/core';
|
||||
import { Component, OnInit, Output, EventEmitter, ViewEncapsulation, Input, ViewChild, ElementRef, SimpleChanges, OnChanges, OnDestroy, ChangeDetectionStrategy } from '@angular/core';
|
||||
import { Observable, of, BehaviorSubject, Subject } from 'rxjs';
|
||||
import { switchMap, debounceTime, distinctUntilChanged, mergeMap, tap, filter, map, takeUntil } from 'rxjs/operators';
|
||||
import { FullNamePipe, IdentityUserModel, IdentityUserService, LogService } from '@alfresco/adf-core';
|
||||
@ -36,6 +36,7 @@ import { trigger, state, style, transition, animate } from '@angular/animations'
|
||||
])
|
||||
],
|
||||
providers: [FullNamePipe],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
|
||||
@ -123,7 +124,9 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.hasPreSelectUsers()) {
|
||||
this.selectedUsers = [...this.preSelectUsers];
|
||||
}
|
||||
this.initSubjects();
|
||||
this.initSearch();
|
||||
|
||||
@ -351,13 +354,10 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
async loadNoValidationPreselectUsers() {
|
||||
let users: IdentityUserModel[];
|
||||
|
||||
users = this.removeDuplicatedUsers(this.preSelectUsers);
|
||||
this.preSelectUsers = [...users];
|
||||
this.selectedUsers = [...this.removeDuplicatedUsers(this.preSelectUsers)];
|
||||
|
||||
if (this.isMultipleMode()) {
|
||||
this.selectedUsersSubject.next(this.preSelectUsers);
|
||||
this.selectedUsersSubject.next(this.selectedUsers);
|
||||
} else {
|
||||
|
||||
if (this.currentTimeout) {
|
||||
@ -365,8 +365,8 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
}
|
||||
|
||||
this.currentTimeout = setTimeout(() => {
|
||||
this.searchUserCtrl.setValue(this.preSelectUsers[0]);
|
||||
this.onSelect(this.preSelectUsers[0]);
|
||||
this.searchUserCtrl.setValue(this.selectedUsers[0]);
|
||||
this.onSelect(this.selectedUsers[0]);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
@ -385,13 +385,24 @@ export class PeopleCloudComponent implements OnInit, OnChanges, OnDestroy {
|
||||
const users = await this.validatePreselectUsers();
|
||||
if (users && users.length > 0) {
|
||||
this.checkPreselectValidationErrors();
|
||||
this.selectedUsers = [...users];
|
||||
this.selectedUsers = [...this.alignPreselectedReadonlyUsersAfterValidation(users)];
|
||||
this.selectedUsersSubject.next(this.selectedUsers);
|
||||
} else {
|
||||
this.checkPreselectValidationErrors();
|
||||
}
|
||||
}
|
||||
|
||||
private alignPreselectedReadonlyUsersAfterValidation(users: IdentityUserModel[]) {
|
||||
this.preSelectUsers.forEach((preSelectedUser, index) => {
|
||||
if (users[index]) {
|
||||
if ((preSelectedUser.id === users[index].id) || (preSelectedUser.username === users[index].username)) {
|
||||
users[index].readonly = preSelectedUser.readonly;
|
||||
}
|
||||
}
|
||||
});
|
||||
return users;
|
||||
}
|
||||
|
||||
public checkPreselectValidationErrors() {
|
||||
if (this.invalidUsers.length > 0) {
|
||||
this.warning.emit({
|
||||
|
Loading…
x
Reference in New Issue
Block a user