AAE-1938 - added first stack of visibility tests for form (#5489)

* AAE-1938 - added first stack of visibility tests for form

* AAE-1938 - fixed unit test after form service changes

* AAE-1938 - rebased with last development

* AAE-1938 - fixed failing e2e

* AAE-1938 - fixed mock definition to match updated service behaviour

* Fixed failing e2e

* AAE-1938 - try to fix cancel uploads
This commit is contained in:
Vito 2020-02-26 14:46:01 +00:00 committed by GitHub
parent 6ef07fe73f
commit 1e67f50346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 2578 additions and 1930 deletions

View File

@ -70,10 +70,21 @@ export class InMemoryFormService extends FormService {
parseForm(json: any, data?: FormValues, readOnly: boolean = false): FormModel {
if (json) {
const form = new FormModel(json, data, readOnly, this);
const flattenForm = {
...json.formRepresentation,
...json.formRepresentation.formDefinition
};
delete flattenForm.formDefinition;
const formValues: FormValues = {};
(data || []).forEach(variable => {
formValues[variable.name] = variable.value;
});
const form = new FormModel(flattenForm, formValues, readOnly, this);
if (!json.fields) {
form.outcomes = [
new FormOutcomeModel(form, {
new FormOutcomeModel(<any> form, {
id: '$save',
name: FormOutcomeModel.SAVE_ACTION,
isSystem: true

View File

@ -79,7 +79,7 @@ describe('Upload component', async () => {
it('[C272793] Should be able to cancel multiple files upload', async () => {
await uploadToggles.enableMultipleFileUpload();
await browser.executeScript(' setTimeout(() => {document.querySelector("#adf-upload-dialog-cancel-all").click();' +
'document.querySelector("#adf-upload-dialog-cancel").click(); }, 4000)');
'document.querySelector("#adf-upload-dialog-cancel").click(); }, 2500)');
await contentServicesPage.uploadMultipleFile([pngFileModel.location, largeFile.location]);
await expect(await uploadDialog.getTitleText()).toEqual('Upload canceled');
@ -92,7 +92,7 @@ describe('Upload component', async () => {
it('[C315257] Should be able to cancel file in upload queue', async () => {
await uploadToggles.enableMultipleFileUpload();
await browser.executeScript('setTimeout(() => {document.querySelector("button[data-automation-id=\'cancel-upload-queue\']").click();}, 2500)');
await browser.executeScript('setTimeout(() => {document.querySelector("button[data-automation-id=\'cancel-upload-queue\']").click();}, 3000)');
await contentServicesPage.uploadMultipleFile([largeFile.location, pngFileModel.location]);
await uploadDialog.fileIsCancelled(pngFileModel.name);
await uploadDialog.clickOnCloseButton();

View File

@ -17,108 +17,110 @@
/* tslint:disable */
export const customDateFormAPS1 = `{
"id": 18977,
"name": "APS1customDateFrom",
"description": "",
"version": 1,
"lastUpdatedBy": 1,
"lastUpdatedByFullName": " Administrator",
"lastUpdated": "2019-08-21T09:29:18.042+0000",
"stencilSetId": 0,
"referenceId": null,
"formDefinition": {
"tabs": [],
"fields": [
{
"fieldType": "ContainerRepresentation",
"id": "1566223482682",
"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": "FormFieldRepresentation",
"id": "datefield",
"name": "DateField",
"type": "date",
"value": null,
"required": false,
"readOnly": false,
"overrideId": false,
"colspan": 1,
"placeholder": null,
"minLength": 0,
"maxLength": 0,
"minValue": "19-7-2019",
"maxValue": "19-8-2019",
"regexPattern": null,
"optionType": null,
"hasEmptyValue": null,
"options": null,
"restUrl": null,
"restResponsePath": null,
"restIdProperty": null,
"restLabelProperty": null,
"tab": null,
"className": null,
"params": {
"existingColspan": 1,
"maxColspan": 2
},
"dateDisplayFormat": "YY-M-D",
"layout": {
"formRepresentation":{
"id": 18977,
"name": "APS1customDateFrom",
"description": "",
"version": 1,
"lastUpdatedBy": 1,
"lastUpdatedByFullName": " Administrator",
"lastUpdated": "2019-08-21T09:29:18.042+0000",
"stencilSetId": 0,
"referenceId": null,
"formDefinition": {
"tabs": [],
"fields": [
{
"fieldType": "ContainerRepresentation",
"id": "1566223482682",
"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": "FormFieldRepresentation",
"id": "datefield",
"name": "DateField",
"type": "date",
"value": null,
"required": false,
"readOnly": false,
"overrideId": false,
"colspan": 1,
"placeholder": null,
"minLength": 0,
"maxLength": 0,
"minValue": "19-7-2019",
"maxValue": "19-8-2019",
"regexPattern": null,
"optionType": null,
"hasEmptyValue": null,
"options": null,
"restUrl": null,
"restResponsePath": null,
"restIdProperty": null,
"restLabelProperty": null,
"tab": null,
"className": null,
"params": {
"existingColspan": 1,
"maxColspan": 2
},
"dateDisplayFormat": "YY-M-D",
"layout": {
"row": -1,
"column": -1,
"colspan": 1
},
"sizeX": 1,
"sizeY": 1,
"row": -1,
"column": -1,
"colspan": 1
},
"sizeX": 1,
"sizeY": 1,
"row": -1,
"col": -1,
"visibilityCondition": null
}
],
"2": []
"col": -1,
"visibilityCondition": null
}
],
"2": []
}
}
}
],
"outcomes": [],
"javascriptEvents": [],
"className": "",
"style": "",
"customFieldTemplates": {},
"metadata": {},
"variables": [],
"customFieldsValueInfo": {},
"gridsterForm": false
],
"outcomes": [],
"javascriptEvents": [],
"className": "",
"style": "",
"customFieldTemplates": {},
"metadata": {},
"variables": [],
"customFieldsValueInfo": {},
"gridsterForm": false
}
}
}`;

View File

@ -0,0 +1,194 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { FormRendererComponent } from './form-renderer.component';
import { FormBaseModule } from '../form-base.module';
import { formDisplayValueVisibility, formDisplayValueForm, formDisplayValueCombinedVisibility } from './mock/form-renderer.component.mock';
import { TranslationService } from 'core/services';
import { TranslationMock } from 'core/mock';
import { TranslateStore } from '@ngx-translate/core';
import { FormService } from '../services/form.service';
import { setupTestBed } from '../../testing/setup-test-bed';
function typeIntoInput(targetInput: HTMLInputElement, message: string ) {
expect(targetInput).not.toBeNull();
targetInput.value = message;
targetInput.dispatchEvent(new Event('input'));
}
function expectElementToBeHidden(targetElement: HTMLElement): void {
expect(targetElement).not.toBeNull();
expect(targetElement).toBeDefined();
expect(targetElement.hidden).toBe(true);
}
function expectElementToBeVisible(targetElement: HTMLElement): void {
expect(targetElement).not.toBeNull();
expect(targetElement).toBeDefined();
expect(targetElement.hidden).toBe(false);
}
function expectInputElementValueIs(targetElement: HTMLInputElement, value: string): void {
expect(targetElement).not.toBeNull();
expect(targetElement).toBeDefined();
expect(targetElement.value).toBe(value);
}
describe('Form Renderer Component', () => {
let formRendererComponent: FormRendererComponent;
let fixture: ComponentFixture<FormRendererComponent>;
let formService: FormService;
setupTestBed({
imports: [
NoopAnimationsModule,
FormBaseModule
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
TranslateStore
]
});
beforeEach(() => {
fixture = TestBed.createComponent(FormRendererComponent);
formRendererComponent = fixture.componentInstance;
formService = TestBed.get(FormService);
});
it('Should be able to see Display value widget when visibility condition refers to another field with specific value', async () => {
formRendererComponent.formDefinition = formService.parseForm(formDisplayValueVisibility);
fixture.detectChanges();
await fixture.whenStable();
let displayValueElementContainer: HTMLDivElement = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
const formInputText: HTMLInputElement = fixture.nativeElement.querySelector('#Text0bq3ar');
expectElementToBeHidden(displayValueElementContainer);
typeIntoInput(formInputText, 'DisplayValue');
fixture.detectChanges();
await fixture.whenStable();
displayValueElementContainer = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectElementToBeVisible(displayValueElementContainer);
const displayValueElement: HTMLInputElement = fixture.nativeElement.querySelector('#Displayvalue0g6092');
expectInputElementValueIs(displayValueElement, 'No field selected');
});
it('Should be able to see Display value widget when visibility condition refers to a form variable and a field', async () => {
formRendererComponent.formDefinition = formService.parseForm(formDisplayValueForm);
fixture.detectChanges();
await fixture.whenStable();
let displayValueElementContainer: HTMLDivElement = fixture.nativeElement.querySelector('#field-DisplayValueOne-container');
expectElementToBeHidden(displayValueElementContainer);
const formInputText: HTMLInputElement = fixture.nativeElement.querySelector('#Text0howrc');
typeIntoInput(formInputText, 'aaa');
fixture.detectChanges();
await fixture.whenStable();
displayValueElementContainer = fixture.nativeElement.querySelector('#field-DisplayValueOne-container');
expectElementToBeVisible(displayValueElementContainer);
const displayValueElement: HTMLInputElement = fixture.nativeElement.querySelector('#DisplayValueOne');
expectInputElementValueIs(displayValueElement, 'No field selected');
typeIntoInput(formInputText, 'aaab');
fixture.detectChanges();
await fixture.whenStable();
displayValueElementContainer = fixture.nativeElement.querySelector('#field-DisplayValueOne-container');
expectElementToBeHidden(displayValueElementContainer);
});
it('Should be able to see Display value widget when visibility condition refers to another field and form variable', async () => {
formRendererComponent.formDefinition = formService.parseForm(formDisplayValueForm);
fixture.detectChanges();
await fixture.whenStable();
let displayValueElementContainer: HTMLDivElement = fixture.nativeElement.querySelector('#field-DisplayValueVariableField-container');
expectElementToBeHidden(displayValueElementContainer);
const formInputText: HTMLInputElement = fixture.nativeElement.querySelector('#TextOne');
typeIntoInput(formInputText, 'aaa');
fixture.detectChanges();
await fixture.whenStable();
displayValueElementContainer = fixture.nativeElement.querySelector('#field-DisplayValueVariableField-container');
expectElementToBeVisible(displayValueElementContainer);
const displayValueElement: HTMLInputElement = fixture.nativeElement.querySelector('#DisplayValueVariableField');
expectInputElementValueIs(displayValueElement, 'No field selected');
typeIntoInput(formInputText, 'aaab');
fixture.detectChanges();
await fixture.whenStable();
displayValueElementContainer = fixture.nativeElement.querySelector('#field-DisplayValueVariableField-container');
expectElementToBeHidden(displayValueElementContainer);
});
it('Should be able to see Display value widget when has multiple visibility conditions and next condition operators', async () => {
formRendererComponent.formDefinition = formService.parseForm(formDisplayValueCombinedVisibility);
fixture.detectChanges();
await fixture.whenStable();
const textInputElement: HTMLInputElement = fixture.nativeElement.querySelector('#Text0bq3ar');
const textTwoInputElement: HTMLInputElement = fixture.nativeElement.querySelector('#TextTwo');
let displayValueHiddenContainer: HTMLDivElement = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectElementToBeVisible(textInputElement);
expectElementToBeVisible(textTwoInputElement);
expectElementToBeHidden(displayValueHiddenContainer);
typeIntoInput(textInputElement, 'aaa');
fixture.detectChanges();
await fixture.whenStable();
displayValueHiddenContainer = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectInputElementValueIs(textInputElement, 'aaa');
expectInputElementValueIs(textTwoInputElement, '');
expectElementToBeVisible(displayValueHiddenContainer);
typeIntoInput(textInputElement, 'bbb');
fixture.detectChanges();
await fixture.whenStable();
displayValueHiddenContainer = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectInputElementValueIs(textInputElement, 'bbb');
expectInputElementValueIs(textTwoInputElement, '');
expectElementToBeHidden(displayValueHiddenContainer);
typeIntoInput(textTwoInputElement, 'aaa');
fixture.detectChanges();
await fixture.whenStable();
displayValueHiddenContainer = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectInputElementValueIs(textInputElement, 'bbb');
expectInputElementValueIs(textTwoInputElement, 'aaa');
expectElementToBeHidden(displayValueHiddenContainer);
typeIntoInput(textInputElement, 'aaa');
fixture.detectChanges();
await fixture.whenStable();
displayValueHiddenContainer = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectInputElementValueIs(textInputElement, 'aaa');
expectInputElementValueIs(textTwoInputElement, 'aaa');
expectElementToBeHidden(displayValueHiddenContainer);
typeIntoInput(textTwoInputElement, 'bbb');
fixture.detectChanges();
await fixture.whenStable();
displayValueHiddenContainer = fixture.nativeElement.querySelector('#field-Displayvalue0g6092-container');
expectInputElementValueIs(textInputElement, 'aaa');
expectInputElementValueIs(textTwoInputElement, 'bbb');
expectElementToBeVisible(displayValueHiddenContainer);
});
});

View File

@ -0,0 +1,422 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const formDisplayValueVisibility = {formRepresentation: {
id: 'form-3175b074-53c6-4b5b-92df-246b62108db3',
name: 'displayValueVisibility',
description: '',
version: 0,
standAlone: true,
formDefinition: {
tabs: [],
fields: [
{
id: '65ba00e6-a669-4710-9a97-0a6e19b429d8',
name: 'Label',
type: 'container',
tab: null,
numberOfColumns: 2,
fields: {
'1': [
{
id: 'Text0bq3ar',
name: 'Text',
type: 'text',
required: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: { existingColspan: 1, maxColspan: 2 }
}
],
'2': [
{
id: 'Displayvalue0g6092',
name: 'Display value',
type: 'readonly',
value: 'No field selected',
colspan: 1,
visibilityCondition: {
leftType: 'field',
leftValue: 'Text0bq3ar',
operator: '==',
rightValue: 'DisplayValue',
rightType: 'value',
nextConditionOperator: '',
nextCondition: null
},
params: {
existingColspan: 1,
maxColspan: 2,
field: {
id: 'Displayvalue0g6092',
name: 'Display value',
type: 'text'
},
responseVariable: true
}
}
]
}
}
],
outcomes: [],
metadata: {},
variables: []
}
}};
export const formDisplayValueForm = { formRepresentation : {
id: 'form-3dd0f2a3-c20a-4195-a760-1db42ec7dcd4',
name: 'displayValue',
description: '',
version: 0,
formDefinition: {
'tabs': [],
'fields': [
{
'id': 'c54f6956-bcf9-4109-a6c1-1daff773936b',
'name': 'Label',
'type': 'container',
'tab': null,
'numberOfColumns': 2,
'fields': {
'1': [
{
'id': 'DisplayValueColspan',
'name': 'DisplayValueColspan',
'type': 'readonly',
'value': 'No field selected',
'colspan': 2,
'visibilityCondition': null,
'params': {
'existingColspan': 1,
'maxColspan': 2,
'field': {
'id': 'Displayvalue0hwgvb',
'name': 'Display value',
'type': 'text'
}
}
},
{
'id': 'DisplayValueFieldValue',
'name': 'DisplayValueFieldValue',
'type': 'readonly',
'value': 'No field selected',
'colspan': 1,
'visibilityCondition': {
'leftFormFieldId': 'TextOne',
'leftRestResponseId': '',
'operator': '==',
'rightValue': 'aaa',
'rightType': null,
'rightFormFieldId': '',
'rightRestResponseId': '',
'nextConditionOperator': '',
'nextCondition': null
},
'params': {
'existingColspan': 1,
'maxColspan': 2,
'field': {
'id': 'Displayvalue0pjsfi',
'name': 'Display value',
'type': 'text'
}
}
},
{
'id': 'DisplayValueVariableField',
'name': 'DisplayValueVariableField',
'type': 'readonly',
'value': 'No field selected',
'colspan': 1,
'visibilityCondition': {
'leftFormFieldId': '',
'leftRestResponseId': 'bcdfe3af-d635-40ee-b9fd-4f9d3655d77b',
'operator': '==',
'rightValue': '',
'rightType': null,
'rightFormFieldId': 'TextOne',
'rightRestResponseId': '',
'nextConditionOperator': '',
'nextCondition': null
},
'params': {
'existingColspan': 1,
'maxColspan': 2,
'field': {
'id': 'Displayvalue0sss8o',
'name': 'Display value',
'type': 'text'
}
}
},
{
'id': 'DisplayValueFieldVariable',
'name': 'DisplayValueFieldVariable',
'type': 'readonly',
'value': 'No field selected',
'colspan': 1,
'visibilityCondition': {
'leftFormFieldId': 'TextOne',
'leftRestResponseId': '',
'operator': '==',
'rightValue': '',
'rightType': null,
'rightFormFieldId': '',
'rightRestResponseId': 'bcdfe3af-d635-40ee-b9fd-4f9d3655d77b',
'nextConditionOperator': '',
'nextCondition': null
},
'params': {
'existingColspan': 1,
'maxColspan': 2,
'field': {
'id': 'Displayvalue0mkrml',
'name': 'Display value',
'type': 'text'
}
}
},
{
'id': 'DisplayValueOne',
'name': 'DisplayValueOne',
'type': 'readonly',
'value': 'No field selected',
'colspan': 1,
'visibilityCondition': {
'leftFormFieldId': 'Text0howrc',
'leftRestResponseId': '',
'operator': '==',
'rightValue': 'aaa',
'rightType': null,
'rightFormFieldId': '',
'rightRestResponseId': '',
'nextConditionOperator': 'and',
'nextCondition': {
'leftFormFieldId': 'TextTwo',
'leftRestResponseId': '',
'operator': '!=',
'rightValue': 'aaa',
'rightType': null,
'rightFormFieldId': '',
'rightRestResponseId': '',
'nextConditionOperator': '',
'nextCondition': null
}
},
'params': {
'existingColspan': 1,
'maxColspan': 2,
'field': {
'id': 'Displayvalue00ldqe',
'name': 'Display value',
'type': 'text'
}
}
}
],
'2': [
{
'id': 'Text0howrc',
'name': 'Text',
'type': 'text',
'required': false,
'colspan': 1,
'placeholder': null,
'minLength': 0,
'maxLength': 0,
'regexPattern': null,
'visibilityCondition': null,
'params': {
'existingColspan': 1,
'maxColspan': 2
}
},
{
'id': 'TextOne',
'name': 'TextOne',
'type': 'text',
'required': false,
'colspan': 1,
'placeholder': null,
'minLength': 0,
'maxLength': 0,
'regexPattern': null,
'visibilityCondition': null,
'params': {
'existingColspan': 1,
'maxColspan': 2
}
},
{
'id': 'TextTwo',
'name': 'TextTwo',
'type': 'text',
'required': false,
'colspan': 1,
'placeholder': null,
'minLength': 0,
'maxLength': 0,
'regexPattern': null,
'visibilityCondition': null,
'params': {
'existingColspan': 1,
'maxColspan': 2
}
},
{
'id': 'bcdfe3af-d635-40ee-b9fd-4f9d3655d77b',
'name': 'vstring',
'type': 'readonly',
'value': 'Show value of vstring',
'colspan': 1,
'visibilityCondition': null,
'params': {
'existingColspan': 1,
'maxColspan': 2,
'field': {
'id': 'bcdfe3af-d635-40ee-b9fd-4f9d3655d77b',
'name': 'vstring',
'type': 'string'
}
}
}
]
}
}
],
'outcomes': [],
'metadata': {},
'variables': [
{
'id': 'bcdfe3af-d635-40ee-b9fd-4f9d3655d77b',
'name': 'vstring',
'type': 'string',
'value': 'aaa'
}
]
}
}};
export const formDisplayValueCombinedVisibility = {
formRepresentation: {
id: 'form-3175b074-53c6-4b5b-92df-246b62108db3',
name: 'displayValueVisibility',
description: '',
version: 0,
standAlone: true,
formDefinition: {
tabs: [],
fields: [
{
id: '65ba00e6-a669-4710-9a97-0a6e19b429d8',
name: 'Label',
type: 'container',
tab: null,
numberOfColumns: 2,
fields: {
'1': [
{
id: 'Text0bq3ar',
name: 'Text',
type: 'text',
required: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: { existingColspan: 1, maxColspan: 2 }
}
],
'2': [
{
id: 'Displayvalue0g6092',
name: 'Display value',
type: 'readonly',
value: 'No field selected',
colspan: 1,
visibilityCondition: {
leftType: 'field',
leftValue: 'Text0bq3ar',
operator: '==',
rightValue: 'aaa',
rightType: 'value',
nextConditionOperator: 'and',
nextCondition: {
leftType: 'field',
leftValue: 'TextTwo',
operator: '!=',
rightValue: 'aaa',
rightType: 'value',
nextConditionOperator: '',
nextCondition: null
}
},
params: {
existingColspan: 1,
maxColspan: 2,
field: {
id: 'Displayvalue0g6092',
name: 'Display value',
type: 'text'
},
responseVariable: true
}
}
]
}
},
{
id: 'b2162507-2204-4fda-a8cb-003dd5d032ef',
name: 'Label',
type: 'container',
tab: null,
numberOfColumns: 2,
fields: {
'1': [
{
id: 'TextTwo',
name: 'TextTwo',
type: 'text',
required: false,
colspan: 1,
placeholder: null,
minLength: 0,
maxLength: 0,
regexPattern: null,
visibilityCondition: null,
params: { existingColspan: 1, maxColspan: 2 }
}
],
'2': []
}
}
],
outcomes: [],
metadata: {},
variables: []
}
}
};

View File

@ -396,7 +396,7 @@ describe('Form service', () => {
});
it('should parse a Form Definition with tabs', () => {
expect(formModelTabs.formDefinition).toBeDefined();
expect(formModelTabs.formRepresentation.formDefinition).toBeDefined();
const formParsed = service.parseForm(formModelTabs);
expect(formParsed).toBeDefined();
});

View File

@ -102,10 +102,21 @@ export class FormService {
*/
parseForm(json: any, data?: FormValues, readOnly: boolean = false): FormModel {
if (json) {
const form = new FormModel(json, data, readOnly, this);
const flattenForm = {
...json.formRepresentation,
...json.formRepresentation.formDefinition
};
delete flattenForm.formDefinition;
const formValues: FormValues = {};
(data || []).forEach(variable => {
formValues[variable.name] = variable.value;
});
const form = new FormModel(flattenForm, formValues, readOnly);
if (!json.fields) {
form.outcomes = [
new FormOutcomeModel(form, {
new FormOutcomeModel(<any> form, {
id: '$save',
name: FormOutcomeModel.SAVE_ACTION,
isSystem: true

File diff suppressed because it is too large Load Diff

View File

@ -16,231 +16,233 @@
*/
export const formModelTabs: any = {
id: 16,
name: 'start event',
description: '',
version: 2,
lastUpdatedBy: 4,
lastUpdatedByFullName: 'User Test',
lastUpdated: '2017-10-04T13:00:03.030+0000',
stencilSetId: null,
referenceId: null,
formDefinition: {
tabs: [],
fields: [
{
fieldType: 'ContainerRepresentation',
id: '1507037668653',
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: 'AmountFieldRepresentation',
id: 'label',
name: 'Label',
type: 'amount',
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,
params: {
existingColspan: 1,
maxColspan: 2
},
dateDisplayFormat: null,
layout: {
row: -1,
column: -1,
colspan: 1
},
sizeX: 1,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null,
enableFractions: false,
currency: null
formRepresentation: {
id: 16,
name: 'start event',
description: '',
version: 2,
lastUpdatedBy: 4,
lastUpdatedByFullName: 'User Test',
lastUpdated: '2017-10-04T13:00:03.030+0000',
stencilSetId: null,
referenceId: null,
formDefinition: {
tabs: [],
fields: [
{
fieldType: 'ContainerRepresentation',
id: '1507037668653',
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: 'AmountFieldRepresentation',
id: 'label',
name: 'Label',
type: 'amount',
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,
params: {
existingColspan: 1,
maxColspan: 2
},
dateDisplayFormat: null,
layout: {
row: -1,
column: -1,
colspan: 1
},
sizeX: 1,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null,
enableFractions: false,
currency: null
}
],
'2': [
{
fieldType: 'FormFieldRepresentation',
id: 'label1',
name: 'Label1',
type: 'date',
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,
params: {
existingColspan: 1,
maxColspan: 1
},
dateDisplayFormat: null,
layout: {
row: -1,
column: -1,
colspan: 1
},
sizeX: 1,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null
}
]
}
],
'2': [
{
fieldType: 'FormFieldRepresentation',
id: 'label1',
name: 'Label1',
type: 'date',
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,
params: {
existingColspan: 1,
maxColspan: 1
},
dateDisplayFormat: null,
layout: {
row: -1,
column: -1,
colspan: 1
},
sizeX: 1,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null
},
{
fieldType: 'ContainerRepresentation',
id: '1507037670167',
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: 'FormFieldRepresentation',
id: 'label2',
name: 'Label2',
type: 'boolean',
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,
params: {
existingColspan: 1,
maxColspan: 2
},
dateDisplayFormat: null,
layout: {
row: -1,
column: -1,
colspan: 1
},
sizeX: 1,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null
}
],
'2': []
}
]
}
},
{
fieldType: 'ContainerRepresentation',
id: '1507037670167',
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: 'FormFieldRepresentation',
id: 'label2',
name: 'Label2',
type: 'boolean',
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,
params: {
existingColspan: 1,
maxColspan: 2
},
dateDisplayFormat: null,
layout: {
row: -1,
column: -1,
colspan: 1
},
sizeX: 1,
sizeY: 1,
row: -1,
col: -1,
visibilityCondition: null
}
],
'2': []
}
}
],
outcomes: [],
javascriptEvents: [],
className: '',
style: '',
customFieldTemplates: {},
metadata: {},
variables: [],
customFieldsValueInfo: {},
gridsterForm: false
}
],
outcomes: [],
javascriptEvents: [],
className: '',
style: '',
customFieldTemplates: {},
metadata: {},
variables: [],
customFieldsValueInfo: {},
gridsterForm: false
}
};