123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import {
- find
- } from 'min-dash';
- import modelingModule from 'lib/features/modeling';
- describe('features/modeling - append shape', function() {
- beforeEach(bootstrapDiagram({ modules: [ modelingModule ] }));
- var diagramRoot, childShape;
- beforeEach(inject(function(elementFactory, canvas) {
- diagramRoot = elementFactory.createRoot({
- id: 'root'
- });
- canvas.setRootElement(diagramRoot);
- childShape = elementFactory.createShape({
- id: 'child',
- x: 110, y: 110, width: 100, height: 100
- });
- canvas.addShape(childShape, diagramRoot);
- }));
- describe('basic handling', function() {
- var newShape;
- beforeEach(inject(function(modeling) {
- // add new shape
- newShape = modeling.appendShape(
- childShape,
- { id: 'appended', width: 50, height: 50 },
- { x: 200, y: 200 }
- );
- }));
- it('should return shape', inject(function() {
- // when
- // shape added
- // then
- expect(newShape).to.exist;
- }));
- it('should position new shape at mid', inject(function() {
- // when
- // shape added
- // then
- expect(newShape).to.exist;
- expect(newShape.x + newShape.width / 2).to.equal(200);
- expect(newShape.y + newShape.height / 2).to.equal(200);
- }));
- it('should render shape', inject(function(elementRegistry) {
- // when
- // shape added
- // then
- expect(elementRegistry.getGraphics(newShape)).to.exist;
- }));
- it('should add connection', inject(function(elementRegistry) {
- // when
- // shape added
- var connection = find(newShape.incoming, function(c) {
- return c.source === childShape;
- });
- // then
- expect(connection).to.exist;
- expect(connection.parent).to.equal(newShape.parent);
- expect(elementRegistry.getGraphics(connection)).to.exist;
- }));
- it('should undo', inject(function(commandStack, elementRegistry) {
- // given
- // shape added
- // when
- commandStack.undo();
- // then
- expect(newShape.parent).to.be.null;
- expect(elementRegistry.getGraphics(newShape)).to.be.undefined;
- }));
- });
- describe('customization', function() {
- it('should pass custom attributes connection', inject(function(modeling) {
- // given
- var connectionProperties = {
- custom: true
- };
- var shapeProps = {
- id: 'appended',
- width: 100,
- height: 100
- };
- var hints = {
- connection: connectionProperties
- };
- // when
- var newShape = modeling.appendShape(childShape, shapeProps, { x: 200, y: 200 }, null, hints);
- var newConnection = newShape.incoming[0];
- // then
- expect(newConnection.custom).to.be.true;
- }));
- });
- describe('connection create behavior', function() {
- it('should only create if not connected already', inject(function(modeling, eventBus) {
- // given
- eventBus.on('commandStack.shape.create.postExecute', function connectListener(event) {
- var context = event.context;
- // connect childShape -> shape
- modeling.connect(childShape, context.shape);
- });
- // when
- var newShape = modeling.appendShape(
- childShape,
- { id: 'appended', width: 100, height: 100 },
- { x: 500, y: 200 }
- );
- var incomingConnections = newShape.incoming;
- // then
- expect(incomingConnections.length).to.eql(1);
- }));
- });
- });
|