123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import modelingModule from 'lib/features/modeling';
- /* global sinon */
- describe('features/modeling - reconnect connection', function() {
- beforeEach(bootstrapDiagram({
- modules: [
- modelingModule,
- {
- layouter: [ 'type', NoopLayouter ]
- }
- ]
- }));
- var parentShape, childShape, childShape2, connection;
- beforeEach(inject(function(elementFactory, canvas) {
- parentShape = elementFactory.createShape({
- id: 'parent',
- x: 100, y: 100, width: 300, height: 300
- });
- canvas.addShape(parentShape);
- 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 }, { x: 150, y: 200 }, { x: 350, y: 150 } ],
- source: childShape,
- target: childShape2
- });
- canvas.addConnection(connection, parentShape);
- }));
- describe('reconnectStart', function() {
- describe('passing position', function() {
- it('should execute', inject(function(modeling) {
- // given
- var newWaypoints = [ { x: 120, y: 120 }, { x: 350, y: 150 } ];
- // when
- modeling.reconnectStart(connection, childShape, { x: 120, y: 120 });
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should undo', inject(function(modeling, commandStack) {
- // given
- var oldWaypoints = connection.waypoints.slice();
- modeling.reconnectStart(connection, childShape, { x: 120, y: 120 });
- // when
- commandStack.undo();
- // then
- expect(connection).to.have.waypoints(oldWaypoints);
- }));
- it('should redo', inject(function(modeling, commandStack) {
- // given
- var newWaypoints = [ { x: 120, y: 120 }, { x: 350, y: 150 } ];
- modeling.reconnectStart(connection, childShape, { x: 120, y: 120 });
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should layout connection', inject(function(modeling) {
- // given
- var layoutSpy = sinon.spy(modeling, 'layoutConnection'),
- docking = { x: 120, y: 120 };
- // when
- modeling.reconnectStart(connection, childShape, docking);
- // then
- expect(layoutSpy).to.have.been.calledOnce;
- expect(layoutSpy.getCall(0).args).to.eql([ connection, { connectionStart: docking }]);
- }));
- });
- describe('passing waypoints', function() {
- it('should execute', inject(function(modeling) {
- // given
- var newWaypoints = [ { x: 110, y: 110 }, { x: 300, y: 300 } ];
- // when
- modeling.reconnectStart(connection, childShape, newWaypoints);
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should undo', inject(function(modeling, commandStack) {
- // given
- var oldWaypoints = connection.waypoints.slice();
- modeling.reconnectStart(connection, childShape, [ { x: 110, y: 110 }, { x: 300, y: 300 } ]);
- // when
- commandStack.undo();
- // then
- expect(connection).to.have.waypoints(oldWaypoints);
- }));
- it('should redo', inject(function(modeling, commandStack) {
- // given
- var newWaypoints = [ { x: 110, y: 110 }, { x: 300, y: 300 } ];
- modeling.reconnectStart(connection, childShape, newWaypoints);
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should layout connection', inject(function(modeling) {
- // given
- var newWaypoints = [ { x: 110, y: 110 }, { x: 300, y: 300 } ],
- docking = newWaypoints[0],
- layoutSpy = sinon.spy(modeling, 'layoutConnection');
- // when
- modeling.reconnectStart(connection, childShape, newWaypoints);
- // then
- expect(layoutSpy).to.have.been.calledOnce;
- expect(layoutSpy.getCall(0).args).to.eql([ connection, { connectionStart: docking }]);
- }));
- });
- });
- describe('reconnectEnd', function() {
- describe('passing position', function() {
- it('should execute', inject(function(modeling) {
- // given
- var newWaypoints = [ { x: 150, y: 150 }, { x: 300, y: 100 } ];
- // when
- modeling.reconnectEnd(connection, childShape2, { x: 300, y: 100 });
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should undo', inject(function(modeling, commandStack) {
- // given
- var oldWaypoints = connection.waypoints.slice();
- modeling.reconnectEnd(connection, childShape2, { x: 300, y: 100 });
- // when
- commandStack.undo();
- // then
- expect(connection).to.have.waypoints(oldWaypoints);
- }));
- it('should redo', inject(function(modeling, commandStack) {
- // given
- var newWaypoints = [ { x: 150, y: 150 }, { x: 300, y: 100 } ];
- // when
- modeling.reconnectEnd(connection, childShape2, { x: 300, y: 100 });
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should layout connection', inject(function(modeling) {
- // given
- var layoutSpy = sinon.spy(modeling, 'layoutConnection'),
- docking = { x: 120, y: 120 };
- // when
- modeling.reconnectEnd(connection, childShape, docking);
- // then
- expect(layoutSpy).to.have.been.calledOnce;
- expect(layoutSpy.getCall(0).args).to.eql([ connection, { connectionEnd: docking }]);
- }));
- });
- describe('passing waypoints', function() {
- it('should execute', inject(function(modeling) {
- // given
- var newWaypoints = [ { x: 110, y: 110 }, { x: 300, y: 300 } ];
- // when
- modeling.reconnectEnd(connection, childShape2, newWaypoints);
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should undo', inject(function(modeling, commandStack) {
- // given
- var oldWaypoints = connection.waypoints.slice();
- modeling.reconnectEnd(connection, childShape2, [ { x: 110, y: 110 }, { x: 300, y: 300 } ]);
- // when
- commandStack.undo();
- // then
- expect(connection).to.have.waypoints(oldWaypoints);
- }));
- it('should redo', inject(function(modeling, commandStack) {
- // given
- var newWaypoints = [ { x: 110, y: 110 }, { x: 300, y: 300 } ];
- modeling.reconnectEnd(connection, childShape2, newWaypoints);
- // when
- commandStack.undo();
- commandStack.redo();
- // then
- expect(connection).to.have.waypoints(newWaypoints);
- }));
- it('should layout connection', inject(function(modeling) {
- // given
- var newWaypoints = [ { x: 110, y: 110 }, { x: 300, y: 300 } ],
- docking = newWaypoints[1],
- layoutSpy = sinon.spy(modeling, 'layoutConnection');
- // when
- modeling.reconnectEnd(connection, childShape, newWaypoints);
- // then
- expect(layoutSpy).to.have.been.calledOnce;
- expect(layoutSpy.getCall(0).args).to.eql([ connection, { connectionEnd: docking }]);
- }));
- });
- });
- });
- // helpers /////////////////////
- /**
- * The most simple of all layouters
- */
- function NoopLayouter() {
- this.layoutConnection = function(connection, hints) {
- hints = hints || {};
- return [
- hints.connectionStart || connection.waypoints[0],
- hints.connectionEnd || connection.waypoints[connection.waypoints.length - 1]
- ];
- };
- }
|