[MNT-22003] - fixed check on variable for visibility service (#6306)

* [MNT-22003] - fixed check on variable for visibility service

* [MNT-22003] - update variable for test

* [MNT-22003] - added extra unit test for checking the process variable passed

Co-authored-by: Vito Albano <vitoalbano@vitoalbano-mbp-0120.local>
This commit is contained in:
Vito 2020-11-04 15:52:12 +00:00 committed by GitHub
parent 66b51a7c93
commit 9c1b6dbc69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 6 deletions

View File

@ -829,6 +829,62 @@ describe('WidgetVisibilityCloudService', () => {
});
});
it('should use the process variables when they are passed to check the visibility', () => {
visibilityObjTest.leftType = WidgetTypeEnum.field;
visibilityObjTest.leftValue = 'FIELD_FORM_EMPTY';
visibilityObjTest.operator = '==';
visibilityObjTest.rightType = WidgetTypeEnum.value;
visibilityObjTest.rightValue = 'PROCESS_RIGHT_FORM_FIELD_VALUE';
const myForm = new FormModel({
id: '9999',
name: 'FORM_PROCESS_VARIABLE_VISIBILITY',
processDefinitionId: 'PROCESS_TEST:9:9999',
processDefinitionName: 'PROCESS_TEST',
processDefinitionKey: 'PROCESS_TEST',
taskId: '999',
taskName: 'TEST',
fields: [
{
fieldType: 'ContainerRepresentation',
id: '000000000000000000',
name: 'Label',
type: 'container',
value: null,
numberOfColumns: 2,
fields: {
1: [
{
fieldType: 'FormFieldRepresentation',
id: 'FIELD_FORM_EMPTY',
name: 'FIELD_FORM_EMPTY',
type: 'text',
value: '',
visibilityCondition: null,
isVisible: true
},
{
fieldType: 'FormFieldRepresentation',
id: 'FIELD_FORM_WITH_CONDITION',
name: 'FIELD_FORM_WITH_CONDITION',
type: 'text',
value: 'field_form_with_condition_value',
visibilityCondition: visibilityObjTest,
isVisible: false
}
]
}
}
]
});
service.refreshVisibility(myForm, [{ id: 'FIELD_FORM_EMPTY', type: 'string', value: 'PROCESS_RIGHT_FORM_FIELD_VALUE' }]);
const fieldWithVisibilityAttached = myForm.getFieldById('FIELD_FORM_WITH_CONDITION');
expect(fieldWithVisibilityAttached.isVisible).toBeTruthy();
});
it('should use the process value to evaluate the False visibility condition if the form value is empty', (done) => {
service.getTaskProcessVariable('9999').subscribe(

View File

@ -43,8 +43,11 @@ export class WidgetVisibilityService {
private logService: LogService) {
}
public refreshVisibility(form: FormModel) {
public refreshVisibility(form: FormModel, processVarList?: TaskProcessVariableModel[]) {
this.form = form;
if (processVarList) {
this.processVarList = processVarList;
}
if (form && form.tabs && form.tabs.length > 0) {
form.tabs.map((tabModel) => this.refreshEntityVisibility(tabModel));
}

View File

@ -205,7 +205,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
this.data = data[1];
const parsedForm = this.parseForm(this.formCloudRepresentationJSON);
this.visibilityService.refreshVisibility(<any> parsedForm);
this.visibilityService.refreshVisibility(<any> parsedForm, this.data);
parsedForm.validateForm();
this.form = parsedForm;
this.form.nodeId = '-my-';

View File

@ -18,8 +18,12 @@
export class TaskVariableCloud {
name: string;
value: any;
type: string;
id: string;
constructor(obj) {
this.id = obj.name || null;
this.name = obj.name || null;
this.value = obj.value || null;
this.type = obj.type || null;
}
}

View File

@ -264,7 +264,8 @@ describe('StartProcessCloudComponent', () => {
it('should be able to start a process with a prefilled valid form', fakeAsync(() => {
component.processDefinitionName = 'processwithform';
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, {
component.values = [{'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, {
'id': '1', 'type': 'string',
'name': 'lastName',
'value': 'FakeLastName'
}];
@ -298,7 +299,8 @@ describe('StartProcessCloudComponent', () => {
it('should NOT be able to start a process with a prefilled NOT valid form', fakeAsync(() => {
component.processDefinitionName = 'processwithform';
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));
component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, {
component.values = [{ 'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, {
'id': '1', 'type': 'string',
'name': 'lastName',
'value': 'FakeLastName'
}];
@ -331,7 +333,8 @@ describe('StartProcessCloudComponent', () => {
}));
it('should create a process instance if the selection is valid', fakeAsync(() => {
component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, {
component.values = [{ 'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, {
'id': '1', 'type': 'string',
'name': 'lastName',
'value': 'FakeLastName'
}];
@ -362,7 +365,8 @@ describe('StartProcessCloudComponent', () => {
}));
it('should have start button enabled when default values are set', fakeAsync(() => {
component.values = [{ 'name': 'firstName', 'value': 'FakeName' }, {
component.values = [{ 'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, {
'id': '1', 'type': 'string',
'name': 'lastName',
'value': 'FakeLastName'
}];