MoveConnectionSpec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - move connection', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
  8. var rootShape, parentShape, sourceShape, targetShape, connection;
  9. beforeEach(inject(function(elementFactory, canvas) {
  10. rootShape = elementFactory.createRoot({
  11. id: 'root'
  12. });
  13. canvas.setRootElement(rootShape);
  14. parentShape = elementFactory.createShape({
  15. id: 'parent',
  16. x: 50, y: 50, width: 400, height: 300
  17. });
  18. canvas.addShape(parentShape, rootShape);
  19. sourceShape = elementFactory.createShape({
  20. id: 'source',
  21. x: 100, y: 100, width: 100, height: 100
  22. });
  23. canvas.addShape(sourceShape, parentShape);
  24. targetShape = elementFactory.createShape({
  25. id: 'target',
  26. x: 300, y: 300, width: 100, height: 100
  27. });
  28. canvas.addShape(targetShape, parentShape);
  29. connection = elementFactory.createConnection({
  30. id: 'connection',
  31. waypoints: [
  32. { x: 150, y: 150, original: { x: 0, y: 0 } },
  33. { x: 150, y: 200 },
  34. { x: 350, y: 150 }
  35. ],
  36. source: sourceShape,
  37. target: targetShape
  38. });
  39. canvas.addConnection(connection, parentShape);
  40. }));
  41. describe('should move by delta', function() {
  42. it('execute', inject(function(modeling) {
  43. // when
  44. modeling.moveConnection(connection, { x: 20, y: 10 });
  45. // then
  46. expect(connection.waypoints).to.eql([
  47. { x: 170, y: 160, original: { x: 20, y: 10 } }, { x: 170, y: 210 }, { x: 370, y: 160 }
  48. ]);
  49. }));
  50. it('undo', inject(function(modeling, commandStack) {
  51. // given
  52. modeling.moveConnection(connection, { x: 20, y: 10 });
  53. // when
  54. commandStack.undo();
  55. // then
  56. expect(connection.waypoints).to.eql([
  57. { x: 150, y: 150, original: { x: 0, y: 0 } }, { x: 150, y: 200 }, { x: 350, y: 150 }
  58. ]);
  59. }));
  60. it('redo', inject(function(modeling, commandStack) {
  61. // given
  62. modeling.moveConnection(connection, { x: 20, y: 10 });
  63. // when
  64. commandStack.undo();
  65. commandStack.redo();
  66. // then
  67. expect(connection.waypoints).to.eql([
  68. { x: 170, y: 160, original: { x: 20, y: 10 } }, { x: 170, y: 210 }, { x: 370, y: 160 }
  69. ]);
  70. }));
  71. });
  72. describe('should move to new parent', function() {
  73. it('execute', inject(function(modeling) {
  74. // when
  75. modeling.moveConnection(connection, { x: 0, y: 0 }, rootShape, 0);
  76. // then
  77. expect(connection.parent).to.equal(rootShape);
  78. expect(rootShape.children[0]).to.equal(connection);
  79. }));
  80. it('undo', inject(function(modeling, commandStack) {
  81. // given
  82. modeling.moveConnection(connection, { x: 0, y: 0 }, rootShape, 0);
  83. // when
  84. commandStack.undo();
  85. // then
  86. expect(connection.parent).to.equal(parentShape);
  87. expect(parentShape.children[2]).to.equal(connection);
  88. }));
  89. it('redo', inject(function(modeling, commandStack) {
  90. // given
  91. modeling.moveConnection(connection, { x: 0, y: 0 }, rootShape, 0);
  92. // when
  93. commandStack.undo();
  94. commandStack.redo();
  95. // then
  96. expect(connection.parent).to.equal(rootShape);
  97. expect(rootShape.children[0]).to.equal(connection);
  98. }));
  99. });
  100. });