ReplaceShapeSpec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - replace shape', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
  8. describe('same size', function() {
  9. var root, parent, child1, child2;
  10. beforeEach(inject(function(elementFactory, canvas, modeling) {
  11. root = elementFactory.createRoot({
  12. id: 'root'
  13. });
  14. canvas.setRootElement(root);
  15. parent = elementFactory.createShape({
  16. id: 'parent',
  17. x: 20, y: 20, width: 200, height: 200
  18. });
  19. child1 = elementFactory.createShape({
  20. id: 'child1',
  21. x: 30, y: 30, width: 50, height: 50
  22. });
  23. child2 = elementFactory.createShape({
  24. id: 'child2',
  25. x: 90, y: 90, width: 50, height: 50
  26. });
  27. canvas.addShape(parent, root);
  28. canvas.addShape(child1, parent);
  29. canvas.addShape(child2, parent);
  30. }));
  31. it('should move children per default', inject(function(elementFactory, modeling) {
  32. // when
  33. var newShapeData = { x: 120, y: 120, width: 200, height: 200 };
  34. var newShape = modeling.replaceShape(parent, newShapeData);
  35. // then
  36. expect(newShape.children).to.have.length(2);
  37. }));
  38. it('should move children when moveChildren=true', inject(function(elementFactory, modeling) {
  39. // when
  40. var newShapeData = { x: 120, y: 120, width: 200, height: 200 };
  41. var newShape = modeling.replaceShape(parent, newShapeData, { moveChildren: true });
  42. // then
  43. expect(newShape.children).to.have.length(2);
  44. }));
  45. it('should remove children when moveChildren=false', inject(function(elementFactory, modeling) {
  46. // when
  47. var newShapeData = { x: 120, y: 120, width: 200, height: 200 };
  48. var newShape = modeling.replaceShape(parent, newShapeData, { moveChildren: false });
  49. // then
  50. expect(newShape.children).to.be.empty;
  51. }));
  52. });
  53. describe('different size', function() {
  54. var root, parent, child1, child2, connection;
  55. beforeEach(inject(function(elementFactory, canvas, modeling) {
  56. root = elementFactory.createRoot({
  57. id: 'root'
  58. });
  59. canvas.setRootElement(root);
  60. parent = elementFactory.createShape({
  61. id: 'parent',
  62. x: 20, y: 20, width: 400, height: 400
  63. });
  64. child1 = elementFactory.createShape({
  65. id: 'child1',
  66. x: 360, y: 30, width: 50, height: 50
  67. });
  68. child2 = elementFactory.createShape({
  69. id: 'child2',
  70. x: 30, y: 30, width: 100, height: 100
  71. });
  72. connection = elementFactory.createConnection({
  73. id: 'connection',
  74. source: child1,
  75. target: child2,
  76. waypoints: [
  77. { x: 360, y: 30 },
  78. { x: 30, y: 30 }
  79. ]
  80. });
  81. canvas.addShape(parent, root);
  82. canvas.addShape(child1, parent);
  83. canvas.addShape(child2, parent);
  84. canvas.addConnection(connection, parent);
  85. modeling.layoutConnection(connection);
  86. }));
  87. it('should relayout connection when replacing elements with different size', inject(function(elementFactory, modeling) {
  88. // given
  89. var newShapeData = { x: 130, y: 130, width: 200, height: 200 };
  90. // when
  91. modeling.replaceShape(child2, newShapeData);
  92. // then
  93. expect(connection.waypoints[0]).to.be.eql({ x: 385, y: 55 });
  94. expect(connection.waypoints[1]).to.be.eql({ x: 130, y: 130 });
  95. }));
  96. });
  97. });