[AAE-10991] Fix task counter decrease (T15330758) (#7922)

* [AAE-10991] Fix task counter decrease

* improve unit tests

* trigger travis
This commit is contained in:
Tomasz Gnyp 2022-10-27 12:33:12 +02:00 committed by GitHub
parent 499725659b
commit c28e23b1cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 64 deletions

View File

@ -16,7 +16,7 @@
*/ */
import { SimpleChange } from '@angular/core'; import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { AppConfigService, setupTestBed } from '@alfresco/adf-core'; import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
import { of, throwError } from 'rxjs'; import { of, throwError } from 'rxjs';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service'; import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
@ -26,8 +26,7 @@ import { TaskFiltersCloudComponent } from './task-filters-cloud.component';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TaskFiltersCloudModule } from '../task-filters-cloud.module'; import { TaskFiltersCloudModule } from '../task-filters-cloud.module';
import { fakeGlobalFilter, taskNotifications, defaultTaskFiltersMock } from '../mock/task-filters-cloud.mock'; import { fakeGlobalFilter, defaultTaskFiltersMock, taskNotifications } from '../mock/task-filters-cloud.mock';
import { TranslateModule } from '@ngx-translate/core';
describe('TaskFiltersCloudComponent', () => { describe('TaskFiltersCloudComponent', () => {
let taskFilterService: TaskFilterCloudService; let taskFilterService: TaskFilterCloudService;
@ -40,7 +39,6 @@ describe('TaskFiltersCloudComponent', () => {
setupTestBed({ setupTestBed({
imports: [ imports: [
TranslateModule.forRoot(),
ProcessServiceCloudTestingModule, ProcessServiceCloudTestingModule,
TaskFiltersCloudModule TaskFiltersCloudModule
], ],
@ -284,78 +282,58 @@ describe('TaskFiltersCloudComponent', () => {
expect(filterCounters[0].nativeElement.innerText).toContain('11'); expect(filterCounters[0].nativeElement.innerText).toContain('11');
}); });
it('should update filter counter when notification received', fakeAsync(() => { it('should update filter counter when notification received', () => {
spyOn(appConfigService, 'get').and.returnValue(true);
component.appName = 'my-app-1'; component.appName = 'my-app-1';
component.ngOnInit();
tick(5000);
fixture.detectChanges();
component.showIcons = true; component.showIcons = true;
fixture.whenStable().then(() => { fixture.detectChanges();
fixture.detectChanges();
const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active')); const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(1); expect(updatedFilterCounters.length).toBe(1);
expect(Object.keys(component.counters$).length).toBe(1); expect(Object.keys(component.counters$).length).toBe(1);
expect(component.counters$['fake-involved-tasks']).toBeDefined(); expect(component.counters$['fake-involved-tasks']).toBeDefined();
}); });
}));
it('should not update filter counter when notifications are disabled from app.config.json', fakeAsync(() => { it('should not update filter counter when notifications are disabled from app.config.json', fakeAsync(() => {
spyOn(appConfigService, 'get').and.returnValue(false); spyOn(appConfigService, 'get').and.returnValue(false);
component.appName = 'my-app-1'; component.appName = 'my-app-1';
component.ngOnInit();
tick(5000);
fixture.detectChanges();
component.showIcons = true; component.showIcons = true;
fixture.whenStable().then(() => { fixture.detectChanges();
fixture.detectChanges();
const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active')); const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(0); expect(updatedFilterCounters.length).toBe(0);
});
})); }));
it('should reset filter counter notification when filter is selected', fakeAsync(() => { it('should reset filter counter notification when filter is selected', () => {
spyOn(appConfigService, 'get').and.returnValue(true); spyOn(appConfigService, 'get').and.returnValue(true);
let change = new SimpleChange(undefined, 'my-app-1', true); const change = new SimpleChange(null, { key: fakeGlobalFilter[0].key }, true);
component.appName = 'my-app-1'; component.appName = 'my-app-1';
component.ngOnInit();
tick(5000);
fixture.detectChanges();
component.showIcons = true; component.showIcons = true;
fixture.whenStable().then(() => { fixture.detectChanges();
fixture.detectChanges();
let updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(1);
component.filters = fakeGlobalFilter; let updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
component.currentFilter = null; expect(updatedFilterCounters.length).toBe(1);
change = new SimpleChange(null, { key: fakeGlobalFilter[0].key }, true); component.filters = fakeGlobalFilter;
component.ngOnChanges({ filterParam: change }); component.currentFilter = null;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(0);
});
});
}));
it('should update filter counter when filter is selected', fakeAsync(() => { component.ngOnChanges({ filterParam: change });
fixture.detectChanges();
updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(0);
});
it('should update filter counter when filter is selected', () => {
component.appName = 'my-app-1'; component.appName = 'my-app-1';
component.ngOnInit();
tick(5000);
fixture.detectChanges();
component.showIcons = true; component.showIcons = true;
fixture.whenStable().then(() => { fixture.detectChanges();
fixture.detectChanges();
const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalFilter[0].key}_filter"]`);
filterButton.click();
fixture.detectChanges(); const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalFilter[0].key}_filter"]`);
expect(getTaskFilterCounterSpy).toHaveBeenCalledWith(fakeGlobalFilter[0]); filterButton.click();
});
})); fixture.detectChanges();
expect(getTaskFilterCounterSpy).toHaveBeenCalledWith(fakeGlobalFilter[0]);
});
describe('Highlight Selected Filter', () => { describe('Highlight Selected Filter', () => {

View File

@ -58,8 +58,8 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
ngOnInit() { ngOnInit() {
this.enableNotifications = this.appConfigService.get('notifications', true); this.enableNotifications = this.appConfigService.get('notifications', true);
this.initFilterCounterNotifications();
this.getFilters(this.appName); this.getFilters(this.appName);
this.initFilterCounterNotifications();
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
@ -105,16 +105,14 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
initFilterCounterNotifications() { initFilterCounterNotifications() {
if (this.appName && this.enableNotifications) { if (this.appName && this.enableNotifications) {
this.taskFilterCloudService.getTaskNotificationSubscription(this.appName) this.taskFilterCloudService.getTaskNotificationSubscription(this.appName)
.pipe(debounceTime(3000)) .pipe(debounceTime(1000))
.subscribe((result: TaskCloudEngineEvent[]) => { .subscribe((result: TaskCloudEngineEvent[]) => {
result.map((taskEvent: TaskCloudEngineEvent) => { result.map((taskEvent: TaskCloudEngineEvent) => {
this.checkFilterCounter(taskEvent.entity); this.checkFilterCounter(taskEvent.entity);
}); });
if (this.updatedCounters.length) { this.updateFilterCounters();
this.updateFilterCounters(); this.filterCounterUpdated.emit(result);
this.filterCounterUpdated.emit(result);
}
}); });
} }
} }