From 669c85c76bd140b73280a9192609d8fcf6384c99 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Tue, 28 Apr 2026 11:24:05 +0100 Subject: [PATCH] =?UTF-8?q?AAE-44946=20-=20Sending=20also=20previous=20val?= =?UTF-8?q?ue=20to=20allow=20valuation=20and=20valida=E2=80=A6=20(#11836)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AAE-44946 - Sending also previous value to allow valuation and validation * AAE-44946 - Sending also previous value to allow valuation and validation * AAE-44749 - Fixed wrong subscribe in test * AAE-45038 - Fixing logs and unit tests --- .../card-view-textitem.component.html | 2 - .../card-view-textitem.component.spec.ts | 34 +++++++++++--- .../card-view-textitem.component.ts | 21 +++++---- .../card-view-update-options.interface.ts | 20 +++++++++ .../interfaces/card-view.interfaces.ts | 1 + .../update-notification.interface.ts | 1 + .../services/card-view-update.service.spec.ts | 45 ++++++++++++++----- .../services/card-view-update.service.ts | 6 ++- 8 files changed, 101 insertions(+), 29 deletions(-) create mode 100644 lib/core/src/lib/card-view/interfaces/card-view-update-options.interface.ts diff --git a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.html b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.html index b6fe7172bd..c771772e0a 100644 --- a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.html +++ b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.html @@ -31,7 +31,6 @@ 'adf-property-value-has-error': isEditable && hasErrors, 'adf-property-value-not-editable': !editable }" - [disabled]="isReadonlyProperty || !editable" title="{{ property.label | translate }}" [placeholder]="property.default" [attr.aria-label]="property.label | translate" @@ -53,7 +52,6 @@ 'adf-property-value-editable': editable, 'adf-property-readonly-value': isReadonlyProperty || !editable, }" - [disabled]="isReadonlyProperty || !editable" [placeholder]="property.default" [attr.aria-label]="property.label | translate" [formControl]="textInput" diff --git a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts index 06b8846f41..e0425e1c5e 100644 --- a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts +++ b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.spec.ts @@ -198,8 +198,11 @@ describe('CardViewTextItemComponent', () => { key: 'namekey', editable: true }); - spyOn(component.property, 'isValid').and.returnValue(false); component.editable = true; + component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); + + spyOn(component.property, 'isValid').and.returnValue(false); spyOn(component.textInput, 'setErrors'); const textField = await getTextField(component.property.key); await textField.blur(); @@ -216,8 +219,11 @@ describe('CardViewTextItemComponent', () => { key: 'namekey', editable: true }); - spyOn(component.property, 'isValid').and.returnValue(false); component.editable = true; + component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); + + spyOn(component.property, 'isValid').and.returnValue(false); spyOn(component.textInput, 'markAsTouched'); const textField = await getTextField(component.property.key); await textField.blur(); @@ -232,6 +238,10 @@ describe('CardViewTextItemComponent', () => { key: 'namekey', editable: true }); + component.editable = true; + component.ngOnChanges({ property: new SimpleChange(null, null, true) }); + fixture.detectChanges(); + spyOn(component.property, 'isValid').and.returnValue(false); spyOn(component.property, 'getValidationErrors').and.returnValue([ { @@ -241,7 +251,6 @@ describe('CardViewTextItemComponent', () => { message: 'Error 2' } ] as CardViewItemValidator[]); - component.editable = true; const textField = await getTextField(component.property.key); await textField.blur(); @@ -544,6 +553,9 @@ describe('CardViewTextItemComponent', () => { target: { ...component.property, isValidValue: true }, changed: { textkey: expectedText + }, + previousValue: { + textkey: 'FAKE-DEFAULT-KEY' } }); @@ -617,7 +629,7 @@ describe('CardViewTextItemComponent', () => { await fixture.whenStable(); const property = { ...component.property, isValidValue: true }; - expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, 'updated-value'); + expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, 'updated-value', { previousValue: 'Lorem ipsum' }); }); it('should trigger the update event if the editedValue is NOT valid', async () => { @@ -629,7 +641,7 @@ describe('CardViewTextItemComponent', () => { await fixture.whenStable(); const property = { ...component.property, isValidValue: false }; - expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, '@invalid-value'); + expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, '@invalid-value', { previousValue: 'Lorem ipsum' }); }); it('should trigger the update event if the editedValue is valid', async () => { @@ -707,6 +719,9 @@ describe('CardViewTextItemComponent', () => { target: { ...component.property, isValidValue: true }, changed: { textkey: expectedText + }, + previousValue: { + textkey: 'Lorem ipsum' } }); }); @@ -752,6 +767,9 @@ describe('CardViewTextItemComponent', () => { target: { ...component.property, isValidValue: true }, changed: { textkey: expectedText + }, + previousValue: { + textkey: 'Lorem ipsum' } }); @@ -871,6 +889,9 @@ describe('CardViewTextItemComponent', () => { target: { ...component.property, isValidValue: true }, changed: { textkey: expectedNumber.toString() + }, + previousValue: { + textkey: 10 } }); @@ -929,6 +950,9 @@ describe('CardViewTextItemComponent', () => { target: { ...component.property, isValidValue: true }, changed: { textkey: expectedNumber.toString() + }, + previousValue: { + textkey: 77.33 } }); diff --git a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.ts b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.ts index 3294e996e4..e5768bab4b 100644 --- a/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.ts +++ b/lib/core/src/lib/card-view/components/card-view-textitem/card-view-textitem.component.ts @@ -81,6 +81,7 @@ export class CardViewTextItemComponent extends BaseCardView { cardViewUpdateService = TestBed.inject(CardViewUpdateService); }); - it('should send updated message with proper parameters', fakeAsync(() => { - cardViewUpdateService.itemUpdated$.subscribe(({ target, changed }) => { - expect(target).toBe(property); - expect(changed).toEqual({ 'property-key': 'changed-property-value' }); - }); + it('should send updated message with proper parameters', async () => { + const updatePromise = firstValueFrom(cardViewUpdateService.itemUpdated$); cardViewUpdateService.update(property, 'changed-property-value'); - })); - it('should send clicked message with proper parameters', fakeAsync(() => { - cardViewUpdateService.itemClicked$.subscribe(({ target }) => { - expect(target).toBe(property); - }); + const { target, changed } = await updatePromise; + expect(target).toBe(property); + expect(changed).toEqual({ 'property-key': 'changed-property-value' }); + }); + + it('should include previousValue when provided', async () => { + const updatePromise = firstValueFrom(cardViewUpdateService.itemUpdated$); + cardViewUpdateService.update(property, 'new-value', { previousValue: 'old-value' }); + + const { target, changed, previousValue } = await updatePromise; + expect(target).toBe(property); + expect(changed).toEqual({ 'property-key': 'new-value' }); + expect(previousValue).toEqual({ 'property-key': 'old-value' }); + }); + + it('should not include previousValue when not provided', async () => { + const updatePromise = firstValueFrom(cardViewUpdateService.itemUpdated$); + cardViewUpdateService.update(property, 'changed-property-value'); + + const notification = await updatePromise; + expect(notification.previousValue).toBeUndefined(); + }); + + it('should send clicked message with proper parameters', async () => { + const clickedPromise = firstValueFrom(cardViewUpdateService.itemClicked$); cardViewUpdateService.clicked(property); - })); + + const { target } = await clickedPromise; + expect(target).toBe(property); + }); }); }); diff --git a/lib/core/src/lib/card-view/services/card-view-update.service.ts b/lib/core/src/lib/card-view/services/card-view-update.service.ts index 62c240fa20..25e21dea15 100644 --- a/lib/core/src/lib/card-view/services/card-view-update.service.ts +++ b/lib/core/src/lib/card-view/services/card-view-update.service.ts @@ -21,6 +21,7 @@ import { BaseCardViewUpdate } from '../interfaces/base-card-view-update.interfac import { ClickNotification } from '../interfaces/click-notification.interface'; import { UpdateNotification } from '../interfaces/update-notification.interface'; import { CardViewBaseItemModel } from '../models/card-view-baseitem.model'; +import { CardViewUpdateOptions } from '../interfaces/card-view-update-options.interface'; export const transformKeyToObject = (key: string, value): any => { const objectLevels: string[] = key.split('.').reverse(); @@ -37,10 +38,11 @@ export class CardViewUpdateService implements BaseCardViewUpdate { updateItem$ = new Subject(); autocompleteInputValue$ = new Subject(); - update(property: CardViewBaseItemModel, newValue: any) { + update(property: CardViewBaseItemModel, newValue: any, options?: CardViewUpdateOptions) { this.itemUpdated$.next({ target: property, - changed: transformKeyToObject(property.key, newValue) + changed: transformKeyToObject(property.key, newValue), + ...(options?.previousValue !== undefined && { previousValue: transformKeyToObject(property.key, options.previousValue) }) }); }