From bc2d7f16fdda43e6e594fdc2c74310ca686b323d Mon Sep 17 00:00:00 2001 From: Urse Daniel Date: Sat, 18 Apr 2020 01:37:49 +0300 Subject: [PATCH] [AAE-2321] Should not be able to start a process with space as name (Process Services) (#5616) * New regex validator for process name for checking if there is a space character as the first or the las one in the name. * Added 2 new error messages for process name: Required and Pattern(no space in the beginning or the end). Changed the disabled start process button validation function. * Unit test to disable the start button if the pattern validator for process name is raised. * Added 2 new error messages for process start --- lib/process-services/src/lib/i18n/en.json | 4 +++- .../components/start-process.component.html | 8 +++++++- .../components/start-process.component.spec.ts | 11 +++++++++++ .../components/start-process.component.ts | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/process-services/src/lib/i18n/en.json b/lib/process-services/src/lib/i18n/en.json index 85c5023471..e0fd931a35 100644 --- a/lib/process-services/src/lib/i18n/en.json +++ b/lib/process-services/src/lib/i18n/en.json @@ -288,7 +288,9 @@ "ERROR": { "LOAD_PROCESS_DEFS": "Couldn't load process definitions, check you have access.", "START": "Couldn't start new process instance, check you have access.", - "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.", + "PROCESS_NAME_REQUIRED": "Process name is required." } }, "PROCESS-ATTACHMENT": { diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.html b/lib/process-services/src/lib/process-list/components/start-process.component.html index ec441f7560..cdec424956 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.html +++ b/lib/process-services/src/lib/process-list/components/start-process.component.html @@ -43,13 +43,19 @@ {{ 'ADF_PROCESS_LIST.START_PROCESS.ERROR.MAXIMUM_LENGTH' | translate : { characters : maxProcessNameLength } }} + + {{ 'ADF_PROCESS_LIST.START_PROCESS.ERROR.PROCESS_NAME_REQUIRED' | translate }} + + + {{ 'ADF_PROCESS_LIST.START_PROCESS.ERROR.SPACE_VALIDATOR' | translate }} + diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts index 7316bacb9d..1fab27e327 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts @@ -129,6 +129,17 @@ describe('StartFormComponent', () => { expect(startBtn.disabled).toBe(true); }); })); + + it('should have start button disabled process name has a space as the first or last character.', async(() => { + component.processNameInput.setValue(' Space in the beginning'); + component.processDefinitionInput.setValue(testProcessDef.name); + fixture.detectChanges(); + const startBtn = fixture.nativeElement.querySelector('#button-start'); + expect(startBtn.disabled).toBe(true); + component.processNameInput.setValue('Space in the end '); + fixture.detectChanges(); + expect(startBtn.disabled).toBe(true); + })); }); describe('with start form', () => { diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.ts b/lib/process-services/src/lib/process-list/components/start-process.component.ts index e4821b46b5..94485c9bdb 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.ts @@ -117,7 +117,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr } ngOnInit() { - this.processNameInput = new FormControl(this.name, [Validators.required, Validators.maxLength(this.maxProcessNameLength)]); + this.processNameInput = new FormControl(this.name, [Validators.required, Validators.maxLength(this.maxProcessNameLength), Validators.pattern('^[^\\s]+(\\s+[^\\s]+)*$')]); this.processDefinitionInput = new FormControl(); this.loadStartProcess();