Skip to content

Commit

Permalink
test: adjust to use getDi utility function
Browse files Browse the repository at this point in the history
Related to #1472
  • Loading branch information
marstamm authored and nikku committed Aug 27, 2021
1 parent 55258fc commit 737d57c
Show file tree
Hide file tree
Showing 26 changed files with 432 additions and 325 deletions.
20 changes: 10 additions & 10 deletions test/matchers/BoundsMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from 'min-dash';

import {
getBusinessObject
getDi
} from 'lib/util/ModelUtil';

var BOUNDS_ATTRS = [ 'x', 'y', 'width', 'height' ],
Expand Down Expand Up @@ -82,11 +82,11 @@ export default function(chai, utils) {
Assertion.addMethod('diBounds', function(exp) {
var obj = this._obj;

var bo = getBusinessObject(obj);
var di = getDi(obj);

expect(bo).to.have.property('di');
expect(di).to.exist;

assertBounds(this, bo.id + '#di', getBounds(bo.di), getBounds(exp));
assertBounds(this, di.id, getBounds(di), getBounds(exp));
});

/**
Expand Down Expand Up @@ -125,11 +125,11 @@ export default function(chai, utils) {

var obj = this._obj;

var bo = getBusinessObject(obj);
var di = getDi(obj);

expect(bo).to.have.property('di');
expect(di).to.exist;

assertDimensions(this, bo.id + '#di', getDimensions(bo.di), getDimensions(exp));
assertDimensions(this, di.id, getDimensions(di), getDimensions(exp));
});


Expand Down Expand Up @@ -169,11 +169,11 @@ export default function(chai, utils) {

var obj = this._obj;

var bo = getBusinessObject(obj);
var di = getDi(obj);

expect(bo).to.have.property('di');
expect(di).to.exist;

assertPosition(this, bo.id + '#di', getPosition(bo.di), getPosition(exp));
assertPosition(this, di.id, getPosition(di), getPosition(exp));
});


Expand Down
10 changes: 5 additions & 5 deletions test/matchers/ConnectionMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from 'min-dash';

import {
getBusinessObject
getDi
} from 'lib/util/ModelUtil';

var POSITION_ATTRS = [ 'x', 'y' ];
Expand Down Expand Up @@ -61,13 +61,13 @@ export default function(chai, utils) {
Assertion.addMethod('diWaypoints', function(exp) {
var obj = this._obj;

var bo = getBusinessObject(obj);
var di = getDi(obj);

expect(bo).to.have.property('di');
expect(di).to.exist;

expect(bo.di).to.have.property('waypoint');
expect(di).to.have.property('waypoint');

assertWaypoints(this, obj.id + '#di#waypoint', getPoints(bo.di.waypoint), getPoints(exp));
assertWaypoints(this, di + '#waypoint', getPoints(di.waypoint), getPoints(exp));
});


Expand Down
4 changes: 3 additions & 1 deletion test/spec/ModelerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
collectTranslations
} from 'test/TestHelper';

import { getDi } from 'lib/util/ModelUtil';


var singleStart = window.__env__ && window.__env__.SINGLE_START === 'modeler';

Expand Down Expand Up @@ -413,7 +415,7 @@ describe('Modeler', function() {
return modeler.importXML(xml).then(function() {

var subProcess = elementRegistry.get('SubProcess_1').businessObject;
var bpmnEdge = elementRegistry.get('SequenceFlow_3').businessObject.di;
var bpmnEdge = getDi(elementRegistry.get('SequenceFlow_3'));

// then
expect(moddle.ids.assigned('SubProcess_1')).to.eql(subProcess);
Expand Down
32 changes: 6 additions & 26 deletions test/spec/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
createViewer
} from 'test/TestHelper';

import { getDi } from 'lib/util/ModelUtil';

var singleStart = window.__env__ && window.__env__.SINGLE_START === 'viewer';


Expand Down Expand Up @@ -960,13 +962,13 @@ describe('Viewer', function() {

expect(err).not.to.exist;

renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di;
renderedDiagram = getDi(viewer.get('canvas').getRootElement());

return viewer.open();
}).then(function() {

// then
expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram);
expect(getDi(viewer.get('canvas').getRootElement())).to.equal(renderedDiagram);
});
});

Expand Down Expand Up @@ -1715,28 +1717,6 @@ describe('Viewer', function() {
expect(clearDiagram).to.not.throw();
});


it('should remove di property', function() {

var xml = require('../fixtures/bpmn/simple.bpmn');

var viewer = new Viewer({ container: container }),
elementRegistry = viewer.get('elementRegistry');

return viewer.importXML(xml).then(function(result) {

var elements = elementRegistry.getAll();

// when
viewer.clear();

// then
expect(elements.some(function(el) {
return el && el.businessObject && el.businessObject.di;
}), 'at least one element still has di').to.be.false;
});
});

});


Expand Down Expand Up @@ -1976,11 +1956,11 @@ describe('Viewer', function() {

expect(err).not.to.exist;

renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di;
renderedDiagram = getDi(viewer.get('canvas').getRootElement());

viewer.open(function(err) {

expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram);
expect(getDi(viewer.get('canvas').getRootElement())).to.equal(renderedDiagram);

done(err);
});
Expand Down
11 changes: 6 additions & 5 deletions test/spec/features/copy-paste/BpmnCopyPasteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {

import {
getBusinessObject,
getDi,
is
} from 'lib/util/ModelUtil';

Expand Down Expand Up @@ -376,14 +377,14 @@ describe('features/copy-paste', function() {
return is(element, 'bpmn:Task');
});

var taskBo = getBusinessObject(task);
var di = getDi(task);

expect(taskBo.di.get('background-color')).to.equal(fill);
expect(taskBo.di.get('border-color')).to.equal(stroke);
expect(di.get('background-color')).to.equal(fill);
expect(di.get('border-color')).to.equal(stroke);

// TODO @barmac: remove when we drop bpmn.io properties
expect(taskBo.di.fill).to.equal(fill);
expect(taskBo.di.stroke).to.equal(stroke);
expect(di.fill).to.equal(fill);
expect(di.stroke).to.equal(stroke);
})
);

Expand Down
69 changes: 43 additions & 26 deletions test/spec/features/modeling/AppendShapeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
find
} from 'min-dash';

import {
getDi
} from 'lib/util/ModelUtil';

import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';

Expand Down Expand Up @@ -41,17 +45,17 @@ describe('features/modeling - append shape', function() {
// given
var startEventShape = elementRegistry.get('StartEvent_1');

var startEvent = startEventShape.businessObject;
var startEventDi = getDi(startEventShape);

// when
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
target = targetShape.businessObject;
targetDi = getDi(targetShape);

// then
expect(target.di).to.exist;
expect(target.di.$parent).to.eql(startEvent.di.$parent);
expect(targetDi).to.exist;
expect(targetDi.$parent).to.eql(startEventDi.$parent);

expect(target.di).to.have.bounds(targetShape);
expect(targetDi).to.have.bounds(targetShape);
}));


Expand Down Expand Up @@ -105,17 +109,19 @@ describe('features/modeling - append shape', function() {
var startEventShape = elementRegistry.get('StartEvent_1'),
subProcessShape = elementRegistry.get('SubProcess_1');

var subProcess = subProcessShape.businessObject;
var subProcess = subProcessShape.businessObject,
subProcessDi = getDi(subProcessShape);

var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
target = targetShape.businessObject;
target = targetShape.businessObject,
targetDi = getDi(targetShape);

// when
commandStack.undo();

// then
expect(subProcess.get('flowElements')).not.to.include(target);
expect(subProcess.di.$parent.get('planeElement')).not.to.include(target.di);
expect(subProcessDi.$parent.get('planeElement')).not.to.include(targetDi);
}));


Expand All @@ -126,14 +132,17 @@ describe('features/modeling - append shape', function() {
subProcessShape = elementRegistry.get('SubProcess_1');

var startEvent = startEventShape.businessObject,
startEventDi = getDi(startEventShape),
subProcess = subProcessShape.businessObject;

var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' }),
target = targetShape.businessObject;

var connection = find(subProcess.get('flowElements'), function(e) {
return e.sourceRef === startEvent && e.targetRef === target;
});
return e.sourceRef === startEvent && e.targetRef === target;
}),
connectionDi = getDi(connection);


// when
commandStack.undo();
Expand All @@ -142,7 +151,7 @@ describe('features/modeling - append shape', function() {
expect(connection.sourceRef).to.be.null;
expect(connection.targetRef).to.be.null;
expect(connection.$parent).to.be.null;
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
expect(startEventDi.$parent.get('planeElement')).not.to.include(connectionDi);

expect(targetShape.label).not.to.exist;
expect(elementRegistry.get(target.id + '_label')).not.to.exist;
Expand All @@ -156,14 +165,16 @@ describe('features/modeling - append shape', function() {
var subProcessShape = elementRegistry.get('SubProcess_1');

var startEvent = startEventShape.businessObject,
subProcess = subProcessShape.businessObject;
subProcess = subProcessShape.businessObject,
subProcessDi = getDi(subProcessShape);

var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
target = targetShape.businessObject;

var connection = find(subProcess.get('flowElements'), function(e) {
return e.sourceRef === startEvent && e.targetRef === target;
});
return e.sourceRef === startEvent && e.targetRef === target;
}),
connectionDi = getDi(connection);

// when
commandStack.undo();
Expand All @@ -176,7 +187,7 @@ describe('features/modeling - append shape', function() {
expect(target.get('incoming')).not.to.include(connection);

expect(connection.$parent).to.be.null;
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
expect(subProcessDi.$parent.get('planeElement')).not.to.include(connectionDi);

expect(elementRegistry.get(targetShape.id)).not.to.exist;
}));
Expand All @@ -189,14 +200,16 @@ describe('features/modeling - append shape', function() {
var subProcessShape = elementRegistry.get('SubProcess_1');

var startEvent = startEventShape.businessObject,
subProcess = subProcessShape.businessObject;
subProcess = subProcessShape.businessObject,
subProcessDi = getDi(subProcessShape);

var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
target = targetShape.businessObject;

var connection = find(subProcess.get('flowElements'), function(e) {
return e.sourceRef === startEvent && e.targetRef === target;
});
return e.sourceRef === startEvent && e.targetRef === target;
}),
connectionDi = getDi(connection);

// when
commandStack.undo();
Expand All @@ -205,7 +218,7 @@ describe('features/modeling - append shape', function() {
expect(connection.sourceRef).to.be.null;
expect(connection.targetRef).to.be.null;
expect(connection.$parent).to.be.null;
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
expect(subProcessDi.$parent.get('planeElement')).not.to.include(connectionDi);

expect(elementRegistry.get(connection.id + '_label')).not.to.exist;
}));
Expand Down Expand Up @@ -248,14 +261,16 @@ describe('features/modeling - append shape', function() {
var subProcessShape = elementRegistry.get('SubProcess_1');

var startEvent = startEventShape.businessObject,
subProcess = subProcessShape.businessObject;
subProcess = subProcessShape.businessObject,
subProcessDi = getDi(subProcessShape);

var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
target = targetShape.businessObject;

var connection = find(subProcess.get('flowElements'), function(e) {
return e.sourceRef === startEvent && e.targetRef === target;
});
return e.sourceRef === startEvent && e.targetRef === target;
}),
connectionDi = getDi(connection);

// when
commandStack.undo();
Expand All @@ -267,7 +282,7 @@ describe('features/modeling - append shape', function() {
expect(connection.targetRef).to.be.null;
expect(connection.$parent).to.be.null;

expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
expect(subProcessDi.$parent.get('planeElement')).not.to.include(connectionDi);
}));

});
Expand Down Expand Up @@ -315,17 +330,19 @@ describe('features/modeling - append shape', function() {
var startEventShape = elementRegistry.get('StartEvent_1');
var subProcessShape = elementRegistry.get('SubProcess_1');

var subProcess = subProcessShape.businessObject;
var subProcess = subProcessShape.businessObject,
subProcessDi = getDi(subProcessShape);

var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:ExclusiveGateway' }),
target = targetShape.businessObject;
target = targetShape.businessObject,
targetDi = getDi(targetShape);

// when
commandStack.undo();

// then
expect(subProcess.get('flowElements')).not.to.include(target);
expect(subProcess.di.$parent.get('planeElement')).not.to.include(target.di);
expect(subProcessDi.$parent.get('planeElement')).not.to.include(targetDi);
}));

});
Expand Down
Loading

0 comments on commit 737d57c

Please sign in to comment.