diff --git a/e2e/process-services-cloud/form-field/visibility-condition.e2e.ts b/e2e/process-services-cloud/form-field/visibility-condition.e2e.ts index e15254eeec..390c92d750 100644 --- a/e2e/process-services-cloud/form-field/visibility-condition.e2e.ts +++ b/e2e/process-services-cloud/form-field/visibility-condition.e2e.ts @@ -23,6 +23,7 @@ import { NavigationBarPage } from '../../pages/adf/navigation-bar.page'; import { checkboxVisibilityFormJson, multipleCheckboxVisibilityFormJson } from '../../resources/forms/checkbox-visibility-condition'; import { multipleTextVisibilityFormJson, multipleVisibilityFormJson } from '../../resources/forms/multiple-visibility-conditions'; import { displayValueTextJson } from '../../resources/forms/display-value-visibility-conditions'; +import { dropdownVisibilityFormFieldJson, dropdownVisibilityFormVariableJson } from '../../resources/forms/dropdown-visibility-condition'; describe('Visibility conditions - cloud', () => { @@ -58,12 +59,29 @@ describe('Visibility conditions - cloud', () => { checkboxVariableVariable: 'CheckboxVariableVariable', checkbox1: 'Checkbox1' }; + const displayValueString = { displayValueNoConditionField: 'DisplayValueNoCondition', displayValueSingleConditionField: 'DisplayValueSingleCondition', displayValueMultipleConditionsField: 'DisplayValueMultipleCondition' }; + const dropdownVisibilityTest = { + widgets: { + textId: 'textFour', + numberId: 'numberOne', + amountId: 'amountOne', + dropdownId: 'dropdownOne' + }, + displayValue: { + text: 'text1', + number: '11' + }, + notDisplayValue: { + amount: '90' + } + }; + beforeAll(async () => { this.alfrescoJsApi = new AlfrescoApi({ provider: 'BPM', @@ -287,6 +305,7 @@ describe('Visibility conditions - cloud', () => { await expect(textOneField).toEqual('dog'); await widget.displayValueWidget().checkDisplayValueWidgetIsHidden(displayValueString.displayValueSingleConditionField); }); + it('[C309871] Should be able to see Display text widget when has multiple visibility conditions and next condition operators', async () => { await formCloudDemoPage.setConfigToEditor(displayValueTextJson); @@ -329,4 +348,25 @@ describe('Visibility conditions - cloud', () => { await widget.displayValueWidget().isDisplayValueWidgetVisible(displayValueString.displayValueMultipleConditionsField); await expect(textDisplayWidgetMultipleCondition).toEqual('more cats'); }); + + it('[C309680] Should be able to see dropdown widget when has multiple Visibility Conditions set on Form Fields', async () => { + await formCloudDemoPage.setConfigToEditor(dropdownVisibilityFormFieldJson); + + await widget.dropdown().isWidgetHidden(dropdownVisibilityTest.widgets.dropdownId); + + await widget.textWidget().setValue(dropdownVisibilityTest.widgets.textId, dropdownVisibilityTest.displayValue.text); + await widget.dropdown().isWidgetHidden(dropdownVisibilityTest.widgets.dropdownId); + + await widget.numberWidget().setFieldValue(dropdownVisibilityTest.widgets.numberId, dropdownVisibilityTest.displayValue.number); + await widget.dropdown().isWidgetVisible(dropdownVisibilityTest.widgets.dropdownId); + + await widget.amountWidget().setFieldValue(dropdownVisibilityTest.widgets.amountId, dropdownVisibilityTest.notDisplayValue.amount); + await widget.dropdown().isWidgetHidden(dropdownVisibilityTest.widgets.dropdownId); + }); + + it('[C309682] Should be able to see dropdown widget when has multiple Visibility Conditions set on Form Variables', async () => { + await formCloudDemoPage.setConfigToEditor(dropdownVisibilityFormVariableJson); + + await widget.dropdown().isWidgetVisible(dropdownVisibilityTest.widgets.dropdownId); + }); }); diff --git a/e2e/resources/forms/dropdown-visibility-condition.ts b/e2e/resources/forms/dropdown-visibility-condition.ts new file mode 100644 index 0000000000..7abb69b666 --- /dev/null +++ b/e2e/resources/forms/dropdown-visibility-condition.ts @@ -0,0 +1,253 @@ +/*! + * @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 dropdownVisibilityFormFieldJson = { + formRepresentation: { + id: 'form-3070ee8d-34d3-4c5a-9dd0-6b244f65d300', + name: 'DropDownWidgetForm1', + description: 'Simple dropdown', + version: 0, + formDefinition: { + tabs: [], + fields: [{ + id: '5e180610-1478-4f80-ad80-e4c57a18fbff', + name: 'Label', + type: 'container', + tab: null, + numberOfColumns: 2, + fields: { + 1: [{ + id: 'textFour', + name: 'textFour', + type: 'text', + required: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + regexPattern: null, + visibilityCondition: null, + params: { + existingColspan: 1, + maxColspan: 2 + } + }, + { + id: 'numberOne', + name: 'numberOne', + type: 'integer', + colspan: 1, + placeholder: null, + minValue: null, + maxValue: null, + required: false, + visibilityCondition: null, + params: { + existingColspan: 1, + maxColspan: 2 + } + }, + { + id: 'amountOne', + name: 'amountOne', + type: 'amount', + required: false, + colspan: 1, + placeholder: '123', + minValue: null, + maxValue: null, + visibilityCondition: null, + params: { + existingColspan: 1, + maxColspan: 2 + }, + enableFractions: false, + currency: '$' + } + ], + 2: [{ + id: 'dropdownOne', + name: 'dropdownOne', + type: 'dropdown', + required: false, + colspan: 1, + optionType: 'manual', + options: [{ + id: 'empty', + name: 'Choose one...' + }, + { + id: 'option_2', + name: '1' + }, + { + id: 'option_3', + name: '2' + } + ], + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + visibilityCondition: { + leftFormFieldId: 'textFour', + leftRestResponseId: '', + operator: '==', + rightValue: 'text1', + rightType: null, + rightFormFieldId: '', + rightRestResponseId: '', + nextConditionOperator: 'and', + nextCondition: { + leftFormFieldId: 'numberOne', + leftRestResponseId: '', + operator: '==', + rightValue: '11', + rightType: null, + rightFormFieldId: '', + rightRestResponseId: '', + nextConditionOperator: 'and', + nextCondition: { + leftFormFieldId: 'amountOne', + leftRestResponseId: '', + operator: '!=', + rightValue: 90, + rightType: null, + rightFormFieldId: '', + rightRestResponseId: '', + nextConditionOperator: '', + nextCondition: null + } + } + }, + params: { + existingColspan: 1, + maxColspan: 2 + } + }] + } + }], + outcomes: [], + metadata: {}, + variables: [] + } + } +}; + +export const dropdownVisibilityFormVariableJson = { + 'formRepresentation': { + 'id': 'form-8fe70790-ba51-4c46-8ef0-efc9044ed51c', + 'name': 'SampleDropdown', + 'description': '', + 'version': 0, + 'formDefinition': { + 'tabs': [], + 'fields': [{ + 'id': 'fde2c0bd-dbd6-4946-945e-4ab20aa1633a', + 'name': 'Label', + 'type': 'container', + 'tab': null, + 'numberOfColumns': 2, + 'fields': { + '1': [{ + 'id': 'dropdownOne', + 'name': 'Dropdown', + 'type': 'dropdown', + 'required': false, + 'colspan': 1, + 'optionType': 'manual', + 'options': [{ + 'id': 'empty', + 'name': 'Choose one...' + }, { + 'id': 'option_2', + 'name': '1' + }, { + 'id': 'option_3', + 'name': '2' + }], + 'restUrl': null, + 'restResponsePath': null, + 'restIdProperty': null, + 'restLabelProperty': null, + 'visibilityCondition': { + 'leftType': 'variable', + 'leftValue': 'name', + 'operator': '==', + 'rightValue': 'value1', + 'rightType': 'value', + 'nextConditionOperator': 'and', + 'nextCondition': { + 'leftType': 'variable', + 'leftValue': 'number', + 'operator': '==', + 'rightValue': 11, + 'rightType': 'value', + 'nextConditionOperator': 'and', + 'nextCondition': { + 'leftType': 'variable', + 'leftValue': 'yesOrNo', + 'operator': '==', + 'rightValue': 'true', + 'rightType': 'value', + 'nextConditionOperator': 'and', + 'nextCondition': { + 'leftType': 'variable', + 'leftValue': 'today', + 'operator': '!=', + 'rightValue': '2019-08-06', + 'rightType': 'value', + 'nextConditionOperator': '', + 'nextCondition': null + } + } + } + }, + 'params': { + 'existingColspan': 1, + 'maxColspan': 2 + } + }], + '2': [] + } + }], + 'outcomes': [], + 'metadata': {}, + 'variables': [{ + 'id': '74cdd5d3-120b-4926-995e-89e929a16c8f', + 'name': 'name', + 'type': 'string', + 'value': 'value1' + }, { + 'id': '4a46531a-c217-4c08-99bb-c510b7c18e63', + 'name': 'number', + 'type': 'integer', + 'value': 11 + }, { + 'id': 'c469fbce-4039-4817-9d1c-5102ccc2bd26', + 'name': 'yesOrNo', + 'type': 'boolean', + 'value': true + }, { + 'id': '36aa1031-3bbe-48f2-9d5d-465bf4158cb9', + 'name': 'today', + 'type': 'date', + 'value': '2019-05-13' + }] + } + } +}; diff --git a/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts b/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts index 26f43fb429..899b7af9c5 100644 --- a/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts +++ b/lib/core/form/components/widgets/dropdown/dropdown.widget.spec.ts @@ -23,6 +23,7 @@ import { WidgetVisibilityService } from '../../../services/widget-visibility.ser import { FormFieldOption } from './../core/form-field-option'; import { FormFieldModel } from './../core/form-field.model'; import { FormModel } from './../core/form.model'; +import { FormFieldTypes } from '../core/form-field-types'; import { DropdownWidgetComponent } from './dropdown.widget'; import { setupTestBed } from '../../../../testing/setup-test-bed'; import { CoreModule } from '../../../../core.module'; @@ -123,6 +124,39 @@ describe('DropdownWidgetComponent', () => { expect(widget.field.options[1]).toBe(restFieldValue); }); + describe('when is required', () => { + + beforeEach(async(() => { + widget.field = new FormFieldModel( new FormModel({ taskId: '' }), { + type: FormFieldTypes.DROPDOWN, + required: true + }); + })); + + it('should be able to display label with asterix', async(() => { + const label = 'MyLabel123'; + widget.field.name = label; + fixture.detectChanges(); + + expect(element.querySelector('label').innerText).toBe(label + '*'); + })); + + it('should be invalid if no default option', async(() => { + fixture.detectChanges(); + + expect(element.querySelector('.adf-invalid')).toBeDefined(); + expect(element.querySelector('.adf-invalid')).not.toBeNull(); + })); + + it('should be valid if default option', async(() => { + widget.field.options = fakeOptionList; + widget.field.value = fakeOptionList[0].id; + fixture.detectChanges(); + + expect(element.querySelector('.adf-invalid')).toBeNull(); + })); + }); + describe('when template is ready', () => { describe('and dropdown is populated via taskId', () => { diff --git a/lib/testing/src/lib/core/pages/form/widgets/dropdown-widget.page.ts b/lib/testing/src/lib/core/pages/form/widgets/dropdown-widget.page.ts index 700b553735..49a54d19c6 100644 --- a/lib/testing/src/lib/core/pages/form/widgets/dropdown-widget.page.ts +++ b/lib/testing/src/lib/core/pages/form/widgets/dropdown-widget.page.ts @@ -43,4 +43,12 @@ export class DropdownWidgetPage { const dropdown = element(by.css(`${locator}`)); await BrowserVisibility.waitUntilElementIsVisible(dropdown); } + + async isWidgetVisible(fieldId): Promise { + await this.formFields.checkWidgetIsVisible(fieldId); + } + + async isWidgetHidden(fieldId): Promise { + await this.formFields.checkWidgetIsHidden(fieldId); + } }