Skip to content

Commit

Permalink
wip wip min max feel
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed May 30, 2023
1 parent f80bdb7 commit 67f1a12
Show file tree
Hide file tree
Showing 11 changed files with 513 additions and 46 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@babel/core": "^7.18.10",
"@babel/plugin-transform-react-jsx": "^7.14.5",
"@babel/plugin-transform-react-jsx-source": "^7.14.5",
"@bpmn-io/properties-panel": "^2.1.0",
"@bpmn-io/properties-panel": "^2.2.0",
"@carbon/react": "^1.24.0",
"@carbon/styles": "^1.23.1",
"@playwright/test": "1.34.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/form-js-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"@bpmn-io/form-js-viewer": "^1.0.0-alpha.0",
"@bpmn-io/properties-panel": "^2.1.0",
"@bpmn-io/properties-panel": "^2.2.0",
"array-move": "^3.0.1",
"big.js": "^6.2.1",
"dragula": "^3.7.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
import {
CheckboxEntry,
isCheckboxEntryEdited,
isNumberFieldEntryEdited,
isFeelEntryEdited,
FeelNumberEntry,
isTextFieldEntryEdited,
NumberFieldEntry,
TextFieldEntry,
SelectEntry
} from '@bpmn-io/properties-panel';

import { useService } from '../hooks';
import { useService, useVariables } from '../hooks';

import { INPUTS } from '../Util';

Expand Down Expand Up @@ -87,15 +87,15 @@ export default function ValidationGroup(field, editField) {
component: MinLength,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
},
{
id: 'maxLength',
component: MaxLength,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
}
);
Expand All @@ -121,15 +121,15 @@ export default function ValidationGroup(field, editField) {
component: Min,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
},
{
id: 'max',
component: Max,
getValue,
field,
isEdited: isNumberFieldEntryEdited,
isEdited: isFeelEntryEdited,
onChange
}
);
Expand Down Expand Up @@ -169,14 +169,18 @@ function MinLength(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
getValue: getValue('minLength'),
id,
label: 'Minimum length',
min: 0,
setValue: onChange('minLength')
setValue: onChange('minLength'),
variables
});
}

Expand All @@ -190,14 +194,18 @@ function MaxLength(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
getValue: getValue('maxLength'),
id,
label: 'Maximum length',
min: 0,
setValue: onChange('maxLength')
setValue: onChange('maxLength'),
variables
});
}

Expand Down Expand Up @@ -231,14 +239,18 @@ function Min(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
id,
label: 'Minimum',
step: 'any',
getValue: getValue('min'),
setValue: onChange('min')
setValue: onChange('min'),
variables
});
}

Expand All @@ -252,14 +264,18 @@ function Max(props) {

const debounce = useService('debounce');

return NumberFieldEntry({
const variables = useVariables().map(name => ({ name }));

return FeelNumberEntry({
debounce,
element: field,
feel: 'optional',
id,
label: 'Maximum',
step: 'any',
getValue: getValue('max'),
setValue: onChange('max')
setValue: onChange('max'),
variables
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,8 @@ describe('properties panel', function() {
});

// assume
const input = screen.getByLabelText('Maximum length');
// the fx toggle is screened as well
const input = screen.getAllByLabelText('Maximum length').find((el) => el.type === 'number');

expect(input.min).to.equal('0');

Expand Down Expand Up @@ -2097,7 +2098,7 @@ describe('properties panel', function() {
});

// assume
const input = screen.getByLabelText('Minimum length');
const input = screen.getAllByLabelText('Minimum length').find((el) => el.type === 'number');

expect(input.min).to.equal('0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ValidationGroup } from '../../../../../src/features/properties-panel/gr

import { WithPropertiesPanelContext, WithPropertiesPanel } from '../helper';

import { setEditorValue } from '../../../../helper';


describe('ValidationGroup', function() {

Expand Down Expand Up @@ -78,6 +80,7 @@ describe('ValidationGroup', function() {

});


describe('validationType', function() {

it('should render for textfield', function() {
Expand Down Expand Up @@ -462,6 +465,21 @@ describe('ValidationGroup', function() {
});


it('should read (expression)', function() {

// given
const field = { type: 'number', validate: { min: '=2' } };

// when
const { container } = renderValidationGroup({ field });

// then
const minInput = findTextbox('min', container);

expect(minInput.textContent).to.eql('2');
});


it('should write', function() {

// given
Expand All @@ -487,6 +505,34 @@ describe('ValidationGroup', function() {
});


it('should write (expression)', async function() {

// given
const field = {
type: 'number',
validate: {
min: '=3'
}
};

const editFieldSpy = sinon.spy();

const { container } = renderValidationGroup({ field, editField: editFieldSpy });

const minInput = findTextbox('min', container);

// assume
expect(minInput.textContent).to.equal('3');

// when
await setEditorValue(minInput, '2');

// then
expect(editFieldSpy).to.have.been.calledOnce;
expect(field.validate.min).to.equal('=2');
});


it('should write decimal', function() {

// given
Expand Down Expand Up @@ -567,6 +613,21 @@ describe('ValidationGroup', function() {
});


it('should read (expression)', function() {

// given
const field = { type: 'number', validate: { max: '=2' } };

// when
const { container } = renderValidationGroup({ field });

// then
const maxInput = findTextbox('max', container);

expect(maxInput.textContent).to.eql('2');
});


it('should write', function() {

// given
Expand All @@ -592,6 +653,34 @@ describe('ValidationGroup', function() {
});


it('should write (expression)', async function() {

// given
const field = {
type: 'number',
validate: {
max: '=3'
}
};

const editFieldSpy = sinon.spy();

const { container } = renderValidationGroup({ field, editField: editFieldSpy });

const maxInput = findTextbox('max', container);

// assume
expect(maxInput.textContent).to.equal('3');

// when
await setEditorValue(maxInput, '2');

// then
expect(editFieldSpy).to.have.been.calledOnce;
expect(field.validate.max).to.equal('=2');
});


it('should write decimal', function() {

// given
Expand Down Expand Up @@ -643,4 +732,8 @@ function findInput(id, container) {

function findSelect(id, container) {
return container.querySelector(`select[name="${id}"]`);
}

function findTextbox(id, container) {
return container.querySelector(`[name=${id}] [role="textbox"]`);
}
Loading

0 comments on commit 67f1a12

Please sign in to comment.