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
  • Loading branch information
barmac committed Nov 8, 2024
1 parent e9f8a22 commit 38b5c31
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,117 @@ import Modeling from 'src/features/modeling';

describe('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 38b5c31

Please sign in to comment.