From f8fa996b04f1ffcda08ad7af340e2a2e24e5ec1a Mon Sep 17 00:00:00 2001 From: Soumyajit Chakraborty <51930458+Isoumyajit@users.noreply.github.com> Date: Wed, 18 Feb 2026 19:00:50 +0530 Subject: [PATCH] AAE-33828 Fix for the runtime errors on data-table should be handled (#11639) * AAE-33828 fix for the runtime errors on datatable should be handled in runtime * AAE-33828 removing the unwanted try catches * AAE-33828 adding units to test the number value is a valid value --- .../amount-cell/amount-cell.component.ts | 16 +++++- .../date-cell/date-cell.component.ts | 1 - .../number-cell/number-cell.component.spec.ts | 57 +++++++++++++++++++ .../number-cell/number-cell.component.ts | 16 +++++- 4 files changed, 85 insertions(+), 5 deletions(-) diff --git a/lib/core/src/lib/datatable/components/amount-cell/amount-cell.component.ts b/lib/core/src/lib/datatable/components/amount-cell/amount-cell.component.ts index 0072ef7901..02b63141c1 100644 --- a/lib/core/src/lib/datatable/components/amount-cell/amount-cell.component.ts +++ b/lib/core/src/lib/datatable/components/amount-cell/amount-cell.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ChangeDetectionStrategy, Component, ViewEncapsulation, Input, DEFAULT_CURRENCY_CODE, inject } from '@angular/core'; +import { ChangeDetectionStrategy, Component, ViewEncapsulation, Input, DEFAULT_CURRENCY_CODE, inject, computed } from '@angular/core'; import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component'; import { CurrencyConfig } from '../../data/data-column.model'; import { CurrencyPipe } from '@angular/common'; @@ -41,5 +41,17 @@ export class AmountCellComponent extends DataTableCellComponent { locale: undefined }; - readonly amountValue = toSignal(this.value$); + private readonly rawAmountValue = toSignal(this.value$); + + readonly amountValue = computed(() => { + const value = this.rawAmountValue(); + + if (value == null || value === '') { + return null; + } + + const numericValue = Number(value); + + return Number.isFinite(numericValue) ? numericValue : null; + }); } diff --git a/lib/core/src/lib/datatable/components/date-cell/date-cell.component.ts b/lib/core/src/lib/datatable/components/date-cell/date-cell.component.ts index 791a9d258b..7c18301696 100644 --- a/lib/core/src/lib/datatable/components/date-cell/date-cell.component.ts +++ b/lib/core/src/lib/datatable/components/date-cell/date-cell.component.ts @@ -63,7 +63,6 @@ export class DateCellComponent extends DataTableCellComponent implements OnInit if (!date) { return ''; } - if (currentConfig.format === 'timeAgo') { return this.timeAgoPipe.transform(date, currentConfig.locale) || ''; } diff --git a/lib/core/src/lib/datatable/components/number-cell/number-cell.component.spec.ts b/lib/core/src/lib/datatable/components/number-cell/number-cell.component.spec.ts index 47fe111dde..50a247dab5 100644 --- a/lib/core/src/lib/datatable/components/number-cell/number-cell.component.spec.ts +++ b/lib/core/src/lib/datatable/components/number-cell/number-cell.component.spec.ts @@ -60,6 +60,63 @@ describe('NumberCellComponent', () => { it('should render decimal value with custom digitsInfo', () => { renderAndCheckNumberValue({ digitsInfo: '1.2-2' }, 123.456789, '123.46'); }); + + describe('numberValue validation', () => { + it('should return valid number for integer input', () => { + component.value$.next(42); + fixture.detectChanges(); + expect(component.numberValue()).toBe(42); + }); + + it('should return valid number for float input', () => { + component.value$.next(3.14159); + fixture.detectChanges(); + expect(component.numberValue()).toBe(3.14159); + }); + + it('should return valid number for negative number', () => { + component.value$.next(-123.45); + fixture.detectChanges(); + expect(component.numberValue()).toBe(-123.45); + }); + + it('should return valid number for zero', () => { + component.value$.next(0); + fixture.detectChanges(); + expect(component.numberValue()).toBe(0); + }); + + it('should return valid number for numeric string', () => { + component.value$.next('456.78'); + fixture.detectChanges(); + expect(component.numberValue()).toBe(456.78); + }); + + it('should return null for boolean true', () => { + (component.value$ as { next: (v: unknown) => void }).next(true); + fixture.detectChanges(); + expect(component.numberValue()).toBeNull(); + }); + + it('should return null for NaN', () => { + component.value$.next(NaN); + fixture.detectChanges(); + expect(component.numberValue()).toBeNull(); + }); + + it('should return null for non-numeric string', () => { + component.value$.next('not a number'); + fixture.detectChanges(); + expect(component.numberValue()).toBeNull(); + }); + + it('should not render span when value is invalid', () => { + component.value$.next(null); + fixture.detectChanges(); + const displayedNumber = testingUtils.getByCSS('span'); + expect(displayedNumber).toBeFalsy(); + }); + }); }); describe('NumberCellComponent locale', () => { diff --git a/lib/core/src/lib/datatable/components/number-cell/number-cell.component.ts b/lib/core/src/lib/datatable/components/number-cell/number-cell.component.ts index 0725126da1..58a6488818 100644 --- a/lib/core/src/lib/datatable/components/number-cell/number-cell.component.ts +++ b/lib/core/src/lib/datatable/components/number-cell/number-cell.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { ChangeDetectionStrategy, Component, ViewEncapsulation, Input } from '@angular/core'; +import { ChangeDetectionStrategy, Component, ViewEncapsulation, Input, computed } from '@angular/core'; import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component'; import { DecimalConfig } from '../../data/data-column.model'; import { CommonModule } from '@angular/common'; @@ -38,5 +38,17 @@ export class NumberCellComponent extends DataTableCellComponent { locale: undefined }; - readonly numberValue = toSignal(this.value$); + private readonly rawNumberValue = toSignal(this.value$); + + readonly numberValue = computed(() => { + const value = this.rawNumberValue(); + + if (value == null || value === '' || typeof value === 'boolean') { + return null; + } + + const numericValue = Number(value); + + return Number.isFinite(numericValue) ? numericValue : null; + }); }