CreateLabelSpec.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - create label', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
  8. var rootShape, parentShape, childShape, childShape2, connection;
  9. beforeEach(inject(function(elementFactory, canvas) {
  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: 100, y: 100, width: 100, height: 100
  22. });
  23. canvas.addShape(childShape, parentShape);
  24. childShape2 = elementFactory.createShape({
  25. id: 'child2',
  26. x: 300, y: 100, width: 100, height: 100
  27. });
  28. canvas.addShape(childShape2, parentShape);
  29. connection = elementFactory.createConnection({
  30. id: 'connection',
  31. waypoints: [ { x: 150, y: 150 }, { x: 350, y: 150 } ],
  32. source: childShape,
  33. target: childShape2
  34. });
  35. canvas.addConnection(connection, parentShape);
  36. }));
  37. describe('on shapes', function() {
  38. var newLabel;
  39. beforeEach(inject(function(modeling) {
  40. // add new shape
  41. newLabel = modeling.createLabel(childShape, { x: 160, y: 250 });
  42. }));
  43. it('should return label', inject(function() {
  44. // when
  45. // label added
  46. // then
  47. expect(newLabel).to.exist;
  48. expect(newLabel.parent).to.equal(parentShape);
  49. }));
  50. it('should render label', inject(function(elementRegistry) {
  51. // when
  52. // label added
  53. // then
  54. expect(elementRegistry.getGraphics(newLabel)).to.exist;
  55. }));
  56. it('should maintain shape relationship', inject(function() {
  57. // when
  58. // label added
  59. // then
  60. expect(newLabel.labelTarget).to.equal(childShape);
  61. expect(childShape.label).to.equal(newLabel);
  62. }));
  63. it('should undo', inject(function(commandStack, elementRegistry) {
  64. // given
  65. // shape added
  66. // when
  67. commandStack.undo();
  68. // then
  69. expect(newLabel.parent).to.be.null;
  70. expect(newLabel.labelTarget).to.be.null;
  71. expect(childShape.label).not.to.exist;
  72. expect(elementRegistry.getGraphics(newLabel)).to.be.undefined;
  73. }));
  74. });
  75. describe('on connections', function() {
  76. var newLabel;
  77. beforeEach(inject(function(modeling) {
  78. // add new shape
  79. newLabel = modeling.createLabel(connection, { x: 160, y: 250 });
  80. }));
  81. it('should return label', inject(function() {
  82. // when
  83. // label added
  84. // then
  85. expect(newLabel).to.exist;
  86. }));
  87. it('should render label', inject(function(elementRegistry) {
  88. // when
  89. // label added
  90. // then
  91. expect(elementRegistry.getGraphics(newLabel)).to.exist;
  92. }));
  93. it('should maintain shape relationship', inject(function() {
  94. // when
  95. // label added
  96. // then
  97. expect(newLabel.labelTarget).to.equal(connection);
  98. expect(connection.label).to.equal(newLabel);
  99. }));
  100. it('should undo', inject(function(commandStack, elementRegistry) {
  101. // given
  102. // shape added
  103. // when
  104. commandStack.undo();
  105. // then
  106. expect(newLabel.parent).to.be.null;
  107. expect(newLabel.labelTarget).to.be.null;
  108. expect(connection.label).not.to.exist;
  109. expect(elementRegistry.getGraphics(newLabel)).to.be.undefined;
  110. }));
  111. });
  112. });