From 7013918d355d4c5d4f027f7bb7b7e7dc46411e5a Mon Sep 17 00:00:00 2001 From: Will Abson Date: Fri, 18 Nov 2016 14:00:33 +0000 Subject: [PATCH] Add additional tests for start button state Refs #1066 --- .../activiti-start-process.component.spec.ts | 22 ++++++++++++------- .../activiti-start-process.component.ts | 7 ++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.spec.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.spec.ts index 09ca27a8b0..77920d296a 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.spec.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.spec.ts @@ -212,6 +212,8 @@ describe('ActivitiStartProcessButton', () => { describe('start forms', () => { + let startBtn; + describe('without start form', () => { beforeEach(async(() => { @@ -220,15 +222,23 @@ describe('ActivitiStartProcessButton', () => { fixture.detectChanges(); component.onProcessDefChange('my:process1'); fixture.whenStable(); + startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]')); })); - it('should indicate start form is missing', async(() => { - expect(component.isStartFormMissingOrValid()).toBe(true); + it('should have start button disabled when name not filled out', async(() => { + component.name = ''; + fixture.detectChanges(); + expect(startBtn.properties['disabled']).toBe(true); + })); + + it('should have start button disabled when name not filled out', async(() => { + component.onProcessDefChange(''); + fixture.detectChanges(); + expect(startBtn.properties['disabled']).toBe(true); })); it('should enable start button when name and process filled out', async(() => { fixture.detectChanges(); - let startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]')); expect(startBtn.properties['disabled']).toBe(false); })); @@ -243,6 +253,7 @@ describe('ActivitiStartProcessButton', () => { component.onProcessDefChange('my:process1'); fixture.detectChanges(); fixture.whenStable(); + startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]')); }); it('should initialize start form', () => { @@ -254,14 +265,9 @@ describe('ActivitiStartProcessButton', () => { expect(getStartFormDefinitionSpy).toHaveBeenCalled(); }); - it('should indicate start form is invalid', async(() => { - expect(component.isStartFormMissingOrValid()).toBe(false); - })); - it('should leave start button disabled when mandatory fields not filled out', async(() => { component.name = 'My new process'; fixture.detectChanges(); - let startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]')); expect(startBtn.properties['disabled']).toBe(true); })); diff --git a/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts b/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts index abc7bcdd3d..7a87a6b6be 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/activiti-start-process.component.ts @@ -120,8 +120,11 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges { let processDef = this.processDefinitions.find((processDefinition) => { return processDefinition.id === processDefinitionId; }); - let clone = JSON.parse(JSON.stringify(processDef)); - this.currentProcessDef = clone; + if (processDef) { + this.currentProcessDef = JSON.parse(JSON.stringify(processDef)); + } else { + this.resetSelectedProcessDefinition(); + } } hasStartForm() {