Skip to content

Commit

Permalink
fix(graphics-factory): do not prepend to self
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme authored and merge-me[bot] committed Jul 18, 2019
1 parent 3f1d558 commit bab7b80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 60 deletions.
20 changes: 14 additions & 6 deletions lib/core/GraphicsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GraphicsFactory.prototype._clear = function(gfx) {
* </g>
*
* @param {String} type the type of the element, i.e. shape | connection
* @param {Snap<SVGElement>} [childrenGfx]
* @param {SVGElement} [childrenGfx]
* @param {Number} [parentIndex] position to create container in parent
* @param {Boolean} [isFrame] is frame element
*
Expand Down Expand Up @@ -157,8 +157,7 @@ GraphicsFactory.prototype.updateContainments = function(elements) {

var children = parent.children;

// no need to update order if less than two children
if (!children || children.length < 2) {
if (!children) {
return;
}

Expand Down Expand Up @@ -197,7 +196,8 @@ GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
};

GraphicsFactory.prototype.update = function(type, element, gfx) {
// Do not update root element

// do NOT update root element
if (!element.parent) {
return;
}
Expand Down Expand Up @@ -232,8 +232,16 @@ GraphicsFactory.prototype.remove = function(element) {
};


// helpers //////////////////////
// helpers //////////

function prependTo(newNode, parentNode, siblingNode) {
parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild);
var node = siblingNode || parentNode.firstChild;

// do not prepend node to itself to prevent IE from crashing
// https://github.com/bpmn-io/bpmn-js/issues/746
if (newNode === node) {
return;
}

parentNode.insertBefore(newNode, node);
}
54 changes: 0 additions & 54 deletions test/spec/core/GraphicsFactorySpec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global sinon */

import {
bootstrapDiagram,
inject
Expand All @@ -9,8 +7,6 @@ import {
classes as svgClasses
} from 'tiny-svg';

var spy = sinon.spy;


describe('GraphicsFactory', function() {

Expand All @@ -33,56 +29,6 @@ describe('GraphicsFactory', function() {
));


describe('#updateContainments', function() {

var parent;

beforeEach(inject(function(canvas, elementFactory) {
var root = elementFactory.createRoot({
id: 'root'
});

canvas.setRootElement(root);

parent = elementFactory.createShape({
id: 'parent',
x: 100,
y: 100,
width: 100,
height: 100
});

canvas.addShape(parent, root);

var child = elementFactory.createShape({
id: 'child',
x: 125,
y: 125,
width: 50,
height: 50
});

canvas.addShape(child, parent);
}));


it('should NOT update containments if less than two children', inject(
function(elementRegistry, graphicsFactory) {

// given
var getGraphicsSpy = spy(elementRegistry, 'getGraphics');

// when
graphicsFactory.updateContainments([ parent ]);

// then
expect(getGraphicsSpy).not.to.have.been.called;
}
));

});


it('should add <djs-frame> class to frames', inject(
function(canvas, graphicsFactory, elementFactory) {

Expand Down

0 comments on commit bab7b80

Please sign in to comment.