mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-459] ProcessCloud - set process definition pre-filled value for one result only (#5277)
* [AAE-459] ProcessCloud - disable process definition pre-fill * refactor e2e test
This commit is contained in:
committed by
Eugenio Romano
parent
7d52449cad
commit
31e1fd8875
@@ -26,7 +26,7 @@ import { StartProcessCloudComponent } from './start-process-cloud.component';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
|
||||
import { ProcessCloudModule } from '../../process-cloud.module';
|
||||
import { fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid,
|
||||
fakeProcessInstance, fakeProcessPayload, fakeNoNameProcessDefinitions } from '../mock/start-process.component.mock';
|
||||
fakeProcessInstance, fakeProcessPayload, fakeNoNameProcessDefinitions, fakeSingleProcessDefinition } from '../mock/start-process.component.mock';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
describe('StartProcessCloudComponent', () => {
|
||||
@@ -37,6 +37,7 @@ describe('StartProcessCloudComponent', () => {
|
||||
let formCloudService: FormCloudService;
|
||||
let getDefinitionsSpy: jasmine.Spy;
|
||||
let startProcessSpy: jasmine.Spy;
|
||||
let formDefinitionSpy: jasmine.Spy;
|
||||
|
||||
const selectOptionByName = (name: string) => {
|
||||
|
||||
@@ -133,8 +134,9 @@ describe('StartProcessCloudComponent', () => {
|
||||
|
||||
it('should be able to start a process with a valid form', async(() => {
|
||||
component.processDefinitionName = 'processwithform';
|
||||
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
||||
fixture.detectChanges();
|
||||
getDefinitionsSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm));
|
||||
formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm));
|
||||
|
||||
const change = new SimpleChange(null, 'MyApp', true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
@@ -153,8 +155,9 @@ describe('StartProcessCloudComponent', () => {
|
||||
|
||||
it('should NOT be able to start a process with a form NOT valid', async(() => {
|
||||
component.processDefinitionName = 'processwithform';
|
||||
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
||||
fixture.detectChanges();
|
||||
getDefinitionsSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartFormNotValid));
|
||||
formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartFormNotValid));
|
||||
|
||||
const change = new SimpleChange(null, 'MyApp', true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
@@ -173,9 +176,10 @@ describe('StartProcessCloudComponent', () => {
|
||||
|
||||
it('should be able to start a process with a prefilled valid form', async(() => {
|
||||
component.processDefinitionName = 'processwithform';
|
||||
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
||||
component.values = [{'name': 'firstName', 'value': 'FakeName'}, {'name': 'lastName', 'value': 'FakeLastName'}];
|
||||
fixture.detectChanges();
|
||||
getDefinitionsSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm));
|
||||
formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm));
|
||||
|
||||
const change = new SimpleChange(null, 'MyApp', true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
@@ -196,15 +200,17 @@ describe('StartProcessCloudComponent', () => {
|
||||
|
||||
it('should NOT be able to start a process with a prefilled NOT valid form', async(() => {
|
||||
component.processDefinitionName = 'processwithform';
|
||||
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
|
||||
component.values = [{'name': 'firstName', 'value': 'FakeName'}, {'name': 'lastName', 'value': 'FakeLastName'}];
|
||||
fixture.detectChanges();
|
||||
getDefinitionsSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartFormNotValid));
|
||||
formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartFormNotValid));
|
||||
|
||||
const change = new SimpleChange(null, 'MyApp', true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(formDefinitionSpy).toHaveBeenCalled();
|
||||
const firstNameEl = fixture.nativeElement.querySelector('#firstName');
|
||||
expect(firstNameEl).toBeDefined();
|
||||
expect(firstNameEl.value).toEqual('FakeName');
|
||||
@@ -295,20 +301,6 @@ describe('StartProcessCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should select processDefinition based on processDefinition input', async(() => {
|
||||
component.name = 'My new process';
|
||||
component.processDefinitionName = 'processwithoutform1';
|
||||
fixture.detectChanges();
|
||||
|
||||
const change = new SimpleChange(null, 'MyApp', true);
|
||||
component.ngOnChanges({ 'appName': change });
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.processPayloadCloud.processDefinitionKey).toBe(JSON.parse(JSON.stringify(fakeProcessDefinitions[0])).key);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should select automatically the processDefinition if the app contain only one', async(() => {
|
||||
getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([fakeProcessDefinitions[0]]));
|
||||
const change = new SimpleChange('myApp', 'myApp1', true);
|
||||
@@ -429,6 +421,16 @@ describe('StartProcessCloudComponent', () => {
|
||||
tick(3000);
|
||||
expect(component.filteredProcesses.length).toEqual(1);
|
||||
}));
|
||||
|
||||
it('should display the process definion field as empty if are more than one process definition in the list', async(() => {
|
||||
getDefinitionsSpy.and.returnValue(of(fakeProcessDefinitions));
|
||||
component.ngOnChanges({ appName: change });
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const processDefinitionInput = fixture.nativeElement.querySelector('#processDefinitionName');
|
||||
expect(processDefinitionInput.textContent).toEqual('');
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('start process', () => {
|
||||
|
@@ -179,7 +179,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe((processDefinitionRepresentations: ProcessDefinitionCloud[]) => {
|
||||
this.processDefinitionList = processDefinitionRepresentations;
|
||||
if (processDefinitionRepresentations.length > 0) {
|
||||
if (processDefinitionRepresentations.length === 1) {
|
||||
this.selectDefaultProcessDefinition();
|
||||
}
|
||||
},
|
||||
|
@@ -64,6 +64,18 @@ export let fakeProcessDefinitions: ProcessDefinitionCloud[] = [
|
||||
})
|
||||
];
|
||||
|
||||
export function fakeSingleProcessDefinition(name: string): ProcessDefinitionCloud[] {
|
||||
return [
|
||||
new ProcessDefinitionCloud({
|
||||
appName: 'startformwithoutupload',
|
||||
formKey: 'form-a5d50817-5183-4850-802d-17af54b2632f',
|
||||
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