ConnectionSegmentMoveSpec.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /* global sinon */
  2. import {
  3. bootstrapDiagram,
  4. inject
  5. } from 'test/TestHelper';
  6. import { createCanvasEvent as canvasEvent } from '../../../util/MockEvents';
  7. import bendpointsModule from 'lib/features/bendpoints';
  8. import modelingModule from 'lib/features/modeling';
  9. import selectModule from 'lib/features/selection';
  10. import CroppingConnectionDocking from 'lib/layout/CroppingConnectionDocking';
  11. var layoutModule = {
  12. connectionDocking: [ 'type', CroppingConnectionDocking ]
  13. };
  14. describe('features/bendpoints - segment move', function() {
  15. describe('should provide hints', function() {
  16. beforeEach(bootstrapDiagram({
  17. modules: [
  18. bendpointsModule,
  19. modelingModule,
  20. selectModule
  21. ]
  22. }));
  23. beforeEach(inject(function(dragging) {
  24. dragging.setOptions({ manual: true });
  25. }));
  26. var sourceShape, targetShape, connection;
  27. beforeEach(inject(function(elementFactory, canvas) {
  28. sourceShape = elementFactory.createShape({
  29. id: 'sourceShape', type: 'A',
  30. x: 100, y: 100,
  31. width: 200, height: 100
  32. });
  33. canvas.addShape(sourceShape);
  34. targetShape = elementFactory.createShape({
  35. id: 'targetShape', type: 'A',
  36. x: 600, y: 100,
  37. width: 100, height: 200
  38. });
  39. canvas.addShape(targetShape);
  40. }));
  41. it('basic', inject(function(canvas, connectionSegmentMove, dragging, eventBus, elementFactory) {
  42. // given
  43. connection = elementFactory.createConnection({
  44. id: 'connection',
  45. waypoints: [
  46. { x: 200, y: 150 },
  47. { x: 200, y: 300 },
  48. { x: 600, y: 300 },
  49. { x: 600, y: 150 }
  50. ],
  51. source: sourceShape,
  52. target: targetShape
  53. });
  54. canvas.addConnection(connection);
  55. var spy = sinon.spy(function(e) {
  56. expect(e.context.hints).to.have.property('segmentMove');
  57. });
  58. eventBus.once('commandStack.execute', spy);
  59. // when
  60. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 1);
  61. dragging.move(canvasEvent({ x: 0, y: 50 }));
  62. dragging.end();
  63. // then
  64. expect(spy).to.have.been.called;
  65. }));
  66. it('remove start segment', inject(function(canvas, connectionSegmentMove, dragging, eventBus, elementFactory) {
  67. // given
  68. connection = elementFactory.createConnection({
  69. id: 'connection',
  70. waypoints: [
  71. { x: 200, y: 150 },
  72. { x: 200, y: 300 },
  73. { x: 600, y: 300 },
  74. { x: 600, y: 150 }
  75. ],
  76. source: sourceShape,
  77. target: targetShape
  78. });
  79. canvas.addConnection(connection);
  80. var spy = sinon.spy(function(e) {
  81. expect(e.context.hints.segmentMove).to.eql({
  82. segmentStartIndex: 1,
  83. newSegmentStartIndex: 0
  84. });
  85. });
  86. eventBus.once('commandStack.execute', spy);
  87. // when
  88. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  89. dragging.move(canvasEvent({ x: 0, y: -150 }));
  90. dragging.end();
  91. // then
  92. expect(spy).to.have.been.called;
  93. }));
  94. describe('remove skewed segments', function() {
  95. it('start', inject(function(canvas, connectionSegmentMove, dragging, eventBus, elementFactory) {
  96. // given
  97. connection = elementFactory.createConnection({
  98. id: 'connection',
  99. waypoints: [
  100. { x: 200, y: 150 },
  101. { x: 50, y: 400 },
  102. { x: 600, y: 400 },
  103. { x: 600, y: 150 }
  104. ],
  105. source: sourceShape,
  106. target: targetShape
  107. });
  108. canvas.addConnection(connection);
  109. var spy = sinon.spy(function(e) {
  110. expect(e.context.hints).to.have.property('segmentMove');
  111. expect(e.context.hints.segmentMove.newSegmentStartIndex).to.eql(0);
  112. });
  113. eventBus.once('commandStack.execute', spy);
  114. // when
  115. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  116. dragging.move(canvasEvent({ x: 0, y: -250 }));
  117. dragging.end();
  118. // then
  119. expect(spy).to.have.been.called;
  120. }));
  121. it('mid (one bendpoint removed)', inject(function(canvas, connectionSegmentMove, dragging, eventBus, elementFactory) {
  122. // given
  123. connection = elementFactory.createConnection({
  124. id: 'connection',
  125. waypoints: [
  126. { x: 200, y: 150 },
  127. { x: 200, y: 400 },
  128. { x: 300, y: 300 },
  129. { x: 600, y: 300 },
  130. { x: 600, y: 150 }
  131. ],
  132. source: sourceShape,
  133. target: targetShape
  134. });
  135. canvas.addConnection(connection);
  136. var spy = sinon.spy(function(e) {
  137. expect(e.context.hints).to.have.property('segmentMove');
  138. expect(e.context.hints.segmentMove.newSegmentStartIndex).to.eql(1);
  139. });
  140. eventBus.once('commandStack.execute', spy);
  141. // when
  142. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 3);
  143. dragging.move(canvasEvent({ x: 0, y: 100 }));
  144. dragging.end();
  145. // then
  146. expect(spy).to.have.been.called;
  147. }));
  148. it('mid (two bendpoints removed)', inject(function(canvas, connectionSegmentMove, dragging, eventBus, elementFactory) {
  149. // given
  150. connection = elementFactory.createConnection({
  151. id: 'connection',
  152. waypoints: [
  153. { x: 200, y: 150 },
  154. { x: 200, y: 400 },
  155. { x: 250, y: 400 },
  156. { x: 300, y: 300 },
  157. { x: 600, y: 300 },
  158. { x: 600, y: 150 }
  159. ],
  160. source: sourceShape,
  161. target: targetShape
  162. });
  163. canvas.addConnection(connection);
  164. var spy = sinon.spy(function(e) {
  165. expect(e.context.hints).to.have.property('segmentMove');
  166. expect(e.context.hints.segmentMove.newSegmentStartIndex).to.eql(1);
  167. });
  168. eventBus.once('commandStack.execute', spy);
  169. // when
  170. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 4);
  171. dragging.move(canvasEvent({ x: 0, y: 100 }));
  172. dragging.end();
  173. // then
  174. expect(spy).to.have.been.called;
  175. }));
  176. });
  177. });
  178. describe('without docking', function() {
  179. beforeEach(bootstrapDiagram({
  180. modules: [
  181. bendpointsModule,
  182. modelingModule,
  183. selectModule
  184. ]
  185. }));
  186. beforeEach(inject(function(dragging) {
  187. dragging.setOptions({ manual: true });
  188. }));
  189. var sourceShape, targetShape, connection;
  190. beforeEach(inject(function(elementFactory, canvas) {
  191. sourceShape = elementFactory.createShape({
  192. id: 'sourceShape', type: 'A',
  193. x: 100, y: 400,
  194. width: 200, height: 100
  195. });
  196. canvas.addShape(sourceShape);
  197. targetShape = elementFactory.createShape({
  198. id: 'targetShape', type: 'A',
  199. x: 600, y: 50,
  200. width: 100, height: 200
  201. });
  202. canvas.addShape(targetShape);
  203. connection = elementFactory.createConnection({
  204. id: 'connection',
  205. waypoints: [
  206. { x: 200, y: 450 },
  207. { x: 400, y: 450 },
  208. { x: 400, y: 150 },
  209. { x: 650, y: 150 }
  210. ],
  211. source: sourceShape,
  212. target: targetShape
  213. });
  214. canvas.addConnection(connection);
  215. }));
  216. it('should vertical move first segment',
  217. inject(function(canvas, connectionSegmentMove, dragging) {
  218. // when
  219. connectionSegmentMove.start(canvasEvent({ x: 275, y: 450 }), connection, 1);
  220. dragging.move(canvasEvent({ x: 275, y: 430 }));
  221. dragging.end();
  222. // then
  223. expect(connection).to.have.waypoints([
  224. { x: 200, y: 430 },
  225. { x: 400, y: 430 },
  226. { x: 400, y: 150 },
  227. { x: 650, y: 150 }
  228. ]);
  229. // not introducing a docking (!)
  230. expect(connection).to.have.startDocking(undefined);
  231. expect(connection).to.have.endDocking(undefined);
  232. })
  233. );
  234. it('should vertical move last segment',
  235. inject(function(canvas, connectionSegmentMove, dragging) {
  236. // when
  237. connectionSegmentMove.start(canvasEvent({ x: 425, y: 150 }), connection, 3);
  238. dragging.move(canvasEvent({ x: 425, y: 210 }));
  239. dragging.end();
  240. // then
  241. expect(connection).to.have.waypoints([
  242. { x: 200, y: 450 },
  243. { x: 400, y: 450 },
  244. { x: 400, y: 210 },
  245. { x: 650, y: 210 }
  246. ]);
  247. // not introducing a docking (!)
  248. expect(connection).to.have.startDocking(undefined);
  249. expect(connection).to.have.endDocking(undefined);
  250. })
  251. );
  252. it('should move mid segment beyond source',
  253. inject(function(canvas, connectionSegmentMove, dragging) {
  254. // when
  255. // moving mid segment left of start shape
  256. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  257. dragging.move(canvasEvent({ x: 50, y: 200 }));
  258. dragging.end();
  259. // then
  260. expect(connection).to.have.waypoints([
  261. { x: 200, y: 450 },
  262. { x: 50, y: 450 },
  263. { x: 50, y: 150 },
  264. { x: 650, y: 150 }
  265. ]);
  266. })
  267. );
  268. it('should move mid segment beyond target',
  269. inject(function(canvas, connectionSegmentMove, dragging) {
  270. // given drag middle to the left
  271. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  272. dragging.move(canvasEvent({ x: 750, y: 200 }));
  273. dragging.end();
  274. // then
  275. expect(connection).to.have.waypoints([
  276. { x: 200, y: 450 },
  277. { x: 750, y: 450 },
  278. { x: 750, y: 150 },
  279. { x: 650, y: 150 }
  280. ]);
  281. })
  282. );
  283. it('should move mid segment, removing last',
  284. inject(function(canvas, connectionSegmentMove, dragging) {
  285. // given drag middle to the left
  286. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  287. dragging.move(canvasEvent({ x: 620, y: 200 }));
  288. dragging.end();
  289. // then
  290. expect(connection.waypoints[2].x).to.eql(620);
  291. })
  292. );
  293. it('should move mid segment, removing first',
  294. inject(function(canvas, connectionSegmentMove, dragging) {
  295. // given drag middle to the left
  296. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  297. dragging.move(canvasEvent({ x: 280, y: 200 }));
  298. dragging.end();
  299. // then
  300. expect(connection.waypoints[0].x).to.eql(280);
  301. expect(connection.waypoints.length).to.eql(3);
  302. })
  303. );
  304. // see issue #367
  305. it('should keep other axis',
  306. inject(function(canvas, connectionSegmentMove, dragging) {
  307. // given drag last intersection down a bit
  308. connectionSegmentMove.start(canvasEvent({ x: 425, y: 150 }), connection, 3);
  309. dragging.move(canvasEvent({ x: 425, y: 210 }));
  310. dragging.end();
  311. // when: middle intersection is dragged to the left
  312. // multiple steps are needed because it needs to pass the shape
  313. connectionSegmentMove.start(canvasEvent({ x: 400, y: 300 }), connection, 2);
  314. dragging.move(canvasEvent({ x: 650, y: 300 }));
  315. dragging.move(canvasEvent({ x: 750, y: 300 }));
  316. dragging.end();
  317. // then: the y axis doesn't change (back to target center)
  318. expect(connection.waypoints[3].y).to.eql(210);
  319. })
  320. );
  321. it('should keep the start docking as long as needed',
  322. inject(function(canvas, connectionSegmentMove, dragging) {
  323. // given
  324. // connection.waypoint[0] === { x: 150, y: 450 }
  325. // when: dragging intersection out of the element
  326. connectionSegmentMove.start(canvasEvent({ x: 275, y: 450 }), connection, 1);
  327. dragging.move(canvasEvent({ x: 275, y: 350 }));
  328. dragging.end();
  329. })
  330. );
  331. it('should keep the end docking as long as needed',
  332. inject(function(canvas, connectionSegmentMove, dragging) {
  333. // given
  334. // connection.waypoints[last] === { x: 680, y: 150 }
  335. // when
  336. // dragging intersection out of the element
  337. connectionSegmentMove.start(canvasEvent({ x: 425, y: 150 }), connection, 3);
  338. dragging.move(canvasEvent({ x: 425, y: 300 }));
  339. dragging.end();
  340. })
  341. );
  342. });
  343. describe('with docking (via connectionDocking)', function() {
  344. beforeEach(bootstrapDiagram({
  345. modules: [
  346. bendpointsModule,
  347. modelingModule,
  348. selectModule,
  349. layoutModule
  350. ]
  351. }));
  352. beforeEach(inject(function(dragging) {
  353. dragging.setOptions({ manual: true });
  354. }));
  355. var sourceShape, targetShape, connection;
  356. beforeEach(inject(function(elementFactory, canvas) {
  357. sourceShape = elementFactory.createShape({
  358. id: 'sourceShape', type: 'A',
  359. x: 100, y: 400,
  360. width: 200, height: 100
  361. });
  362. canvas.addShape(sourceShape);
  363. targetShape = elementFactory.createShape({
  364. id: 'targetShape', type: 'A',
  365. x: 600, y: 50,
  366. width: 100, height: 200
  367. });
  368. canvas.addShape(targetShape);
  369. connection = elementFactory.createConnection({
  370. id: 'connection',
  371. waypoints: [
  372. { x: 300, y: 450, original: { x: 250, y: 450 } },
  373. { x: 400, y: 450 },
  374. { x: 400, y: 150 },
  375. { x: 600, y: 150, original: { x: 650, y: 150 } }
  376. ],
  377. source: sourceShape,
  378. target: targetShape
  379. });
  380. canvas.addConnection(connection);
  381. }));
  382. it('should vertical move first segment',
  383. inject(function(canvas, connectionSegmentMove, dragging) {
  384. // given
  385. var oldEnd = connection.waypoints[3];
  386. // when
  387. connectionSegmentMove.start(canvasEvent({ x: 275, y: 450 }), connection, 1);
  388. dragging.move(canvasEvent({ x: 275, y: 430 }));
  389. dragging.end();
  390. // then
  391. expect(connection).to.have.waypoints([
  392. { x: 300, y: 430 },
  393. { x: 400, y: 430 },
  394. { x: 400, y: 150 },
  395. { x: 600, y: 150 }
  396. ]);
  397. // updating start docking
  398. expect(connection).to.have.startDocking({ x: 250, y: 430 });
  399. expect(connection).to.have.endDocking(oldEnd.original);
  400. })
  401. );
  402. it('should vertical move last segment',
  403. inject(function(canvas, connectionSegmentMove, dragging) {
  404. // given
  405. var oldStart = connection.waypoints[0];
  406. // when
  407. connectionSegmentMove.start(canvasEvent({ x: 425, y: 150 }), connection, 3);
  408. dragging.move(canvasEvent({ x: 425, y: 210 }));
  409. dragging.end();
  410. // then
  411. expect(connection).to.have.waypoints([
  412. { x: 300, y: 450 },
  413. { x: 400, y: 450 },
  414. { x: 400, y: 210 },
  415. { x: 600, y: 210 }
  416. ]);
  417. // updating end docking
  418. expect(connection).to.have.startDocking(oldStart.original);
  419. expect(connection).to.have.endDocking({ x: 650, y: 210 });
  420. })
  421. );
  422. it('should move mid segment beyond source',
  423. inject(function(canvas, connectionSegmentMove, dragging) {
  424. // given
  425. var oldEnd = connection.waypoints[3];
  426. // when
  427. // moving mid segment left of start shape
  428. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  429. dragging.move(canvasEvent({ x: 50, y: 200 }));
  430. dragging.end();
  431. // then
  432. expect(connection).to.have.waypoints([
  433. { x: 100, y: 450 },
  434. { x: 50, y: 450 },
  435. { x: 50, y: 150 },
  436. { x: 600, y: 150 }
  437. ]);
  438. // updating end docking
  439. expect(connection).to.have.startDocking({ x: 250, y: 450 });
  440. expect(connection).to.have.endDocking(oldEnd.original);
  441. })
  442. );
  443. it('should move mid segment beyond target',
  444. inject(function(canvas, connectionSegmentMove, dragging) {
  445. // given
  446. var oldStart = connection.waypoints[0];
  447. // given drag middle to the left
  448. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  449. dragging.move(canvasEvent({ x: 750, y: 200 }));
  450. dragging.end();
  451. // then
  452. expect(connection).to.have.waypoints([
  453. { x: 300, y: 450 },
  454. { x: 750, y: 450 },
  455. { x: 750, y: 150 },
  456. { x: 700, y: 150 }
  457. ]);
  458. // updating end docking
  459. expect(connection).to.have.startDocking(oldStart.original);
  460. expect(connection).to.have.endDocking({ x: 650, y: 150 });
  461. })
  462. );
  463. it('should move mid segment, removing last',
  464. inject(function(canvas, connectionSegmentMove, dragging) {
  465. // given
  466. var oldStart = connection.waypoints[0];
  467. // given drag middle to the left
  468. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  469. dragging.move(canvasEvent({ x: 620, y: 200 }));
  470. dragging.end();
  471. // then
  472. expect(connection).to.have.waypoints([
  473. { x: 300, y: 450 },
  474. { x: 620, y: 450 },
  475. { x: 620, y: 250 }
  476. ]);
  477. // updating end docking
  478. expect(connection).to.have.startDocking(oldStart.original);
  479. expect(connection).to.have.endDocking({ x: 620, y: 150 });
  480. })
  481. );
  482. it('should move mid segment, removing first',
  483. inject(function(canvas, connectionSegmentMove, dragging) {
  484. // given
  485. var oldEnd = connection.waypoints[3];
  486. // given drag middle to the left
  487. connectionSegmentMove.start(canvasEvent({ x: 400, y: 200 }), connection, 2);
  488. dragging.move(canvasEvent({ x: 280, y: 200 }));
  489. dragging.end();
  490. // then
  491. expect(connection).to.have.waypoints([
  492. { x: 280, y: 400 },
  493. { x: 280, y: 150 },
  494. { x: 600, y: 150 }
  495. ]);
  496. // updating end docking
  497. expect(connection).to.have.startDocking({ x: 280, y: 450 });
  498. expect(connection).to.have.endDocking(oldEnd.original);
  499. })
  500. );
  501. });
  502. describe('width docking (skewed segments, no filteredWaypoints)', function() {
  503. beforeEach(bootstrapDiagram({
  504. modules: [
  505. bendpointsModule,
  506. modelingModule,
  507. selectModule,
  508. layoutModule
  509. ]
  510. }));
  511. beforeEach(inject(function(dragging) {
  512. dragging.setOptions({ manual: true });
  513. }));
  514. var sourceShape, targetShape, createConnection;
  515. beforeEach(inject(function(elementFactory, canvas) {
  516. sourceShape = elementFactory.createShape({
  517. id: 'sourceShape', type: 'A',
  518. x: 100, y: 100,
  519. width: 100, height: 100
  520. });
  521. canvas.addShape(sourceShape);
  522. targetShape = elementFactory.createShape({
  523. id: 'targetShape', type: 'A',
  524. x: 600, y: 100,
  525. width: 100, height: 100
  526. });
  527. canvas.addShape(targetShape);
  528. createConnection = function(waypoints) {
  529. return elementFactory.createConnection({
  530. id: 'connection',
  531. waypoints: waypoints,
  532. source: sourceShape,
  533. target: targetShape
  534. });
  535. };
  536. }));
  537. it('two skewed side segments', inject(function(canvas, connectionSegmentMove, dragging) {
  538. // given
  539. var connection = createConnection([
  540. { x: 150, y: 150 },
  541. { x: 50, y: 400 },
  542. { x: 750, y: 400 },
  543. { x: 650, y: 150 }
  544. ]);
  545. canvas.addConnection(connection);
  546. // when
  547. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  548. dragging.move(canvasEvent({ x: 0, y: -250 }));
  549. dragging.end();
  550. // then
  551. expect(connection).to.have.waypoints([
  552. { x: 200, y: 150 },
  553. { x: 600, y: 150 }
  554. ]);
  555. }));
  556. it('4 manhatten waypoints in the middle', inject(function(canvas, connectionSegmentMove, dragging) {
  557. // given
  558. var connection = createConnection([
  559. { x: 150, y: 200 },
  560. { x: 150, y: 400 },
  561. { x: 300, y: 400 },
  562. { x: 300, y: 450 },
  563. { x: 500, y: 450 },
  564. { x: 500, y: 400 },
  565. { x: 650, y: 400 },
  566. { x: 650, y: 200 }
  567. ]);
  568. canvas.addConnection(connection);
  569. // when
  570. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 4);
  571. dragging.move(canvasEvent({ x: 0, y: -50 }));
  572. dragging.end();
  573. // then
  574. expect(connection).to.have.waypoints([
  575. { x: 150, y: 200 },
  576. { x: 150, y: 400 },
  577. { x: 650, y: 400 },
  578. { x: 650, y: 200 }
  579. ]);
  580. }));
  581. it('4 waypoints in the middle, 2 skewed side-segments', inject(function(canvas, connectionSegmentMove, dragging) {
  582. // given
  583. var connection = createConnection([
  584. { x: 150, y: 200 },
  585. { x: 150, y: 400 },
  586. { x: 300, y: 400 },
  587. { x: 350, y: 450 },
  588. { x: 450, y: 450 },
  589. { x: 500, y: 400 },
  590. { x: 650, y: 400 },
  591. { x: 650, y: 200 }
  592. ]);
  593. canvas.addConnection(connection);
  594. // when
  595. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 4);
  596. dragging.move(canvasEvent({ x: 0, y: -50 }));
  597. dragging.end();
  598. // then
  599. expect(connection).to.have.waypoints([
  600. { x: 150, y: 200 },
  601. { x: 150, y: 400 },
  602. { x: 650, y: 400 },
  603. { x: 650, y: 200 }
  604. ]);
  605. }));
  606. it('2 waypoints in the middle with skewed segments', inject(function(canvas, connectionSegmentMove, dragging) {
  607. // given
  608. var connection = createConnection([
  609. { x: 150, y: 200 },
  610. { x: 150, y: 400 },
  611. { x: 300, y: 300 },
  612. { x: 500, y: 300 },
  613. { x: 650, y: 400 },
  614. { x: 650, y: 200 }
  615. ]);
  616. canvas.addConnection(connection);
  617. // when
  618. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 3);
  619. dragging.move(canvasEvent({ x: 0, y: 100 }));
  620. dragging.end();
  621. // then
  622. expect(connection).to.have.waypoints([
  623. { x: 150, y: 200 },
  624. { x: 150, y: 400 },
  625. { x: 650, y: 400 },
  626. { x: 650, y: 200 }
  627. ]);
  628. }));
  629. it('two horizontal segment in the middle, in front of last segment', inject(function(canvas, connectionSegmentMove, dragging) {
  630. // given
  631. var connection = createConnection([
  632. { x: 150, y: 200 },
  633. { x: 150, y: 400 },
  634. { x: 500, y: 400 },
  635. { x: 500, y: 450 },
  636. { x: 650, y: 450 },
  637. { x: 650, y: 200 }
  638. ]);
  639. canvas.addConnection(connection);
  640. // when
  641. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  642. dragging.move(canvasEvent({ x: 0, y: 50 }));
  643. dragging.end();
  644. // then
  645. expect(connection).to.have.waypoints([
  646. { x: 150, y: 200 },
  647. { x: 150, y: 450 },
  648. { x: 650, y: 450 },
  649. { x: 650, y: 200 }
  650. ]);
  651. }));
  652. it('one skewed segment in the middle, in front of last segment', inject(function(canvas, connectionSegmentMove, dragging) {
  653. // given
  654. var connection = createConnection([
  655. { x: 150, y: 200 },
  656. { x: 150, y: 400 },
  657. { x: 500, y: 400 },
  658. { x: 650, y: 450 },
  659. { x: 650, y: 200 }
  660. ]);
  661. canvas.addConnection(connection);
  662. // when
  663. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  664. dragging.move(canvasEvent({ x: 0, y: 50 }));
  665. dragging.end();
  666. // then
  667. expect(connection).to.have.waypoints([
  668. { x: 150, y: 200 },
  669. { x: 150, y: 450 },
  670. { x: 650, y: 450 },
  671. { x: 650, y: 200 }
  672. ]);
  673. }));
  674. it('one skewed and one horizontal segment in the middle, in front of last segment', inject(function(canvas, connectionSegmentMove, dragging) {
  675. // given
  676. var connection = createConnection([
  677. { x: 150, y: 200 },
  678. { x: 150, y: 400 },
  679. { x: 500, y: 400 },
  680. { x: 550, y: 450 },
  681. { x: 650, y: 450 },
  682. { x: 650, y: 200 }
  683. ]);
  684. canvas.addConnection(connection);
  685. // when
  686. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  687. dragging.move(canvasEvent({ x: 0, y: 50 }));
  688. dragging.end();
  689. // then
  690. expect(connection).to.have.waypoints([
  691. { x: 150, y: 200 },
  692. { x: 150, y: 450 },
  693. { x: 650, y: 450 },
  694. { x: 650, y: 200 }
  695. ]);
  696. }));
  697. it('skewed segment on start', inject(function(canvas, connectionSegmentMove, dragging) {
  698. // given
  699. var connection = createConnection([
  700. { x: 150, y: 200 },
  701. { x: 50, y: 300 },
  702. { x: 50, y: 400 },
  703. { x: 650, y: 400 },
  704. { x: 650, y: 200 }
  705. ]);
  706. canvas.addConnection(connection);
  707. // when
  708. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 2);
  709. dragging.move(canvasEvent({ x: 100, y: 0 }));
  710. dragging.end();
  711. // then
  712. expect(connection).to.have.waypoints([
  713. { x: 150, y: 200 },
  714. { x: 150, y: 400 },
  715. { x: 650, y: 400 },
  716. { x: 650, y: 200 }
  717. ]);
  718. }));
  719. it('skewed segment on end', inject(function(canvas, connectionSegmentMove, dragging) {
  720. // given
  721. var connection = createConnection([
  722. { x: 150, y: 200 },
  723. { x: 150, y: 400 },
  724. { x: 750, y: 400 },
  725. { x: 750, y: 250 },
  726. { x: 650, y: 200 }
  727. ]);
  728. canvas.addConnection(connection);
  729. // when
  730. connectionSegmentMove.start(canvasEvent({ x: 0, y: 0 }), connection, 3);
  731. dragging.move(canvasEvent({ x: -100, y: 0 }));
  732. dragging.end();
  733. // then
  734. expect(connection).to.have.waypoints([
  735. { x: 150, y: 200 },
  736. { x: 150, y: 400 },
  737. { x: 650, y: 400 },
  738. { x: 650, y: 200 }
  739. ]);
  740. }));
  741. });
  742. });