mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
AAE 31996 refresh button on filters not working as expected (#10712)
* AAE-31996 Refresh button on filters not working code fix test * AAE-31996 Altering the notification service for Refresh button * AAE-31996 Refrehs button notifications issues fix * updating to match develop * AAE-31996 resolving PR comments and removing unwanted changes * AAE-31996 resolving PR comments for units
This commit is contained in:
parent
34c0d88bbe
commit
677150e9d3
@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testing';
|
||||||
import { of, throwError } from 'rxjs';
|
import { first, of, throwError } from 'rxjs';
|
||||||
import { ProcessFilterCloudService } from '../../services/process-filter-cloud.service';
|
import { ProcessFilterCloudService } from '../../services/process-filter-cloud.service';
|
||||||
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
|
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
@ -529,7 +529,7 @@ describe('ProcessFiltersCloudComponent', () => {
|
|||||||
processFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
|
processFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.updatedFiltersSet.size).toBe(0);
|
expect(component.updatedFiltersSet.has(filterKeyTest)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Highlight Selected Filter', () => {
|
describe('Highlight Selected Filter', () => {
|
||||||
@ -578,67 +578,61 @@ describe('ProcessFiltersCloudComponent', () => {
|
|||||||
expect(getProcessNotificationSubscriptionSpy).toHaveBeenCalled();
|
expect(getProcessNotificationSubscriptionSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not emit filter key when filter counter is set for first time', () => {
|
it('should emit filter key when filter counter is set for first time', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
expect(updatedFilterSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
it('should not emit filter key when filter counter has not changed', fakeAsync(() => {
|
||||||
it('should not emit filter key when filter counter has not changd', () => {
|
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.updatedFilter.pipe(first()).subscribe(() => {
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
fail('Should not have been called if the filterKey value is already there');
|
||||||
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should emit filter key when filter counter is increased', () => {
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
|
flush();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should emit filter key when filter counter is increased', (done) => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
fixture.detectChanges();
|
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
||||||
|
expect(updatedFilter).toBe(fakeFilterKey);
|
||||||
expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(10);
|
done();
|
||||||
|
});
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey);
|
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
|
||||||
});
|
});
|
||||||
|
it('should emit filter key when filter counter is decreased', (done) => {
|
||||||
it('should emit filter key when filter counter is decreased', () => {
|
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
fixture.detectChanges();
|
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
||||||
|
expect(updatedFilter).toBe(fakeFilterKey);
|
||||||
expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(5);
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(10);
|
done();
|
||||||
|
});
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey);
|
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(5);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -293,11 +293,7 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number): void {
|
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number): void {
|
||||||
if (!this.currentFiltersValues[filterKey]) {
|
if (this.currentFiltersValues[filterKey] === undefined || this.currentFiltersValues[filterKey] !== filterValue) {
|
||||||
this.currentFiltersValues[filterKey] = filterValue;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.currentFiltersValues[filterKey] !== filterValue) {
|
|
||||||
this.currentFiltersValues[filterKey] = filterValue;
|
this.currentFiltersValues[filterKey] = filterValue;
|
||||||
this.updatedFilter.emit(filterKey);
|
this.updatedFilter.emit(filterKey);
|
||||||
this.updatedFiltersSet.add(filterKey);
|
this.updatedFiltersSet.add(filterKey);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { AppConfigService } from '@alfresco/adf-core';
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, fakeAsync, flush } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { first, of, throwError } from 'rxjs';
|
import { first, of, throwError } from 'rxjs';
|
||||||
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
|
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
|
||||||
@ -325,6 +325,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
spyOn(appConfigService, 'get').and.returnValue(false);
|
spyOn(appConfigService, 'get').and.returnValue(false);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(fixture.componentInstance.counters).toBeDefined();
|
||||||
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);
|
||||||
});
|
});
|
||||||
@ -468,40 +469,42 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
expect(component.getFilters).toHaveBeenCalledWith(appName);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not emit filter key when filter counter is set for first time', () => {
|
it('should emit filter key when filter counter is set for first time', () => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
expect(updatedFilterSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
it('should not emit filter key when filter counter has not changed', fakeAsync(() => {
|
||||||
it('should not emit filter key when filter counter has not changd', () => {
|
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
const fakeFilterValue = 10;
|
const fakeFilterValue = 10;
|
||||||
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues).not.toEqual({});
|
expect(component.currentFiltersValues).not.toEqual({});
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
|
|
||||||
|
component.updatedFilter.pipe(first()).subscribe(() => {
|
||||||
|
fail('Should not have been called if the filterKey value is already there');
|
||||||
|
});
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
|
||||||
expect(updatedFilterSpy).not.toHaveBeenCalled();
|
flush();
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should emit filter key when filter counter is increased', (done) => {
|
it('should emit filter key when filter counter is increased', (done) => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
|
|
||||||
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
||||||
expect(updatedFilter).toBe(fakeFilterKey);
|
expect(updatedFilter).toBe(fakeFilterKey);
|
||||||
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
|
||||||
@ -510,17 +513,14 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit filter key when filter counter is decreased', (done) => {
|
it('should emit filter key when filter counter is decreased', (done) => {
|
||||||
component.currentFiltersValues = {};
|
component.currentFiltersValues = {};
|
||||||
const fakeFilterKey = 'testKey';
|
const fakeFilterKey = 'testKey';
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
|
||||||
|
|
||||||
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
|
||||||
expect(updatedFilter).toBe(fakeFilterKey);
|
expect(updatedFilter).toBe(fakeFilterKey);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
@ -534,7 +534,7 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
taskFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
|
taskFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.updatedCountersSet.size).toBe(0);
|
expect(component.updatedCountersSet.has(filterKeyTest)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove key from set of updated filters when clicked on filter', async () => {
|
it('should remove key from set of updated filters when clicked on filter', async () => {
|
||||||
@ -542,13 +542,13 @@ describe('TaskFiltersCloudComponent', () => {
|
|||||||
component.updatedCountersSet.add(filter.key);
|
component.updatedCountersSet.add(filter.key);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.updatedCountersSet.size).toBe(1);
|
expect(component.updatedCountersSet.has(filter.key)).toBeTruthy();
|
||||||
|
|
||||||
component.onFilterClick(filter);
|
component.onFilterClick(filter);
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.updatedCountersSet.size).toBe(0);
|
expect(component.updatedCountersSet.has(filter.key)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add key to set of updated filters when value has changed', () => {
|
it('should add key to set of updated filters when value has changed', () => {
|
||||||
|
@ -156,7 +156,10 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
initFilterCounterNotifications() {
|
initFilterCounterNotifications() {
|
||||||
if (this.appName && this.enableNotifications) {
|
if (!this.appName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.enableNotifications) {
|
||||||
this.taskFilterCloudService
|
this.taskFilterCloudService
|
||||||
.getTaskNotificationSubscription(this.appName)
|
.getTaskNotificationSubscription(this.appName)
|
||||||
.pipe(debounceTime(1000))
|
.pipe(debounceTime(1000))
|
||||||
@ -168,6 +171,8 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
|||||||
this.updateFilterCounters();
|
this.updateFilterCounters();
|
||||||
this.filterCounterUpdated.emit(result);
|
this.filterCounterUpdated.emit(result);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.counters = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,11 +266,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number) {
|
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number) {
|
||||||
if (!this.currentFiltersValues[filterKey]) {
|
if (this.currentFiltersValues[filterKey] === undefined || this.currentFiltersValues[filterKey] !== filterValue) {
|
||||||
this.currentFiltersValues[filterKey] = filterValue;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.currentFiltersValues[filterKey] !== filterValue) {
|
|
||||||
this.currentFiltersValues[filterKey] = filterValue;
|
this.currentFiltersValues[filterKey] = filterValue;
|
||||||
this.updatedFilter.emit(filterKey);
|
this.updatedFilter.emit(filterKey);
|
||||||
this.updatedCountersSet.add(filterKey);
|
this.updatedCountersSet.add(filterKey);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user