123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import modelingModule from 'lib/features/modeling';
- describe('features/modeling - create shape', function() {
- beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
- var rootShape, parentShape, newShape;
- beforeEach(inject(function(elementFactory, canvas) {
- rootShape = elementFactory.createRoot({
- id: 'root'
- });
- canvas.setRootElement(rootShape);
- parentShape = elementFactory.createShape({
- id: 'parent',
- x: 100, y: 100, width: 300, height: 300
- });
- canvas.addShape(parentShape, rootShape);
- newShape = elementFactory.createShape({
- id: 'newShape',
- x: 0, y: 0, width: 100, height: 100
- });
- }));
- var position = {
- x: 175,
- y: 175
- };
- describe('basics', function() {
- describe('should create', function() {
- it('execute', inject(function(modeling, elementRegistry) {
- // when
- modeling.createShape(newShape, position, parentShape);
- var shape = elementRegistry.get('newShape');
- // then
- expect(shape).to.include({
- id: 'newShape',
- x: 125, y: 125,
- width: 100, height: 100
- });
- }));
- it('undo', inject(function(modeling, commandStack, elementRegistry) {
- // given
- modeling.createShape(newShape, position, parentShape);
- // when
- commandStack.undo();
- var shape = elementRegistry.get('newShape');
- // then
- expect(shape).not.to.exist;
- expect(newShape.parent).not.to.exist;
- expect(parentShape.children).not.to.contain(newShape);
- }));
- });
- it('should have a parent', inject(function(modeling) {
- // given
- modeling.createShape(newShape, position, parentShape);
- // when
- var parent = newShape.parent;
- // then
- expect(parent).to.equal(parentShape);
- }));
- it('should have parentIndex', inject(function(modeling) {
- // given
- modeling.createShape(newShape, position, rootShape, 0);
- // when
- var children = rootShape.children;
- // then
- expect(children).to.eql([
- newShape,
- parentShape
- ]);
- }));
- it('should return a graphics element', inject(function(modeling, elementRegistry) {
- // given
- modeling.createShape(newShape, position, parentShape);
- // when
- var shape = elementRegistry.getGraphics(newShape);
- // then
- expect(shape).to.exist;
- }));
- });
- });
|