mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[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:
@@ -41,7 +41,8 @@
|
|||||||
"START": "Couldn't start new process instance, check you have access.",
|
"START": "Couldn't start new process instance, check you have access.",
|
||||||
"PROCESS_NAME_REQUIRED": "Process Name is required",
|
"PROCESS_NAME_REQUIRED": "Process Name is required",
|
||||||
"PROCESS_DEFINITION_REQUIRED": "Process Definition 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."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -45,6 +45,9 @@
|
|||||||
<mat-error id="adf-start-process-maxlength-error" *ngIf="processInstanceName.hasError('maxlength')">
|
<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 } }}
|
{{ 'ADF_CLOUD_PROCESS_LIST.ADF_CLOUD_START_PROCESS.ERROR.MAXIMUM_LENGTH' | translate : { characters : maxNameLength } }}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
|
<mat-error *ngIf="processInstanceName.hasError('pattern')">
|
||||||
|
{{ 'ADF_PROCESS_LIST.START_PROCESS.ERROR.SPACE_VALIDATOR' | translate }}
|
||||||
|
</mat-error>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@@ -639,6 +639,18 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
expect(processInstanceName.valid).toBeTruthy();
|
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) => {
|
it('should emit processDefinitionSelection event when a process definition is selected', (done) => {
|
||||||
component.processDefinitionSelection.subscribe((processDefinition) => {
|
component.processDefinitionSelection.subscribe((processDefinition) => {
|
||||||
expect(processDefinition).toEqual(fakeProcessDefinitions[0]);
|
expect(processDefinition).toEqual(fakeProcessDefinitions[0]);
|
||||||
|
@@ -109,8 +109,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.processForm = this.formBuilder.group({
|
this.processForm = this.formBuilder.group({
|
||||||
processInstanceName: new FormControl(this.name, [Validators.required, Validators.maxLength(this.getMaxNameLength()), this.whitespaceValidator]),
|
processInstanceName: new FormControl(this.name, [Validators.required, Validators.maxLength(this.getMaxNameLength()), Validators.pattern('^[^\\s]+(\\s+[^\\s]+)*$')]),
|
||||||
processDefinition: new FormControl('', [Validators.required, this.processDefinitionNameValidator()])
|
processDefinition: new FormControl(this.processDefinitionName, [Validators.required, this.processDefinitionNameValidator()])
|
||||||
});
|
});
|
||||||
|
|
||||||
this.processDefinition.valueChanges
|
this.processDefinition.valueChanges
|
||||||
@@ -341,12 +341,6 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
return !!process.name ? process.name : process.key;
|
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 {
|
get processInstanceName(): AbstractControl {
|
||||||
return this.processForm.get('processInstanceName');
|
return this.processForm.get('processInstanceName');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user