CreateConnectionSpec.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - create connection', function() {
  7. beforeEach(bootstrapDiagram({
  8. modules: [
  9. modelingModule
  10. ]
  11. }));
  12. var rootShape,
  13. parentShape,
  14. sourceShape,
  15. targetShape,
  16. newConnection;
  17. beforeEach(inject(function(elementFactory, canvas) {
  18. rootShape = elementFactory.createRoot({
  19. id: 'root'
  20. });
  21. canvas.setRootElement(rootShape);
  22. parentShape = elementFactory.createShape({
  23. id: 'parent',
  24. x: 100, y: 100, width: 300, height: 300
  25. });
  26. canvas.addShape(parentShape, rootShape);
  27. sourceShape = elementFactory.createShape({
  28. id: 'sourceShape',
  29. x: 110, y: 110, width: 40, height: 40
  30. });
  31. canvas.addShape(sourceShape, parentShape);
  32. targetShape = elementFactory.createShape({
  33. id: 'targetShape',
  34. x: 210, y: 110, width: 40, height: 40
  35. });
  36. canvas.addShape(targetShape, parentShape);
  37. newConnection = elementFactory.createConnection({
  38. id: 'newConnection'
  39. });
  40. }));
  41. describe('basics', function() {
  42. describe('should create', function() {
  43. it('execute', inject(function(modeling, elementRegistry) {
  44. // when
  45. modeling.connect(sourceShape, targetShape, newConnection);
  46. var connection = elementRegistry.get('newConnection');
  47. // then
  48. expect(connection.id).to.eql('newConnection');
  49. expect(connection.waypoints).to.eql([
  50. { x: 130, y: 130 },
  51. { x: 230, y: 130 }
  52. ]);
  53. }));
  54. it('undo', inject(function(modeling, commandStack, elementRegistry) {
  55. // given
  56. modeling.connect(sourceShape, targetShape, newConnection);
  57. // when
  58. commandStack.undo();
  59. // then
  60. expect(parentShape.children).not.to.contain(newConnection);
  61. expect(newConnection.parent).not.to.exist;
  62. expect(elementRegistry.get('newConnection')).not.to.exist;
  63. }));
  64. });
  65. it('should have a parent', inject(function(modeling) {
  66. // given
  67. modeling.createConnection(sourceShape, targetShape, newConnection, rootShape);
  68. // when
  69. var parent = newConnection.parent;
  70. // then
  71. expect(parent).to.equal(rootShape);
  72. }));
  73. it('should have parentIndex', inject(function(modeling) {
  74. // given
  75. modeling.createConnection(sourceShape, targetShape, 0, newConnection, parentShape);
  76. // when
  77. var children = parentShape.children;
  78. // then
  79. expect(children).to.eql([
  80. newConnection,
  81. sourceShape,
  82. targetShape
  83. ]);
  84. }));
  85. });
  86. });