LayoutConnectionSpec.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import customModelingModule from './custom';
  6. describe('features/modeling - layout connection', function() {
  7. beforeEach(bootstrapDiagram({
  8. modules: [
  9. customModelingModule
  10. ]
  11. }));
  12. describe('layout waypoints', function() {
  13. var rootShape, sourceShape, targetShape, connection;
  14. beforeEach(inject(function(elementFactory, canvas) {
  15. rootShape = elementFactory.createRoot({
  16. id: 'root'
  17. });
  18. canvas.setRootElement(rootShape);
  19. sourceShape = elementFactory.createShape({
  20. id: 'source',
  21. x: 100, y: 100, width: 100, height: 100
  22. });
  23. canvas.addShape(sourceShape);
  24. targetShape = elementFactory.createShape({
  25. id: 'target',
  26. x: 300, y: 300, width: 100, height: 100
  27. });
  28. canvas.addShape(targetShape);
  29. connection = elementFactory.createConnection({
  30. id: 'connection',
  31. waypoints: [
  32. { x: 150, y: 150, original: { x: 125, y: 125 } },
  33. { x: 150, y: 200 },
  34. { x: 350, y: 150, original: { x: 325, y: 125 } }
  35. ],
  36. source: sourceShape,
  37. target: targetShape
  38. });
  39. canvas.addConnection(connection);
  40. }));
  41. it('should execute, adding new original waypoints', inject(function(modeling) {
  42. // when
  43. modeling.layoutConnection(connection);
  44. // then
  45. expect(connection.waypoints).to.eql([
  46. { x: 200, y: 200, original: { x: 150, y: 150 } },
  47. { x: 300, y: 300, original: { x: 350, y: 350 } }
  48. ]);
  49. }));
  50. it('should execute with custom connectionStart', inject(function(modeling) {
  51. // given
  52. var hints = {
  53. connectionStart: { x: 100, y: 100 }
  54. };
  55. // when
  56. modeling.layoutConnection(connection, hints);
  57. // then
  58. expect(connection.waypoints).to.eql([
  59. { x: 150, y: 150, original: { x: 100, y: 100 } },
  60. { x: 300, y: 300, original: { x: 350, y: 350 } }
  61. ]);
  62. }));
  63. it('should execute with custom connectionEnd', inject(function(modeling) {
  64. // given
  65. var hints = {
  66. connectionEnd: { x: 400, y: 400 }
  67. };
  68. // when
  69. modeling.layoutConnection(connection, hints);
  70. // then
  71. expect(connection.waypoints).to.eql([
  72. { x: 200, y: 200, original: { x: 150, y: 150 } },
  73. { x: 350, y: 350, original: { x: 400, y: 400 } }
  74. ]);
  75. }));
  76. it('should undo', inject(function(modeling, commandStack) {
  77. // given
  78. modeling.layoutConnection(connection);
  79. // when
  80. commandStack.undo();
  81. // then
  82. expect(connection.waypoints).to.eql([
  83. { x: 150, y: 150, original: { x: 125, y: 125 } },
  84. { x: 150, y: 200 },
  85. { x: 350, y: 150, original: { x: 325, y: 125 } }
  86. ]);
  87. }));
  88. });
  89. describe('z-order handling', function() {
  90. var container1,
  91. container2,
  92. sourceShape,
  93. targetShape,
  94. connection;
  95. beforeEach(inject(function(elementFactory, canvas) {
  96. sourceShape = elementFactory.createShape({
  97. id: 'source',
  98. x: 10, y: 10, width: 50, height: 50
  99. });
  100. canvas.addShape(sourceShape);
  101. targetShape = elementFactory.createShape({
  102. id: 'target',
  103. x: 200, y: 10, width: 50, height: 50
  104. });
  105. canvas.addShape(targetShape);
  106. connection = elementFactory.createConnection({
  107. id: 'connection',
  108. waypoints: [ { x: 35, y: 35 }, { x: 225, y: 35 } ],
  109. source: sourceShape,
  110. target: targetShape
  111. });
  112. canvas.addConnection(connection);
  113. container1 = elementFactory.createShape({
  114. id: 'container1',
  115. x: 100, y: 100, width: 300, height: 300
  116. });
  117. canvas.addShape(container1);
  118. container2 = elementFactory.createShape({
  119. id: 'container2',
  120. x: 120, y: 120, width: 200, height: 200
  121. });
  122. canvas.addShape(container2, container1);
  123. }));
  124. describe('keep z-index after moving target to nested child', function() {
  125. it('should execute', inject(function(modeling) {
  126. // when
  127. modeling.moveShape(targetShape, { x: 0, y: 200 }, container2);
  128. // then
  129. var connectionSiblings = connection.parent.children;
  130. expect(connectionSiblings).to.eql([
  131. sourceShape,
  132. connection,
  133. container1
  134. ]);
  135. }));
  136. it('should undo', inject(function(modeling, commandStack) {
  137. // given
  138. modeling.moveShape(targetShape, { x: 0, y: 200 }, container2);
  139. // when
  140. commandStack.undo();
  141. // then
  142. var connectionSiblings = connection.parent.children;
  143. expect(connectionSiblings).to.eql([
  144. sourceShape,
  145. targetShape,
  146. connection,
  147. container1
  148. ]);
  149. }));
  150. });
  151. });
  152. });