Skip to content

Commit

Permalink
feat: adjust user-task-form error messages to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Nov 7, 2023
1 parent 0773f18 commit 94e011d
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 13 deletions.
23 changes: 20 additions & 3 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { is, isAny } from 'bpmnlint-utils';

import {
every,
isArray
isArray,
isString
} from 'min-dash';

import { getTypeString } from './types';
Expand Down Expand Up @@ -394,6 +395,10 @@ function getPropertyNotAllowedErrorMessage(report, executionPlatform, executionP
return getSupportedMessage(`${ getIndefiniteArticle(typeString) } <${ typeString }> with <${ TIMER_PROPERTY_LABELS[ property ] }>`, executionPlatform, executionPlatformVersion, allowedVersion);
}

if (is(node, 'zeebe:FormDefinition') && property === 'formId') {
return getSupportedMessage(`${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Camunda form (linked)>`, executionPlatform, executionPlatformVersion, allowedVersion);
}

return message;
}

Expand Down Expand Up @@ -483,12 +488,20 @@ function getPropertyRequiredErrorMessage(report, executionPlatform, executionPla
return `${ getIndefiniteArticle(typeString) } <${ typeString }> must have a defined <Signal Reference>`;
}

if (is(node, 'zeebe:FormDefinition') && requiredProperty === 'formKey') {
if (is(node, 'zeebe:FormDefinition')
&& (
requiredProperty === 'formKey'
|| (isArray(requiredProperty) && requiredProperty.includes('formKey') && isEmptyString(node.get('formKey')))
)) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Custom form key> must have a defined <Form key>`;
}

if (is(node, 'zeebe:FormDefinition') && isArray(requiredProperty) && requiredProperty.includes('formId') && isEmptyString(node.get('formId'))) {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Camunda form (linked)> must have a defined <Form ID>`;
}

if (is(node, 'zeebe:UserTaskForm') && requiredProperty === 'body') {
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Camunda forms> must have a defined <Form JSON configuration>`;
return `${ getIndefiniteArticle(typeString) } <${ typeString }> with <Form type: Camunda form (embedded)> must have a defined <Form JSON configuration>`;
}

if (is(node, 'bpmn:SequenceFlow') && requiredProperty === 'conditionExpression') {
Expand Down Expand Up @@ -672,4 +685,8 @@ function getLoopNotAllowedErrorMessage(report) {
const { elements } = data;

return `A <Process> is not allowed to contain a straight-through processing loop: ${ elements.map(element => `<${ element }>`).join(', ') }`;
}

function isEmptyString(value) {
return isString(value) && value.trim() === '';
}
34 changes: 33 additions & 1 deletion lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { isArray } from 'min-dash';
import {
isArray,
isString
} from 'min-dash';

import { is } from 'bpmnlint-utils';

Expand Down Expand Up @@ -159,6 +162,23 @@ export function getEntryIds(report) {
return [ 'customFormKey' ];
}

if (isType(data, 'zeebe:FormDefinition')) {
const {
node,
requiredProperty
} = data;

if (isArray(requiredProperty) && requiredProperty.includes('formKey') && isEmptyString(node.get('formKey'))) {
return [ 'customFormKey' ];
} else if (isArray(requiredProperty) && requiredProperty.includes('formId') && isEmptyString(node.get('formId'))) {
return [ 'formId' ];
}
}

if (isPropertyError(data, 'formId', 'zeebe:FormDefinition')) {
return [ 'formId' ];
}

if (isPropertyError(data, 'body', 'zeebe:UserTaskForm')) {
return [ 'formConfiguration' ];
}
Expand Down Expand Up @@ -396,6 +416,14 @@ export function getErrorMessage(id, report) {
return 'Form key must be defined.';
}

if (id === 'formId') {
if (data.type === ERROR_TYPES.PROPERTY_REQUIRED) {
return 'Form ID must be defined.';
} else if (data.type === ERROR_TYPES.PROPERTY_NOT_ALLOWED) {
return 'Form ID not supported.';
}
}

if (id === 'formConfiguration') {
return 'Form JSON configuration must be defined.';
}
Expand Down Expand Up @@ -547,4 +575,8 @@ function isElementPropertyValueDuplicated(data, propertyName, type) {

function getBusinessObject(element) {
return element.businessObject || element;
}

function isEmptyString(value) {
return isString(value) && value.trim() === '';
}
2 changes: 1 addition & 1 deletion test/spec/modeler/Linting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { getErrors } from '../../../lib/utils/properties-panel';
import diagramCSS from 'bpmn-js/dist/assets/diagram-js.css';
import bpmnCSS from 'bpmn-js/dist/assets/bpmn-js.css';
import bpmnFont from 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
import propertiesPanelCSS from '@bpmn-io/properties-panel/assets/properties-panel.css';
import propertiesPanelCSS from '@bpmn-io/properties-panel/dist/assets/properties-panel.css';
import elementTemplatesCSS from 'bpmn-js-element-templates/dist/assets/element-templates.css';
import lintingCSS from '../../../assets/linting.css';

Expand Down
87 changes: 82 additions & 5 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ describe('utils/error-messages', function() {
});


it('should adjust (form key)', async function() {
it('should adjust (form key) (Camunda 8.3 and older)', async function() {

// given
const node = createElement('bpmn:UserTask', {
Expand All @@ -1141,7 +1141,7 @@ describe('utils/error-messages', function() {

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule);
const report = await getLintError(node, rule, { version: '8.3' });

// when
const errorMessage = getErrorMessage(report);
Expand All @@ -1151,7 +1151,84 @@ describe('utils/error-messages', function() {
});


it('should adjust (body)', async function() {
it('should adjust (form key) (Camunda 8.4 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:FormDefinition', {
formKey: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.4' });

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('A <User Task> with <Form type: Custom form key> must have a defined <Form key>');
});


it('should adjust (form ID) (Camunda 8.3 and older)', async function() {

// given
const executionPlatformVersion = '8.3';

const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:FormDefinition', {
formId: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: executionPlatformVersion });

// when
const errorMessage = getErrorMessage(report, 'Camunda Cloud', executionPlatformVersion);

// then
expect(errorMessage).to.equal('A <User Task> with <Form type: Camunda form (linked)> is only supported by Camunda 8.4 or newer');
});


it('should adjust (form ID) (Camunda 8.4 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:FormDefinition', {
formId: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.4' });

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('A <User Task> with <Form type: Camunda form (linked)> must have a defined <Form ID>');
});


it.only('should adjust (body)', async function() {

// given
const process = createElement('bpmn:Process', {
Expand Down Expand Up @@ -1179,13 +1256,13 @@ describe('utils/error-messages', function() {

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule);
const report = await getLintError(node, rule, { version: '8.3' });

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('A <User Task> with <Form type: Camunda forms> must have a defined <Form JSON configuration>');
expect(errorMessage).to.equal('A <User Task> with <Form type: Camunda form (embedded)> must have a defined <Form JSON configuration>');
});


Expand Down
87 changes: 84 additions & 3 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ describe('utils/properties-panel', function() {
});


it('user-task-form - Form key', async function() {
it('user-task-form - Form key (Camunda 8.3 and older)', async function() {

// given
const node = createElement('bpmn:UserTask', {
Expand All @@ -812,7 +812,34 @@ describe('utils/properties-panel', function() {

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule);
const report = await getLintError(node, rule, { version: '8.3' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'customFormKey' ]);

expectErrorMessage(entryIds[ 0 ], 'Form key must be defined.', report);
});


it('user-task-form - Form key (Camunda 8.4 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:FormDefinition', {
formKey: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.4' });

// when
const entryIds = getEntryIds(report);
Expand All @@ -824,6 +851,60 @@ describe('utils/properties-panel', function() {
});


it('user-task-form - Form ID (Camunda 8.3 and older)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:FormDefinition', {
formId: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.3' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'formId' ]);

expectErrorMessage(entryIds[ 0 ], 'Form ID not supported.', report);
});


it('user-task-form - Form ID (Camunda 8.4 and newer)', async function() {

// given
const node = createElement('bpmn:UserTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:FormDefinition', {
formId: ''
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule, { version: '8.4' });

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'formId' ]);

expectErrorMessage(entryIds[ 0 ], 'Form ID must be defined.', report);
});


it('user-task-form - Form JSON configuration', async function() {

// given
Expand Down Expand Up @@ -852,7 +933,7 @@ describe('utils/properties-panel', function() {

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/user-task-form');

const report = await getLintError(node, rule);
const report = await getLintError(node, rule, { version: '8.2' });

// when
const entryIds = getEntryIds(report);
Expand Down

0 comments on commit 94e011d

Please sign in to comment.