Skip to content

Commit

Permalink
feat(create): allow attachment of shapes with labels on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oguz Eroglu committed Oct 2, 2019
1 parent 09d13e9 commit 5d6e598
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/features/create/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export default function Create(
return !element.parent;
});

// ignore labels being created with their targets
elements = filter(elements, function(element) {
return !(isLabel(element) && elements.indexOf(element.labelTarget) > -1);
});

var shape = find(elements, function(element) {
return !isConnection(element);
});
Expand Down Expand Up @@ -330,4 +335,8 @@ function isConnection(element) {

function isSingleShape(elements) {
return elements && elements.length === 1 && !isConnection(elements[0]);
}
}

function isLabel(element) {
return !!element.labelTarget;
}
39 changes: 39 additions & 0 deletions test/spec/features/create/CreateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,45 @@ describe('features/create - Create', function() {
}));


it('should attach with label', inject(function(create, dragging, elementRegistry, elementFactory) {

// given
var hostShapeGfx = elementRegistry.getGraphics('hostShape');

var label = elementFactory.createLabel({
labelTarget: newShape,
x: 0,
y: 0,
width: 50,
height: 50
});

// when
create.start(canvasEvent({ x: 0, y: 0 }), [ newShape, label ]);

dragging.hover({ element: hostShape, gfx: hostShapeGfx });

dragging.move(canvasEvent(getMid(hostShape)));

dragging.end();

// then
var createdShape = elementRegistry.get('newShape');

expect(createdShape).to.exist;
expect(createdShape).to.equal(newShape);

expect(createdShape.parent).to.equal(rootShape);
expect(createdShape.host).to.equal(hostShape);

expect(hostShape.attachers).to.have.length;
expect(hostShape.attachers[0]).to.equal(createdShape);

expect(createdShape.labels).to.have.length(1);
expect(createdShape.labels[0]).to.equal(label);
}));


it('should append AND attach', inject(function(create, dragging, elementRegistry) {

// given
Expand Down

0 comments on commit 5d6e598

Please sign in to comment.