DeleteShapeSpec.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. import contextPadModule from 'lib/features/context-pad';
  7. import selectionModule from 'lib/features/selection';
  8. describe('features/modeling - #removeShape', function() {
  9. describe('basics', function() {
  10. var rootShape,
  11. parentShape,
  12. childShape,
  13. childShape2,
  14. childShape3,
  15. childShape4,
  16. connection,
  17. connection2;
  18. beforeEach(bootstrapDiagram({
  19. modules: [
  20. modelingModule
  21. ]
  22. }));
  23. beforeEach(inject(function(elementFactory, canvas) {
  24. rootShape = elementFactory.createRoot({
  25. id: 'root'
  26. });
  27. canvas.setRootElement(rootShape);
  28. parentShape = elementFactory.createShape({
  29. id: 'parent',
  30. x: 100, y: 100, width: 300, height: 300
  31. });
  32. canvas.addShape(parentShape, rootShape);
  33. childShape = elementFactory.createShape({
  34. id: 'child',
  35. x: 110, y: 110, width: 100, height: 100
  36. });
  37. canvas.addShape(childShape, parentShape);
  38. childShape2 = elementFactory.createShape({
  39. id: 'child2',
  40. x: 200, y: 110, width: 100, height: 100
  41. });
  42. canvas.addShape(childShape2, parentShape);
  43. connection = elementFactory.createConnection({
  44. id: 'connection',
  45. waypoints: [
  46. { x: 150, y: 150 },
  47. { x: 150, y: 200 },
  48. { x: 350, y: 150 }
  49. ],
  50. source: childShape,
  51. target: childShape2
  52. });
  53. canvas.addConnection(connection, parentShape);
  54. childShape3 = elementFactory.createShape({
  55. id: 'child3',
  56. x: 600, y: 100, width: 100, height: 100
  57. });
  58. canvas.addShape(childShape3, rootShape);
  59. childShape4 = elementFactory.createShape({
  60. id: 'child4',
  61. x: 100, y: 500, width: 100, height: 100
  62. });
  63. canvas.addShape(childShape4, rootShape);
  64. connection2 = elementFactory.createConnection({
  65. id: 'connection2',
  66. waypoints: [ { x: 650, y: 150 }, { x: 150, y: 550 } ],
  67. source: childShape3,
  68. target: childShape4
  69. });
  70. canvas.addConnection(connection2, parentShape);
  71. }));
  72. it('should remove shape', inject(function(modeling, elementRegistry) {
  73. // when
  74. modeling.removeShape(childShape);
  75. // then
  76. expect(elementRegistry.get(childShape.id)).to.be.undefined;
  77. expect(childShape.parent).not.to.exist;
  78. expect(parentShape.children).not.to.contain(childShape);
  79. }));
  80. it('should remove incoming connection', inject(function(modeling) {
  81. // when
  82. modeling.removeShape(childShape2);
  83. // then
  84. expect(connection.parent).not.to.exist;
  85. }));
  86. it('should remove outgoing connection', inject(function(modeling) {
  87. // when
  88. modeling.removeShape(childShape);
  89. // then
  90. expect(connection.parent).not.to.exist;
  91. }));
  92. it('should remove children', inject(function(modeling) {
  93. // when
  94. modeling.removeShape(parentShape);
  95. // then
  96. expect(parentShape.parent).not.to.exist;
  97. expect(childShape.parent).not.to.exist;
  98. expect(childShape2.parent).not.to.exist;
  99. expect(connection.parent).not.to.exist;
  100. expect(childShape3.outgoing.length).to.equal(0);
  101. expect(childShape4.incoming.length).to.equal(0);
  102. }));
  103. it('ensure revert works', inject(function(modeling, elementRegistry, commandStack) {
  104. // when
  105. modeling.removeShape(childShape);
  106. // when
  107. commandStack.undo();
  108. // then
  109. expect(childShape.parent).to.equal(parentShape);
  110. expect(connection.parent).to.equal(parentShape);
  111. expect(childShape3.outgoing.length).to.equal(1);
  112. expect(childShape4.incoming.length).to.equal(1);
  113. }));
  114. });
  115. describe('context pad interaction', function() {
  116. beforeEach(bootstrapDiagram({ modules: [ modelingModule, contextPadModule, selectionModule ] }));
  117. it('should close context pad on remove shape', inject(function(canvas, modeling, contextPad, selection) {
  118. // given
  119. var shape = canvas.addShape({
  120. id: 'shape',
  121. x: 100, y: 100, width: 300, height: 300
  122. });
  123. selection.select(shape);
  124. // when
  125. modeling.removeShape(shape);
  126. // then
  127. expect(contextPad.isOpen()).to.be.false;
  128. }));
  129. });
  130. });