123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import {
- pick
- } from 'min-dash';
- import modelingModule from 'lib/features/modeling';
- function containment(element) {
- return pick(element, [ 'x', 'y', 'parent' ]);
- }
- describe('features/modeling - move elements', function() {
- beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
- var rootShape, parentShape, otherParentShape, childShape, otherChildShape, connection;
- beforeEach(inject(function(elementFactory, canvas) {
- rootShape = elementFactory.createRoot({
- id: 'root'
- });
- canvas.setRootElement(rootShape);
- parentShape = elementFactory.createShape({
- id: 'parent',
- x: 100, y: 100,
- width: 300, height: 300
- });
- canvas.addShape(parentShape, rootShape);
- otherParentShape = elementFactory.createShape({
- id: 'other-parent',
- x: 500, y: 200,
- width: 300, height: 300
- });
- canvas.addShape(otherParentShape, rootShape);
- childShape = elementFactory.createShape({
- id: 'child',
- x: 110, y: 110,
- width: 100, height: 100
- });
- canvas.addShape(childShape, parentShape);
- otherChildShape = elementFactory.createShape({
- id: 'other-child',
- x: 250, y: 160,
- width: 100, height: 100
- });
- canvas.addShape(otherChildShape, parentShape);
- connection = elementFactory.createConnection({
- id: 'connection',
- waypoints: [
- { x: 160, y: 160 },
- { x: 160, y: 300 },
- { x: 300, y: 210 }
- ],
- source: childShape,
- target: otherChildShape
- });
- canvas.addConnection(connection, parentShape);
- }));
- describe('should move', function() {
- it('execute', inject(function(modeling) {
- // when
- modeling.moveElements([ childShape, otherChildShape ], { x: -20, y: +20 }, otherParentShape);
- // then
- expect(childShape.x).to.equal(90);
- expect(childShape.y).to.equal(130);
- expect(otherChildShape.x).to.equal(230);
- expect(otherChildShape.y).to.equal(180);
- // update parent(s)
- expect(childShape.parent).to.equal(otherParentShape);
- expect(otherChildShape.parent).to.equal(otherParentShape);
- }));
- it('undo', inject(function(modeling, commandStack) {
- var oldContainment = containment(childShape),
- oldContainment2 = containment(otherChildShape);
- // given
- modeling.moveElements([ childShape, otherChildShape ], { x: -20, y: +20 }, otherParentShape);
- modeling.moveElements([ childShape ], { x: +40, y: -40 }, parentShape);
- // when
- commandStack.undo();
- commandStack.undo();
- // then
- expect(containment(childShape)).to.eql(oldContainment);
- expect(containment(otherChildShape)).to.eql(oldContainment2);
- }));
- it('redo', inject(function(modeling, commandStack) {
- // given
- modeling.moveElements([ childShape, otherChildShape ], { x: -20, y: +20 }, otherParentShape);
- modeling.moveElements([ childShape ], { x: +40, y: -40 }, parentShape);
- var newContainment = containment(childShape),
- newContainment2 = containment(otherChildShape);
- // when
- commandStack.undo();
- commandStack.undo();
- commandStack.redo();
- commandStack.redo();
- // then
- expect(containment(childShape)).to.eql(newContainment);
- expect(containment(otherChildShape)).to.eql(newContainment2);
- // correct positioning
- expect(childShape.x).to.equal(130);
- expect(childShape.y).to.equal(90);
- expect(otherChildShape.x).to.equal(230);
- expect(otherChildShape.y).to.equal(180);
- }));
- });
- describe('move children with container', function() {
- it('execute', inject(function(modeling) {
- // when
- modeling.moveElements([ parentShape ], { x: -20, y: +20 }, otherParentShape);
- // then
- expect(childShape.x).to.eql(90);
- expect(childShape.y).to.eql(130);
- expect(otherChildShape.x).to.eql(230);
- expect(otherChildShape.y).to.eql(180);
- // children remain unaffected
- expect(childShape.parent).to.equal(parentShape);
- expect(otherChildShape.parent).to.equal(parentShape);
- expect(parentShape.parent).to.equal(otherParentShape);
- expect(otherParentShape.children).to.eql([ parentShape ]);
- expect(parentShape.children).to.eql([ childShape, otherChildShape, connection ]);
- }));
- it('undo', inject(function(modeling, commandStack) {
- // given
- modeling.moveElements([ parentShape ], { x: -20, y: +20 }, otherParentShape);
- // when
- commandStack.undo();
- // then
- expect(childShape.x).to.eql(110);
- expect(childShape.y).to.eql(110);
- expect(otherChildShape.x).to.eql(250);
- expect(otherChildShape.y).to.eql(160);
- expect(childShape.parent).to.eql(parentShape);
- expect(otherChildShape.parent).to.eql(parentShape);
- expect(parentShape.children).to.eql([ childShape, otherChildShape, connection ]);
- expect(otherParentShape.children).to.be.empty;
- }));
- it('redo', inject(function(modeling, commandStack) {
- // given
- modeling.moveElements([ parentShape ], { x: -20, y: 20 }, otherParentShape);
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(childShape.x).to.eql(90);
- expect(childShape.y).to.eql(130);
- expect(otherChildShape.x).to.eql(230);
- expect(otherChildShape.y).to.eql(180);
- // children remain unaffected
- expect(childShape.parent).to.equal(parentShape);
- expect(otherChildShape.parent).to.equal(parentShape);
- expect(parentShape.parent).to.equal(otherParentShape);
- expect(otherParentShape.children).to.eql([ parentShape ]);
- expect(parentShape.children).to.eql([ childShape, otherChildShape, connection ]);
- }));
- });
- function waypoints(connection) {
- return connection.waypoints.map(function(p) {
- return { x: p.x, y: p.y };
- });
- }
- // See https://github.com/bpmn-io/bpmn-js/issues/200
- // If a connection is moved without moving the source
- // and target shape the connection should be relayouted
- // instead of beeing moved
- it('should layout dangling connection', inject(function(modeling) {
- // when
- modeling.moveElements([ childShape, connection ], { x: 0, y: -50 }, rootShape);
- // then
- // expect relayouted connection
- expect(connection).to.have.waypoints([
- { x: 160, y: 110 },
- { x: 300, y: 210 }
- ]);
- }));
- it('should move included connection', inject(function(modeling) {
- // when
- modeling.moveElements([ childShape, connection, otherChildShape ], { x: 0, y: -50 }, rootShape);
- // then
- // expect moved
- expect(waypoints(connection)).to.eql([
- { x: 160, y: 110 },
- { x: 160, y: 250 },
- { x: 300, y: 160 }
- ]);
- }));
- describe('multiple selection', function() {
- it('should keep parent of secondary shape (scenario 1)', inject(function(modeling) {
- // scenario 1:
- // primary shape parent hover: does not change
- // secondary shape parent hover: does not change
- // given
- modeling.moveElements([ childShape ], { x: 350, y: -50 }, rootShape);
- // when
- modeling.moveElements([ childShape, otherChildShape ], { x: 0, y: 20 }, parentShape,
- { primaryShape: otherChildShape });
- // then
- expect(otherChildShape.parent).to.equal(parentShape);
- expect(childShape.parent).to.equal(rootShape);
- }));
- it('should keep parent of secondary shape (scenario 2)', inject(function(modeling) {
- // scenario 2:
- // primary shape parent hover: does not change
- // secondary shape parent hover: does change
- // given
- modeling.moveElements([ childShape ], { x: 330, y: -50 }, rootShape);
- // when
- modeling.moveElements([ childShape, otherChildShape ], { x: -145, y: 100 }, parentShape,
- { primaryShape: otherChildShape });
- // then
- expect(otherChildShape.parent).to.equal(parentShape);
- expect(childShape.parent).to.equal(rootShape);
- }));
- it('should set parent of sec. shape to parent of prim. shape (scenario 3)', inject(function(modeling) {
- // scenario 3:
- // primary shape parent hover: does change
- // secondary shape parent hover: does not change
- // given
- modeling.moveElements([ childShape ], { x: 350, y: -50 }, rootShape);
- // when
- modeling.moveElements(
- [ childShape, otherChildShape ],
- { x: 400, y: 200 },
- otherParentShape,
- { primaryShape: otherChildShape }
- );
- // then
- expect(otherChildShape.parent).to.equal(otherParentShape);
- expect(childShape.parent).to.equal(otherParentShape);
- }));
- it('should set parent of sec. shape to parent of prim. shape (scenario 4)', inject(function(modeling) {
- // scenario 4:
- // primary shape parent hover: does change
- // secondary shape parent hover: does change
- // given
- modeling.moveElements([ childShape ], { x: 300, y: -50 }, rootShape);
- // when
- modeling.moveElements(
- [ childShape, otherChildShape ],
- { x: 280, y: 200 },
- otherParentShape,
- { primaryShape: otherChildShape }
- );
- // then
- expect(otherChildShape.parent).to.equal(otherParentShape);
- expect(childShape.parent).to.equal(otherParentShape);
- }));
- // See https://github.com/bpmn-io/bpmn-js/issues/525
- it('should keep parent of connection',
- inject(function(modeling) {
- // given
- var elements = [
- childShape,
- otherChildShape,
- otherParentShape
- ];
- // when
- modeling.moveElements(
- elements,
- { x: 0, y: -50 },
- rootShape,
- { primaryShape: otherParentShape }
- );
- // then
- expect(connection.parent).to.equal(parentShape);
- })
- );
- // See https://github.com/bpmn-io/bpmn-js/issues/525
- it('should keep parent of connection when moving with selection',
- inject(function(modeling) {
- // given
- var elements = [
- childShape,
- connection,
- otherChildShape,
- otherParentShape
- ];
- // when
- modeling.moveElements(
- elements,
- { x: 0, y: -50 },
- rootShape,
- { primaryShape: otherParentShape }
- );
- // then
- expect(connection.parent).to.equal(parentShape);
- })
- );
- });
- describe('drop', function() {
- // @see DropShapeSpec.js
- });
- });
|