[AAE-2321] Should not be able to start a process with space(s) in the beginning/end of process name (Process Services Cloud) (#5639)

* Changed the validator for process name - added a new regex that restricts having space(s) in the beginning/end of the name.

* Added new error message for whitespace regex.

* 1 new error message for whitespace

* Unit test for whitespace restriction (process name)
This commit is contained in:
Urse Daniel
2020-04-26 13:14:36 +03:00
committed by GitHub
parent 444ebcdfd8
commit ebfeb053ce
4 changed files with 19 additions and 9 deletions

View File

@@ -41,7 +41,8 @@
"START": "Couldn't start new process instance, check you have access.",
"PROCESS_NAME_REQUIRED": "Process Name is required",
"PROCESS_DEFINITION_REQUIRED": "Process Definition is required",
"MAXIMUM_LENGTH": "Length exceeded, {{characters}} characters max."
"MAXIMUM_LENGTH": "Length exceeded, {{characters}} characters max.",
"SPACE_VALIDATOR": "Space is not allowed in the beginning or the end of the text."
}
}
},

View File

@@ -45,6 +45,9 @@
<mat-error id="adf-start-process-maxlength-error" *ngIf="processInstanceName.hasError('maxlength')">
{{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.MAXIMUM_LENGTH' | translate : { characters : maxNameLength } }}
</mat-error>
<mat-error *ngIf="processInstanceName.hasError('pattern')">
{{ 'ADF_PROCESS_LIST.START_PROCESS.ERROR.SPACE_VALIDATOR' | translate }}
</mat-error>
</mat-form-field>
</form>

View File

@@ -639,6 +639,18 @@ describe('StartProcessCloudComponent', () => {
expect(processInstanceName.valid).toBeTruthy();
});
it('should have start button disabled process name has a space as the first or last character.', async(() => {
component.appName = 'myApp';
component.processDefinitionName = ' Space in the beginning';
component.ngOnChanges({});
fixture.detectChanges();
const startBtn = fixture.nativeElement.querySelector('#button-start');
expect(startBtn.disabled).toBe(true);
component.processDefinitionName = 'Space in the end ';
fixture.detectChanges();
expect(startBtn.disabled).toBe(true);
}));
it('should emit processDefinitionSelection event when a process definition is selected', (done) => {
component.processDefinitionSelection.subscribe((processDefinition) => {
expect(processDefinition).toEqual(fakeProcessDefinitions[0]);

View File

@@ -109,8 +109,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
ngOnInit() {
this.processForm = this.formBuilder.group({
processInstanceName: new FormControl(this.name, [Validators.required, Validators.maxLength(this.getMaxNameLength()), this.whitespaceValidator]),
processDefinition: new FormControl('', [Validators.required, this.processDefinitionNameValidator()])
processInstanceName: new FormControl(this.name, [Validators.required, Validators.maxLength(this.getMaxNameLength()), Validators.pattern('^[^\\s]+(\\s+[^\\s]+)*$')]),
processDefinition: new FormControl(this.processDefinitionName, [Validators.required, this.processDefinitionNameValidator()])
});
this.processDefinition.valueChanges
@@ -341,12 +341,6 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
return !!process.name ? process.name : process.key;
}
public whitespaceValidator(control: FormControl) {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = !isWhitespace;
return isValid ? null : { 'whitespace': true };
}
get processInstanceName(): AbstractControl {
return this.processForm.get('processInstanceName');
}