mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-10991] Fix task counter decrease (T15330758) (#7922)
* [AAE-10991] Fix task counter decrease * improve unit tests * trigger travis
This commit is contained in:
parent
499725659b
commit
c28e23b1cb
@ -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'));
|
let updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
|
||||||
expect(updatedFilterCounters.length).toBe(1);
|
expect(updatedFilterCounters.length).toBe(1);
|
||||||
|
|
||||||
component.filters = fakeGlobalFilter;
|
component.filters = fakeGlobalFilter;
|
||||||
component.currentFilter = null;
|
component.currentFilter = null;
|
||||||
|
|
||||||
change = new SimpleChange(null, { key: fakeGlobalFilter[0].key }, true);
|
|
||||||
component.ngOnChanges({ filterParam: change });
|
component.ngOnChanges({ filterParam: change });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
|
updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
|
||||||
expect(updatedFilterCounters.length).toBe(0);
|
expect(updatedFilterCounters.length).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should update filter counter when filter is selected', fakeAsync(() => {
|
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"]`);
|
const filterButton = fixture.debugElement.nativeElement.querySelector(`[data-automation-id="${fakeGlobalFilter[0].key}_filter"]`);
|
||||||
filterButton.click();
|
filterButton.click();
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(getTaskFilterCounterSpy).toHaveBeenCalledWith(fakeGlobalFilter[0]);
|
expect(getTaskFilterCounterSpy).toHaveBeenCalledWith(fakeGlobalFilter[0]);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
describe('Highlight Selected Filter', () => {
|
describe('Highlight Selected Filter', () => {
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user