Skip to content

Commit

Permalink
fix: formal params sync
Browse files Browse the repository at this point in the history
Closes #896
  • Loading branch information
abdul99ahad authored and barmac committed Nov 14, 2024
1 parent 75c490c commit 1344ecb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const FunctionDefinitionEditorComponent = withChangeSupport(
props => [ props.expression ]
);


function _FunctionDefinitionEditorComponent({ expression }, context) {
const functionDefinition = context.injector.get('functionDefinition');
const contextMenu = context.injector.get('contextMenu');
Expand Down Expand Up @@ -50,7 +51,7 @@ function _FunctionDefinitionEditorComponent({ expression }, context) {
parameters={ parameters }
openEditor={ openFormalParametersEditor }
/>
<BodyExpression expression={ body } />
<BodyExpression expression={ body } parameters={ parameters } />
</div>
);
}
Expand Down Expand Up @@ -102,14 +103,18 @@ function _Parameter({ parameter }) {
</span>;
}

function BodyExpression({ expression }, context) {
const BodyExpression = withChangeSupport(_BodyExpression, props => props.parameters);

function _BodyExpression({ expression, parameters }, context) {
const Expression = context.components.getComponent('expression', {
expression
});

console.log('parameters BodyExpression: ', parameters);

return (
<div className="function-definition-body">
<Expression expression={ expression } />
<Expression expression={ expression } parameters={ parameters } />
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
/* global sinon */

import { bootstrapModeler, inject } from 'test/helper';

import functionDefinitionXML from './function-definition.dmn';

import { waitFor } from '@testing-library/dom';

describe('FunctionDefinitionEditor', function() {

beforeEach(bootstrapModeler(functionDefinitionXML));
const variableResolver = {
getVariables: () => [
{ name: 'Variable', typeRef: 'string' }
],
registerProvider: () => {}
};

beforeEach(bootstrapModeler(functionDefinitionXML, {
additionalModules: [
{
variableResolver: [ 'value', variableResolver ]
}
]
}));

describe('#getParameters', function() {

Expand Down Expand Up @@ -102,6 +119,11 @@ describe('FunctionDefinitionEditor', function() {

describe('#updateParameter', function() {

afterEach(function() {
sinon.restore();
});


it('should update parameter', inject(
function(viewer, functionDefinition) {

Expand All @@ -120,5 +142,28 @@ describe('FunctionDefinitionEditor', function() {
expect(updated).to.have.property('typeRef', 'bar');
})
);

it('should update variable', inject(
async function(viewer, functionDefinition) {

// given
const bkm = viewer.getRootElement();
const expression = bkm.get('encapsulatedLogic');
const parameters = functionDefinition.getParameters(expression);
const parameter = parameters[0];

const getVariablesSpy = sinon.spy(variableResolver, 'getVariables');

// when
functionDefinition.updateParameter(
parameter, { name: 'foo-blocker', typeRef: 'bar' }
);

// then
await waitFor(() => {
expect(getVariablesSpy).to.have.been.called;
});
})
);
});
});

0 comments on commit 1344ecb

Please sign in to comment.