DropShapeSpec.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - move shape - drop', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
  8. var rootShape, parent1, parent2, parent3, shape1, shape2, shape3;
  9. beforeEach(inject(function(elementFactory, canvas) {
  10. rootShape = elementFactory.createRoot({
  11. id: 'root'
  12. });
  13. canvas.setRootElement(rootShape);
  14. // parents
  15. parent1 = elementFactory.createShape({
  16. id: 'parent1',
  17. x: 10, y: 50, width: 70, height: 70
  18. });
  19. canvas.addShape(parent1, rootShape);
  20. parent2 = elementFactory.createShape({
  21. id: 'parent2',
  22. x: 100, y: 50, width: 70, height: 70
  23. });
  24. canvas.addShape(parent2, rootShape);
  25. parent3 = elementFactory.createShape({
  26. id: 'parent3',
  27. x: 190, y: 50, width: 120, height: 120
  28. });
  29. canvas.addShape(parent3, rootShape);
  30. // childs
  31. shape1 = elementFactory.createShape({
  32. id: 'shape1',
  33. x: 10, y: 10, width: 10, height: 10
  34. });
  35. canvas.addShape(shape1, rootShape);
  36. shape2 = elementFactory.createShape({
  37. id: 'shape2',
  38. x: 30, y: 10, width: 10, height: 10
  39. });
  40. canvas.addShape(shape2, rootShape);
  41. shape3 = elementFactory.createShape({
  42. id: 'shape3',
  43. x: 50, y: 10, width: 10, height: 10
  44. });
  45. canvas.addShape(shape3, rootShape);
  46. }));
  47. describe('bootstrap', function() {
  48. it('should bootstrap diagram with component', inject(function() {}));
  49. });
  50. describe('shapes', function() {
  51. it('should drop single shape', inject(function(modeling) {
  52. // given
  53. // when
  54. modeling.moveShape(shape1, { x: 5, y: 50 }, parent1);
  55. // then
  56. expect(shape1.parent).to.equal(parent1);
  57. }));
  58. it('should drop multiple shapes', inject(function(modeling) {
  59. // given
  60. // when
  61. modeling.moveElements([shape1, shape2], { x: 5, y: 50 }, parent1);
  62. // then
  63. expect(shape1.parent).to.equal(parent1);
  64. expect(shape2.parent).to.equal(parent1);
  65. }));
  66. it('should drop multiple shapes from multiple source parents', inject(function(modeling) {
  67. // given
  68. modeling.moveShape(shape1, { x: 5, y: 50 }, parent1);
  69. modeling.moveShape(shape2, { x: 75, y: 50 }, parent2);
  70. // when
  71. modeling.moveElements([shape1, shape2], { x: 180, y: 0 }, parent3);
  72. // then
  73. expect(shape1.parent).to.equal(parent3);
  74. expect(shape2.parent).to.equal(parent3);
  75. }));
  76. it('should drop container in container', inject(function(modeling) {
  77. // given
  78. modeling.moveElements([shape1, shape2], { x: 110, y: 50 }, parent2);
  79. // when
  80. modeling.moveShape(parent2, { x: 115, y: 25 }, parent3);
  81. // then
  82. expect(shape1.parent).to.equal(parent2);
  83. expect(shape2.parent).to.equal(parent2);
  84. expect(parent2.parent).to.equal(parent3);
  85. }));
  86. });
  87. });