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 <nico.rehwaldt@camunda.com>
  • Loading branch information
barmac and nikku committed Nov 8, 2024
1 parent d6ee809 commit ce75a55
Show file tree
Hide file tree
Showing 3 changed files with 98 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
4 changes: 4 additions & 0 deletions packages/dmn-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ___Note:__ Yet to be released changes appear here._

* Keyboard (DRD) is now implicit, and canvas is focusable, cf. [bpmn-io/diagram-js#662](https://github.com/bpmn-io/diagram-js/pull/662))

## 16.8.2

* `FIX`: make name change behavior not break on name change ([#917](https://github.com/bpmn-io/dmn-js/pull/917))

## 16.8.1

* `FIX`: make literal expression editor hitbox bigger in BKM ([camunda/camunda-modeler#4545](https://github.com/camunda/camunda-modeler/issues/4545))
Expand Down

0 comments on commit ce75a55

Please sign in to comment.