mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-8929] Get start event form static inputs (#7652)
* [AAE-8929] Get start event form static inputs * [AAE-8929] Fix tests
This commit is contained in:
committed by
GitHub
parent
4457aed5b4
commit
243803d4d3
@@ -843,5 +843,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultProject": "demoshell"
|
"defaultProject": "demoshell",
|
||||||
}
|
"cli": {
|
||||||
|
"analytics": false
|
||||||
|
}
|
||||||
|
}
|
@@ -64,7 +64,7 @@
|
|||||||
<adf-cloud-form
|
<adf-cloud-form
|
||||||
[appName]="appName"
|
[appName]="appName"
|
||||||
[appVersion]="processDefinitionCurrent.appVersion"
|
[appVersion]="processDefinitionCurrent.appVersion"
|
||||||
[data]="values"
|
[data]="resolvedValues"
|
||||||
[formId]="processDefinitionCurrent.formKey"
|
[formId]="processDefinitionCurrent.formKey"
|
||||||
[showSaveButton]="false"
|
[showSaveButton]="false"
|
||||||
[showCompleteButton]="false"
|
[showCompleteButton]="false"
|
||||||
|
@@ -44,7 +44,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
import { ProcessNameCloudPipe } from '../../../pipes/process-name-cloud.pipe';
|
import { ProcessNameCloudPipe } from '../../../pipes/process-name-cloud.pipe';
|
||||||
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
||||||
import { ESCAPE } from '@angular/cdk/keycodes';
|
import { ESCAPE } from '@angular/cdk/keycodes';
|
||||||
import { ProcessDefinitionCloud } from 'process-services-cloud';
|
import { ProcessDefinitionCloud, TaskVariableCloud } from 'process-services-cloud';
|
||||||
|
|
||||||
describe('StartProcessCloudComponent', () => {
|
describe('StartProcessCloudComponent', () => {
|
||||||
|
|
||||||
@@ -56,6 +56,7 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
let startProcessSpy: jasmine.Spy;
|
let startProcessSpy: jasmine.Spy;
|
||||||
let createProcessSpy: jasmine.Spy;
|
let createProcessSpy: jasmine.Spy;
|
||||||
let formDefinitionSpy: jasmine.Spy;
|
let formDefinitionSpy: jasmine.Spy;
|
||||||
|
let getStartEventFormStaticValuesMappingSpy: jasmine.Spy;
|
||||||
|
|
||||||
const firstChange = new SimpleChange(undefined, 'myApp', true);
|
const firstChange = new SimpleChange(undefined, 'myApp', true);
|
||||||
|
|
||||||
@@ -106,6 +107,7 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
spyOn(processService, 'updateProcess').and.returnValue(of());
|
spyOn(processService, 'updateProcess').and.returnValue(of());
|
||||||
startProcessSpy = spyOn(processService, 'startCreatedProcess').and.returnValue(of(fakeProcessInstance));
|
startProcessSpy = spyOn(processService, 'startCreatedProcess').and.returnValue(of(fakeProcessInstance));
|
||||||
createProcessSpy = spyOn(processService, 'createProcess').and.returnValue(of(fakeCreatedProcessInstance));
|
createProcessSpy = spyOn(processService, 'createProcess').and.returnValue(of(fakeCreatedProcessInstance));
|
||||||
|
getStartEventFormStaticValuesMappingSpy = spyOn(processService, 'getStartEventFormStaticValuesMapping').and.returnValue(of([]));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -202,6 +204,34 @@ describe('StartProcessCloudComponent', () => {
|
|||||||
expect(startBtn.disabled).toBe(true);
|
expect(startBtn.disabled).toBe(true);
|
||||||
expect(component.isProcessFormValid()).toBe(false);
|
expect(component.isProcessFormValid()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include the static input mappings in the resolved values', fakeAsync(() => {
|
||||||
|
const values: TaskVariableCloud[] = [
|
||||||
|
new TaskVariableCloud({name: 'value1', value: 'value'}),
|
||||||
|
new TaskVariableCloud({name: 'value2', value: 1}),
|
||||||
|
new TaskVariableCloud({name: 'value3', value: false})
|
||||||
|
];
|
||||||
|
const staticInputs: TaskVariableCloud[] = [
|
||||||
|
new TaskVariableCloud({name: 'static1', value: 'static value'}),
|
||||||
|
new TaskVariableCloud({name: 'static2', value: 0}),
|
||||||
|
new TaskVariableCloud({name: 'static3', value: true})
|
||||||
|
];
|
||||||
|
component.name = 'My new process';
|
||||||
|
component.processDefinitionName = 'processwithoutform2';
|
||||||
|
component.values = values;
|
||||||
|
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinitionWithoutForm(component.processDefinitionName)));
|
||||||
|
getStartEventFormStaticValuesMappingSpy.and.returnValue(of(staticInputs));
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const change = new SimpleChange(null, 'MyApp', true);
|
||||||
|
component.ngOnChanges({ appName: change });
|
||||||
|
fixture.detectChanges();
|
||||||
|
tick(550);
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(component.resolvedValues).toEqual(staticInputs.concat(values));
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('start a process with start form', () => {
|
describe('start a process with start form', () => {
|
||||||
|
@@ -109,6 +109,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
formCloud: FormModel;
|
formCloud: FormModel;
|
||||||
currentCreatedProcess: ProcessInstanceCloud;
|
currentCreatedProcess: ProcessInstanceCloud;
|
||||||
disableStartButton: boolean = true;
|
disableStartButton: boolean = true;
|
||||||
|
staticMappings: TaskVariableCloud[] = [];
|
||||||
|
resolvedValues: TaskVariableCloud[];
|
||||||
|
|
||||||
protected onDestroy$ = new Subject<boolean>();
|
protected onDestroy$ = new Subject<boolean>();
|
||||||
processDefinitionLoaded = false;
|
processDefinitionLoaded = false;
|
||||||
@@ -153,6 +155,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
this.loadProcessDefinitions();
|
this.loadProcessDefinitions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changes['values'] && changes['values'].currentValue !== changes['values'].previousValue) {
|
||||||
|
this.resolvedValues = this.staticMappings.concat(this.values || []);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('keydown', ['$event'])
|
@HostListener('keydown', ['$event'])
|
||||||
@@ -203,6 +209,15 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
this.processDefinitionCurrent = this.filteredProcesses.find((process: ProcessDefinitionCloud) =>
|
this.processDefinitionCurrent = this.filteredProcesses.find((process: ProcessDefinitionCloud) =>
|
||||||
process.name === selectedProcessDefinitionName || process.key === selectedProcessDefinitionName);
|
process.name === selectedProcessDefinitionName || process.key === selectedProcessDefinitionName);
|
||||||
|
|
||||||
|
this.startProcessCloudService.getStartEventFormStaticValuesMapping(this.appName, this.processDefinitionCurrent.id)
|
||||||
|
.subscribe(
|
||||||
|
staticMappings => {
|
||||||
|
this.staticMappings = staticMappings;
|
||||||
|
this.resolvedValues = this.staticMappings.concat(this.values || []);
|
||||||
|
},
|
||||||
|
() => this.resolvedValues = this.values
|
||||||
|
);
|
||||||
|
|
||||||
this.isFormCloudLoaded = false;
|
this.isFormCloudLoaded = false;
|
||||||
this.processPayloadCloud.processDefinitionKey = this.processDefinitionCurrent.key;
|
this.processPayloadCloud.processDefinitionKey = this.processDefinitionCurrent.key;
|
||||||
}
|
}
|
||||||
|
@@ -156,4 +156,30 @@ describe('StartProcessCloudService', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should transform the response into task variables', (done) => {
|
||||||
|
const appName = 'test-app';
|
||||||
|
const processDefinitionId = 'processDefinitionId';
|
||||||
|
const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi']);
|
||||||
|
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true }));
|
||||||
|
spyOn(alfrescoApiService, 'getInstance').and.returnValue({
|
||||||
|
oauth2Auth
|
||||||
|
});
|
||||||
|
|
||||||
|
service.getStartEventFormStaticValuesMapping(appName, processDefinitionId).subscribe((result) => {
|
||||||
|
expect(result.length).toEqual(3);
|
||||||
|
expect(result[0].name).toEqual('static1');
|
||||||
|
expect(result[0].id).toEqual('static1');
|
||||||
|
expect(result[0].value).toEqual('value');
|
||||||
|
expect(result[1].name).toEqual('static2');
|
||||||
|
expect(result[1].id).toEqual('static2');
|
||||||
|
expect(result[1].value).toEqual(0);
|
||||||
|
expect(result[2].name).toEqual('static3');
|
||||||
|
expect(result[2].id).toEqual('static3');
|
||||||
|
expect(result[2].value).toEqual(true);
|
||||||
|
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/rb/v1/process-definitions/${processDefinitionId}/static-values`)).toBeTruthy();
|
||||||
|
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -23,6 +23,7 @@ import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
|||||||
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
||||||
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
|
||||||
import { BaseCloudService } from '../../../services/base-cloud.service';
|
import { BaseCloudService } from '../../../services/base-cloud.service';
|
||||||
|
import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -126,4 +127,24 @@ export class StartProcessCloudService extends BaseCloudService {
|
|||||||
|
|
||||||
return this.delete(url);
|
return this.delete(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the static values mapped to the start form of a process definition.
|
||||||
|
*
|
||||||
|
* @param appName Name of the app
|
||||||
|
* @param processDefinitionId ID of the target process definition
|
||||||
|
* @returns Static mappings for the start event
|
||||||
|
*/
|
||||||
|
getStartEventFormStaticValuesMapping(appName: string, processDefinitionId: string): Observable<TaskVariableCloud[]> {
|
||||||
|
const apiUrl = `${this.getBasePath(appName)}/rb/v1/process-definitions/${processDefinitionId}/static-values`;
|
||||||
|
return this.get(apiUrl).pipe(
|
||||||
|
map((res: { [key: string]: any }) => {
|
||||||
|
const result = [];
|
||||||
|
if (res) {
|
||||||
|
Object.keys(res).forEach(mapping => result.push(new TaskVariableCloud({ name: mapping, value: res[mapping] })));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user