From 66c2b0b125c22bb9a493f2020894b5434212f9a9 Mon Sep 17 00:00:00 2001 From: Mercy Chrysolite <48274621+mcchrys@users.noreply.github.com> Date: Wed, 27 May 2020 18:30:51 +0530 Subject: [PATCH] [ACA-3271] START PROCESS button is inactive first time when process model is loaded (#5700) * [ACA-3271] START PROCESS button is inactive first time when process model is loaded * Fixed lint error * Fixed failing unit tests --- .../start-process-cloud.component.spec.ts | 61 ++++++++++--------- .../start-process-cloud.component.ts | 5 +- .../mock/start-process.component.mock.ts | 12 ++++ 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts index 25d54e4712..dd8963578d 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts @@ -38,7 +38,8 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid, fakeProcessInstance, fakeNoNameProcessDefinitions, - fakeSingleProcessDefinition, fakeCreatedProcessInstance + fakeSingleProcessDefinition, fakeCreatedProcessInstance, + fakeSingleProcessDefinitionWithoutForm } from '../mock/start-process.component.mock'; import { By } from '@angular/platform-browser'; import { ProcessPayloadCloud } from '../models/process-payload-cloud.model'; @@ -112,12 +113,20 @@ describe('StartProcessCloudComponent', () => { describe('start a process without start form', () => { - it('should create a process instance if the selection is valid', fakeAsync(() => { - component.name = 'testFormWithProcess'; - component.processDefinitionName = 'processwithoutform2'; - getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName))); + beforeEach(() => { + component.name = 'My new process'; + component.appName = 'myApp'; + fixture.detectChanges(); + const change = new SimpleChange(null, 'MyApp', true); + component.ngOnChanges({ 'appName': change }); + fixture.detectChanges(); + }); + + it('should be able to start a process with a valid process name and process definition', fakeAsync(() => { + component.name = 'My new process'; + component.processDefinitionName = 'processwithoutform2'; + getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinitionWithoutForm(component.processDefinitionName))); fixture.detectChanges(); - formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm)); const change = new SimpleChange(null, 'MyApp', true); component.ngOnChanges({ 'appName': change }); @@ -126,35 +135,30 @@ describe('StartProcessCloudComponent', () => { fixture.whenStable().then(() => { fixture.detectChanges(); - const firstNameEl = fixture.nativeElement.querySelector('#firstName'); - expect(firstNameEl).toBeDefined(); - const lastNameEl = fixture.nativeElement.querySelector('#lastName'); - expect(lastNameEl).toBeDefined(); const startBtn = fixture.nativeElement.querySelector('#button-start'); - expect(component.formCloud.isValid).toBe(true); + expect(component.isProcessFormValid()).toBe(true); expect(startBtn.disabled).toBe(false); }); })); - it('should be able to start a process with a valid process name and process definition', async(() => { - component.name = 'My new process'; - component.processDefinitionName = 'processwithoutform2'; - fixture.detectChanges(); + it('should create a process instance if the selection is valid', async(() => { - const change = new SimpleChange(null, 'MyApp', true); - component.ngOnChanges({ 'appName': change }); - fixture.detectChanges(); + getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions)); + component.name = 'My new process'; + component.processDefinitionName = 'process'; + selectOptionByName('process'); fixture.whenStable().then(() => { + expect(component.processDefinitionCurrent.name).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[1])).name); const startBtn = fixture.nativeElement.querySelector('#button-start'); - expect(startBtn.disabled).toBe(false); expect(component.isProcessFormValid()).toBe(true); + expect(startBtn.disabled).toBe(false); }); })); it('should have start button disabled if create operation failed', fakeAsync(() => { createProcessSpy.and.returnValue(throwError('fake error')); - const change = new SimpleChange(null, 'MyApp', true); + const change = new SimpleChange(null, 'MyApp', false); fixture.detectChanges(); component.ngOnChanges({ 'appName': change }); @@ -179,10 +183,6 @@ describe('StartProcessCloudComponent', () => { component.processDefinitionName = ''; fixture.detectChanges(); - const change = new SimpleChange(null, 'MyApp', true); - component.ngOnChanges({ 'appName': change }); - fixture.detectChanges(); - fixture.whenStable().then(() => { const startBtn = fixture.nativeElement.querySelector('#button-start'); expect(startBtn.disabled).toBe(true); @@ -195,10 +195,6 @@ describe('StartProcessCloudComponent', () => { component.processDefinitionName = 'processwithoutform2'; fixture.detectChanges(); - const change = new SimpleChange(null, 'MyApp', true); - component.ngOnChanges({ 'appName': change }); - fixture.detectChanges(); - fixture.whenStable().then(() => { const startBtn = fixture.nativeElement.querySelector('#button-start'); expect(startBtn.disabled).toBe(true); @@ -301,7 +297,7 @@ describe('StartProcessCloudComponent', () => { }); })); - it('should NOT be able to start a process with a prefilled NOT valid form', async(() => { + it('should NOT be able to start a process with a prefilled NOT valid form', fakeAsync(() => { component.processDefinitionName = 'processwithform'; getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName))); component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, { @@ -315,7 +311,14 @@ describe('StartProcessCloudComponent', () => { component.ngOnChanges({ 'appName': change }); fixture.detectChanges(); + tick(); + typeValueInto('#processName', 'My new process with form'); + typeValueInto('#processDefinitionName', 'processwithform'); + fixture.detectChanges(); + tick(4500); + fixture.whenStable().then(() => { + fixture.detectChanges(); expect(formDefinitionSpy).toHaveBeenCalled(); const firstNameEl = fixture.nativeElement.querySelector('#firstName'); expect(firstNameEl).toBeDefined(); diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts index e938277009..68637c5ce7 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts @@ -223,10 +223,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy private selectDefaultProcessDefinition() { const selectedProcess = this.getProcessDefinitionByName(this.processDefinitionName); if (selectedProcess) { - this.processDefinitionCurrent = selectedProcess; - this.isFormCloudLoaded = false; this.processDefinition.setValue(selectedProcess.name); - this.processPayloadCloud.processDefinitionKey = selectedProcess.key; } } @@ -241,6 +238,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy this.processDefinitionList = processDefinitionRepresentations; if (processDefinitionRepresentations.length === 1) { this.selectDefaultProcessDefinition(); + } else if (this.processDefinitionName) { + this.processDefinition.setValue(this.processDefinitionName); } }, () => { diff --git a/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts b/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts index bf0d6976c7..eaa2bf4652 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts @@ -88,6 +88,18 @@ export function fakeSingleProcessDefinition(name: string): ProcessDefinitionClou ]; } +export function fakeSingleProcessDefinitionWithoutForm(name: string): ProcessDefinitionCloud[] { + return [ + new ProcessDefinitionCloud({ + appName: 'startformwithoutupload', + formKey: '', + id: 'd00c0237-8772-11e9-859a-428f83d5904f', + key: 'process-5151ad1d-f992-4ee6-9742-3a04617469fe', + name: name + }) + ]; +} + export let fakeNoNameProcessDefinitions: ProcessDefinitionCloud[] = [ new ProcessDefinitionCloud({ appName: 'myApp',