CreateShapeSpec.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {
  2. bootstrapDiagram,
  3. inject
  4. } from 'test/TestHelper';
  5. import modelingModule from 'lib/features/modeling';
  6. describe('features/modeling - create shape', function() {
  7. beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
  8. var rootShape, parentShape, newShape;
  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. newShape = elementFactory.createShape({
  20. id: 'newShape',
  21. x: 0, y: 0, width: 100, height: 100
  22. });
  23. }));
  24. var position = {
  25. x: 175,
  26. y: 175
  27. };
  28. describe('basics', function() {
  29. describe('should create', function() {
  30. it('execute', inject(function(modeling, elementRegistry) {
  31. // when
  32. modeling.createShape(newShape, position, parentShape);
  33. var shape = elementRegistry.get('newShape');
  34. // then
  35. expect(shape).to.include({
  36. id: 'newShape',
  37. x: 125, y: 125,
  38. width: 100, height: 100
  39. });
  40. }));
  41. it('undo', inject(function(modeling, commandStack, elementRegistry) {
  42. // given
  43. modeling.createShape(newShape, position, parentShape);
  44. // when
  45. commandStack.undo();
  46. var shape = elementRegistry.get('newShape');
  47. // then
  48. expect(shape).not.to.exist;
  49. expect(newShape.parent).not.to.exist;
  50. expect(parentShape.children).not.to.contain(newShape);
  51. }));
  52. });
  53. it('should have a parent', inject(function(modeling) {
  54. // given
  55. modeling.createShape(newShape, position, parentShape);
  56. // when
  57. var parent = newShape.parent;
  58. // then
  59. expect(parent).to.equal(parentShape);
  60. }));
  61. it('should have parentIndex', inject(function(modeling) {
  62. // given
  63. modeling.createShape(newShape, position, rootShape, 0);
  64. // when
  65. var children = rootShape.children;
  66. // then
  67. expect(children).to.eql([
  68. newShape,
  69. parentShape
  70. ]);
  71. }));
  72. it('should return a graphics element', inject(function(modeling, elementRegistry) {
  73. // given
  74. modeling.createShape(newShape, position, parentShape);
  75. // when
  76. var shape = elementRegistry.getGraphics(newShape);
  77. // then
  78. expect(shape).to.exist;
  79. }));
  80. });
  81. });