[ACA-3881] Able to start form with preselected ACS nodes (#6700)

* Move the node to ps before loading

* Add unit test on start process with preseleted nodes

* Fix unit test

* Wrap calls and improve if

* Add type
This commit is contained in:
Maurizio Vitale
2021-02-19 13:25:03 +00:00
committed by GitHub
parent e96617a676
commit 75f011292e
6 changed files with 261 additions and 17 deletions

View File

@@ -1011,3 +1011,217 @@ export let startMockFormWithTab = {
gridsterForm: false,
globalDateFormat: 'D - M - YYYY'
};
export const taskFormSingleUploadMock = {
id: 4,
name: 'Translation request',
processDefinitionId: 'TranslationProcess:2:8',
processDefinitionName: 'Translation Process',
processDefinitionKey: 'TranslationProcess',
taskId: '91',
taskDefinitionKey: 'sid-DDECD9E4-0299-433F-9193-C3D905C3EEBE',
tabs: [],
fields: [
{
fieldType: 'ContainerRepresentation',
id: '1582747052793',
name: 'Label',
type: 'container',
value: null,
required: false,
readOnly: false,
overrideId: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
minValue: null,
maxValue: null,
regexPattern: null,
optionType: null,
hasEmptyValue: null,
options: null,
restUrl: null,
restResponsePath: null,
restIdProperty: null,
restLabelProperty: null,
tab: null,
className: null,
dateDisplayFormat: null,
layout: null,
sizeX: 2,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null,
numberOfColumns: 2,
fields: {
'1': [
{
fieldType: 'AttachFileFieldRepresentation',
id: 'fake-single-upload',
name: 'Attach file - single type',
type: 'upload',
value: null,
required: false,
readOnly: false,
overrideId: false,
colspan: 1,
params: {
existingColspan: 1,
maxColspan: 2,
fileSource: {
serviceId: 'all-file-sources',
name: 'All file sources'
},
link: true
},
visibilityCondition: null
}
]
}
}
],
outcomes: [],
javascriptEvents: [],
className: '',
style: '',
customFieldTemplates: {},
metadata: {},
variables: [],
customFieldsValueInfo: {},
gridsterForm: false,
globalDateFormat: 'D-M-YYYY'
};
export const taskFormMultipleUploadMock = {
id: 4,
name: 'Translation request',
processDefinitionId: 'TranslationProcess:2:8',
processDefinitionName: 'Translation Process',
processDefinitionKey: 'TranslationProcess',
taskId: '91',
taskDefinitionKey: 'sid-DDECD9E4-0299-433F-9193-C3D905C3EEBE',
tabs: [],
fields: [
{
fieldType: 'ContainerRepresentation',
id: '1582747052793',
name: 'Label',
type: 'container',
value: null,
required: false,
readOnly: false,
overrideId: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
minValue: null,
maxValue: null,
regexPattern: null,
optionType: null,
hasEmptyValue: null,
options: null,
restUrl: null,
restResponsePath: null,
restIdProperty: null,
restLabelProperty: null,
tab: null,
className: null,
dateDisplayFormat: null,
layout: null,
sizeX: 2,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null,
numberOfColumns: 2,
fields: {
'1': [
{
fieldType: 'AttachFileFieldRepresentation',
id: 'fake-multiple-upload',
name: 'Attach file - multiple type',
type: 'upload',
value: null,
required: false,
readOnly: false,
overrideId: false,
colspan: 1,
params: {
existingColspan: 1,
maxColspan: 2,
fileSource: {
serviceId: 'all-file-sources',
name: 'All file sources'
},
link: true,
multiple: true
},
visibilityCondition: null
}
]
}
}
],
outcomes: [],
javascriptEvents: [],
className: '',
style: '',
customFieldTemplates: {},
metadata: {},
variables: [],
customFieldsValueInfo: {},
gridsterForm: false,
globalDateFormat: 'D-M-YYYY'
};
export const preselectedSingleNode = {
'fake-single-upload': [
{
id: 1027,
name: 'fake-file.docx',
relatedContent: false,
contentAvailable: true,
link: true,
source: 'alfresco-1-adw-contentAlfresco',
sourceId: '4a440e8f-7fe5-4d83-a042-a19ee10125fb;2.0@',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
simpleType: 'word',
previewStatus: 'queued',
thumbnailStatus: 'queued'
}
]
};
export const preselectedMultipleeNode = {
'fake-multiple-upload': [
{
id: 1027,
name: 'fake-file.docx',
relatedContent: false,
contentAvailable: true,
link: true,
source: 'alfresco-1-adw-contentAlfresco',
sourceId: '4a440e8f-7fe5-4d83-a042-a19ee10125fb;2.0@',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
simpleType: 'word',
previewStatus: 'queued',
thumbnailStatus: 'queued'
},
{
id: 1028,
name: 'fake-file2.docx',
relatedContent: false,
contentAvailable: true,
link: true,
source: 'alfresco-1-adw-contentAlfresco',
sourceId: '4a440e8f-7fe5-4d83-a042-a19ee10125fb;2.0@',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
simpleType: 'word',
previewStatus: 'queued',
thumbnailStatus: 'queued'
}
]
};

View File

@@ -21,7 +21,8 @@ import { of, throwError } from 'rxjs';
import {
startFormDateWidgetMock, startFormDropdownDefinitionMock,
startFormTextDefinitionMock, startMockForm, startMockFormWithTab,
startFormAmountWidgetMock, startFormNumberWidgetMock, startFormRadioButtonWidgetMock
startFormAmountWidgetMock, startFormNumberWidgetMock, startFormRadioButtonWidgetMock,
taskFormSingleUploadMock, taskFormMultipleUploadMock, preselectedSingleNode, preselectedMultipleeNode
} from './start-form.component.mock';
import { StartFormComponent } from './start-form.component';
import { FormService, WidgetVisibilityService, setupTestBed, FormModel, FormOutcomeModel } from '@alfresco/adf-core';
@@ -93,6 +94,26 @@ describe('StartFormComponent', () => {
expect(formService.getStartFormDefinition).not.toHaveBeenCalled();
});
it('should be able to inject sigle file as value into the form with an upload single widget', () => {
getStartFormSpy.and.returnValue(of(taskFormSingleUploadMock));
component.data = preselectedSingleNode;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId1, true) });
expect(component.form.getFieldById('fake-single-upload').value).toBeDefined();
expect(component.form.getFieldById('fake-single-upload').value.length).toBe(1);
expect(component.form.getFieldById('fake-single-upload').value).toBe(preselectedSingleNode['fake-single-upload']);
});
it('should be able to inject multiple files as value into the form with an upload multiple widget', () => {
getStartFormSpy.and.returnValue(of(taskFormMultipleUploadMock));
component.data = preselectedMultipleeNode;
component.ngOnChanges({ processDefinitionId: new SimpleChange(exampleId1, exampleId1, true) });
expect(component.form.getFieldById('fake-multiple-upload').value).toBeDefined();
expect(component.form.getFieldById('fake-multiple-upload').value.length).toBe(2);
expect(component.form.getFieldById('fake-multiple-upload').value).toBe(preselectedMultipleeNode['fake-multiple-upload']);
});
it('should consume errors encountered when loading start form', () => {
getStartFormSpy.and.returnValue(throwError({}));
component.processDefinitionId = exampleId1;

View File

@@ -84,6 +84,12 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
return;
}
const data = changes['data'];
if (data && data.currentValue) {
this.parseRefreshVisibilityValidateForm(this.form.json);
return;
}
const processId = changes['processId'];
if (processId && processId.currentValue) {
this.visibilityService.cleanProcessVariable();
@@ -103,11 +109,7 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
if (instance.variables) {
form.processVariables = instance.variables;
}
this.form = this.parseForm(form);
this.visibilityService.refreshVisibility(this.form);
this.form.validateForm();
this.form.readOnly = this.readOnlyForm;
this.onFormLoaded(this.form);
this.parseRefreshVisibilityValidateForm(form);
},
(error) => this.handleError(error)
);
@@ -120,16 +122,20 @@ export class StartFormComponent extends FormComponent implements OnChanges, OnIn
.subscribe(
(form) => {
this.formName = form.processDefinitionName;
this.form = this.parseForm(form);
this.visibilityService.refreshVisibility(this.form);
this.form.validateForm();
this.form.readOnly = this.readOnlyForm;
this.onFormLoaded(this.form);
this.parseRefreshVisibilityValidateForm(form);
},
(error) => this.handleError(error)
);
}
parseRefreshVisibilityValidateForm(form) {
this.form = this.parseForm(form);
this.visibilityService.refreshVisibility(this.form);
this.form.validateForm();
this.form.readOnly = this.readOnlyForm;
this.onFormLoaded(this.form);
}
/** @override */
isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean {
if (outcome && outcome.isSystem && (outcome.name === FormOutcomeModel.SAVE_ACTION ||

View File

@@ -81,7 +81,7 @@
<ng-container *ngIf="hasStartForm(); else noStartFormTemplate">
<adf-start-form
#startForm
[data]="values"
[data]="movedNodeToPS"
[disableStartProcessButton]="processNameInput.invalid"
[processDefinitionId]="selectedProcessDef.id"
(outcomeClick)="onOutcomeClick($event)"

View File

@@ -241,7 +241,7 @@ describe('StartFormComponent', () => {
component.moveNodeFromCStoPS();
fixture.whenStable().then(() => {
expect(component.values.file[0].id).toBe(1234);
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalled();
});
}));
@@ -266,9 +266,9 @@ describe('StartFormComponent', () => {
component.moveNodeFromCStoPS();
fixture.whenStable().then(() => {
expect(component.values.file.length).toBe(3);
expect(component.values.file[0].id).toBe(1234);
expect(component.values.file[1].id).toBe(1234);
expect(component.movedNodeToPS.file.length).toBe(3);
expect(component.movedNodeToPS.file[0].id).toBe(1234);
expect(component.movedNodeToPS.file[1].id).toBe(1234);
expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3);
});
}));

View File

@@ -127,6 +127,7 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
isProcessDefinitionsLoading = true;
isAppsLoading = true;
movedNodeToPS: FormValues;
private onDestroy$ = new Subject<boolean>();
constructor(private activitiProcess: ProcessService,
@@ -364,7 +365,9 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
const currentValue = Array.isArray(this.values[key]) ? this.values[key] : [this.values[key]];
const contents = currentValue.filter((value: any) => value && value.isFile)
.map((content: MinimalNode) => this.activitiContentService.applyAlfrescoNode(content, null, accountIdentifier));
forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => this.values[key] = [...res] );
forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => {
this.movedNodeToPS = { [key]: [...res]};
});
}
}
}