Skip to content

Commit

Permalink
feat(cloud): don't apply length and pattern validation to FEEL
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 5, 2024
1 parent e7b60db commit 0be4966
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cloud-element-templates/util/propertyUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@ export function validateProperty(value, property, translate = defaultTranslate)
return `${label} ${translate('must not be empty.')}`;
}

if (isFeel(value)) {
return;
}

if (maxLength && (value || '').length > maxLength) {
return `${label} ${translate('must have max length {maxLength}.', { maxLength })}`;
}
Expand Down Expand Up @@ -968,3 +972,7 @@ function defaultTranslate(template, replacements) {
return replacements[key] || '{' + key + '}';
});
}

function isFeel(value) {
return isString(value) && value.trim().startsWith('=');
}
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ function propertyValidator(translate, property) {
return translate('Must not be empty.');
}

if (isFeel(value)) {
return;
}

if (maxLength && value.length > maxLength) {
return translate('Must have max length {maxLength}.', { maxLength });
}
Expand Down Expand Up @@ -989,4 +993,8 @@ function groupByGroupId(properties) {

function findCustomGroup(groups, id) {
return find(groups, g => g.id === id);
}

function isFeel(value) {
return isString(value) && value.trim().startsWith('=');
}
28 changes: 28 additions & 0 deletions test/spec/cloud-element-templates/linting/LinterPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ const valid = [
config: {
templates
}
},
{
name: 'FEEL (Non Empty)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOO" zeebe:modelerTemplate="constraints.notEmpty" />')),
config: {
templates
}
},
{
name: 'FEEL (Min Length)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOO" zeebe:modelerTemplate="constraints.minLength" />')),
config: {
templates
}
},
{
name: 'FEEL (Max Length)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOOBAR" zeebe:modelerTemplate="constraints.maxLength" />')),
config: {
templates
}
},
{
name: 'FEEL (Pattern)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOO" zeebe:modelerTemplate="constraints.pattern" />')),
config: {
templates
}
}
];

Expand Down
92 changes: 92 additions & 0 deletions test/spec/element-templates/properties/CustomProperties.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ describe('provider/element-templates - CustomProperties', function() {

expect(input).to.have.property('disabled', true);
});

});


Expand Down Expand Up @@ -1641,6 +1642,97 @@ describe('provider/element-templates - CustomProperties', function() {

});


describe('FEEL', function() {

[
[ 'String', 'input' ],
[ 'TextArea', 'textarea' ]
].forEach(function([ name, selector ]) {

describe(name, function() {

it('should validate nonEmpty', async function() {

// given
await expectSelected('ValidateTask');

const entry = findEntry(`custom-entry-com.validated-inputs.Task-${selector}-0`, container),
input = domQuery(selector, entry);

// assume
expectError(entry, 'Must not be empty.');

// when
changeInput(input, '=FOO');

// then
expectValid(entry);
});


it('should not validate minLength', async function() {

// given
await expectSelected('ValidateTask');

const entry = findEntry(`custom-entry-com.validated-inputs.Task-${selector}-1`, container),
input = domQuery(selector, entry);

// assume
expectError(entry, 'Must have min length 5.');

// when
changeInput(input, '=FOO');

// then
expectValid(entry);
});


it('should not validate maxLength', async function() {

// given
await expectSelected('ValidateTask');

const entry = findEntry(`custom-entry-com.validated-inputs.Task-${selector}-2`, container),
input = domQuery(selector, entry);

// assume
expectValid(entry);

// when
changeInput(input, '=FOOBAR');

// then
expectValid(entry);
});


it('should not validate pattern', async function() {

// given
await expectSelected('ValidateTask');

const entry = findEntry(`custom-entry-com.validated-inputs.Task-${selector}-3`, container),
input = domQuery(selector, entry);

// assume
expectError(entry, 'Must match pattern A+B.');

// when
changeInput(input, '=FOO');

// then
expectValid(entry);
});

});

});

});

});


Expand Down

0 comments on commit 0be4966

Please sign in to comment.