From 08fd1f3d12ce8885e2c58564f2a2d20f62927570 Mon Sep 17 00:00:00 2001 From: Michaela <85624192+mkrbr@users.noreply.github.com> Date: Tue, 11 Mar 2025 16:48:41 +0100 Subject: [PATCH] Revert "AAE 31996 refresh button on filters not working as expected (#10698)" (#10709) This reverts commit 946fe889e1e4b4eed6a3e03ecb0539471ab4852d. --- .../display-rich-text.widget.ts | 2 +- .../process-filters-cloud.component.spec.ts | 57 +++++++++++-------- .../process-filters-cloud.component.ts | 6 +- .../task-filters-cloud.component.spec.ts | 27 ++++----- .../task-filters-cloud.component.ts | 6 +- 5 files changed, 57 insertions(+), 41 deletions(-) diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.ts index a2bbfa164c..2230f427b7 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/display-rich-text/display-rich-text.widget.ts @@ -68,7 +68,7 @@ export class DisplayRichTextWidgetComponent extends WidgetComponent implements O } ngOnInit(): void { - this.parsedHTML = edjsHTML(DisplayRichTextWidgetComponent.CUSTOM_PARSER, { strict: true }).parse(this.field.value); + this.parsedHTML = edjsHTML(DisplayRichTextWidgetComponent.CUSTOM_PARSER, { strict: true }).parse(this.field.value); if (!(this.parsedHTML instanceof Error)) { this.sanitizeHtmlContent(); diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.spec.ts index 20db43fe8a..0091ec8a86 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.spec.ts @@ -16,8 +16,8 @@ */ import { SimpleChange } from '@angular/core'; -import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testing'; -import { first, of, throwError } from 'rxjs'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { 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'; @@ -578,60 +578,67 @@ describe('ProcessFiltersCloudComponent', () => { expect(getProcessNotificationSubscriptionSpy).toHaveBeenCalled(); }); - it('should emit filter key when filter counter is set for first time', () => { + it('should not 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).toHaveBeenCalled(); + expect(updatedFilterSpy).not.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 = {}; 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); - flush(); - })); + expect(updatedFilterSpy).not.toHaveBeenCalled(); + }); - it('should emit filter key when filter counter is increased', (done) => { + it('should emit filter key when filter counter is increased', () => { component.currentFiltersValues = {}; const fakeFilterKey = 'testKey'; + const updatedFilterSpy = spyOn(component.updatedFilter, 'emit'); component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10); - component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => { - expect(updatedFilter).toBe(fakeFilterKey); - expect(component.currentFiltersValues[fakeFilterKey]).toBe(20); - done(); - }); + fixture.detectChanges(); + + expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey); + expect(component.currentFiltersValues[fakeFilterKey]).toBe(10); + 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', (done) => { + + it('should emit filter key when filter counter is decreased', () => { component.currentFiltersValues = {}; const fakeFilterKey = 'testKey'; + const updatedFilterSpy = spyOn(component.updatedFilter, 'emit'); component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 10); - component.updatedFilter.pipe(first()).subscribe((updatedFilter: string) => { - expect(updatedFilter).toBe(fakeFilterKey); - done(); - }); + fixture.detectChanges(); + + expect(updatedFilterSpy).not.toHaveBeenCalledWith(fakeFilterKey); + expect(component.currentFiltersValues[fakeFilterKey]).toBe(10); + component.checkIfFilterValuesHasBeenUpdated(fakeFilterKey, 5); fixture.detectChanges(); + + expect(updatedFilterSpy).toHaveBeenCalledWith(fakeFilterKey); + expect(component.currentFiltersValues[fakeFilterKey]).toBe(5); }); }); }); diff --git a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.ts index 63cd5db8cd..389328b818 100644 --- a/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/process-filters/components/process-filters/process-filters-cloud.component.ts @@ -293,7 +293,11 @@ export class ProcessFiltersCloudComponent implements OnInit, OnChanges { } checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number): void { - if (this.currentFiltersValues[filterKey] === undefined || this.currentFiltersValues[filterKey] !== filterValue) { + if (!this.currentFiltersValues[filterKey]) { + this.currentFiltersValues[filterKey] = filterValue; + return; + } + if (this.currentFiltersValues[filterKey] !== filterValue) { this.currentFiltersValues[filterKey] = filterValue; this.updatedFilter.emit(filterKey); this.updatedFiltersSet.add(filterKey); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.spec.ts index d3cf7c66af..206d0deb90 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.spec.ts @@ -17,7 +17,7 @@ import { AppConfigService } from '@alfresco/adf-core'; import { SimpleChange } from '@angular/core'; -import { ComponentFixture, TestBed, fakeAsync, flush } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync } 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'; @@ -468,42 +468,40 @@ describe('TaskFiltersCloudComponent', () => { expect(component.getFilters).toHaveBeenCalledWith(appName); }); - it('should emit filter key when filter counter is set for first time', () => { + it('should not 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).toHaveBeenCalled(); + expect(updatedFilterSpy).not.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 = {}; 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); - flush(); - })); + expect(updatedFilterSpy).not.toHaveBeenCalled(); + }); 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); @@ -512,14 +510,17 @@ 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(); }); diff --git a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.ts index 3f4d4c54dc..2994d3a4e2 100644 --- a/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-filters/components/task-filters/task-filters-cloud.component.ts @@ -261,7 +261,11 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp } checkIfFilterValuesHasBeenUpdated(filterKey: string, filterValue: number) { - if (this.currentFiltersValues[filterKey] == undefined || this.currentFiltersValues[filterKey] !== filterValue) { + if (!this.currentFiltersValues[filterKey]) { + this.currentFiltersValues[filterKey] = filterValue; + return; + } + if (this.currentFiltersValues[filterKey] !== filterValue) { this.currentFiltersValues[filterKey] = filterValue; this.updatedFilter.emit(filterKey); this.updatedCountersSet.add(filterKey);