Skip to content

Commit

Permalink
fix: make name change behavior not break on name change
Browse files Browse the repository at this point in the history
Related to bpmn-io/dmn-js-properties-panel#103
Related to camunda/camunda-modeler#4684

Co-authored-by: Nico Rehwaldt <[email protected]>
  • Loading branch information
barmac and nikku authored Nov 8, 2024
1 parent e9f8a22 commit 4b4fd90
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,119 @@ import CoreModule from 'src/core';
import Modeling from 'src/features/modeling';


describe('NameChangeBehavior', function() {
describe('features/modeling - NameChangeBehavior', function() {

describe('with label change', function() {
beforeEach(bootstrapModeler(simpleStringEditXML, {
modules: [
CoreModule,
Modeling
],
}));

beforeEach(bootstrapModeler(simpleStringEditXML, {
modules: [
CoreModule,
Modeling
],
}));

describe('should update variable name when label is changed', function() {


it('<do>', inject(
function(modeling, elementRegistry) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;

// when
modeling.updateLabel(decision,'foo');
describe('should update variable name when label is changed', function() {

// then
expect(variable.get('name')).to.equal('foo');
}
));


it('<undo>', inject(function(modeling, elementRegistry, commandStack) {
it('<do>', inject(
function(modeling, elementRegistry) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;
modeling.updateLabel(decision,'foo');

// when
commandStack.undo();
modeling.updateLabel(decision,'foo');

// then
expect(variable.get('name')).to.equal('season');
}));
expect(variable.get('name')).to.equal('foo');
}
));


it('<undo>', inject(function(modeling, elementRegistry, commandStack) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;
modeling.updateLabel(decision,'foo');

// when
commandStack.undo();

// then
expect(variable.get('name')).to.equal('season');
}));


it('<redo>', inject(function(modeling, elementRegistry, commandStack) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;
modeling.updateLabel(decision,'foo');

// when
commandStack.undo();
commandStack.redo();

// then
expect(variable.get('name')).to.equal('foo');
}));
});


describe('should update variable name when element name is changed', function() {

it('<redo>', inject(function(modeling, elementRegistry, commandStack) {

it('<do>', inject(
function(modeling, elementRegistry) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;
modeling.updateLabel(decision,'foo');

// when
commandStack.undo();
commandStack.redo();
modeling.updateProperties(decision, { name: 'foo' });

// then
expect(variable.get('name')).to.equal('foo');
}));
});
}
));


it('<undo>', inject(function(modeling, elementRegistry, commandStack) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;
modeling.updateProperties(decision, { name: 'foo' });

// when
commandStack.undo();

// then
expect(variable.get('name')).to.equal('season');
}));


it('<redo>', inject(function(modeling, elementRegistry, commandStack) {

// given
const decision = elementRegistry.get('season'),
bo = decision.businessObject,
variable = bo.variable;
modeling.updateProperties(decision, { name: 'foo' });

// when
commandStack.undo();
commandStack.redo();

// then
expect(variable.get('name')).to.equal('foo');
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class NameChangeBehavior extends CommandInterceptor {
return;
}

else if (!this.isElementVariable(element)) {
else if (!this.shouldSyncVariable(element)) {
this.syncElementVariableChange(bo);
}
};
Expand All @@ -68,9 +68,10 @@ export default class NameChangeBehavior extends CommandInterceptor {
);
}

isElementVariable(element) {
const variable = element.get('variable');
return variable && (element.name === variable.name);
shouldSyncVariable(element) {
const bo = getBusinessObject(element),
variable = bo.get('variable');
return variable && (bo.name === variable.name);
}

syncElementVariableChange(businessObject) {
Expand Down

0 comments on commit 4b4fd90

Please sign in to comment.