mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +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 {
|
||||
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();
|
||||
|
@@ -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);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
|
@@ -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',
|
||||
|
Reference in New Issue
Block a user