mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Fix process cloud page (#4075)
* Fix process cloud page * Use FilterParamModel * Rollback method * Fix core unit test related to identity service * Fix process filters cloud Get user info from different keys * Select the my-task filter in case the task has been created * Add family_name and given_name to the jwt token
This commit is contained in:
committed by
Eugenio Romano
parent
511087f6b1
commit
e241779f3a
@@ -19,7 +19,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed, IdentityUserService } from '@alfresco/adf-core';
|
||||
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { of } from 'rxjs';
|
||||
@@ -32,6 +32,7 @@ import { ProcessFilterCloudService } from '../services/process-filter-cloud.serv
|
||||
describe('EditProcessFilterCloudComponent', () => {
|
||||
let component: EditProcessFilterCloudComponent;
|
||||
let service: ProcessFilterCloudService;
|
||||
let identityService: IdentityUserService;
|
||||
let fixture: ComponentFixture<EditProcessFilterCloudComponent>;
|
||||
let dialog: MatDialog;
|
||||
|
||||
@@ -56,6 +57,7 @@ describe('EditProcessFilterCloudComponent', () => {
|
||||
fixture = TestBed.createComponent(EditProcessFilterCloudComponent);
|
||||
component = fixture.componentInstance;
|
||||
service = TestBed.get(ProcessFilterCloudService);
|
||||
identityService = TestBed.get(IdentityUserService);
|
||||
dialog = TestBed.get(MatDialog);
|
||||
spyOn(dialog, 'open').and.returnValue({ afterClosed() { return of({
|
||||
action: ProcessFilterDialogCloudComponent.ACTION_SAVE,
|
||||
@@ -236,6 +238,7 @@ describe('EditProcessFilterCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should emit save event and save the filter on click save button', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue({username: 'currentUser'});
|
||||
const saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(fakeFilter);
|
||||
let saveSpy: jasmine.Spy = spyOn(component.action, 'emit');
|
||||
fixture.detectChanges();
|
||||
@@ -257,6 +260,7 @@ describe('EditProcessFilterCloudComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit delete event and delete the filter on click of delete button', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue({username: 'currentUser'});
|
||||
const deleteFilterSpy = spyOn(service, 'deleteFilter').and.callThrough();
|
||||
let deleteSpy: jasmine.Spy = spyOn(component.action, 'emit');
|
||||
fixture.detectChanges();
|
||||
@@ -265,16 +269,17 @@ describe('EditProcessFilterCloudComponent', () => {
|
||||
const stateElement = fixture.debugElement.query(By.css('#adf-process-filter-state-id .mat-select-trigger')).nativeElement;
|
||||
stateElement.click();
|
||||
fixture.detectChanges();
|
||||
let deleteButton = fixture.debugElement.nativeElement.querySelector('#adf-delete-id');
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
let deleteButton = fixture.debugElement.nativeElement.querySelector('#adf-delete-id');
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(deleteFilterSpy).toHaveBeenCalled();
|
||||
expect(deleteSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit saveAs event and add filter on click of saveAs button', async(() => {
|
||||
it('should emit saveAs event and add filter on click saveAs button', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue({username: 'currentUser'});
|
||||
const saveAsFilterSpy = spyOn(service, 'addFilter').and.callThrough();
|
||||
let saveAsSpy: jasmine.Spy = spyOn(component.action, 'emit');
|
||||
fixture.detectChanges();
|
||||
@@ -283,35 +288,17 @@ describe('EditProcessFilterCloudComponent', () => {
|
||||
const stateElement = fixture.debugElement.query(By.css('#adf-process-filter-state-id .mat-select-trigger')).nativeElement;
|
||||
stateElement.click();
|
||||
fixture.detectChanges();
|
||||
const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-as-id');
|
||||
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
|
||||
stateOptions[2].nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
saveButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-as-id');
|
||||
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
|
||||
stateOptions[2].nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
saveButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(saveAsFilterSpy).toHaveBeenCalled();
|
||||
expect(saveAsSpy).toHaveBeenCalled();
|
||||
expect(dialog.open).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should able to open save dialog on click of saveAs button', async(() => {
|
||||
fixture.detectChanges();
|
||||
let expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
|
||||
expansionPanel.click();
|
||||
const stateElement = fixture.debugElement.query(By.css('#adf-process-filter-state-id .mat-select-trigger')).nativeElement;
|
||||
stateElement.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-as-id');
|
||||
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
|
||||
stateOptions[2].nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
saveButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -20,6 +20,7 @@ import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { from, Observable } from 'rxjs';
|
||||
import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
|
||||
import { FilterParamsModel } from '../../task-cloud/models/filter-cloud.model';
|
||||
import { ProcessFilterCloudService } from '../services/process-filter-cloud.service';
|
||||
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
@@ -62,14 +63,6 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
resolve(fakeGlobalFilter);
|
||||
});
|
||||
|
||||
let fakeGlobalEmptyFilter = {
|
||||
message: 'invalid data'
|
||||
};
|
||||
|
||||
let fakeGlobalEmptyFilterPromise = new Promise(function (resolve, reject) {
|
||||
resolve(fakeGlobalEmptyFilter);
|
||||
});
|
||||
|
||||
let mockErrorFilterList = {
|
||||
error: 'wrong request'
|
||||
};
|
||||
@@ -187,25 +180,10 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
|
||||
}));
|
||||
|
||||
it('should be able to fetch and select the default filters if the input filter is not valid', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalEmptyFilterPromise));
|
||||
spyOn(component, 'createFilters').and.callThrough();
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
|
||||
component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(component.createFilters).not.toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should select the filter based on the input by name param', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new ProcessFilterCloudModel({ name: 'FakeRunningProcesses' });
|
||||
component.filterParam = new FilterParamsModel({ name: 'FakeRunningProcesses' });
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -224,7 +202,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
it('should select the filter based on the input by key param', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new ProcessFilterCloudModel({ key: 'completed-processes' });
|
||||
component.filterParam = new FilterParamsModel({ key: 'completed-processes' });
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -244,7 +222,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
it('should select the default filter if filter input does not exist', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new ProcessFilterCloudModel({ name: 'UnexistableFilter' });
|
||||
component.filterParam = new FilterParamsModel({ name: 'UnexistableFilter' });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
@@ -265,7 +243,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
it('should select the filter based on the input by index param', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new ProcessFilterCloudModel({ index: 2 });
|
||||
component.filterParam = new FilterParamsModel({ index: 2 });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
@@ -285,7 +263,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
it('should select the filter based on the input by id param', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new ProcessFilterCloudModel({ id: '12' });
|
||||
component.filterParam = new FilterParamsModel({ id: '12' });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
@@ -304,7 +282,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
||||
it('should emit an event when a filter is selected', (done) => {
|
||||
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new ProcessFilterCloudModel({ id: '10' });
|
||||
component.filterParam = new FilterParamsModel({ id: '10' });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
|
@@ -19,6 +19,7 @@ import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from
|
||||
import { Observable } from 'rxjs';
|
||||
import { ProcessFilterCloudService } from '../services/process-filter-cloud.service';
|
||||
import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
|
||||
import { FilterParamsModel } from '../../task-cloud/models/filter-cloud.model';
|
||||
import { TranslationService } from '@alfresco/adf-core';
|
||||
@Component({
|
||||
selector: 'adf-cloud-process-filters',
|
||||
@@ -33,7 +34,7 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
|
||||
/** (optional) The filter to be selected by default */
|
||||
@Input()
|
||||
filterParam: ProcessFilterCloudModel;
|
||||
filterParam: FilterParamsModel;
|
||||
|
||||
/** (optional) The flag hides/shows icon against each filter */
|
||||
@Input()
|
||||
@@ -59,7 +60,7 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
|
||||
constructor(
|
||||
private processFilterCloudService: ProcessFilterCloudService,
|
||||
private translate: TranslationService ) { }
|
||||
private translationService: TranslationService ) { }
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
const appName = changes['appName'];
|
||||
@@ -67,7 +68,7 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
if (appName && appName.currentValue) {
|
||||
this.getFilters(appName.currentValue);
|
||||
} else if (filter && filter.currentValue !== filter.previousValue) {
|
||||
this.selectFilterAndEmit(filter.currentValue);
|
||||
this.selectFilter(filter.currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,12 +80,8 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
|
||||
this.filters$.subscribe(
|
||||
(res: ProcessFilterCloudModel[]) => {
|
||||
if (res.length === 0) {
|
||||
this.createFilters(appName);
|
||||
} else {
|
||||
this.resetFilter();
|
||||
this.filters = res;
|
||||
}
|
||||
this.resetFilter();
|
||||
this.filters = Object.assign([], res);
|
||||
this.selectFilterAndEmit(this.filterParam);
|
||||
this.success.emit(res);
|
||||
},
|
||||
@@ -94,33 +91,16 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default filters by appName
|
||||
*/
|
||||
createFilters(appName?: string) {
|
||||
this.filters$ = this.processFilterCloudService.createDefaultFilters(appName);
|
||||
|
||||
this.filters$.subscribe(
|
||||
(resDefault: ProcessFilterCloudModel[]) => {
|
||||
this.resetFilter();
|
||||
this.filters = resDefault;
|
||||
},
|
||||
(errDefault: any) => {
|
||||
this.error.emit(errDefault);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass the selected filter as next
|
||||
*/
|
||||
public selectFilter(filterParam: ProcessFilterCloudModel) {
|
||||
if (filterParam) {
|
||||
public selectFilter(paramFilter: FilterParamsModel) {
|
||||
if (paramFilter) {
|
||||
this.currentFilter = this.filters.find((filter, index) => {
|
||||
return filterParam.id === filter.id ||
|
||||
(filterParam.name && this.checkFilterNamesEquality(filterParam.name, filter.name)) ||
|
||||
(filterParam.key && (filterParam.key === filter.key)) ||
|
||||
filterParam.index === index;
|
||||
return paramFilter.id === filter.id ||
|
||||
(paramFilter.name && this.checkFilterNamesEquality(paramFilter.name, filter.name)) ||
|
||||
(paramFilter.key && (paramFilter.key === filter.key)) ||
|
||||
paramFilter.index === index;
|
||||
});
|
||||
}
|
||||
if (!this.currentFilter) {
|
||||
@@ -132,8 +112,8 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
* Check equality of the filter names by translating the given name strings
|
||||
*/
|
||||
private checkFilterNamesEquality(name1: string, name2: string ): boolean {
|
||||
const translatedName1 = this.translate.instant(name1);
|
||||
const translatedName2 = this.translate.instant(name2);
|
||||
const translatedName1 = this.translationService.instant(name1);
|
||||
const translatedName2 = this.translationService.instant(name2);
|
||||
|
||||
return translatedName1.toLocaleLowerCase() === translatedName2.toLocaleLowerCase();
|
||||
}
|
||||
@@ -141,8 +121,8 @@ export class ProcessFiltersCloudComponent implements OnChanges {
|
||||
/**
|
||||
* Select and emit the given filter
|
||||
*/
|
||||
public selectFilterAndEmit(newFilter: ProcessFilterCloudModel) {
|
||||
this.selectFilter(newFilter);
|
||||
public selectFilterAndEmit(newParamFilter: FilterParamsModel) {
|
||||
this.selectFilter(newParamFilter);
|
||||
this.filterClick.emit(this.currentFilter);
|
||||
}
|
||||
|
||||
|
@@ -15,15 +15,22 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { StorageService } from '@alfresco/adf-core';
|
||||
import { StorageService, IdentityUserService, IdentityUserModel } from '@alfresco/adf-core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
|
||||
|
||||
@Injectable()
|
||||
export class ProcessFilterCloudService {
|
||||
|
||||
constructor(private storage: StorageService) {
|
||||
private filtersSubject: BehaviorSubject<ProcessFilterCloudModel[]>;
|
||||
filters$: Observable<ProcessFilterCloudModel[]>;
|
||||
|
||||
constructor(
|
||||
private storage: StorageService,
|
||||
private identityUserService: IdentityUserService) {
|
||||
this.filtersSubject = new BehaviorSubject([]);
|
||||
this.filters$ = this.filtersSubject.asObservable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,15 +38,13 @@ export class ProcessFilterCloudService {
|
||||
* @param appName Name of the target app
|
||||
* @returns Observable of default filters just created
|
||||
*/
|
||||
public createDefaultFilters(appName: string): Observable<ProcessFilterCloudModel[]> {
|
||||
private createDefaultFilters(appName: string) {
|
||||
const allProcessesFilter = this.getAllProcessesFilter(appName);
|
||||
this.addFilter(allProcessesFilter);
|
||||
const runningProcessesFilter = this.getRunningProcessesFilter(appName);
|
||||
this.addFilter(runningProcessesFilter);
|
||||
const completedProcessesFilter = this.getCompletedProcessesFilter(appName);
|
||||
this.addFilter(completedProcessesFilter);
|
||||
|
||||
return this.getProcessFilters(appName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,12 +53,16 @@ export class ProcessFilterCloudService {
|
||||
* @returns Observable of process filter details
|
||||
*/
|
||||
getProcessFilters(appName: string): Observable<ProcessFilterCloudModel[]> {
|
||||
let key = 'process-filters-' + appName;
|
||||
const user: IdentityUserModel = this.identityUserService.getCurrentUserInfo();
|
||||
const key = `process-filters-${appName}-${user.username}`;
|
||||
const filters = JSON.parse(this.storage.getItem(key) || '[]');
|
||||
return new Observable(function(observer) {
|
||||
observer.next(filters);
|
||||
observer.complete();
|
||||
});
|
||||
|
||||
if (filters.length === 0) {
|
||||
this.createDefaultFilters(appName);
|
||||
} else {
|
||||
this.addFiltersToStream(filters);
|
||||
}
|
||||
return this.filters$;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +72,8 @@ export class ProcessFilterCloudService {
|
||||
* @returns Details of process filter
|
||||
*/
|
||||
getProcessFilterById(appName: string, id: string): ProcessFilterCloudModel {
|
||||
const key = 'process-filters-' + appName;
|
||||
const user: IdentityUserModel = this.identityUserService.getCurrentUserInfo();
|
||||
const key = `process-filters-${appName}-${user.username}`;
|
||||
let filters = [];
|
||||
filters = JSON.parse(this.storage.getItem(key)) || [];
|
||||
return filters.filter((filterTmp: ProcessFilterCloudModel) => id === filterTmp.id)[0];
|
||||
@@ -75,11 +85,14 @@ export class ProcessFilterCloudService {
|
||||
* @returns Details of process filter just added
|
||||
*/
|
||||
addFilter(filter: ProcessFilterCloudModel) {
|
||||
const key = 'process-filters-' + filter.appName;
|
||||
const user: IdentityUserModel = this.identityUserService.getCurrentUserInfo();
|
||||
const key = `process-filters-${filter.appName}-${user.username}`;
|
||||
const storedFilters = JSON.parse(this.storage.getItem(key) || '[]');
|
||||
|
||||
storedFilters.push(filter);
|
||||
this.storage.setItem(key, JSON.stringify(storedFilters));
|
||||
|
||||
this.addFiltersToStream(storedFilters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,12 +100,14 @@ export class ProcessFilterCloudService {
|
||||
* @param filter The new filter to update
|
||||
*/
|
||||
updateFilter(filter: ProcessFilterCloudModel) {
|
||||
const key = 'process-filters-' + filter.appName;
|
||||
const user: IdentityUserModel = this.identityUserService.getCurrentUserInfo();
|
||||
const key = `process-filters-${filter.appName}-${user.username}`;
|
||||
if (key) {
|
||||
let filters = JSON.parse(this.storage.getItem(key) || '[]');
|
||||
let itemIndex = filters.findIndex((flt: ProcessFilterCloudModel) => flt.id === filter.id);
|
||||
filters[itemIndex] = filter;
|
||||
this.storage.setItem(key, JSON.stringify(filters));
|
||||
this.addFiltersToStream(filters);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,11 +116,17 @@ export class ProcessFilterCloudService {
|
||||
* @param filter The new filter to delete
|
||||
*/
|
||||
deleteFilter(filter: ProcessFilterCloudModel) {
|
||||
const key = 'process-filters-' + filter.appName;
|
||||
const user: IdentityUserModel = this.identityUserService.getCurrentUserInfo();
|
||||
const key = `process-filters-${filter.appName}-${user.username}`;
|
||||
if (key) {
|
||||
let filters = JSON.parse(this.storage.getItem(key) || '[]');
|
||||
filters = filters.filter((item) => item.id !== filter.id);
|
||||
this.storage.setItem(key, JSON.stringify(filters));
|
||||
if (filters.length === 0) {
|
||||
this.createDefaultFilters(filter.appName);
|
||||
} else {
|
||||
this.addFiltersToStream(filters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,4 +180,8 @@ export class ProcessFilterCloudService {
|
||||
order: 'DESC'
|
||||
});
|
||||
}
|
||||
|
||||
private addFiltersToStream(filters: ProcessFilterCloudModel []) {
|
||||
this.filtersSubject.next(filters);
|
||||
}
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ describe('PeopleCloudComponent', () => {
|
||||
}));
|
||||
|
||||
it('should not list the current logged in user when showCurrentUser is false', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue(of(mockUsers[1]));
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue(mockUsers[1]);
|
||||
component.showCurrentUser = false;
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
|
@@ -62,7 +62,7 @@ describe('StartTaskCloudComponent', () => {
|
||||
createNewTaskSpy = spyOn(service, 'createNewTask').and.returnValue(of(taskDetailsMock));
|
||||
getRolesByUserIdSpy = spyOn(identityService, 'getUserRoles').and.returnValue(of(mockRoles));
|
||||
getUserSpy = spyOn(identityService, 'getUsers').and.returnValue(of(mockUsers));
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue(of(new IdentityUserModel({username: 'currentUser'})));
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue(new IdentityUserModel({username: 'currentUser'}));
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
|
@@ -128,8 +128,8 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
|
||||
StartTaskCloudComponent.MAX_NAME_LENGTH : this.maxNameLength;
|
||||
}
|
||||
|
||||
private async loadCurrentUser() {
|
||||
this.currentUser = await this.identityUserService.getCurrentUserInfo().toPromise();
|
||||
private loadCurrentUser() {
|
||||
this.currentUser = this.identityUserService.getCurrentUserInfo();
|
||||
}
|
||||
|
||||
public saveTask() {
|
||||
|
@@ -44,7 +44,20 @@ export class TaskFilterCloudModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class FilterParamsModel {
|
||||
id?: string;
|
||||
name?: string;
|
||||
key?: string;
|
||||
index?: number;
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.id = obj.id || null;
|
||||
this.name = obj.name || null;
|
||||
this.key = obj.key || null;
|
||||
this.index = obj.index;
|
||||
}
|
||||
}
|
||||
}
|
||||
export interface FilterActionType {
|
||||
actionType: string;
|
||||
id: string;
|
||||
|
@@ -35,7 +35,7 @@ export class TaskFilterCloudService {
|
||||
* @param appName Name of the target app
|
||||
* @returns Observable of default filters just created
|
||||
*/
|
||||
public createDefaultFilters(appName: string) {
|
||||
private createDefaultFilters(appName: string) {
|
||||
let myTasksFilter = this.getMyTasksFilterInstance(appName);
|
||||
this.addFilter(myTasksFilter);
|
||||
|
||||
@@ -102,6 +102,7 @@ export class TaskFilterCloudService {
|
||||
let itemIndex = filters.findIndex((flt: TaskFilterCloudModel) => flt.id === filter.id);
|
||||
filters[itemIndex] = filter;
|
||||
this.storage.setItem(key, JSON.stringify(filters));
|
||||
this.addFiltersToStream(filters);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -19,7 +19,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed, IdentityUserService } from '@alfresco/adf-core';
|
||||
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
|
||||
import { TaskFilterCloudModel } from '../models/filter-cloud.model';
|
||||
import { TaskCloudModule } from './../task-cloud.module';
|
||||
@@ -32,6 +32,7 @@ import { TaskFilterDialogCloudComponent } from './task-filter-dialog-cloud.compo
|
||||
describe('EditTaskFilterCloudComponent', () => {
|
||||
let component: EditTaskFilterCloudComponent;
|
||||
let service: TaskFilterCloudService;
|
||||
let identityService: IdentityUserService;
|
||||
let fixture: ComponentFixture<EditTaskFilterCloudComponent>;
|
||||
let dialog: MatDialog;
|
||||
|
||||
@@ -56,6 +57,7 @@ describe('EditTaskFilterCloudComponent', () => {
|
||||
fixture = TestBed.createComponent(EditTaskFilterCloudComponent);
|
||||
component = fixture.componentInstance;
|
||||
service = TestBed.get(TaskFilterCloudService);
|
||||
identityService = TestBed.get(IdentityUserService);
|
||||
dialog = TestBed.get(MatDialog);
|
||||
spyOn(dialog, 'open').and.returnValue({ afterClosed() { return of({
|
||||
action: TaskFilterDialogCloudComponent.ACTION_SAVE,
|
||||
@@ -223,6 +225,7 @@ describe('EditTaskFilterCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should emit save event and save the filter on click save button', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue({username: 'currentUser'});
|
||||
const saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(fakeFilter);
|
||||
let saveSpy: jasmine.Spy = spyOn(component.action, 'emit');
|
||||
fixture.detectChanges();
|
||||
@@ -244,6 +247,7 @@ describe('EditTaskFilterCloudComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit delete event and delete the filter on click of delete button', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue({username: 'currentUser'});
|
||||
const deleteFilterSpy = spyOn(service, 'deleteFilter').and.callThrough();
|
||||
let deleteSpy: jasmine.Spy = spyOn(component.action, 'emit');
|
||||
fixture.detectChanges();
|
||||
@@ -262,6 +266,7 @@ describe('EditTaskFilterCloudComponent', () => {
|
||||
}));
|
||||
|
||||
it('should emit saveAs event and add filter on click saveAs button', async(() => {
|
||||
spyOn(identityService, 'getCurrentUserInfo').and.returnValue({username: 'currentUser'});
|
||||
const saveAsFilterSpy = spyOn(service, 'addFilter').and.callThrough();
|
||||
let saveAsSpy: jasmine.Spy = spyOn(component.action, 'emit');
|
||||
fixture.detectChanges();
|
||||
@@ -272,7 +277,7 @@ describe('EditTaskFilterCloudComponent', () => {
|
||||
fixture.detectChanges();
|
||||
const saveButton = fixture.debugElement.nativeElement.querySelector('#adf-save-as-id');
|
||||
const stateOptions = fixture.debugElement.queryAll(By.css('.mat-option-text'));
|
||||
stateOptions[3].nativeElement.click();
|
||||
stateOptions[2].nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
saveButton.click();
|
||||
fixture.detectChanges();
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<div class="menu-container">
|
||||
<mat-list class="adf-menu-list" *ngIf="filters$ | async as filterList; else loading">
|
||||
<mat-list-item (click)="selectFilterAndEmit(filter)" *ngFor="let filter of filterList"
|
||||
<mat-list-item (click)="selectFilterAndEmit({id: filter.id})" *ngFor="let filter of filterList"
|
||||
class="adf-filters__entry" [class.adf-active]="currentFilter === filter">
|
||||
<mat-icon *ngIf="showIcons && filter.icon" matListIcon class="adf-filters__entry-icon">{{filter.icon}}
|
||||
</mat-icon>
|
||||
|
@@ -19,7 +19,7 @@ import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { from, Observable } from 'rxjs';
|
||||
import { TaskFilterCloudModel } from '../models/filter-cloud.model';
|
||||
import { TaskFilterCloudModel, FilterParamsModel } from '../models/filter-cloud.model';
|
||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||
import { TaskFiltersCloudComponent } from './task-filters-cloud.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
@@ -201,7 +201,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
it('should select the task filter based on the input by name param', async(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new TaskFilterCloudModel({ name: 'FakeMyTasks1' });
|
||||
component.filterParam = new FilterParamsModel({ name: 'FakeMyTasks1' });
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -219,7 +219,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
it('should select the default task filter if filter input does not exist', async(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new TaskFilterCloudModel({ name: 'UnexistableFilter' });
|
||||
component.filterParam = new FilterParamsModel({ name: 'UnexistableFilter' });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
@@ -238,7 +238,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
it('should select the task filter based on the input by index param', async(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new TaskFilterCloudModel({ index: 2 });
|
||||
component.filterParam = new FilterParamsModel({ index: 2 });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
@@ -257,8 +257,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
it('should select the task filter based on the input by id param', async(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new TaskFilterCloudModel({ id: 12 });
|
||||
|
||||
component.filterParam = new FilterParamsModel({ id: 12 });
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
|
||||
@@ -276,7 +275,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
it('should emit an event when a filter is selected', async(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
|
||||
component.filterParam = new TaskFilterCloudModel({ id: 12 });
|
||||
component.filterParam = new FilterParamsModel({ id: 12 });
|
||||
|
||||
const appName = 'my-app-1';
|
||||
let change = new SimpleChange(null, appName, true);
|
||||
@@ -286,7 +285,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
spyOn(component, 'selectFilterAndEmit').and.stub();
|
||||
let filterButton = fixture.debugElement.nativeElement.querySelector('span[data-automation-id="fake-my-tast1-filter"]');
|
||||
filterButton.click();
|
||||
expect(component.selectFilterAndEmit).toHaveBeenCalledWith(fakeGlobalFilter[1]);
|
||||
expect(component.selectFilterAndEmit).toHaveBeenCalledWith({id: fakeGlobalFilter[1].id});
|
||||
}));
|
||||
|
||||
it('should reload filters by appName on binding changes', () => {
|
||||
@@ -347,7 +346,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
});
|
||||
|
||||
it('should return the current filter after one is selected', () => {
|
||||
let filter = new TaskFilterCloudModel({ name: 'FakeInvolvedTasks' });
|
||||
let filter = new FilterParamsModel({ name: 'FakeInvolvedTasks' });
|
||||
component.filters = fakeGlobalFilter;
|
||||
|
||||
expect(component.currentFilter).toBeUndefined();
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||
import { TaskFilterCloudModel } from '../models/filter-cloud.model';
|
||||
import { TaskFilterCloudModel, FilterParamsModel } from '../models/filter-cloud.model';
|
||||
import { TranslationService } from '@alfresco/adf-core';
|
||||
@Component({
|
||||
selector: 'adf-cloud-task-filters',
|
||||
@@ -35,7 +35,7 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
||||
* (the first one in the list) is selected.
|
||||
*/
|
||||
@Input()
|
||||
filterParam: TaskFilterCloudModel;
|
||||
filterParam: FilterParamsModel;
|
||||
|
||||
/** Toggles display of the filter's icons. */
|
||||
@Input()
|
||||
@@ -91,14 +91,14 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
||||
);
|
||||
}
|
||||
|
||||
public selectFilter(newFilter: TaskFilterCloudModel) {
|
||||
if (newFilter) {
|
||||
public selectFilter(paramFilter: FilterParamsModel) {
|
||||
if (paramFilter) {
|
||||
this.currentFilter = this.filters.find( (filter: TaskFilterCloudModel, index) =>
|
||||
newFilter.index === index ||
|
||||
newFilter.key === filter.key ||
|
||||
newFilter.id === filter.id ||
|
||||
(newFilter.name &&
|
||||
(newFilter.name.toLocaleLowerCase() === this.translationService.instant(filter.name).toLocaleLowerCase())
|
||||
paramFilter.index === index ||
|
||||
paramFilter.key === filter.key ||
|
||||
paramFilter.id === filter.id ||
|
||||
(paramFilter.name &&
|
||||
(paramFilter.name.toLocaleLowerCase() === this.translationService.instant(filter.name).toLocaleLowerCase())
|
||||
));
|
||||
}
|
||||
if (!this.currentFilter) {
|
||||
@@ -106,8 +106,8 @@ export class TaskFiltersCloudComponent implements OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
public selectFilterAndEmit(newFilter: TaskFilterCloudModel) {
|
||||
this.selectFilter(newFilter);
|
||||
public selectFilterAndEmit(newParamFilter: FilterParamsModel) {
|
||||
this.selectFilter(newParamFilter);
|
||||
this.filterClick.emit(this.currentFilter);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user