mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[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
This commit is contained in:
@@ -38,7 +38,8 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|||||||
import {
|
import {
|
||||||
fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid,
|
fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid,
|
||||||
fakeProcessInstance, fakeNoNameProcessDefinitions,
|
fakeProcessInstance, fakeNoNameProcessDefinitions,
|
||||||
fakeSingleProcessDefinition, fakeCreatedProcessInstance
|
fakeSingleProcessDefinition, fakeCreatedProcessInstance,
|
||||||
|
fakeSingleProcessDefinitionWithoutForm
|
||||||
} from '../mock/start-process.component.mock';
|
} from '../mock/start-process.component.mock';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
||||||
@@ -112,12 +113,20 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
|
|
||||||
describe('start a process without start form', () => {
|
describe('start a process without start form', () => {
|
||||||
|
|
||||||
it('should create a process instance if the selection is valid', fakeAsync(() => {
|
beforeEach(() => {
|
||||||
component.name = 'testFormWithProcess';
|
component.name = 'My new process';
|
||||||
component.processDefinitionName = 'processwithoutform2';
|
component.appName = 'myApp';
|
||||||
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
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();
|
fixture.detectChanges();
|
||||||
formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm));
|
|
||||||
|
|
||||||
const change = new SimpleChange(null, 'MyApp', true);
|
const change = new SimpleChange(null, 'MyApp', true);
|
||||||
component.ngOnChanges({ 'appName': change });
|
component.ngOnChanges({ 'appName': change });
|
||||||
@@ -126,35 +135,30 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
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');
|
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
||||||
expect(component.formCloud.isValid).toBe(true);
|
expect(component.isProcessFormValid()).toBe(true);
|
||||||
expect(startBtn.disabled).toBe(false);
|
expect(startBtn.disabled).toBe(false);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to start a process with a valid process name and process definition', async(() => {
|
it('should create a process instance if the selection is valid', async(() => {
|
||||||
component.name = 'My new process';
|
|
||||||
component.processDefinitionName = 'processwithoutform2';
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
const change = new SimpleChange(null, 'MyApp', true);
|
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions));
|
||||||
component.ngOnChanges({ 'appName': change });
|
component.name = 'My new process';
|
||||||
fixture.detectChanges();
|
component.processDefinitionName = 'process';
|
||||||
|
selectOptionByName('process');
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
|
expect(component.processDefinitionCurrent.name).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[1])).name);
|
||||||
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
||||||
expect(startBtn.disabled).toBe(false);
|
|
||||||
expect(component.isProcessFormValid()).toBe(true);
|
expect(component.isProcessFormValid()).toBe(true);
|
||||||
|
expect(startBtn.disabled).toBe(false);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should have start button disabled if create operation failed', fakeAsync(() => {
|
it('should have start button disabled if create operation failed', fakeAsync(() => {
|
||||||
createProcessSpy.and.returnValue(throwError('fake error'));
|
createProcessSpy.and.returnValue(throwError('fake error'));
|
||||||
const change = new SimpleChange(null, 'MyApp', true);
|
const change = new SimpleChange(null, 'MyApp', false);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.ngOnChanges({ 'appName': change });
|
component.ngOnChanges({ 'appName': change });
|
||||||
@@ -179,10 +183,6 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
component.processDefinitionName = '';
|
component.processDefinitionName = '';
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const change = new SimpleChange(null, 'MyApp', true);
|
|
||||||
component.ngOnChanges({ 'appName': change });
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
||||||
expect(startBtn.disabled).toBe(true);
|
expect(startBtn.disabled).toBe(true);
|
||||||
@@ -195,10 +195,6 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
component.processDefinitionName = 'processwithoutform2';
|
component.processDefinitionName = 'processwithoutform2';
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const change = new SimpleChange(null, 'MyApp', true);
|
|
||||||
component.ngOnChanges({ 'appName': change });
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
const startBtn = fixture.nativeElement.querySelector('#button-start');
|
||||||
expect(startBtn.disabled).toBe(true);
|
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';
|
component.processDefinitionName = 'processwithform';
|
||||||
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
||||||
component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, {
|
component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, {
|
||||||
@@ -315,7 +311,14 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
component.ngOnChanges({ 'appName': change });
|
component.ngOnChanges({ 'appName': change });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
tick();
|
||||||
|
typeValueInto('#processName', 'My new process with form');
|
||||||
|
typeValueInto('#processDefinitionName', 'processwithform');
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick(4500);
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
expect(formDefinitionSpy).toHaveBeenCalled();
|
expect(formDefinitionSpy).toHaveBeenCalled();
|
||||||
const firstNameEl = fixture.nativeElement.querySelector('#firstName');
|
const firstNameEl = fixture.nativeElement.querySelector('#firstName');
|
||||||
expect(firstNameEl).toBeDefined();
|
expect(firstNameEl).toBeDefined();
|
||||||
|
@@ -223,10 +223,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
private selectDefaultProcessDefinition() {
|
private selectDefaultProcessDefinition() {
|
||||||
const selectedProcess = this.getProcessDefinitionByName(this.processDefinitionName);
|
const selectedProcess = this.getProcessDefinitionByName(this.processDefinitionName);
|
||||||
if (selectedProcess) {
|
if (selectedProcess) {
|
||||||
this.processDefinitionCurrent = selectedProcess;
|
|
||||||
this.isFormCloudLoaded = false;
|
|
||||||
this.processDefinition.setValue(selectedProcess.name);
|
this.processDefinition.setValue(selectedProcess.name);
|
||||||
this.processPayloadCloud.processDefinitionKey = selectedProcess.key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,6 +238,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
this.processDefinitionList = processDefinitionRepresentations;
|
this.processDefinitionList = processDefinitionRepresentations;
|
||||||
if (processDefinitionRepresentations.length === 1) {
|
if (processDefinitionRepresentations.length === 1) {
|
||||||
this.selectDefaultProcessDefinition();
|
this.selectDefaultProcessDefinition();
|
||||||
|
} else if (this.processDefinitionName) {
|
||||||
|
this.processDefinition.setValue(this.processDefinitionName);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
|
@@ -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[] = [
|
export let fakeNoNameProcessDefinitions: ProcessDefinitionCloud[] = [
|
||||||
new ProcessDefinitionCloud({
|
new ProcessDefinitionCloud({
|
||||||
appName: 'myApp',
|
appName: 'myApp',
|
||||||
|
Reference in New Issue
Block a user