mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-10911] Fix Cardview Int validator for only spaces (#7889)
* [AAE-10911] Fix Cardview Int validator for only spaces * [AAE-10911] added unit tests
This commit is contained in:
@@ -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 () => {
|
||||||
fixture.detectChanges();
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
|
|
||||||
updateTextField(component.property.key, ' ');
|
updateTextField(component.property.key, ' ');
|
||||||
tick(600);
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
const error = getTextFieldError(component.property.key);
|
const errorMessage = getTextFieldError(component.property.key);
|
||||||
expect(error).toEqual('CORE.CARDVIEW.VALIDATORS.INT_VALIDATION_ERROR');
|
expect(errorMessage).toEqual('CORE.CARDVIEW.VALIDATORS.INT_VALIDATION_ERROR');
|
||||||
expect(component.property.value).toBe(10);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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) => {
|
it('should show validation error for float number', fakeAsync((done) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@@ -26,11 +26,15 @@ export class CardViewItemIntValidator implements CardViewItemValidator {
|
|||||||
return value.every(this.isIntegerNumber);
|
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 {
|
isIntegerNumber(value: any): boolean {
|
||||||
const parsedNumber = Number(value);
|
const parsedNumber = Number(value);
|
||||||
return (parsedNumber | 0) === parsedNumber;
|
return (parsedNumber | 0) === parsedNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isNotOnlySpace(value: any): boolean {
|
||||||
|
return String(value).trim() !== '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user