Skip to content

Commit fe3bc35

Browse files
committed
chore: fix test cases
closes #1472
1 parent 089829e commit fe3bc35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+550
-481
lines changed

lib/BaseViewer.js

-13
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,6 @@ BaseViewer.prototype.clear = function() {
528528
return;
529529
}
530530

531-
// remove businessObject#di binding
532-
//
533-
// this is necessary, as we establish the bindings
534-
// in the BpmnTreeWalker (and assume none are given
535-
// on reimport)
536-
this.get('elementRegistry').forEach(function(element) {
537-
var bo = element.businessObject;
538-
539-
if (bo && bo.di) {
540-
delete bo.di;
541-
}
542-
});
543-
544531
// remove drawn elements
545532
Diagram.prototype.clear.call(this);
546533
};

lib/draw/BpmnRenderer.js

-1
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,6 @@ export default function BpmnRenderer(
11011101
var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
11021102

11031103
var expanded = isExpanded(element);
1104-
console.log('isExpanded', expanded);
11051104

11061105
if (isEventSubProcess(element)) {
11071106
svgAttr(rect, {

lib/features/context-pad/ContextPadProvider.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
197197
}
198198

199199

200-
if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(businessObject)) {
200+
if (isAny(businessObject, [ 'bpmn:Lane', 'bpmn:Participant' ]) && isExpanded(element)) {
201201

202202
var childLanes = getChildLanes(element);
203203

lib/features/copy-paste/BpmnCopyPaste.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
getBusinessObject,
3+
getDi,
34
is
45
} from '../../util/ModelUtil';
56

@@ -45,23 +46,13 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
4546
element = context.element;
4647

4748
var businessObject = descriptor.oldBusinessObject = getBusinessObject(element);
49+
var di = descriptor.oldDi = getDi(element);
4850

4951
descriptor.type = element.type;
5052

5153
copyProperties(businessObject, descriptor, 'name');
5254

53-
descriptor.di = {};
54-
55-
// colors will be set to DI
56-
copyProperties(businessObject.di, descriptor.di, [
57-
'fill',
58-
'stroke',
59-
'background-color',
60-
'border-color',
61-
'color'
62-
]);
63-
64-
copyProperties(businessObject.di, descriptor, 'isExpanded');
55+
copyProperties(di, descriptor, 'isExpanded');
6556

6657
if (isLabel(descriptor)) {
6758
return descriptor;
@@ -135,11 +126,13 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
135126
var cache = context.cache,
136127
descriptor = context.descriptor,
137128
oldBusinessObject = descriptor.oldBusinessObject,
138-
newBusinessObject;
129+
oldDi = descriptor.oldDi,
130+
newBusinessObject, newDi;
139131

140132
// do NOT copy business object if external label
141133
if (isLabel(descriptor)) {
142134
descriptor.businessObject = getBusinessObject(cache[ descriptor.labelTarget ]);
135+
descriptor.di = getDi(cache[ descriptor.labelTarget ]);
143136

144137
return;
145138
}
@@ -151,6 +144,13 @@ export default function BpmnCopyPaste(bpmnFactory, eventBus, moddleCopy) {
151144
newBusinessObject
152145
);
153146

147+
newDi = bpmnFactory.create(oldDi.$type);
148+
149+
descriptor.di = moddleCopy.copyElement(
150+
oldDi,
151+
newDi
152+
);
153+
154154
// resolve references e.g. default sequence flow
155155
resolveReferences(descriptor, cache);
156156

lib/features/di-ordering/BpmnDiOrdering.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { getDi } from '../../draw/BpmnRenderUtil';
2-
import { getBusinessObject } from '../../util/ModelUtil';
32

43
import {
54
filter,
@@ -17,7 +16,7 @@ export default function BpmnDiOrdering(eventBus, canvas) {
1716

1817
function orderDi() {
1918
var root = canvas.getRootElement(),
20-
rootDi = getBusinessObject(root).di,
19+
rootDi = getDi(root),
2120
elements,
2221
diElements;
2322

lib/features/label-editing/LabelEditingPreview.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from 'tiny-svg';
77

88
import {
9-
getBusinessObject,
9+
getDi,
1010
is
1111
} from '../../util/ModelUtil';
1212

@@ -132,7 +132,7 @@ LabelEditingPreview.$inject = [
132132
// helpers ///////////////////
133133

134134
function getStrokeColor(element, defaultColor) {
135-
var bo = getBusinessObject(element);
135+
var di = getDi(element);
136136

137-
return bo.di.get('stroke') || defaultColor || 'black';
137+
return di.get('stroke') || defaultColor || 'black';
138138
}

lib/features/label-editing/cmd/UpdateLabelHandler.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export default function UpdateLabelHandler(modeling, textRenderer) {
6767

6868
modeling.createLabel(element, labelCenter, {
6969
id: businessObject.id + '_label',
70-
businessObject: businessObject
70+
businessObject: businessObject,
71+
di: element.di
7172
});
7273
}
7374
}

lib/features/modeling/BpmnUpdater.js

+39-29
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616

1717
import {
1818
getBusinessObject,
19+
getDi,
1920
is
2021
} from '../../util/ModelUtil';
2122

@@ -307,9 +308,9 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
307308
var parentShape = element.parent;
308309

309310
var businessObject = element.businessObject,
310-
di = element.di,
311+
di = getDi(element),
311312
parentBusinessObject = parentShape && parentShape.businessObject,
312-
parentDi = parentShape && parentShape.di;
313+
parentDi = getDi(parentShape);
313314

314315
if (is(element, 'bpmn:FlowNode')) {
315316
this.updateFlowNodeRefs(businessObject, parentBusinessObject, oldParent && oldParent.businessObject);
@@ -343,7 +344,7 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
343344

344345
BpmnUpdater.prototype.updateBounds = function(shape) {
345346

346-
var di = shape.di;
347+
var di = getDi(shape);
347348

348349
var target = (shape instanceof Label) ? this._getLabel(di) : di;
349350

@@ -383,14 +384,17 @@ BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainme
383384

384385

385386
// update existing sourceElement and targetElement di information
386-
BpmnUpdater.prototype.updateDiConnection = function(di, newSource, newTarget) {
387+
BpmnUpdater.prototype.updateDiConnection = function(connection, newSource, newTarget) {
388+
var connectionDi = getDi(connection),
389+
newSourceDi = getDi(newSource),
390+
newTargetDi = getDi(newTarget);
387391

388-
if (di.sourceElement && di.sourceElement.bpmnElement !== newSource) {
389-
di.sourceElement = newSource && newSource.di;
392+
if (connectionDi.sourceElement && connectionDi.sourceElement.bpmnElement !== getBusinessObject(newSource)) {
393+
connectionDi.sourceElement = newSource && newSourceDi;
390394
}
391395

392-
if (di.targetElement && di.targetElement.bpmnElement !== newTarget) {
393-
di.targetElement = newTarget && newTarget.di;
396+
if (connectionDi.targetElement && connectionDi.targetElement.bpmnElement !== getBusinessObject(newTarget)) {
397+
connectionDi.targetElement = newTarget && newTargetDi;
394398
}
395399

396400
};
@@ -406,6 +410,11 @@ BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
406410
return;
407411
}
408412

413+
// Cover the case where di.$parent === undefined and parentDi === null
414+
if (!parentDi && !di.$parent) {
415+
return;
416+
}
417+
409418
var planeElements = (parentDi || di.$parent).get('planeElement');
410419

411420
if (parentDi) {
@@ -615,71 +624,72 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent,
615624

616625

617626
BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
618-
connection.di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
627+
var di = getDi(connection);
628+
629+
di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
619630
};
620631

621632

622633
BpmnUpdater.prototype.updateConnection = function(context) {
623-
624634
var connection = context.connection,
625635
businessObject = getBusinessObject(connection),
626-
newSource = getBusinessObject(connection.source),
627-
newTarget = getBusinessObject(connection.target),
636+
newSource = connection.source,
637+
newSourceBo = getBusinessObject(newSource),
638+
newTarget = connection.target,
639+
newTargetBo = getBusinessObject(connection.target),
628640
visualParent;
629641

630642
if (!is(businessObject, 'bpmn:DataAssociation')) {
631643

632644
var inverseSet = is(businessObject, 'bpmn:SequenceFlow');
633645

634-
if (businessObject.sourceRef !== newSource) {
646+
if (businessObject.sourceRef !== newSourceBo) {
635647
if (inverseSet) {
636648
collectionRemove(businessObject.sourceRef && businessObject.sourceRef.get('outgoing'), businessObject);
637649

638-
if (newSource && newSource.get('outgoing')) {
639-
newSource.get('outgoing').push(businessObject);
650+
if (newSourceBo && newSourceBo.get('outgoing')) {
651+
newSourceBo.get('outgoing').push(businessObject);
640652
}
641653
}
642654

643-
businessObject.sourceRef = newSource;
655+
businessObject.sourceRef = newSourceBo;
644656
}
645657

646-
if (businessObject.targetRef !== newTarget) {
658+
if (businessObject.targetRef !== newTargetBo) {
647659
if (inverseSet) {
648660
collectionRemove(businessObject.targetRef && businessObject.targetRef.get('incoming'), businessObject);
649661

650-
if (newTarget && newTarget.get('incoming')) {
651-
newTarget.get('incoming').push(businessObject);
662+
if (newTargetBo && newTargetBo.get('incoming')) {
663+
newTargetBo.get('incoming').push(businessObject);
652664
}
653665
}
654666

655-
businessObject.targetRef = newTarget;
667+
businessObject.targetRef = newTargetBo;
656668
}
657669
} else
658670

659671
if (is(businessObject, 'bpmn:DataInputAssociation')) {
660672

661673
// handle obnoxious isMsome sourceRef
662-
businessObject.get('sourceRef')[0] = newSource;
674+
businessObject.get('sourceRef')[0] = newSourceBo;
663675

664-
visualParent = context.parent || context.newParent || newTarget;
676+
visualParent = context.parent || context.newParent || newTargetBo;
665677

666-
this.updateSemanticParent(businessObject, newTarget, visualParent);
678+
this.updateSemanticParent(businessObject, newTargetBo, visualParent);
667679
} else
668680

669681
if (is(businessObject, 'bpmn:DataOutputAssociation')) {
670-
visualParent = context.parent || context.newParent || newSource;
682+
visualParent = context.parent || context.newParent || newSourceBo;
671683

672-
this.updateSemanticParent(businessObject, newSource, visualParent);
684+
this.updateSemanticParent(businessObject, newSourceBo, visualParent);
673685

674686
// targetRef = new target
675-
businessObject.targetRef = newTarget;
687+
businessObject.targetRef = newTargetBo;
676688
}
677689

678690
this.updateConnectionWaypoints(connection);
679691

680-
console.log(context);
681-
682-
this.updateDiConnection(businessObject.di, newSource, newTarget);
692+
this.updateDiConnection(connection, newSource, newTarget);
683693
};
684694

685695

lib/features/modeling/ElementFactory.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ ElementFactory.prototype.create = function(elementType, attrs) {
4646
// we assume their businessObjects have already been created
4747
// and wired via attrs
4848
if (elementType === 'label') {
49-
return this.baseCreate(elementType, assign({ type: 'label' }, DEFAULT_LABEL_SIZE, attrs));
49+
var di = attrs.di || this._bpmnFactory.createDiLabel();
50+
return this.baseCreate(elementType, assign({ type: 'label', di: di }, DEFAULT_LABEL_SIZE, attrs));
5051
}
5152

5253
return this.createBpmnElement(elementType, attrs);
@@ -71,7 +72,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
7172

7273
if (!di) {
7374
if (elementType === 'root') {
74-
businessObject.di = this._bpmnFactory.createDiPlane(businessObject, [], {
75+
di = this._bpmnFactory.createDiPlane(businessObject, [], {
7576
id: businessObject.id + '_di'
7677
});
7778
} else
@@ -84,8 +85,6 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
8485
id: businessObject.id + '_di'
8586
});
8687
}
87-
88-
attrs.di = di;
8988
}
9089

9190
if (is(businessObject, 'bpmn:Group')) {
@@ -132,6 +131,7 @@ ElementFactory.prototype.createBpmnElement = function(elementType, attrs) {
132131

133132
attrs = assign({
134133
businessObject: businessObject,
134+
di: di,
135135
id: businessObject.id
136136
}, size, attrs);
137137

lib/features/modeling/behavior/DataStoreBehavior.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
44

55
import {
66
getBusinessObject,
7+
getDi,
78
is
89
} from '../../../util/ModelUtil';
910

@@ -45,8 +46,9 @@ export default function DataStoreBehavior(
4546

4647
commandStack.execute('dataStore.updateContainment', {
4748
dataStoreBo: dataStoreBo,
49+
dataStoreDi: getDi(dataStore),
4850
newSemanticParent: newDataStoreParentBo.processRef || newDataStoreParentBo,
49-
newDiParent: newDataStoreParentBo.di
51+
newDiParent: getDi(newDataStoreParent)
5052
});
5153
}
5254
}

lib/features/modeling/behavior/IsHorizontalFix.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import inherits from 'inherits';
33
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
44

55
import {
6-
getBusinessObject
6+
getBusinessObject,
7+
getDi
78
} from '../../../util/ModelUtil';
89

910
import {
@@ -26,12 +27,14 @@ export default function IsHorizontalFix(eventBus) {
2627
];
2728

2829
this.executed([ 'shape.move', 'shape.create', 'shape.resize' ], function(event) {
29-
var bo = getBusinessObject(event.context.shape);
30+
var shape = event.context.shape,
31+
bo = getBusinessObject(shape),
32+
di = getDi(shape);
3033

31-
if (isAny(bo, elementTypesToUpdate) && !bo.di.get('isHorizontal')) {
34+
if (isAny(bo, elementTypesToUpdate) && !di.get('isHorizontal')) {
3235

3336
// set attribute directly to avoid modeling#updateProperty side effects
34-
bo.di.set('isHorizontal', true);
37+
di.set('isHorizontal', true);
3538
}
3639
});
3740

0 commit comments

Comments
 (0)