DeleteConnectionSpec.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - remove connection', function() {
  7. beforeEach(bootstrapDiagram({
  8. modules: [
  9. modelingModule
  10. ]
  11. }));
  12. var rootShape, parentShape, childShape, childShape2, connection;
  13. beforeEach(inject(function(elementFactory, canvas, elementRegistry) {
  14. rootShape = elementFactory.createRoot({
  15. id: 'root'
  16. });
  17. canvas.setRootElement(rootShape);
  18. parentShape = elementFactory.createShape({
  19. id: 'parent',
  20. x: 100, y: 100, width: 300, height: 300
  21. });
  22. canvas.addShape(parentShape, rootShape);
  23. childShape = elementFactory.createShape({
  24. id: 'child',
  25. x: 110, y: 110, width: 100, height: 100
  26. });
  27. canvas.addShape(childShape, parentShape);
  28. childShape2 = elementFactory.createShape({
  29. id: 'child2',
  30. x: 200, y: 110, width: 100, height: 100
  31. });
  32. canvas.addShape(childShape2, parentShape);
  33. connection = elementFactory.createConnection({
  34. id: 'connection',
  35. waypoints: [ { x: 150, y: 150 }, { x: 150, y: 200 }, { x: 350, y: 150 } ],
  36. source: childShape,
  37. target: childShape2
  38. });
  39. canvas.addConnection(connection, parentShape);
  40. }));
  41. it('should remove connection', inject(function(modeling, elementRegistry) {
  42. // when
  43. modeling.removeConnection(connection);
  44. // then
  45. expect(connection.parent).not.to.exist;
  46. }));
  47. it('should clean up incoming/outgoing on connected shapes ', inject(function(modeling, elementRegistry) {
  48. // when
  49. modeling.removeConnection(connection);
  50. // then
  51. expect(childShape.outgoing).not.to.contain(connection);
  52. expect(connection.source).not.to.exist;
  53. expect(childShape2.incoming).not.to.contain(connection);
  54. expect(connection.target).not.to.exist;
  55. }));
  56. describe('undo support', function() {
  57. it('should revert', inject(function(modeling, elementRegistry, commandStack) {
  58. // given
  59. modeling.removeConnection(connection);
  60. // when
  61. commandStack.undo();
  62. // then
  63. expect(connection.parent).to.equal(parentShape);
  64. }));
  65. it('should restore correct source/target', inject(function(modeling, elementRegistry, commandStack) {
  66. // given
  67. modeling.removeConnection(connection);
  68. // when
  69. commandStack.undo();
  70. // then
  71. expect(childShape.outgoing).to.contain(connection);
  72. expect(connection.source).to.equal(childShape);
  73. expect(childShape2.incoming).to.contain(connection);
  74. expect(connection.target).to.equal(childShape2);
  75. }));
  76. it('should restore reference after multiple undo', inject(function(modeling, elementRegistry, commandStack) {
  77. // given
  78. modeling.removeConnection(connection);
  79. modeling.removeShape(childShape);
  80. // when
  81. commandStack.undo();
  82. commandStack.undo();
  83. // then
  84. expect(childShape.outgoing).to.contain(connection);
  85. expect(childShape2.incoming).to.contain(connection);
  86. }));
  87. });
  88. });