Skip to content

Commit

Permalink
fix(selection): select all created elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Aug 8, 2019
1 parent aa252f0 commit 8726a13
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/features/selection/SelectionBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export default function SelectionBehavior(

eventBus.on('create.end', 500, function(e) {

// select the created shape after a
// select the created shapes after a
// successful create operation
if (e.context.canExecute) {
selection.select(e.context.shape);

selection.select(e.context.elements);
}
});

Expand Down
53 changes: 53 additions & 0 deletions test/spec/features/selection/SelectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'test/TestHelper';

import coreModule from 'lib/core';
import createModule from 'lib/features/create';
import draggingModule from 'lib/features/dragging';
import modelingModule from 'lib/features/modeling';
import moveModule from 'lib/features/move';
Expand All @@ -23,6 +24,7 @@ describe('features/selection/Selections', function() {
coreModule,
draggingModule,
modelingModule,
createModule,
moveModule,
selectionModule
]
Expand Down Expand Up @@ -197,4 +199,55 @@ describe('features/selection/Selections', function() {

});


describe('integration', function() {

var newElements = [];

this.beforeEach(inject(function(elementFactory) {

var shape1 = elementFactory.createShape({
id: 'newShape1',
width: 50,
height: 50
});

newElements.push(shape1);

var shape2 = elementFactory.createShape({
id: 'newShape2',
width: 100,
height: 100,
x: 100
});

newElements.push(shape2);
}));

it('should select all created elements', inject(
function(canvas, create, dragging, selection) {

// given
var rootShape = canvas.getRootElement(),
rootGfx = canvas.getGraphics(rootShape);

// when
create.start(canvasEvent({ x: 0, y: 0 }), newElements);

dragging.hover({ element: rootShape, gfx: rootGfx });

dragging.move(canvasEvent({ x: 200, y: 200 }));

dragging.end();

var selectedElements = selection.get();

// then
expect(selectedElements).to.exist;
expect(selectedElements).to.eql(newElements);
}
));

});

});

0 comments on commit 8726a13

Please sign in to comment.