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:
Soumyajit Chakraborty 2025-03-12 17:10:11 +05:30 committed by GitHub
parent 34c0d88bbe
commit 677150e9d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 54 additions and 63 deletions

View File

@ -16,8 +16,8 @@
*/
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testing';
import { first, of, throwError } from 'rxjs';
import { ProcessFilterCloudService } from '../../services/process-filter-cloud.service';
import { ProcessFiltersCloudComponent } from './process-filters-cloud.component';
import { By } from '@angular/platform-browser';
@ -529,7 +529,7 @@ describe('ProcessFiltersCloudComponent', () => {
processFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
fixture.detectChanges();
expect(component.updatedFiltersSet.size).toBe(0);
expect(component.updatedFiltersSet.has(filterKeyTest)).toBeFalsy();
});
describe('Highlight Selected Filter', () => {
@ -578,67 +578,61 @@ describe('ProcessFiltersCloudComponent', () => {
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 = {};
const fakeFilterKey = 'testKey';
const fakeFilterValue = 10;
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
fixture.detectChanges();
expect(component.currentFiltersValues).not.toEqual({});
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
expect(updatedFilterSpy).not.toHaveBeenCalled();
expect(updatedFilterSpy).toHaveBeenCalled();
});
it('should not emit filter key when filter counter has not changd', () => {
it('should not emit filter key when filter counter has not changed', fakeAsync(() => {
component.currentFiltersValues = {};
const fakeFilterKey = 'testKey';
const fakeFilterValue = 10;
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
fixture.detectChanges();
expect(component.currentFiltersValues).not.toEqual({});
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
expect(updatedFilterSpy).not.toHaveBeenCalled();
});
component.updatedFilter.pipe(first()).subscribe(() => {
fail('Should not have been called if the filterKey value is already there');
});
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 = {};
const fakeFilterKey = 'testKey';
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
fixture.detectChanges();
expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(10);
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
expect(updatedFilter).toBe(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
done();
});
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
fixture.detectChanges();
expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
});
it('should emit filter key when filter counter is decreased', () => {
it('should emit filter key when filter counter is decreased', (done) => {
component.currentFiltersValues = {};
const fakeFilterKey = 'testKey';
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
fixture.detectChanges();
expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(10);
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
expect(updatedFilter).toBe(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(5);
done();
});
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
fixture.detectChanges();
expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(5);
});
});
});

View File

@ -293,11 +293,7 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges {
}
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number): void {
if (!this.currentFiltersValues[filterKey]) {
this.currentFiltersValues[filterKey] = filterValue;
return;
}
if (this.currentFiltersValues[filterKey] !== filterValue) {
if (this.currentFiltersValues[filterKey] === undefined || this.currentFiltersValues[filterKey] !== filterValue) {
this.currentFiltersValues[filterKey] = filterValue;
this.updatedFilter.emit(filterKey);
this.updatedFiltersSet.add(filterKey);

View File

@ -17,7 +17,7 @@
import { AppConfigService } from '@alfresco/adf-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 { first, of, throwError } from 'rxjs';
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../../services/cloud-token.service';
@ -325,6 +325,7 @@ describe('TaskFiltersCloudComponent', () => {
spyOn(appConfigService, 'get').and.returnValue(false);
fixture.detectChanges();
expect(fixture.componentInstance.counters).toBeDefined();
const updatedFilterCounters = fixture.debugElement.queryAll(By.css('span.adf-active'));
expect(updatedFilterCounters.length).toBe(0);
});
@ -468,40 +469,42 @@ describe('TaskFiltersCloudComponent', () => {
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 = {};
const fakeFilterKey = 'testKey';
const fakeFilterValue = 10;
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
fixture.detectChanges();
expect(component.currentFiltersValues).not.toEqual({});
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
expect(updatedFilterSpy).not.toHaveBeenCalled();
expect(updatedFilterSpy).toHaveBeenCalled();
});
it('should not emit filter key when filter counter has not changd', () => {
it('should not emit filter key when filter counter has not changed', fakeAsync(() => {
component.currentFiltersValues = {};
const fakeFilterKey = 'testKey';
const fakeFilterValue = 10;
const updatedFilterSpy = spyOn(component.updatedFilter, 'emit');
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, fakeFilterValue);
fixture.detectChanges();
expect(component.currentFiltersValues).not.toEqual({});
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);
fixture.detectChanges();
expect(component.currentFiltersValues[fakeFilterKey]).toBe(fakeFilterValue);
expect(updatedFilterSpy).not.toHaveBeenCalled();
});
flush();
}));
it('should emit filter key when filter counter is increased', (done) => {
component.currentFiltersValues = {};
const fakeFilterKey = 'testKey';
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
expect(updatedFilter).toBe(fakeFilterKey);
expect(component.currentFiltersValues[fakeFilterKey]).toBe(20);
@ -510,17 +513,14 @@ describe('TaskFiltersCloudComponent', () => {
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 20);
fixture.detectChanges();
});
it('should emit filter key when filter counter is decreased', (done) => {
component.currentFiltersValues = {};
const fakeFilterKey = 'testKey';
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10);
component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => {
expect(updatedFilter).toBe(fakeFilterKey);
done();
});
component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5);
fixture.detectChanges();
});
@ -534,7 +534,7 @@ describe('TaskFiltersCloudComponent', () => {
taskFilterService.filterKeyToBeRefreshed$ = of(filterKeyTest);
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 () => {
@ -542,13 +542,13 @@ describe('TaskFiltersCloudComponent', () => {
component.updatedCountersSet.add(filter.key);
fixture.detectChanges();
expect(component.updatedCountersSet.size).toBe(1);
expect(component.updatedCountersSet.has(filter.key)).toBeTruthy();
component.onFilterClick(filter);
await fixture.whenStable();
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', () => {

View File

@ -156,7 +156,10 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
}
initFilterCounterNotifications() {
if (this.appName && this.enableNotifications) {
if (!this.appName) {
return;
}
if (this.enableNotifications) {
this.taskFilterCloudService
.getTaskNotificationSubscription(this.appName)
.pipe(debounceTime(1000))
@ -168,6 +171,8 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
this.updateFilterCounters();
this.filterCounterUpdated.emit(result);
});
} else {
this.counters = {};
}
}
@ -261,11 +266,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
}
checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number) {
if (!this.currentFiltersValues[filterKey]) {
this.currentFiltersValues[filterKey] = filterValue;
return;
}
if (this.currentFiltersValues[filterKey] !== filterValue) {
if (this.currentFiltersValues[filterKey] === undefined || this.currentFiltersValues[filterKey] !== filterValue) {
this.currentFiltersValues[filterKey] = filterValue;
this.updatedFilter.emit(filterKey);
this.updatedCountersSet.add(filterKey);