Add additional tests for start button state

Refs #1066
This commit is contained in:
Will Abson
2016-11-18 14:00:33 +00:00
committed by Mario Romano
parent ac4c31a1d0
commit 7013918d35
2 changed files with 19 additions and 10 deletions

View File

@@ -212,6 +212,8 @@ describe('ActivitiStartProcessButton', () => {
describe('start forms', () => { describe('start forms', () => {
let startBtn;
describe('without start form', () => { describe('without start form', () => {
beforeEach(async(() => { beforeEach(async(() => {
@@ -220,15 +222,23 @@ describe('ActivitiStartProcessButton', () => {
fixture.detectChanges(); fixture.detectChanges();
component.onProcessDefChange('my:process1'); component.onProcessDefChange('my:process1');
fixture.whenStable(); fixture.whenStable();
startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]'));
})); }));
it('should indicate start form is missing', async(() => { it('should have start button disabled when name not filled out', async(() => {
expect(component.isStartFormMissingOrValid()).toBe(true); 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(() => { it('should enable start button when name and process filled out', async(() => {
fixture.detectChanges(); fixture.detectChanges();
let startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]'));
expect(startBtn.properties['disabled']).toBe(false); expect(startBtn.properties['disabled']).toBe(false);
})); }));
@@ -243,6 +253,7 @@ describe('ActivitiStartProcessButton', () => {
component.onProcessDefChange('my:process1'); component.onProcessDefChange('my:process1');
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable(); fixture.whenStable();
startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]'));
}); });
it('should initialize start form', () => { it('should initialize start form', () => {
@@ -254,14 +265,9 @@ describe('ActivitiStartProcessButton', () => {
expect(getStartFormDefinitionSpy).toHaveBeenCalled(); 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(() => { it('should leave start button disabled when mandatory fields not filled out', async(() => {
component.name = 'My new process'; component.name = 'My new process';
fixture.detectChanges(); fixture.detectChanges();
let startBtn = debugElement.query(By.css('[data-automation-id="btn-start"]'));
expect(startBtn.properties['disabled']).toBe(true); expect(startBtn.properties['disabled']).toBe(true);
})); }));

View File

@@ -120,8 +120,11 @@ export class ActivitiStartProcessButton implements OnInit, OnChanges {
let processDef = this.processDefinitions.find((processDefinition) => { let processDef = this.processDefinitions.find((processDefinition) => {
return processDefinition.id === processDefinitionId; return processDefinition.id === processDefinitionId;
}); });
let clone = JSON.parse(JSON.stringify(processDef)); if (processDef) {
this.currentProcessDef = clone; this.currentProcessDef = JSON.parse(JSON.stringify(processDef));
} else {
this.resetSelectedProcessDefinition();
}
} }
hasStartForm() { hasStartForm() {