prepare tests for ng-12 upgrade (#7099)

* prepare tests for ng12 upgrade

* fix lint

* fix tests

* test fixes

* fix code and tests

* fix code and tests

* test fixes

* test fixes
This commit is contained in:
Denys Vuika
2021-06-11 07:36:32 +01:00
committed by GitHub
parent 558056b05c
commit eb71a79d1e
112 changed files with 982 additions and 1057 deletions

View File

@@ -34,7 +34,7 @@ describe('AppListCloudComponent', () => {
let getAppsSpy: jasmine.Spy;
let alfrescoApiService: AlfrescoApiService;
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
},

View File

@@ -30,7 +30,7 @@ describe('AppsProcessCloudService', () => {
let appConfigService: AppConfigService;
let apiService: AlfrescoApiService;
const apiMock = {
const apiMock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve({list : { entries: [ {entry: fakeApplicationInstance[0]}, {entry: fakeApplicationInstance[1]}] }})
},

View File

@@ -53,7 +53,7 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { CloudFormRenderingService } from './cloud-form-rendering.service';
import { Node } from '@alfresco/js-api';
const mockOauth2Auth = {
const mockOauth2Auth: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve()
},
@@ -310,7 +310,7 @@ describe('FormCloudComponent', () => {
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
spyOn(formCloudService, 'getTask').and.callFake((currentTaskId) => {
return new Observable((observer) => {
observer.next({ formRepresentation: { taskId: currentTaskId } });
observer.next({ formRepresentation: { taskId: currentTaskId } } as any);
observer.complete();
});
});
@@ -357,7 +357,7 @@ describe('FormCloudComponent', () => {
});
it('should refresh visibility when the form is loaded', () => {
spyOn(formCloudService, 'getForm').and.returnValue(of({ formRepresentation: {} }));
spyOn(formCloudService, 'getForm').and.returnValue(of({ formRepresentation: {} } as any));
const formId = '123';
const appName = 'test-app';

View File

@@ -44,7 +44,7 @@ describe('FormDefinitionCloudComponent', () => {
fixture = TestBed.createComponent(FormDefinitionSelectorCloudComponent);
element = fixture.nativeElement;
service = TestBed.inject(FormDefinitionSelectorCloudService);
getFormsSpy = spyOn(service, 'getStandAloneTaskForms').and.returnValue(of([{ id: 'fake-form', name: 'fakeForm' }]));
getFormsSpy = spyOn(service, 'getStandAloneTaskForms').and.returnValue(of([{ id: 'fake-form', name: 'fakeForm' } as any]));
});
it('should load the forms by default', () => {

View File

@@ -227,11 +227,11 @@ export const expectedValues = {
pfx_property_two: true
};
export const mockNodeId = new Promise(function(resolve) {
export const mockNodeId = new Promise<string>(function(resolve) {
resolve('mock-node-id');
});
export const mockNodeIdBasedOnStringVariableValue = new Promise(function(resolve) {
export const mockNodeIdBasedOnStringVariableValue = new Promise<string>(function(resolve) {
resolve('mock-string-value-node-id');
});

View File

@@ -759,7 +759,7 @@ export const emptyFormRepresentationJSON = {
'version': 0
};
export const conditionalUploadWidgetsMock = {
export const conditionalUploadWidgetsMock: any = {
'formRepresentation': {
'id': 'form-fb7858f7-5cf6-4afe-b462-c15a5dc0c34c',
'name': 'AttachVisibility',
@@ -847,7 +847,7 @@ export const conditionalUploadWidgetsMock = {
}
};
export const multilingualForm = {
export const multilingualForm: any = {
'formRepresentation': {
'id': 'form-2aaaf20e-43d3-46bf-89be-859d5f512dd2',
'name': 'multilingualform',

View File

@@ -56,7 +56,7 @@ describe('Form Cloud service', () => {
return false;
},
reply: jasmine.createSpy('reply')
});
} as any);
});
describe('Form tests', () => {
@@ -195,8 +195,11 @@ describe('Form Cloud service', () => {
it('should fetch task form flattened', (done) => {
spyOn(service, 'getTask').and.returnValue(of(responseBody.entry));
spyOn(service, 'getForm').and.returnValue(of({
formRepresentation: {name: 'task-form', formDefinition: {} }
}));
formRepresentation: {
name: 'task-form',
formDefinition: {}
}
} as any));
service.getTaskForm(appName, taskId).subscribe((result) => {
expect(result).toBeDefined();

View File

@@ -76,7 +76,7 @@ describe('Form Definition Selector Cloud Service', () => {
return false;
},
reply: jasmine.createSpy('reply')
});
} as any);
});
it('should fetch all the forms when getForms is called', (done) => {

View File

@@ -40,7 +40,7 @@ describe('GroupCloudComponent', () => {
let alfrescoApiService: AlfrescoApiService;
let findGroupsByNameSpy: jasmine.Spy;
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve(mockIdentityGroups)
},
@@ -648,7 +648,7 @@ describe('GroupCloudComponent', () => {
describe('Preselected groups and validation enabled', () => {
it('should check validation only for the first group and emit warning when group is invalid - single mode', (done) => {
spyOn(identityGroupService, 'findGroupsByName').and.returnValue(Promise.resolve([]));
spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of([]));
const expectedWarning = {
message: 'INVALID_PRESELECTED_GROUPS',
@@ -671,7 +671,7 @@ describe('GroupCloudComponent', () => {
});
it('should check validation for all the groups and emit warning - multiple mode', (done) => {
spyOn(identityGroupService, 'findGroupsByName').and.returnValue(Promise.resolve(undefined));
spyOn(identityGroupService, 'findGroupsByName').and.returnValue(of(undefined));
const expectedWarning = {
message: 'INVALID_PRESELECTED_GROUPS',

View File

@@ -40,7 +40,7 @@ describe('PeopleCloudComponent', () => {
let alfrescoApiService: AlfrescoApiService;
let findUsersByNameSpy: jasmine.Spy;
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve(mockUsers)
},
@@ -740,7 +740,7 @@ describe('PeopleCloudComponent', () => {
describe('Preselected users and validation enabled', () => {
it('should check validation only for the first user and emit warning when user is invalid - single mode', (done) => {
spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve([]));
spyOn(identityService, 'findUserById').and.returnValue(of([]));
const expectedWarning = {
message: 'INVALID_PRESELECTED_USERS',
users: [{
@@ -762,7 +762,7 @@ describe('PeopleCloudComponent', () => {
});
it('should skip warnings if validation disabled', () => {
spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve([]));
spyOn(identityService, 'findUserById').and.returnValue(of([]));
spyOn(component, 'compare').and.returnValue(false);
let warnings = 0;
@@ -779,7 +779,7 @@ describe('PeopleCloudComponent', () => {
});
it('should check validation for all the users and emit warning - multiple mode', (done) => {
spyOn(identityService, 'findUserById').and.returnValue(Promise.resolve(undefined));
spyOn(identityService, 'findUserById').and.returnValue(of(undefined));
const expectedWarning = {
message: 'INVALID_PRESELECTED_USERS',

View File

@@ -30,7 +30,7 @@ describe('ProcessNameCloudPipe', () => {
const defaultName = 'default-name';
const datetimeIdentifier = '%{datetime}';
const processDefinitionIdentifier = '%{processDefinition}';
const mockCurrentDate = 'Wed Oct 23 2019';
const mockCurrentDate = new Date('Wed Oct 23 2019');
const mockLocalizedCurrentDate = 'Oct 23, 2019, 12:00:00 AM';
const nameWithProcessDefinitionIdentifier = `${defaultName} - ${processDefinitionIdentifier}`;
const nameWithDatetimeIdentifier = `${defaultName} - ${datetimeIdentifier}`;

View File

@@ -39,6 +39,7 @@ import { ProcessCloudService } from '../../services/process-cloud.service';
import { DateCloudFilterType } from '../../../models/date-cloud-filter.model';
import { ApplicationVersionModel } from '../../../models/application-version.model';
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
describe('EditProcessFilterCloudComponent', () => {
let component: EditProcessFilterCloudComponent;
@@ -64,7 +65,7 @@ describe('EditProcessFilterCloudComponent', () => {
sort: 'id'
});
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
},
@@ -103,7 +104,7 @@ describe('EditProcessFilterCloudComponent', () => {
name: 'fake-name'
});
}
});
} as any);
getProcessFilterByIdSpy = spyOn(service, 'getFilterById').and.returnValue(of(fakeFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock);
@@ -535,7 +536,7 @@ describe('EditProcessFilterCloudComponent', () => {
});
it('should fetch process definitions when processDefinitionName filter property is set', async(() => {
const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }]));
const processSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })]));
fixture.detectChanges();
component.filterProperties = ['processDefinitionName'];
fixture.detectChanges();
@@ -633,14 +634,19 @@ describe('EditProcessFilterCloudComponent', () => {
beforeEach(() => {
const processFilterIdChange = new SimpleChange(null, 'mock-process-filter-id', true);
component.ngOnChanges({ 'id': processFilterIdChange });
getProcessFilterByIdSpy.and.returnValue(of(fakeFilter));
component.ngOnChanges({ 'id': processFilterIdChange });
fixture.detectChanges();
});
afterEach(() => {
fixture.destroy();
});
it('should emit save event and save the filter on click save button', async(() => {
component.toggleFilterActions = true;
const saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(of(fakeFilter));
const saveFilterSpy = spyOn(service, 'updateFilter').and.returnValue(of([fakeFilter]));
const saveSpy: jasmine.Spy = spyOn(component.action, 'emit');
fixture.detectChanges();
@@ -661,30 +667,33 @@ describe('EditProcessFilterCloudComponent', () => {
});
}));
it('should emit delete event and delete the filter on click of delete button', (done) => {
it('should emit delete event and delete the filter on click of delete button', async () => {
component.toggleFilterActions = true;
const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of({}));
const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of({} as any));
const deleteSpy = spyOn(component.action, 'emit');
fixture.detectChanges();
await fixture.whenStable();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
fixture.detectChanges();
await fixture.whenStable();
const stateElement = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-cloud-edit-process-property-status"] .mat-select-trigger');
stateElement.click();
fixture.detectChanges();
await fixture.whenStable();
const deleteButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="adf-filter-action-delete"]');
deleteButton.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(deleteFilterSpy).toHaveBeenCalled();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(deleteSpy).toHaveBeenCalled();
done();
});
await fixture.whenStable();
});
expect(deleteFilterSpy).toHaveBeenCalled();
expect(deleteSpy).toHaveBeenCalled();
});
it('should emit saveAs event and add filter on click saveAs button', async(() => {
@@ -910,7 +919,7 @@ describe('EditProcessFilterCloudComponent', () => {
it('should not call restore default filters service on deletion first filter', (done) => {
component.toggleFilterActions = true;
const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of([{ name: 'mock-filter-name'}]));
const deleteFilterSpy = spyOn(service, 'deleteFilter').and.returnValue(of([new ProcessFilterCloudModel({ name: 'mock-filter-name'})]));
const restoreFiltersSpy = spyOn(component, 'restoreDefaultProcessFilters').and.returnValue(of([]));
const deleteSpy: jasmine.Spy = spyOn(component.action, 'emit');
fixture.detectChanges();

View File

@@ -16,9 +16,9 @@
*/
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed } from '@alfresco/adf-core';
import { from, Observable } from 'rxjs';
import { of, throwError } from 'rxjs';
import { ProcessFilterCloudService } from '../services/process-filter-cloud.service';
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
import { By } from '@angular/platform-browser';
@@ -30,27 +30,10 @@ import { TranslateModule } from '@ngx-translate/core';
import { mockProcessFilters } from '../mock/process-filters-cloud.mock';
describe('ProcessFiltersCloudComponent', () => {
let processFilterService: ProcessFilterCloudService;
const fakeGlobalFilterObservable =
new Observable(function(observer) {
observer.next(mockProcessFilters);
observer.complete();
});
const fakeGlobalFilterPromise = new Promise(function (resolve) {
resolve(mockProcessFilters);
});
const mockErrorFilterList = {
error: 'wrong request'
};
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
let component: ProcessFiltersCloudComponent;
let fixture: ComponentFixture<ProcessFiltersCloudComponent>;
let getProcessFiltersSpy: jasmine.Spy;
setupTestBed({
imports: [
@@ -68,198 +51,183 @@ describe('ProcessFiltersCloudComponent', () => {
component = fixture.componentInstance;
processFilterService = TestBed.inject(ProcessFilterCloudService);
getProcessFiltersSpy = spyOn(processFilterService, 'getProcessFilters').and.returnValue(of(mockProcessFilters));
});
it('should attach specific icon for each filter if hasIcon is true', async(() => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
afterEach(() => {
fixture.destroy();
});
it('should attach specific icon for each filter if hasIcon is true', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.filters.length).toBe(3);
const filters = fixture.nativeElement.querySelectorAll('.adf-icon');
expect(filters.length).toBe(3);
expect(filters[0].innerText).toContain('adjust');
expect(filters[1].innerText).toContain('inbox');
expect(filters[2].innerText).toContain('done');
});
}));
it('should not attach icons for each filter if hasIcon is false', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise));
fixture.detectChanges();
await fixture.whenStable();
expect(component.filters.length).toBe(3);
const filters = fixture.nativeElement.querySelectorAll('.adf-icon');
expect(filters.length).toBe(3);
expect(filters[0].innerText).toContain('adjust');
expect(filters[1].innerText).toContain('inbox');
expect(filters[2].innerText).toContain('done');
});
it('should not attach icons for each filter if hasIcon is false', async () => {
component.showIcons = false;
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
done();
});
fixture.detectChanges();
await fixture.whenStable();
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
});
it('should display the filters', async(() => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
it('should display the filters', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
const filters = fixture.debugElement.queryAll(By.css('.adf-filters__entry'));
expect(component.filters.length).toBe(3);
expect(filters.length).toBe(3);
expect(filters[0].nativeElement.innerText).toContain('FakeAllProcesses');
expect(filters[1].nativeElement.innerText).toContain('FakeRunningProcesses');
expect(filters[2].nativeElement.innerText).toContain('FakeCompletedProcesses');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const filters = fixture.debugElement.queryAll(By.css('.adf-filters__entry'));
expect(component.filters.length).toBe(3);
expect(filters.length).toBe(3);
expect(filters[0].nativeElement.innerText).toContain('FakeAllProcesses');
expect(filters[1].nativeElement.innerText).toContain('FakeRunningProcesses');
expect(filters[2].nativeElement.innerText).toContain('FakeCompletedProcesses');
});
it('should emit an error with a bad response', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(mockErrorFilterPromise));
const mockErrorFilterList = {
error: 'wrong request'
};
getProcessFiltersSpy.and.returnValue(throwError(mockErrorFilterList));
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({'appName': change});
component.error.subscribe((err) => {
expect(err).toBeDefined();
done();
});
});
it('should emit success with the filters when filters are loaded', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(from(fakeGlobalFilterPromise));
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.filters).toBeDefined();
expect(component.filters[0].name).toEqual('FakeAllProcesses');
expect(component.filters[1].name).toEqual('FakeRunningProcesses');
expect(component.filters[2].name).toEqual('FakeCompletedProcesses');
done();
});
});
it('should select the first filter as default', async(() => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
});
it('should emit success with the filters when filters are loaded', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
});
expect(component.filters).toBeDefined();
expect(component.filters[0].name).toEqual('FakeAllProcesses');
expect(component.filters[1].name).toEqual('FakeRunningProcesses');
expect(component.filters[2].name).toEqual('FakeCompletedProcesses');
});
}));
it('should select the first process cloud filter as default', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
it('should select the filter based on the input by name param', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
});
it('should select the filter based on the input by name param', async () => {
component.filterParam = { name: 'FakeRunningProcesses' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeRunningProcesses');
done();
});
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeRunningProcesses');
});
it('should select the filter based on the input by key param', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
it('should select the filter based on the input by key param', async () => {
component.filterParam = { key: 'completed-processes' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
done();
});
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
});
it('should select the filter based on the input by index param', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
it('should select the filter based on the input by index param', async () => {
component.filterParam = { index: 2 };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
done();
});
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
});
it('should select the filter based on the input by id param', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
it('should select the filter based on the input by id param', async () => {
component.filterParam = { id: '12' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.filterSelected.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
done();
});
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeCompletedProcesses');
});
it('should filterClicked emit when a filter is clicked from the UI', (done) => {
spyOn(processFilterService, 'getProcessFilters').and.returnValue(fakeGlobalFilterObservable);
it('should filterClicked emit when a filter is clicked from the UI', async () => {
component.filterParam = { id: '10' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
component.filterClicked.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
done();
});
fixture.detectChanges();
await fixture.whenStable();
const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${mockProcessFilters[0].key}_filter"]`);
filterButton.click();
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeAllProcesses');
});
it('should not emit a filter click event on binding changes', () => {
@@ -270,7 +238,7 @@ describe('ProcessFiltersCloudComponent', () => {
fixture.detectChanges();
expect(component.selectFilterAndEmit).toHaveBeenCalled();
expect(component.currentFilter).not.toBeDefined();
expect(component.currentFilter).toBe(mockProcessFilters[0]);
});
it('should reload filters by appName on binding changes', () => {

View File

@@ -94,8 +94,16 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges, OnDestro
this.filters$.pipe(takeUntil(this.onDestroy$)).subscribe(
(res: ProcessFilterCloudModel[]) => {
this.resetFilter();
this.filters = Object.assign([], res);
this.selectFilterAndEmit(this.filterParam);
this.filters = res || [];
if (this.filterParam) {
this.selectFilterAndEmit(this.filterParam);
}
if (!this.currentFilter && this.filters.length > 0) {
this.currentFilter = this.filters[0];
}
this.success.emit(res);
},
(err: any) => {

View File

@@ -51,28 +51,28 @@ export const fakeProcessCloudFilters = [
}
];
export const mockProcessFilters = [
new ProcessFilterCloudModel({
export const mockProcessFilters: any[] = [
{
name: 'FakeAllProcesses',
key: 'FakeAllProcesses',
icon: 'adjust',
id: '10',
status: ''
}),
new ProcessFilterCloudModel({
},
{
name: 'FakeRunningProcesses',
key: 'FakeRunningProcesses',
icon: 'inbox',
id: '11',
status: 'RUNNING'
}),
new ProcessFilterCloudModel({
},
{
name: 'FakeCompletedProcesses',
key: 'completed-processes',
icon: 'done',
id: '12',
status: 'COMPLETED'
})
}
];
export const fakeProcessFilter: ProcessFilterCloudModel = new ProcessFilterCloudModel({

View File

@@ -24,16 +24,17 @@ import { ProcessHeaderCloudComponent } from './process-header-cloud.component';
import { ProcessHeaderCloudModule } from '../process-header-cloud.module';
import { ProcessCloudService } from '../../services/process-cloud.service';
import { TranslateModule } from '@ngx-translate/core';
import { ProcessInstanceCloud } from '../../start-process/models/process-instance-cloud.model';
const processInstanceDetailsCloudMock = {
const processInstanceDetailsCloudMock: ProcessInstanceCloud = {
appName: 'app-form-mau',
businessKey: 'MyBusinessKey',
id: '00fcc4ab-4290-11e9-b133-0a586460016a',
initiator: 'devopsuser',
lastModified: 1552152187081,
lastModified: new Date(1552152187081),
name: 'new name',
parentId: '00fcc4ab-4290-11e9-b133-0a586460016b',
startDate: 1552152187080,
startDate: new Date(1552152187080),
status: 'RUNNING'
};

View File

@@ -24,7 +24,7 @@ describe('ProcessListCloudService', () => {
let service: ProcessListCloudService;
let alfrescoApiService: AlfrescoApiService;
function returnCallQueryParameters() {
function returnCallQueryParameters(): any {
return {
oauth2Auth: {
callCustomApi: (_queryUrl, _operation, _context, queryParams) => {
@@ -37,7 +37,7 @@ describe('ProcessListCloudService', () => {
};
}
function returnCallUrl() {
function returnCallUrl(): any {
return {
oauth2Auth: {
callCustomApi: (queryUrl) => {

View File

@@ -28,7 +28,7 @@ describe('StartProcessCloudService', () => {
let service: StartProcessCloudService;
let alfrescoApiService: AlfrescoApiService;
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve({
entry: {
@@ -86,7 +86,7 @@ describe('StartProcessCloudService', () => {
});
it('should be able to get all the process definitions', (done) => {
spyOn(service, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }]));
spyOn(service, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })]));
service.getProcessDefinitions('appName1')
.subscribe(
(res: ProcessDefinitionCloud[]) => {

View File

@@ -25,10 +25,10 @@ import { Apollo } from 'apollo-angular';
describe('NotificationCloudService', () => {
let service: NotificationCloudService;
let apollo: Apollo;
let apolloCreateSpy;
let apolloSubscribeSpy;
let apolloCreateSpy: jasmine.Spy;
let apolloSubscribeSpy: jasmine.Spy;
let apiService: AlfrescoApiService;
const useMock = {
const useMock: any = {
subscribe() {}
};
@@ -43,7 +43,7 @@ describe('NotificationCloudService', () => {
}
`;
const apiServiceMock = {
const apiServiceMock: any = {
oauth2Auth: {
token: '1234567'
},

View File

@@ -33,7 +33,7 @@ describe('PreferenceService', () => {
state: 404, stateText: 'Not Found'
};
function apiMock(mockResponse) {
function apiMock(mockResponse): any {
return {
oauth2Auth: {
callCustomApi: () => {
@@ -47,7 +47,7 @@ describe('PreferenceService', () => {
};
}
const apiErrorMock = {
const apiErrorMock: any = {
oauth2Auth: {
callCustomApi: () => Promise.reject(errorResponse)
},

View File

@@ -32,7 +32,7 @@ describe('Task Cloud Service', () => {
let identityUserService: IdentityUserService;
let translateService: TranslationService;
function returnFakeTaskCompleteResults() {
function returnFakeTaskCompleteResults(): any {
return {
oauth2Auth: {
callCustomApi : () => {
@@ -45,7 +45,7 @@ describe('Task Cloud Service', () => {
};
}
function returnFakeTaskCompleteResultsError() {
function returnFakeTaskCompleteResultsError(): any {
return {
oauth2Auth: {
callCustomApi : () => {
@@ -58,7 +58,7 @@ describe('Task Cloud Service', () => {
};
}
function returnFakeTaskDetailsResults() {
function returnFakeTaskDetailsResults(): any {
return {
oauth2Auth: {
callCustomApi : () => {
@@ -71,7 +71,7 @@ describe('Task Cloud Service', () => {
};
}
function returnFakeCandidateUsersResults() {
function returnFakeCandidateUsersResults(): any {
return {
oauth2Auth: {
callCustomApi : () => {
@@ -84,7 +84,7 @@ describe('Task Cloud Service', () => {
};
}
function returnFakeCandidateGroupResults() {
function returnFakeCandidateGroupResults(): any {
return {
oauth2Auth: {
callCustomApi : () => {

View File

@@ -38,7 +38,7 @@ describe('StartTaskCloudComponent', () => {
let createNewTaskSpy: jasmine.Spy;
let alfrescoApiService: AlfrescoApiService;
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve(taskDetailsMock)
},
@@ -68,7 +68,7 @@ describe('StartTaskCloudComponent', () => {
alfrescoApiService = TestBed.inject(AlfrescoApiService);
formDefinitionSelectorCloudService = TestBed.inject(FormDefinitionSelectorCloudService);
spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock);
createNewTaskSpy = spyOn(service, 'createNewTask').and.returnValue(of(taskDetailsMock));
createNewTaskSpy = spyOn(service, 'createNewTask').and.returnValue(of(taskDetailsMock as any));
spyOn(identityService, 'getCurrentUserInfo').and.returnValue(mockUser);
spyOn(formDefinitionSelectorCloudService, 'getForms').and.returnValue(of([]));
fixture.detectChanges();

View File

@@ -34,6 +34,7 @@ import { fakeServiceFilter } from '../../mock/task-filters-cloud.mock';
import { TranslateModule } from '@ngx-translate/core';
import { EditServiceTaskFilterCloudComponent } from './edit-service-task-filter-cloud.component';
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { ProcessDefinitionCloud } from '../../../../models/process-definition-cloud.model';
describe('EditServiceTaskFilterCloudComponent', () => {
let component: EditServiceTaskFilterCloudComponent;
@@ -71,7 +72,7 @@ describe('EditServiceTaskFilterCloudComponent', () => {
icon: 'icon',
name: 'fake-name'
})
});
} as any);
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeServiceFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
fixture.detectChanges();
@@ -94,7 +95,9 @@ describe('EditServiceTaskFilterCloudComponent', () => {
});
it('should fetch process definitions when processDefinitionName filter property is set', async(() => {
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }]));
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([
new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })
]));
fixture.detectChanges();
component.filterProperties = ['processDefinitionName'];
fixture.detectChanges();
@@ -602,7 +605,7 @@ describe('EditServiceTaskFilterCloudComponent', () => {
it('should emit save event and save the filter on click save button', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'updateFilter').and.returnValue(of({}));
spyOn(service, 'updateFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -625,7 +628,7 @@ describe('EditServiceTaskFilterCloudComponent', () => {
it('should emit delete event and delete the filter on click of delete button', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'deleteFilter').and.returnValue(of({}));
spyOn(service, 'deleteFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -645,7 +648,7 @@ describe('EditServiceTaskFilterCloudComponent', () => {
it('should emit saveAs event and add filter on click saveAs button', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'addFilter').and.returnValue(of({}));
spyOn(service, 'addFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();

View File

@@ -39,6 +39,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { DateCloudFilterType } from '../../../../models/date-cloud-filter.model';
import { TaskFilterCloudModel } from '../../models/filter-cloud.model';
import { PeopleCloudModule } from '../../../../people/people-cloud.module';
import { ProcessDefinitionCloud } from '../../../../models/process-definition-cloud.model';
describe('EditTaskFilterCloudComponent', () => {
let component: EditTaskFilterCloudComponent;
@@ -51,7 +52,7 @@ describe('EditTaskFilterCloudComponent', () => {
let getRunningApplicationsSpy: jasmine.Spy;
let taskService: TaskCloudService;
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve(fakeApplicationInstance)
},
@@ -88,7 +89,7 @@ describe('EditTaskFilterCloudComponent', () => {
icon: 'icon',
name: 'fake-name'
})
});
} as any);
spyOn(alfrescoApiService, 'getInstance').and.returnValue(mock);
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeFilter));
getRunningApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
@@ -112,7 +113,7 @@ describe('EditTaskFilterCloudComponent', () => {
});
it('should fetch process definitions when processDefinitionName filter property is set', async(() => {
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([{ id: 'fake-id', name: 'fake-name' }]));
const processSpy = spyOn(taskService, 'getProcessDefinitions').and.returnValue(of([new ProcessDefinitionCloud({ id: 'fake-id', name: 'fake-name' })]));
fixture.detectChanges();
component.filterProperties = ['processDefinitionName'];
fixture.detectChanges();
@@ -935,7 +936,7 @@ describe('EditTaskFilterCloudComponent', () => {
it('should emit save event and save the filter on click save button', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'updateFilter').and.returnValue(of({}));
spyOn(service, 'updateFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -958,7 +959,7 @@ describe('EditTaskFilterCloudComponent', () => {
it('should emit delete event and delete the filter on click of delete button', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'deleteFilter').and.returnValue(of({}));
spyOn(service, 'deleteFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -978,7 +979,7 @@ describe('EditTaskFilterCloudComponent', () => {
it('should emit saveAs event and add filter on click saveAs button', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'addFilter').and.returnValue(of({}));
spyOn(service, 'addFilter').and.returnValue(of(null));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');
expansionPanel.click();
@@ -1024,7 +1025,7 @@ describe('EditTaskFilterCloudComponent', () => {
it('should not call restore default filters service on deletion of first filter', async(() => {
component.toggleFilterActions = true;
spyOn(service, 'deleteFilter').and.returnValue(of([{ name: 'mock-filter-name' }]));
spyOn(service, 'deleteFilter').and.returnValue(of([new TaskFilterCloudModel({ name: 'mock-filter-name' })]));
const restoreDefaultFiltersSpy = spyOn(component, 'restoreDefaultTaskFilters').and.returnValue(of([]));
fixture.detectChanges();
const expansionPanel = fixture.debugElement.nativeElement.querySelector('mat-expansion-panel-header');

View File

@@ -16,9 +16,9 @@
*/
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed } from '@alfresco/adf-core';
import { from, Observable } from 'rxjs';
import { of, throwError } from 'rxjs';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
import { By } from '@angular/platform-browser';
@@ -30,24 +30,8 @@ import { ServiceTaskFilterCloudService } from '../services/service-task-filter-c
import { ServiceTaskFiltersCloudComponent } from './service-task-filters-cloud.component';
describe('ServiceTaskFiltersCloudComponent', () => {
let serviceTaskFilterCloudService: ServiceTaskFilterCloudService;
const fakeGlobalFilterObservable =
new Observable(function(observer) {
observer.next(fakeGlobalServiceFilters);
observer.complete();
});
const fakeGlobalFilterPromise = new Promise(function (resolve) {
resolve(fakeGlobalServiceFilters);
});
const mockErrorFilterList = {
error: 'wrong request'
};
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
let getTaskListFiltersSpy: jasmine.Spy;
let component: ServiceTaskFiltersCloudComponent;
let fixture: ComponentFixture<ServiceTaskFiltersCloudComponent>;
@@ -68,194 +52,186 @@ describe('ServiceTaskFiltersCloudComponent', () => {
component = fixture.componentInstance;
serviceTaskFilterCloudService = TestBed.inject(ServiceTaskFilterCloudService);
getTaskListFiltersSpy = spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(of(fakeGlobalServiceFilters));
});
it('should attach specific icon for each filter if hasIcon is true', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
afterEach(() => {
fixture.destroy();
});
it('should attach specific icon for each filter if hasIcon is true', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.filters.length).toBe(3);
const filters = fixture.nativeElement.querySelectorAll('.adf-icon');
expect(filters.length).toBe(3);
expect(filters[0].innerText).toContain('adjust');
expect(filters[1].innerText).toContain('done');
expect(filters[2].innerText).toContain('inbox');
});
}));
it('should not attach icons for each filter if hasIcon is false', (done) => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise));
fixture.detectChanges();
await fixture.whenStable();
expect(component.filters.length).toBe(3);
const filters = fixture.nativeElement.querySelectorAll('.adf-icon');
expect(filters.length).toBe(3);
expect(filters[0].innerText).toContain('adjust');
expect(filters[1].innerText).toContain('done');
expect(filters[2].innerText).toContain('inbox');
});
it('should not attach icons for each filter if hasIcon is false', async () => {
component.showIcons = false;
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
done();
});
fixture.detectChanges();
await fixture.whenStable();
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
});
it('should display the filters', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
it('should display the filters', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({'appName': change});
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry'));
expect(component.filters.length).toBe(3);
expect(filters.length).toBe(3);
expect(filters[0].nativeElement.innerText).toContain('FakeServiceTasks');
expect(filters[1].nativeElement.innerText).toContain('FakeMyServiceTasks1');
expect(filters[2].nativeElement.innerText).toContain('FakeMyServiceTasks2');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry'));
expect(component.filters.length).toBe(3);
expect(filters.length).toBe(3);
expect(filters[0].nativeElement.innerText).toContain('FakeServiceTasks');
expect(filters[1].nativeElement.innerText).toContain('FakeMyServiceTasks1');
expect(filters[2].nativeElement.innerText).toContain('FakeMyServiceTasks2');
});
it('should emit an error with a bad response', (done) => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise));
const mockErrorFilterList = {
error: 'wrong request'
};
getTaskListFiltersSpy.and.returnValue(throwError(mockErrorFilterList));
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({'appName': change});
component.error.subscribe((err) => {
expect(err).toBeDefined();
done();
});
component.ngOnChanges({'appName': change});
fixture.detectChanges();
});
it('should return the filter task list', (done) => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise));
it('should return the filter task list', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.filters).toBeDefined();
expect(component.filters.length).toEqual(3);
done();
});
});
it('should return the filter task list, filtered By Name', (done) => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise));
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.filters).toBeDefined();
expect(component.filters[0].name).toEqual('FakeServiceTasks');
expect(component.filters[1].name).toEqual('FakeMyServiceTasks1');
expect(component.filters[2].name).toEqual('FakeMyServiceTasks2');
done();
});
});
it('should select the first filter as default', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
await fixture.whenStable();
expect(component.filters).toBeDefined();
expect(component.filters.length).toEqual(3);
});
it('should return the filter task list, filtered By Name', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeServiceTasks');
});
fixture.detectChanges();
await fixture.whenStable();
}));
expect(component.filters).toBeDefined();
expect(component.filters[0].name).toEqual('FakeServiceTasks');
expect(component.filters[1].name).toEqual('FakeMyServiceTasks1');
expect(component.filters[2].name).toEqual('FakeMyServiceTasks2');
});
it('should select the task filter based on the input by name param', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
it('should select the first service task filter as default', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeServiceTasks');
});
it('should select the task filter based on the input by name param', async () => {
component.filterParam = { name: 'FakeMyServiceTasks1' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks1');
});
fixture.detectChanges();
await fixture.whenStable();
}));
it('should select the default task filter if filter input does not exist', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks1');
});
it('should select the default task filter if filter input does not exist', async () => {
component.filterParam = { name: 'UnexistableFilter' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeServiceTasks');
});
fixture.detectChanges();
await fixture.whenStable();
}));
it('should select the task filter based on the input by index param', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
expect(component.currentFilter).toBeDefined('current filter not found');
expect(component.currentFilter.name).toEqual('FakeServiceTasks');
});
it('should select the task filter based on the input by index param', async () => {
component.filterParam = { index: 2 };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2');
});
fixture.detectChanges();
await fixture.whenStable();
}));
it('should select the task filter based on the input by id param', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2');
});
it('should select the task filter based on the input by id param', async () => {
component.filterParam = { id: '12' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2');
});
fixture.detectChanges();
await fixture.whenStable();
}));
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyServiceTasks2');
});
it('should emit the selected filter based on the filterParam input', async () => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterSelected, 'emit');
const filterParam = { id: '10' };
@@ -264,12 +240,12 @@ describe('ServiceTaskFiltersCloudComponent', () => {
component.ngOnChanges({ 'filterParam': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
});
it('should filterClicked emit when a filter is clicked from the UI', async () => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterClicked, 'emit');
fixture.detectChanges();
@@ -284,9 +260,7 @@ describe('ServiceTaskFiltersCloudComponent', () => {
expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalServiceFilters[0]);
});
it('should reset the filter when the param is undefined', async(() => {
spyOn(serviceTaskFilterCloudService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component, 'selectFilterAndEmit');
it('should reset the filter when the param is undefined', async () => {
component.currentFilter = null;
const filterName = undefined;
@@ -294,9 +268,10 @@ describe('ServiceTaskFiltersCloudComponent', () => {
component.ngOnChanges({ 'filterParam': change });
fixture.detectChanges();
expect(component.selectFilterAndEmit).toHaveBeenCalledWith(undefined);
expect(component.currentFilter).toEqual(undefined);
}));
await fixture.whenStable();
expect(component.currentFilter).toBe(fakeGlobalServiceFilters[0]);
});
it('should reload filters by appName on binding changes', () => {
spyOn(component, 'getFilters').and.stub();
@@ -312,37 +287,35 @@ describe('ServiceTaskFiltersCloudComponent', () => {
component.filters = fakeGlobalServiceFilters;
component.currentFilter = null;
const change = new SimpleChange(null, { name: fakeGlobalServiceFilters[1].name }, true);
const name = fakeGlobalServiceFilters[1].name;
const change = new SimpleChange(null, { name }, true);
component.ngOnChanges({ 'filterParam': change });
fixture.whenStable().then(() => {
expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[1].name);
});
expect(component.currentFilter).toBeDefined('current filter not found');
expect(component.currentFilter.name).toEqual(name);
});
it('should change current filter when filterParam (key) changes', () => {
component.filters = fakeGlobalServiceFilters;
component.currentFilter = null;
const change = new SimpleChange(null, { key: fakeGlobalServiceFilters[2].key }, true);
const key = fakeGlobalServiceFilters[2].key;
const change = new SimpleChange(null, { key }, true);
component.ngOnChanges({ 'filterParam': change });
fixture.whenStable().then(() => {
expect(component.currentFilter.key).toEqual(fakeGlobalServiceFilters[2].key);
});
expect(component.currentFilter.key).toEqual(key);
});
it('should change current filter when filterParam (index) changes', () => {
component.filters = fakeGlobalServiceFilters;
component.currentFilter = null;
const position = 1;
const change = new SimpleChange(null, { index: position }, true);
const change = new SimpleChange(null, { index: 1 }, true);
component.ngOnChanges({ 'filterParam': change });
fixture.whenStable().then(() => {
expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[position].name);
});
expect(component.currentFilter.name).toEqual(fakeGlobalServiceFilters[1].name);
});
it('should reload filters by app name on binding changes', () => {

View File

@@ -69,8 +69,13 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
this.filters$.pipe(takeUntil(this.onDestroy$)).subscribe(
(res: ServiceTaskFilterCloudModel[]) => {
this.resetFilter();
this.filters = Object.assign([], res);
this.selectFilterAndEmit(this.filterParam);
this.filters = res || [];
if (this.filterParam) {
this.selectFilterAndEmit(this.filterParam);
}
this.ensureFilterSelected();
this.success.emit(res);
},
(err: any) => {
@@ -88,15 +93,24 @@ export class ServiceTaskFiltersCloudComponent extends BaseTaskFiltersCloudCompon
(paramFilter.name &&
(paramFilter.name.toLocaleLowerCase() === this.translationService.instant(filter.name).toLocaleLowerCase())
));
if (this.currentFilter) {
this.filterSelected.emit(this.currentFilter);
}
}
}
public selectFilterAndEmit(newParamFilter: FilterParamsModel) {
if (newParamFilter) {
this.selectFilter(newParamFilter);
this.filterSelected.emit(this.currentFilter);
} else {
this.currentFilter = undefined;
}
this.ensureFilterSelected();
}
private ensureFilterSelected() {
if (!this.currentFilter && this.filters.length > 0) {
this.currentFilter = this.filters[0];
}
}

View File

@@ -16,9 +16,9 @@
*/
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
import { from, Observable, of } from 'rxjs';
import { of, throwError } from 'rxjs';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
@@ -30,29 +30,13 @@ import { fakeGlobalFilter, taskNotifications } from '../mock/task-filters-cloud.
import { TranslateModule } from '@ngx-translate/core';
describe('TaskFiltersCloudComponent', () => {
let taskFilterService: TaskFilterCloudService;
let appConfigService: AppConfigService;
const fakeGlobalFilterObservable =
new Observable(function (observer) {
observer.next(fakeGlobalFilter);
observer.complete();
});
const fakeGlobalFilterPromise = new Promise(function (resolve) {
resolve(fakeGlobalFilter);
});
const mockErrorFilterList = {
error: 'wrong request'
};
const mockErrorFilterPromise = Promise.reject(mockErrorFilterList);
let component: TaskFiltersCloudComponent;
let fixture: ComponentFixture<TaskFiltersCloudComponent>;
let getTaskFilterCounterSpy;
let getTaskFilterCounterSpy: jasmine.Spy;
let getTaskListFiltersSpy: jasmine.Spy;
setupTestBed({
imports: [
@@ -66,202 +50,190 @@ describe('TaskFiltersCloudComponent', () => {
});
beforeEach(() => {
fixture = TestBed.createComponent(TaskFiltersCloudComponent);
component = fixture.componentInstance;
taskFilterService = TestBed.inject(TaskFilterCloudService);
getTaskFilterCounterSpy = spyOn(taskFilterService, 'getTaskFilterCounter').and.returnValue(of(11));
spyOn(taskFilterService, 'getTaskNotificationSubscription').and.returnValue(of(taskNotifications));
getTaskListFiltersSpy = spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(of(fakeGlobalFilter));
appConfigService = TestBed.inject(AppConfigService);
fixture = TestBed.createComponent(TaskFiltersCloudComponent);
component = fixture.componentInstance;
});
it('should attach specific icon for each filter if hasIcon is true', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
afterEach(() => {
fixture.destroy();
});
it('should attach specific icon for each filter if hasIcon is true', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.filters.length).toBe(3);
const filters = fixture.nativeElement.querySelectorAll('.adf-icon');
expect(filters.length).toBe(3);
expect(filters[0].innerText).toContain('adjust');
expect(filters[1].innerText).toContain('done');
expect(filters[2].innerText).toContain('inbox');
});
}));
it('should not attach icons for each filter if hasIcon is false', (done) => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise));
fixture.detectChanges();
await fixture.whenStable();
expect(component.filters.length).toBe(3);
const filters = fixture.nativeElement.querySelectorAll('.adf-icon');
expect(filters.length).toBe(3);
expect(filters[0].innerText).toContain('adjust');
expect(filters[1].innerText).toContain('done');
expect(filters[2].innerText).toContain('inbox');
});
it('should not attach icons for each filter if hasIcon is false', async () => {
component.showIcons = false;
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
done();
});
fixture.detectChanges();
await fixture.whenStable();
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
});
it('should display the filters', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
it('should display the filters', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry'));
expect(component.filters.length).toBe(3);
expect(filters.length).toBe(3);
expect(filters[0].nativeElement.innerText).toContain('FakeInvolvedTasks');
expect(filters[1].nativeElement.innerText).toContain('FakeMyTasks1');
expect(filters[2].nativeElement.innerText).toContain('FakeMyTasks2');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const filters = fixture.debugElement.queryAll(By.css('.adf-task-filters__entry'));
expect(component.filters.length).toBe(3);
expect(filters.length).toBe(3);
expect(filters[0].nativeElement.innerText).toContain('FakeInvolvedTasks');
expect(filters[1].nativeElement.innerText).toContain('FakeMyTasks1');
expect(filters[2].nativeElement.innerText).toContain('FakeMyTasks2');
});
it('should emit an error with a bad response', (done) => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(mockErrorFilterPromise));
const mockErrorFilterList = {
error: 'wrong request'
};
getTaskListFiltersSpy.and.returnValue(throwError(mockErrorFilterList));
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.error.subscribe((err) => {
expect(err).toBeDefined();
done();
});
});
it('should return the filter task list', (done) => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise));
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.filters).toBeDefined();
expect(component.filters.length).toEqual(3);
done();
});
});
it('should return the filter task list, filtered By Name', (done) => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(from(fakeGlobalFilterPromise));
it('should return the filter task list', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.filters).toBeDefined();
expect(component.filters[0].name).toEqual('FakeInvolvedTasks');
expect(component.filters[1].name).toEqual('FakeMyTasks1');
expect(component.filters[2].name).toEqual('FakeMyTasks2');
done();
});
});
it('should select the first filter as default', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
await fixture.whenStable();
expect(component.filters).toBeDefined();
expect(component.filters.length).toEqual(3);
});
it('should return the filter task list, filtered By Name', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
});
fixture.detectChanges();
await fixture.whenStable();
}));
expect(component.filters).toBeDefined();
expect(component.filters[0].name).toEqual('FakeInvolvedTasks');
expect(component.filters[1].name).toEqual('FakeMyTasks1');
expect(component.filters[2].name).toEqual('FakeMyTasks2');
});
it('should select the task filter based on the input by name param', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
it('should select the first cloud task filter as default', async () => {
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.filters.length).toBe(fakeGlobalFilter.length);
expect(component.currentFilter).toBeDefined('current filter not found');
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
});
it('should select the task filter based on the input by name param', async () => {
component.filterParam = { name: 'FakeMyTasks1' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyTasks1');
});
}));
it('should select the default task filter if filter input does not exist', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyTasks1');
});
it('should select the default task filter if filter input does not exist', async () => {
component.filterParam = { name: 'UnexistableFilter' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
});
fixture.detectChanges();
await fixture.whenStable();
}));
it('should select the task filter based on the input by index param', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
expect(component.currentFilter).toBeDefined('current filter not found');
expect(component.currentFilter.name).toEqual('FakeInvolvedTasks');
});
it('should select the task filter based on the input by index param', async () => {
component.filterParam = { index: 2 };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
});
fixture.detectChanges();
await fixture.whenStable();
}));
it('should select the task filter based on the input by id param', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
});
it('should select the task filter based on the input by id param', async () => {
component.filterParam = { id: '12' };
const appName = 'my-app-1';
const change = new SimpleChange(null, appName, true);
fixture.detectChanges();
component.ngOnChanges({ 'appName': change });
component.success.subscribe((res) => {
expect(res).toBeDefined();
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
});
fixture.detectChanges();
await fixture.whenStable();
}));
expect(component.currentFilter).toBeDefined();
expect(component.currentFilter.name).toEqual('FakeMyTasks2');
});
it('should emit the selected filter based on the filterParam input', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
it('should emit the selected filter based on the filterParam input', async () => {
spyOn(component.filterSelected, 'emit');
const filterParam = { id: '10' };
@@ -269,13 +241,14 @@ describe('TaskFiltersCloudComponent', () => {
component.filterParam = filterParam;
component.ngOnChanges({ 'filterParam': change });
fixture.detectChanges();
await fixture.whenStable();
expect(component.filterSelected.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]);
}));
});
it('should filterClicked emit when a filter is clicked from the UI', async () => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component.filterClicked, 'emit');
fixture.detectChanges();
@@ -290,9 +263,7 @@ describe('TaskFiltersCloudComponent', () => {
expect(component.filterClicked.emit).toHaveBeenCalledWith(fakeGlobalFilter[0]);
});
it('should reset the filter when the param is undefined', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(component, 'selectFilterAndEmit');
it('should reset the filter when the param is undefined', async () => {
component.currentFilter = null;
const filterName = undefined;
@@ -300,9 +271,10 @@ describe('TaskFiltersCloudComponent', () => {
component.ngOnChanges({ 'filterParam': change });
fixture.detectChanges();
expect(component.selectFilterAndEmit).toHaveBeenCalledWith(undefined);
expect(component.currentFilter).toEqual(undefined);
}));
await fixture.whenStable();
expect(component.currentFilter).toEqual(fakeGlobalFilter[0]);
});
it('should reload filters by appName on binding changes', () => {
spyOn(component, 'getFilters').and.stub();
@@ -333,9 +305,7 @@ describe('TaskFiltersCloudComponent', () => {
const change = new SimpleChange(null, { key: fakeGlobalFilter[2].key }, true);
component.ngOnChanges({ 'filterParam': change });
fixture.whenStable().then(() => {
expect(component.currentFilter.key).toEqual(fakeGlobalFilter[2].key);
});
expect(component.currentFilter.key).toEqual(fakeGlobalFilter[2].key);
});
it('should change current filter when filterParam (index) changes', () => {
@@ -346,9 +316,7 @@ describe('TaskFiltersCloudComponent', () => {
const change = new SimpleChange(null, { index: position }, true);
component.ngOnChanges({ 'filterParam': change });
fixture.whenStable().then(() => {
expect(component.currentFilter.name).toEqual(fakeGlobalFilter[position].name);
});
expect(component.currentFilter.name).toEqual(fakeGlobalFilter[position].name);
});
it('should reload filters by app name on binding changes', () => {
@@ -370,23 +338,25 @@ describe('TaskFiltersCloudComponent', () => {
expect(component.currentFilter).toBe(fakeGlobalFilter[0]);
});
it('should display filter counter if property set to true', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
it('should display filter counter if property set to true', async () => {
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({ 'appName': change });
fixture.detectChanges();
await fixture.whenStable();
component.showIcons = true;
fixture.whenStable().then(() => {
fixture.detectChanges();
const filterCounters = fixture.debugElement.queryAll(By.css('.adf-filter-action-button__counter'));
expect(component.filters.length).toBe(3);
expect(filterCounters.length).toBe(1);
expect(filterCounters[0].nativeElement.innerText).toContain('11');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const filterCounters = fixture.debugElement.queryAll(By.css('.adf-filter-action-button__counter'));
expect(component.filters.length).toBe(3);
expect(filterCounters.length).toBe(1);
expect(filterCounters[0].nativeElement.innerText).toContain('11');
});
it('should update filter counter when notification received', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(appConfigService, 'get').and.returnValue(true);
component.appName = 'my-app-1';
component.ngOnInit();
@@ -403,7 +373,6 @@ describe('TaskFiltersCloudComponent', () => {
}));
it('should not update filter counter when notifications are disabled from app.config.json', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(appConfigService, 'get').and.returnValue(false);
component.appName = 'my-app-1';
component.ngOnInit();
@@ -418,7 +387,6 @@ describe('TaskFiltersCloudComponent', () => {
}));
it('should reset filter counter notification when filter is selected', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
spyOn(appConfigService, 'get').and.returnValue(true);
let change = new SimpleChange(undefined, 'my-app-1', true);
component.appName = 'my-app-1';
@@ -446,7 +414,6 @@ describe('TaskFiltersCloudComponent', () => {
}));
it('should update filter counter when filter is selected', fakeAsync(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
component.appName = 'my-app-1';
component.ngOnInit();
tick(5000);

View File

@@ -79,8 +79,16 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
this.filters$.pipe(takeUntil(this.onDestroy$)).subscribe(
(res: TaskFilterCloudModel[]) => {
this.resetFilter();
this.filters = Object.assign([], res);
this.selectFilterAndEmit(this.filterParam);
this.filters = res || [];
if (this.filterParam) {
this.selectFilterAndEmit(this.filterParam);
}
if (!this.currentFilter && this.filters.length > 0) {
this.currentFilter = this.filters[0];
}
this.updateFilterCounters();
this.success.emit(res);
},
@@ -145,12 +153,19 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
public selectFilterAndEmit(newParamFilter: FilterParamsModel) {
if (newParamFilter) {
this.selectFilter(newParamFilter);
if (this.currentFilter) {
this.resetFilterCounter(this.currentFilter.key);
this.filterSelected.emit(this.currentFilter);
}
} else {
this.currentFilter = undefined;
}
this.ensureFilterSelected();
}
private ensureFilterSelected() {
if (!this.currentFilter && this.filters.length > 0) {
this.currentFilter = this.filters[0];
}
}

View File

@@ -18,8 +18,8 @@
import { assignedTaskDetailsCloudMock } from '../../task-header/mocks/task-details-cloud.mock';
import { TaskFilterCloudModel, ServiceTaskFilterCloudModel } from '../models/filter-cloud.model';
export const fakeGlobalFilter = [
new TaskFilterCloudModel({
export const fakeGlobalFilter: any[] = [
{
name: 'FakeInvolvedTasks',
key: 'fake-involved-tasks',
icon: 'adjust',
@@ -27,8 +27,8 @@ export const fakeGlobalFilter = [
status: 'ASSIGNED',
assignee: 'AssignedTaskUser',
showCounter: true
}),
new TaskFilterCloudModel({
},
{
name: 'FakeMyTasks1',
key: 'fake-my-tast1',
icon: 'done',
@@ -36,18 +36,18 @@ export const fakeGlobalFilter = [
status: 'open',
assignee: 'fake-assignee',
showCounter: false
}),
new TaskFilterCloudModel({
},
{
name: 'FakeMyTasks2',
key: 'fake-my-tast2',
icon: 'inbox',
id: '12',
status: 'open',
assignee: 'fake-assignee'
})
}
];
export const fakeGlobalServiceFilters = [
export const fakeGlobalServiceFilters: ServiceTaskFilterCloudModel[] = [
{
name: 'FakeServiceTasks',
key: 'fake-involved-tasks',

View File

@@ -49,7 +49,7 @@ describe('TaskHeaderCloudComponent', () => {
const mockCandidateUsers = ['mockuser1', 'mockuser2', 'mockuser3'];
const mockCandidateGroups = ['mockgroup1', 'mockgroup2', 'mockgroup3'];
const mock = {
const mock: any = {
oauth2Auth: {
callCustomApi: () => Promise.resolve({})
},

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
export const taskClaimCloudMock = {
export const taskClaimCloudMock: any = {
'entry': {
'appName': 'simple-app',
'appVersion': '',

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
export const taskCompleteCloudMock = {
export const taskCompleteCloudMock: any = {
'entry': {
'appName': 'simple-app',
'appVersion': '',

View File

@@ -26,7 +26,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
let service: ServiceTaskListCloudService;
let alfrescoApiService: AlfrescoApiService;
function returnCallQueryParameters() {
function returnCallQueryParameters(): any {
return {
oauth2Auth: {
callCustomApi: (_queryUrl, _operation, _context, queryParams) => {
@@ -40,7 +40,7 @@ describe('Activiti ServiceTaskList Cloud Service', () => {
};
}
function returnCallUrl() {
function returnCallUrl(): any {
return {
oauth2Auth: {
callCustomApi: (queryUrl) => {

View File

@@ -27,7 +27,7 @@ describe('TaskListCloudService', () => {
let service: TaskListCloudService;
let alfrescoApiService: AlfrescoApiService;
function returnCallQueryParameters() {
function returnCallQueryParameters(): any {
return {
oauth2Auth: {
callCustomApi : (_queryUrl, _operation, _context, queryParams) => {
@@ -41,7 +41,7 @@ describe('TaskListCloudService', () => {
};
}
function returnCallUrl() {
function returnCallUrl(): any {
return {
oauth2Auth: {
callCustomApi : (queryUrl) => {