Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Linting of User Task Forms #148

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rules/camunda-cloud/user-task-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { skipInNonExecutableProcess } = require('../utils/rule');

const { greaterOrEqual } = require('../utils/version');

const formIdAllowedVersion = '8.3';
const formIdAllowedVersion = '8.4';

module.exports = skipInNonExecutableProcess(function({ version }) {
function check(node, reporter) {
Expand Down
20 changes: 16 additions & 4 deletions rules/utils/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const {
isFunction,
isNil,
isObject,
isString,
isUndefined,
some
} = require('min-dash');

Expand Down Expand Up @@ -141,7 +143,7 @@ module.exports.hasProperties = function(node, properties, parentNode = null) {

const propertyValue = node.get(propertyName);

if (propertyChecks.required && !propertyValue) {
if (propertyChecks.required && isEmptyValue(propertyValue)) {
return [
...results,
{
Expand All @@ -164,7 +166,7 @@ module.exports.hasProperties = function(node, properties, parentNode = null) {
if (propertyChecks.dependentRequired) {
const dependency = node.get(propertyChecks.dependentRequired);

if (dependency && !propertyValue) {
if (dependency && isEmptyValue(propertyValue)) {
return [
...results,
{
Expand Down Expand Up @@ -303,7 +305,9 @@ function findProperties(node, propertyNames) {
const properties = [];

for (const propertyName of propertyNames) {
if (isDefined(node.get(propertyName))) {
const propertyValue = node.get(propertyName);

if (!isEmptyValue(propertyValue)) {
properties.push(node.get(propertyName));
}
}
Expand Down Expand Up @@ -470,4 +474,12 @@ function findParent(node, type) {
return findParent(parent, type);
}

module.exports.findParent = findParent;
module.exports.findParent = findParent;

function isEmptyString(value) {
return isString(value) && value.trim() === '';
}

function isEmptyValue(value) {
return isUndefined(value) || isNil(value) || isEmptyString(value);
}
25 changes: 25 additions & 0 deletions test/camunda-cloud/integration/user-task-form-form-id-errors.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1k80tzz" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.4.2" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
<bpmn:process id="Process_003d7f9" isExecutable="true">
<bpmn:userTask id="Activity_0tbaw9y">
<bpmn:extensionElements>
<zeebe:formDefinition formId="" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="Activity_0al8bht">
<bpmn:extensionElements>
<zeebe:formDefinition formKey="foo" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_003d7f9">
<bpmndi:BPMNShape id="Activity_1eofini_di" bpmnElement="Activity_0tbaw9y">
<dc:Bounds x="160" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_00hzkfi_di" bpmnElement="Activity_0al8bht">
<dc:Bounds x="280" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
25 changes: 25 additions & 0 deletions test/camunda-cloud/integration/user-task-form-form-id.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1k80tzz" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.4.2" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.1.0">
<bpmn:process id="Process_003d7f9" isExecutable="true">
<bpmn:userTask id="Activity_0tbaw9y">
<bpmn:extensionElements>
<zeebe:formDefinition formId="bar" />
</bpmn:extensionElements>
</bpmn:userTask>
<bpmn:userTask id="Activity_0al8bht">
<bpmn:extensionElements>
<zeebe:formDefinition formKey="foo" />
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_003d7f9">
<bpmndi:BPMNShape id="Activity_1eofini_di" bpmnElement="Activity_0tbaw9y">
<dc:Bounds x="160" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_00hzkfi_di" bpmnElement="Activity_0al8bht">
<dc:Bounds x="280" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
84 changes: 70 additions & 14 deletions test/camunda-cloud/integration/user-task-form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,75 @@ const NodeResolver = require('bpmnlint/lib/resolver/node-resolver');

const { readModdle } = require('../../helper');

const versions = [
'1.0',
'1.1',
'1.2',
'1.3',
'8.0',
'8.1',
'8.2'
];

describe('integration - user-task-form', function() {

versions.forEach(function(version) {
[
'1.0',
'1.1',
'1.2',
'1.3',
'8.0',
'8.1',
'8.2',
'8.3',
'8.4'
].forEach(function(version) {

let linter;

beforeEach(function() {
linter = new Linter({
config: {
extends: `plugin:camunda-compat/camunda-cloud-${ version.replace('.', '-') }`
},
resolver: new NodeResolver()
});
});


describe(`Camunda Cloud ${ version } (form key)`, function() {

describe('no errors', function() {

it('should not have errors', async function() {

// given
const { root } = await readModdle('test/camunda-cloud/integration/user-task-form-form-key.bpmn');

// when
const reports = await linter.lint(root);

// then
expect(reports[ 'camunda-compat/user-task-form' ]).not.to.exist;
});

});


describe('errors', function() {

it('should have errors', async function() {

// given
const { root } = await readModdle('test/camunda-cloud/integration/user-task-form-form-key-errors.bpmn');

// when
const reports = await linter.lint(root);

// then
expect(reports[ 'camunda-compat/user-task-form' ]).to.exist;
});

});

});

});


[
'8.4'
].forEach(function(version) {

let linter;

Expand All @@ -32,14 +88,14 @@ describe('integration - user-task-form', function() {
});


describe(`Camunda Cloud ${ version }`, function() {
describe(`Camunda Cloud ${ version } (form ID)`, function() {

describe('no errors', function() {

it('should not have errors', async function() {

// given
const { root } = await readModdle('test/camunda-cloud/integration/user-task-form.bpmn');
const { root } = await readModdle('test/camunda-cloud/integration/user-task-form-form-id.bpmn');

// when
const reports = await linter.lint(root);
Expand All @@ -56,7 +112,7 @@ describe('integration - user-task-form', function() {
it('should have errors', async function() {

// given
const { root } = await readModdle('test/camunda-cloud/integration/user-task-form-errors.bpmn');
const { root } = await readModdle('test/camunda-cloud/integration/user-task-form-form-id-errors.bpmn');

// when
const reports = await linter.lint(root);
Expand Down
Loading