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 848d3cbf33..34063d3b92 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 @@ -735,21 +735,35 @@ describe('CardViewTextItemComponent', () => { }); })); - it('should show validation error for empty string', fakeAsync((done) => { + it('should show validation error for only spaces string', async () => { + updateTextField(component.property.key, ' '); + await fixture.whenStable(); fixture.detectChanges(); - fixture.whenStable().then(() => { - updateTextField(component.property.key, ' '); - tick(600); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const error = getTextFieldError(component.property.key); - expect(error).toEqual('CORE.CARDVIEW.VALIDATORS.INT_VALIDATION_ERROR'); - expect(component.property.value).toBe(10); - done(); - }); - }); - })); + const errorMessage = getTextFieldError(component.property.key); + expect(errorMessage).toEqual('CORE.CARDVIEW.VALIDATORS.INT_VALIDATION_ERROR'); + }); + + it('should NOT show validation error for empty string', async () => { + updateTextField(component.property.key, ''); + await fixture.whenStable(); + fixture.detectChanges(); + + const errorElement = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-error-textkey"]')); + expect(errorElement).toBeNull(); + }); + + it('should NOT show validation error for null', async () => { + updateTextField(component.property.key, null); + await fixture.whenStable(); + fixture.detectChanges(); + + const inputElement = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-textkey"]')); + const errorElement = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-error-textkey"]')); + + expect(inputElement.nativeElement.value).toBe(''); + expect(errorElement).toBeNull(); + }); it('should show validation error for float number', fakeAsync((done) => { fixture.detectChanges(); diff --git a/lib/core/src/lib/card-view/validators/card-view-item-int.validator.ts b/lib/core/src/lib/card-view/validators/card-view-item-int.validator.ts index a4193a7b24..52123654ce 100644 --- a/lib/core/src/lib/card-view/validators/card-view-item-int.validator.ts +++ b/lib/core/src/lib/card-view/validators/card-view-item-int.validator.ts @@ -26,11 +26,15 @@ export class CardViewItemIntValidator implements CardViewItemValidator { return value.every(this.isIntegerNumber); } - return value === '' || !isNaN(value) && this.isIntegerNumber(value); + return value === '' || !isNaN(value) && this.isIntegerNumber(value) && this.isNotOnlySpace(value); } isIntegerNumber(value: any): boolean { const parsedNumber = Number(value); return (parsedNumber | 0) === parsedNumber; } + + isNotOnlySpace(value: any): boolean { + return String(value).trim() !== ''; + } }