mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5379] Add a way to disable WS notifications (#6924)
* [ADF-5379] Add a way to disable WS notifications * Update app-notifications.service.ts * Update task-filters-cloud.component.spec.ts * Move flag to upper level in config.json * Create new notification section in app.config.json * Update implementation * Improve naming
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { from, Observable, of } from 'rxjs';
|
||||
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
|
||||
import { LocalPreferenceCloudService } from '../../../services/local-preference-cloud.service';
|
||||
@@ -32,6 +32,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
describe('TaskFiltersCloudComponent', () => {
|
||||
|
||||
let taskFilterService: TaskFilterCloudService;
|
||||
let appConfigService: AppConfigService;
|
||||
|
||||
const fakeGlobalFilterObservable =
|
||||
new Observable(function (observer) {
|
||||
@@ -71,6 +72,8 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
taskFilterService = TestBed.inject(TaskFilterCloudService);
|
||||
getTaskFilterCounterSpy = spyOn(taskFilterService, 'getTaskFilterCounter').and.returnValue(of(11));
|
||||
spyOn(taskFilterService, 'getTaskNotificationSubscription').and.returnValue(of(taskNotifications));
|
||||
|
||||
appConfigService = TestBed.inject(AppConfigService);
|
||||
});
|
||||
|
||||
it('should attach specific icon for each filter if hasIcon is true', async(() => {
|
||||
@@ -384,6 +387,7 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
|
||||
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();
|
||||
tick(5000);
|
||||
@@ -398,8 +402,24 @@ 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();
|
||||
tick(5000);
|
||||
fixture.detectChanges();
|
||||
component.showIcons = true;
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
|
||||
expect(updatedFilterCounters.length).toBe(0);
|
||||
});
|
||||
}));
|
||||
|
||||
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';
|
||||
component.ngOnInit();
|
||||
|
@@ -19,7 +19,7 @@ import { Component, EventEmitter, OnChanges, Output, SimpleChanges, OnInit } fro
|
||||
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 { AppConfigService, TranslationService } from '@alfresco/adf-core';
|
||||
import { debounceTime, takeUntil } from 'rxjs/operators';
|
||||
import { BaseTaskFiltersCloudComponent } from './base-task-filters-cloud.component';
|
||||
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
|
||||
@@ -31,6 +31,7 @@ import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';
|
||||
styleUrls: ['base-task-filters-cloud.component.scss']
|
||||
})
|
||||
export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent implements OnInit, OnChanges {
|
||||
|
||||
/** Emitted when a filter is being selected based on the filterParam input. */
|
||||
@Output()
|
||||
filterSelected = new EventEmitter<TaskFilterCloudModel>();
|
||||
@@ -46,13 +47,16 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
filters$: Observable<TaskFilterCloudModel[]>;
|
||||
filters: TaskFilterCloudModel[] = [];
|
||||
currentFilter: TaskFilterCloudModel;
|
||||
enableNotifications: boolean;
|
||||
|
||||
constructor(private taskFilterCloudService: TaskFilterCloudService,
|
||||
private translationService: TranslationService) {
|
||||
private translationService: TranslationService,
|
||||
private appConfigService: AppConfigService) {
|
||||
super();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.enableNotifications = this.appConfigService.get('notifications', true);
|
||||
this.initFilterCounterNotifications();
|
||||
this.getFilters(this.appName);
|
||||
}
|
||||
@@ -98,7 +102,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
}
|
||||
|
||||
initFilterCounterNotifications() {
|
||||
if (this.appName) {
|
||||
if (this.appName && this.enableNotifications) {
|
||||
this.taskFilterCloudService.getTaskNotificationSubscription(this.appName)
|
||||
.pipe(debounceTime(3000))
|
||||
.subscribe((result: TaskCloudEngineEvent[]) => {
|
||||
|
Reference in New Issue
Block a user