Skip to content

Commit

Permalink
fix(Id): create validation function as callback
Browse files Browse the repository at this point in the history
closes #1021
  • Loading branch information
marstamm committed Feb 1, 2024
1 parent 716f8fc commit 1d81541
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/provider/bpmn/properties/IdProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {

import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';

import { useCallback } from '@bpmn-io/properties-panel/preact/hooks';

import {
useService
} from '../../../hooks';
Expand Down Expand Up @@ -50,15 +52,15 @@ function Id(props) {
});
};

const getValue = (element) => {
const getValue = useCallback((element) => {
return element.businessObject.id;
};
}, []);

const validate = (value) => {
const validate = useCallback((value) => {
const businessObject = getBusinessObject(element);

return isIdValid(businessObject, value, translate);
};
}, [ element, translate ]);

return TextFieldEntry({
element,
Expand Down
6 changes: 4 additions & 2 deletions src/provider/bpmn/properties/ProcessProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { is } from 'bpmn-js/lib/util/ModelUtil';

import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';

import { useCallback } from '@bpmn-io/properties-panel/preact/hooks';

import {
useService
} from '../../../hooks';
Expand Down Expand Up @@ -104,9 +106,9 @@ function ProcessId(props) {
);
};

const validate = (value) => {
const validate = useCallback((value) => {
return isIdValid(process, value, translate);
};
}, [ process, translate ]);

return TextFieldEntry({
element,
Expand Down
20 changes: 20 additions & 0 deletions test/spec/provider/bpmn/IdProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ describe('provider/bpmn - IdProps', function() {

describe('validation', function() {

it.only('should set invalid', inject(async function(elementRegistry, selection) {

Check failure on line 116 in test/spec/provider/bpmn/IdProps.spec.js

View workflow job for this annotation

GitHub Actions / Build (true, [email protected] [email protected])

Unexpected exclusive mocha test

Check failure on line 116 in test/spec/provider/bpmn/IdProps.spec.js

View workflow job for this annotation

GitHub Actions / Build (true, @bpmn-io/properties-panel@3)

Unexpected exclusive mocha test

Check failure on line 116 in test/spec/provider/bpmn/IdProps.spec.js

View workflow job for this annotation

GitHub Actions / Build (false)

Unexpected exclusive mocha test

// given
const task = elementRegistry.get('Task_1');

await act(() => {
selection.select(task);
});

// when
const idInput = domQuery('input[name=id]', container);
changeInput(idInput, '');
await act(() => {});

// then
const error = domQuery('.bio-properties-panel-error', container);
expect(error).to.exist;
}));


it('should NOT remove id', inject(async function(elementRegistry, selection) {

// given
Expand Down
20 changes: 20 additions & 0 deletions test/spec/provider/bpmn/ProcessProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,26 @@ describe('provider/bpmn - ProcessProps', function() {

describe('validation', function() {

it('should set invalid', inject(async function(elementRegistry, selection) {

// given
const participant = elementRegistry.get('Participant_1');

await act(() => {
selection.select(participant);
});

// when
const processIdInput = domQuery('input[name=processId]', container);
changeInput(processIdInput, '');
await act(() => {});

// then
const error = domQuery('.bio-properties-panel-error', container);
expect(error).to.exist;
}));


it('should NOT remove id', inject(async function(elementRegistry, selection) {

// given
Expand Down

0 comments on commit 1d81541

Please sign in to comment.