DeleteElementsSpec.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - #removeElements', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
  8. var rootShape, parentShape, childShape, childShape2, connection;
  9. beforeEach(inject(function(elementFactory, canvas, elementRegistry) {
  10. rootShape = elementFactory.createRoot({
  11. id: 'root'
  12. });
  13. canvas.setRootElement(rootShape);
  14. parentShape = elementFactory.createShape({
  15. id: 'parent',
  16. x: 100, y: 100, width: 300, height: 300
  17. });
  18. canvas.addShape(parentShape, rootShape);
  19. childShape = elementFactory.createShape({
  20. id: 'child',
  21. x: 110, y: 110, width: 100, height: 100
  22. });
  23. canvas.addShape(childShape, parentShape);
  24. childShape2 = elementFactory.createShape({
  25. id: 'child2',
  26. x: 200, y: 110, width: 100, height: 100
  27. });
  28. canvas.addShape(childShape2, parentShape);
  29. connection = elementFactory.createConnection({
  30. id: 'connection',
  31. waypoints: [ { x: 150, y: 150 }, { x: 150, y: 200 }, { x: 350, y: 150 } ],
  32. source: childShape,
  33. target: childShape2
  34. });
  35. canvas.addConnection(connection, parentShape);
  36. }));
  37. describe('remove multiple elements', function() {
  38. it('should execute', inject(function(modeling, elementRegistry) {
  39. // when
  40. modeling.removeElements([ connection, childShape, parentShape ]);
  41. // then
  42. expect(elementRegistry.get(connection.id)).to.be.undefined;
  43. expect(elementRegistry.get(childShape.id)).to.be.undefined;
  44. expect(elementRegistry.get(parentShape.id)).to.be.undefined;
  45. }));
  46. it('should revert', inject(function(modeling, elementRegistry, commandStack) {
  47. // given
  48. modeling.removeElements([ connection, childShape, parentShape ]);
  49. // when
  50. commandStack.undo();
  51. // then
  52. expect(elementRegistry.get(connection.id)).to.exist;
  53. expect(elementRegistry.get(childShape.id)).to.exist;
  54. expect(elementRegistry.get(parentShape.id)).to.exist;
  55. }));
  56. it('should redo', inject(function(modeling, elementRegistry, commandStack) {
  57. // given
  58. modeling.removeElements([ connection, childShape, parentShape ]);
  59. // when
  60. commandStack.undo();
  61. commandStack.redo();
  62. // then
  63. expect(elementRegistry.get(connection.id)).to.be.undefined;
  64. expect(elementRegistry.get(childShape.id)).to.be.undefined;
  65. expect(elementRegistry.get(parentShape.id)).to.be.undefined;
  66. }));
  67. });
  68. });