Skip to content

Commit 737d57c

Browse files
marstammnikku
authored andcommitted
test: adjust to use getDi utility function
Related to #1472
1 parent 55258fc commit 737d57c

26 files changed

+432
-325
lines changed

test/matchers/BoundsMatchers.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
} from 'min-dash';
44

55
import {
6-
getBusinessObject
6+
getDi
77
} from 'lib/util/ModelUtil';
88

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

85-
var bo = getBusinessObject(obj);
85+
var di = getDi(obj);
8686

87-
expect(bo).to.have.property('di');
87+
expect(di).to.exist;
8888

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

9292
/**
@@ -125,11 +125,11 @@ export default function(chai, utils) {
125125

126126
var obj = this._obj;
127127

128-
var bo = getBusinessObject(obj);
128+
var di = getDi(obj);
129129

130-
expect(bo).to.have.property('di');
130+
expect(di).to.exist;
131131

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

135135

@@ -169,11 +169,11 @@ export default function(chai, utils) {
169169

170170
var obj = this._obj;
171171

172-
var bo = getBusinessObject(obj);
172+
var di = getDi(obj);
173173

174-
expect(bo).to.have.property('di');
174+
expect(di).to.exist;
175175

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

179179

test/matchers/ConnectionMatchers.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
} from 'min-dash';
44

55
import {
6-
getBusinessObject
6+
getDi
77
} from 'lib/util/ModelUtil';
88

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

64-
var bo = getBusinessObject(obj);
64+
var di = getDi(obj);
6565

66-
expect(bo).to.have.property('di');
66+
expect(di).to.exist;
6767

68-
expect(bo.di).to.have.property('waypoint');
68+
expect(di).to.have.property('waypoint');
6969

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

7373

test/spec/ModelerSpec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
collectTranslations
1515
} from 'test/TestHelper';
1616

17+
import { getDi } from 'lib/util/ModelUtil';
18+
1719

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

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

415417
var subProcess = elementRegistry.get('SubProcess_1').businessObject;
416-
var bpmnEdge = elementRegistry.get('SequenceFlow_3').businessObject.di;
418+
var bpmnEdge = getDi(elementRegistry.get('SequenceFlow_3'));
417419

418420
// then
419421
expect(moddle.ids.assigned('SubProcess_1')).to.eql(subProcess);

test/spec/ViewerSpec.js

+6-26
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
createViewer
1313
} from 'test/TestHelper';
1414

15+
import { getDi } from 'lib/util/ModelUtil';
16+
1517
var singleStart = window.__env__ && window.__env__.SINGLE_START === 'viewer';
1618

1719

@@ -960,13 +962,13 @@ describe('Viewer', function() {
960962

961963
expect(err).not.to.exist;
962964

963-
renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di;
965+
renderedDiagram = getDi(viewer.get('canvas').getRootElement());
964966

965967
return viewer.open();
966968
}).then(function() {
967969

968970
// then
969-
expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram);
971+
expect(getDi(viewer.get('canvas').getRootElement())).to.equal(renderedDiagram);
970972
});
971973
});
972974

@@ -1715,28 +1717,6 @@ describe('Viewer', function() {
17151717
expect(clearDiagram).to.not.throw();
17161718
});
17171719

1718-
1719-
it('should remove di property', function() {
1720-
1721-
var xml = require('../fixtures/bpmn/simple.bpmn');
1722-
1723-
var viewer = new Viewer({ container: container }),
1724-
elementRegistry = viewer.get('elementRegistry');
1725-
1726-
return viewer.importXML(xml).then(function(result) {
1727-
1728-
var elements = elementRegistry.getAll();
1729-
1730-
// when
1731-
viewer.clear();
1732-
1733-
// then
1734-
expect(elements.some(function(el) {
1735-
return el && el.businessObject && el.businessObject.di;
1736-
}), 'at least one element still has di').to.be.false;
1737-
});
1738-
});
1739-
17401720
});
17411721

17421722

@@ -1976,11 +1956,11 @@ describe('Viewer', function() {
19761956

19771957
expect(err).not.to.exist;
19781958

1979-
renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di;
1959+
renderedDiagram = getDi(viewer.get('canvas').getRootElement());
19801960

19811961
viewer.open(function(err) {
19821962

1983-
expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram);
1963+
expect(getDi(viewer.get('canvas').getRootElement())).to.equal(renderedDiagram);
19841964

19851965
done(err);
19861966
});

test/spec/features/copy-paste/BpmnCopyPasteSpec.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424

2525
import {
2626
getBusinessObject,
27+
getDi,
2728
is
2829
} from 'lib/util/ModelUtil';
2930

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

379-
var taskBo = getBusinessObject(task);
380+
var di = getDi(task);
380381

381-
expect(taskBo.di.get('background-color')).to.equal(fill);
382-
expect(taskBo.di.get('border-color')).to.equal(stroke);
382+
expect(di.get('background-color')).to.equal(fill);
383+
expect(di.get('border-color')).to.equal(stroke);
383384

384385
// TODO @barmac: remove when we drop bpmn.io properties
385-
expect(taskBo.di.fill).to.equal(fill);
386-
expect(taskBo.di.stroke).to.equal(stroke);
386+
expect(di.fill).to.equal(fill);
387+
expect(di.stroke).to.equal(stroke);
387388
})
388389
);
389390

test/spec/features/modeling/AppendShapeSpec.js

+43-26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {
77
find
88
} from 'min-dash';
99

10+
import {
11+
getDi
12+
} from 'lib/util/ModelUtil';
13+
1014
import modelingModule from 'lib/features/modeling';
1115
import coreModule from 'lib/core';
1216

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

44-
var startEvent = startEventShape.businessObject;
48+
var startEventDi = getDi(startEventShape);
4549

4650
// when
4751
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
48-
target = targetShape.businessObject;
52+
targetDi = getDi(targetShape);
4953

5054
// then
51-
expect(target.di).to.exist;
52-
expect(target.di.$parent).to.eql(startEvent.di.$parent);
55+
expect(targetDi).to.exist;
56+
expect(targetDi.$parent).to.eql(startEventDi.$parent);
5357

54-
expect(target.di).to.have.bounds(targetShape);
58+
expect(targetDi).to.have.bounds(targetShape);
5559
}));
5660

5761

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

108-
var subProcess = subProcessShape.businessObject;
112+
var subProcess = subProcessShape.businessObject,
113+
subProcessDi = getDi(subProcessShape);
109114

110115
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
111-
target = targetShape.businessObject;
116+
target = targetShape.businessObject,
117+
targetDi = getDi(targetShape);
112118

113119
// when
114120
commandStack.undo();
115121

116122
// then
117123
expect(subProcess.get('flowElements')).not.to.include(target);
118-
expect(subProcess.di.$parent.get('planeElement')).not.to.include(target.di);
124+
expect(subProcessDi.$parent.get('planeElement')).not.to.include(targetDi);
119125
}));
120126

121127

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

128134
var startEvent = startEventShape.businessObject,
135+
startEventDi = getDi(startEventShape),
129136
subProcess = subProcessShape.businessObject;
130137

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

134141
var connection = find(subProcess.get('flowElements'), function(e) {
135-
return e.sourceRef === startEvent && e.targetRef === target;
136-
});
142+
return e.sourceRef === startEvent && e.targetRef === target;
143+
}),
144+
connectionDi = getDi(connection);
145+
137146

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

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

158167
var startEvent = startEventShape.businessObject,
159-
subProcess = subProcessShape.businessObject;
168+
subProcess = subProcessShape.businessObject,
169+
subProcessDi = getDi(subProcessShape);
160170

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

164174
var connection = find(subProcess.get('flowElements'), function(e) {
165-
return e.sourceRef === startEvent && e.targetRef === target;
166-
});
175+
return e.sourceRef === startEvent && e.targetRef === target;
176+
}),
177+
connectionDi = getDi(connection);
167178

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

178189
expect(connection.$parent).to.be.null;
179-
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
190+
expect(subProcessDi.$parent.get('planeElement')).not.to.include(connectionDi);
180191

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

191202
var startEvent = startEventShape.businessObject,
192-
subProcess = subProcessShape.businessObject;
203+
subProcess = subProcessShape.businessObject,
204+
subProcessDi = getDi(subProcessShape);
193205

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

197209
var connection = find(subProcess.get('flowElements'), function(e) {
198-
return e.sourceRef === startEvent && e.targetRef === target;
199-
});
210+
return e.sourceRef === startEvent && e.targetRef === target;
211+
}),
212+
connectionDi = getDi(connection);
200213

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

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

250263
var startEvent = startEventShape.businessObject,
251-
subProcess = subProcessShape.businessObject;
264+
subProcess = subProcessShape.businessObject,
265+
subProcessDi = getDi(subProcessShape);
252266

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

256270
var connection = find(subProcess.get('flowElements'), function(e) {
257-
return e.sourceRef === startEvent && e.targetRef === target;
258-
});
271+
return e.sourceRef === startEvent && e.targetRef === target;
272+
}),
273+
connectionDi = getDi(connection);
259274

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

270-
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
285+
expect(subProcessDi.$parent.get('planeElement')).not.to.include(connectionDi);
271286
}));
272287

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

318-
var subProcess = subProcessShape.businessObject;
333+
var subProcess = subProcessShape.businessObject,
334+
subProcessDi = getDi(subProcessShape);
319335

320336
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:ExclusiveGateway' }),
321-
target = targetShape.businessObject;
337+
target = targetShape.businessObject,
338+
targetDi = getDi(targetShape);
322339

323340
// when
324341
commandStack.undo();
325342

326343
// then
327344
expect(subProcess.get('flowElements')).not.to.include(target);
328-
expect(subProcess.di.$parent.get('planeElement')).not.to.include(target.di);
345+
expect(subProcessDi.$parent.get('planeElement')).not.to.include(targetDi);
329346
}));
330347

331348
});

0 commit comments

Comments
 (0)