[ADF-4068] StartTaskComponent - add description empty space validator (#4341)

* [ADF-4068] StartTaskComponent - add description empty space validator

* [ADF-4068] StartTaskCloudComponent - add unit tests

* [ADF-4068] - lint
This commit is contained in:
Silviu Popa
2019-02-22 03:48:22 +02:00
committed by Eugenio Romano
parent bfec78aec9
commit b967b77946
2 changed files with 12 additions and 3 deletions

View File

@@ -213,4 +213,14 @@ describe('StartTaskCloudComponent', () => {
fixture.detectChanges();
expect(name.valid).toBeTruthy();
});
it('should emit error when description have only white spaces', () => {
fixture.detectChanges();
let description = component.taskForm.controls['description'];
description.setValue(' ');
fixture.detectChanges();
expect(description.valid).toBeFalsy();
description.setValue('');
fixture.detectChanges();
expect(description.valid).toBeTruthy();
});
});

View File

@@ -131,7 +131,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
this.taskForm = this.formBuilder.group({
name: new FormControl(this.name, [Validators.required, Validators.maxLength(this.getMaxNameLength()), this.whitespaceValidator]),
priority: new FormControl(),
description: new FormControl()
description: new FormControl('', [this.whitespaceValidator])
});
}
@@ -206,7 +206,7 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
public whitespaceValidator(control: FormControl) {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = !isWhitespace;
const isValid = control.value.length === 0 || !isWhitespace;
return isValid ? null : { 'whitespace': true };
}
@@ -217,5 +217,4 @@ export class StartTaskCloudComponent implements OnInit, OnDestroy {
get priorityController(): AbstractControl {
return this.taskForm.get('priority');
}
}