[ACA-4299] Add e2e tests for task counters and notifications (#6726)

* [ACA-4299] Add ete tests for task counters and notifications

* Fix unit test

* Fix update for indirect counter changes
This commit is contained in:
davidcanonieto
2021-02-26 08:57:27 +01:00
committed by GitHub
parent f3c4680c2c
commit e96491fe25
15 changed files with 349 additions and 94 deletions
@@ -25,6 +25,11 @@ import { Apollo } from 'apollo-angular';
describe('NotificationCloudService', () => {
let service: NotificationCloudService;
let apollo: Apollo;
let apolloCreateSpy;
let apolloSubscribeSpy;
const useMock = {
subscribe() {}
};
const queryMock = `
subscription {
@@ -47,12 +52,13 @@ describe('NotificationCloudService', () => {
beforeEach(async(() => {
service = TestBed.inject(NotificationCloudService);
apollo = TestBed.inject(Apollo);
service.appsListening = [];
apolloCreateSpy = spyOn(apollo, 'createNamed');
apolloSubscribeSpy = spyOn(apollo, 'use').and.returnValue(useMock);
}));
it('should not create more than one websocket per app if it was already created', () => {
const apolloCreateSpy = spyOn(apollo, 'create');
const apolloSubscribeSpy = spyOn(apollo, 'subscribe');
service.makeGQLQuery('myAppName', queryMock);
expect(service.appsListening.length).toBe(1);
expect(service.appsListening[0]).toBe('myAppName');
@@ -61,12 +67,20 @@ describe('NotificationCloudService', () => {
expect(service.appsListening.length).toBe(1);
expect(service.appsListening[0]).toBe('myAppName');
service.makeGQLQuery('myAppName2', queryMock);
expect(apolloCreateSpy).toHaveBeenCalledTimes(1);
expect(apolloSubscribeSpy).toHaveBeenCalledTimes(2);
});
it('should create new websocket if it is subscribing to new app', () => {
service.makeGQLQuery('myAppName', queryMock);
expect(service.appsListening.length).toBe(1);
expect(service.appsListening[0]).toBe('myAppName');
service.makeGQLQuery('myOtherAppName', queryMock);
expect(service.appsListening.length).toBe(2);
expect(service.appsListening[0]).toBe('myAppName');
expect(service.appsListening[1]).toBe('myAppName2');
expect(service.appsListening[1]).toBe('myOtherAppName');
expect(apolloCreateSpy).toHaveBeenCalledTimes(2);
expect(apolloSubscribeSpy).toHaveBeenCalledTimes(3);
expect(apolloSubscribeSpy).toHaveBeenCalledTimes(2);
});
});
@@ -71,15 +71,15 @@ export class NotificationCloudService extends BaseCloudService {
httpLink
);
this.apollo.create(<any> {
this.apollo.createNamed(appName, {
link,
cache: new InMemoryCache({})
cache: new InMemoryCache()
});
}
}
makeGQLQuery(appName: string, gqlQuery: string) {
this.initNotificationsForApp(appName);
return this.apollo.subscribe({ query : gql(gqlQuery) });
return this.apollo.use(appName).subscribe({ query: gql(gqlQuery) });
}
}
@@ -383,8 +383,8 @@ describe('TaskFiltersCloudComponent', () => {
it('should update filter counter when notification received', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
const change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({ 'appName': change });
component.appName = 'my-app-1';
component.ngOnInit();
fixture.detectChanges();
component.showIcons = true;
fixture.whenStable().then(() => {
@@ -399,7 +399,8 @@ describe('TaskFiltersCloudComponent', () => {
it('should reset filter counter notification when filter is selected', async(() => {
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
let change = new SimpleChange(undefined, 'my-app-1', true);
component.ngOnChanges({ 'appName': change });
component.appName = 'my-app-1';
component.ngOnInit();
fixture.detectChanges();
component.showIcons = true;
fixture.whenStable().then(() => {
@@ -20,7 +20,7 @@ import { Observable } from 'rxjs';
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
import { TaskFilterCloudModel, FilterParamsModel } from '../models/filter-cloud.model';
import { TranslationService } from '@alfresco/adf-core';
import { map, takeUntil } from 'rxjs/operators';
import { takeUntil } from 'rxjs/operators';
import { BaseTaskFiltersCloudComponent } from './base-task-filters-cloud.component';
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';
@@ -78,7 +78,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
this.resetFilter();
this.filters = Object.assign([], res);
this.selectFilterAndEmit(this.filterParam);
this.initFilterCounters();
this.updateFilterCounters();
this.success.emit(res);
},
(err: any) => {
@@ -87,7 +87,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
);
}
initFilterCounters() {
updateFilterCounters() {
this.filters.forEach((filter) => {
if (filter.showCounter) {
this.counters$[filter.key] = this.taskFilterCloudService.getTaskFilterCounter(filter);
@@ -96,27 +96,32 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
}
initFilterCounterNotifications() {
this.taskFilterCloudService.getTaskNotificationSubscription(this.appName)
.subscribe((result: TaskCloudEngineEvent[]) => {
result.map((taskEvent: TaskCloudEngineEvent) => {
this.updateFilterCounter(taskEvent.entity);
if (this.appName) {
this.taskFilterCloudService.getTaskNotificationSubscription(this.appName)
.subscribe((result: TaskCloudEngineEvent[]) => {
result.map((taskEvent: TaskCloudEngineEvent) => {
this.checkFilterCounter(taskEvent.entity);
});
this.filterCounterUpdated.emit(result);
});
this.filterCounterUpdated.emit(result);
});
}
}
updateFilterCounter(filterNotification: TaskDetailsCloudModel) {
checkFilterCounter(filterNotification: TaskDetailsCloudModel) {
this.filters.map((filter) => {
if (this.isFilterPresent(filter, filterNotification)) {
this.counters$[filter.key] = this.counters$[filter.key].pipe(map((counter) => counter + 1));
this.addToUpdatedCounters(filter.key);
}
});
if (this.updatedCounters.length) {
this.updateFilterCounters();
}
}
isFilterPresent(filter: TaskFilterCloudModel, filterNotification: TaskDetailsCloudModel): boolean {
return filter.status === filterNotification.status
&& filter.assignee === filterNotification.assignee;
&& (filter.assignee === filterNotification.assignee || filterNotification.assignee === undefined);
}
public selectFilter(paramFilter: FilterParamsModel) {
@@ -34,8 +34,8 @@ const TASK_EVENT_SUBSCRIPTION_QUERY = `
TASK_ASSIGNED
TASK_ACTIVATED
TASK_SUSPENDED
TASK_CANCELLED
TASK_UPDATED
TASK_CANCELLED,
TASK_CREATED
]) {
eventType
entity