123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- /* global sinon */
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import modelingModule from 'lib/features/modeling';
- describe('features/modeling - move shape', function() {
- beforeEach(bootstrapDiagram({
- modules: [
- modelingModule
- ]
- }));
- var rootShape, parentShape, childShape, childShape2, 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);
- childShape = elementFactory.createShape({
- id: 'child',
- x: 110, y: 110,
- width: 100, height: 100
- });
- canvas.addShape(childShape, parentShape);
- childShape2 = elementFactory.createShape({
- id: 'child2',
- x: 200, y: 110,
- width: 100, height: 100
- });
- canvas.addShape(childShape2, parentShape);
- connection = elementFactory.createConnection({
- id: 'connection',
- waypoints: [
- { x: 150, y: 150, original: { x: 150, y: 150 } },
- { x: 150, y: 200 },
- { x: 350, y: 150 }
- ],
- source: childShape,
- target: childShape2
- });
- canvas.addConnection(connection, parentShape);
- }));
- describe('should move according to delta', function() {
- it('execute', inject(function(modeling) {
- // when
- modeling.moveShape(childShape, { x: -20, y: +20 });
- // then
- expect(childShape.x).to.equal(90);
- expect(childShape.y).to.equal(130);
- // keep old parent
- expect(childShape.parent).to.equal(parentShape);
- }));
- it('should update parent', inject(function(modeling) {
- // when
- modeling.moveShape(childShape, { x: -20, y: +20 }, rootShape);
- // then
- // update parent
- expect(childShape.parent).to.equal(rootShape);
- }));
- it('undo', inject(function(modeling, commandStack) {
- // given
- modeling.moveShape(childShape, { x: -20, y: +20 });
- // when
- commandStack.undo();
- // then
- expect(childShape.x).to.equal(110);
- expect(childShape.y).to.equal(110);
- // keep old parent
- expect(childShape.parent).to.equal(parentShape);
- }));
- it('redo', inject(function(modeling, commandStack) {
- // given
- modeling.moveShape(childShape, { x: -20, y: +20 });
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(childShape.x).to.equal(90);
- expect(childShape.y).to.equal(130);
- // keep old parent
- expect(childShape.parent).to.equal(parentShape);
- }));
- });
- describe('should update parent', function() {
- it('execute', inject(function(modeling) {
- // when
- modeling.moveShape(childShape, { x: 0, y: 0 }, rootShape);
- // then
- // update parent
- expect(childShape.parent).to.equal(rootShape);
- }));
- it('undo', inject(function(modeling, commandStack) {
- // given
- modeling.moveShape(childShape, { x: 0, y: 0 }, rootShape);
- // when
- commandStack.undo();
- // then
- // update parent
- expect(childShape.parent).to.equal(parentShape);
- }));
- it('redo', inject(function(modeling, commandStack) {
- // given
- modeling.moveShape(childShape, { x: 0, y: 0 }, rootShape);
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- // update parent
- expect(childShape.parent).to.equal(rootShape);
- }));
- });
- describe('should update parent with parentIndex', function() {
- it('execute', inject(function(modeling) {
- // when
- modeling.moveShape(childShape, { x: -20, y: +20 }, rootShape, 0);
- // then
- expect(rootShape.children[0]).to.equal(childShape);
- }));
- it('undo', inject(function(modeling, commandStack) {
- // given
- modeling.moveShape(childShape, { x: -20, y: +20 }, rootShape, 0);
- // when
- commandStack.undo();
- // then
- expect(rootShape.children).not.to.contain(childShape);
- expect(parentShape.children[0]).to.equal(childShape);
- }));
- it('execute', inject(function(modeling, commandStack) {
- // given
- modeling.moveShape(childShape, { x: -20, y: +20 }, rootShape, 0);
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(rootShape.children[0]).to.equal(childShape);
- }));
- });
- describe('layout connections', function() {
- it('should layout after move', inject(function(modeling) {
- // when
- modeling.moveShape(childShape, { x: -20, y: +20 }, parentShape);
- // then
- // update parent
- expect(connection).to.have.waypoints([
- { x: 130, y: 170 },
- { x: 250, y: 160 }
- ]);
- }));
- it('should provide original waypoints to layout', inject(function(eventBus, modeling) {
- // given
- var originalWaypoints = connection.waypoints;
- var preLayoutSpy = sinon.spy(function(event) {
- var context = event.context,
- connection = context.connection;
- expect(connection).to.have.waypoints(originalWaypoints);
- expect(connection).to.have.startDocking({ x: 150, y: 150 });
- });
- eventBus.on('commandStack.connection.layout.preExecute', preLayoutSpy);
- // when
- modeling.moveShape(childShape, { x: -20, y: +20 }, parentShape);
- // then
- expect(preLayoutSpy).to.have.been.called;
- }));
- });
- });
|