[AAE-1943] Dropdown widget unit test (#5513)

* [AAE-2034] Radio Button displaued in read-only mode

* [AAE-2034] Added tests and disable for all radio group and not every button

* [AAE-1943] C309672 and C309675 into unit tests

* [AAE-1943] C309680 automated

* [AAE-1943] C309682 automated
This commit is contained in:
Baptiste Mahé
2020-02-28 14:03:13 +00:00
committed by GitHub
parent a9b49a1eb7
commit 7a79d5bebf
4 changed files with 335 additions and 0 deletions

View File

@@ -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);
});
});

View File

@@ -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'
}]
}
}
};

View File

@@ -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: '<id>' }), {
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', () => {

View File

@@ -43,4 +43,12 @@ export class DropdownWidgetPage {
const dropdown = element(by.css(`${locator}`));
await BrowserVisibility.waitUntilElementIsVisible(dropdown);
}
async isWidgetVisible(fieldId): Promise<void> {
await this.formFields.checkWidgetIsVisible(fieldId);
}
async isWidgetHidden(fieldId): Promise<void> {
await this.formFields.checkWidgetIsHidden(fieldId);
}
}