2014-07-30 14:07:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
/* global bootstrapModeler, inject */
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var find = require('lodash/collection/find');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var assign = require('lodash/object/assign');
|
|
|
|
|
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var modelingModule = require('../../../../lib/features/modeling'),
|
2014-10-30 11:06:43 +00:00
|
|
|
coreModule = require('../../../../lib/core');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
var LabelUtil = require('../../../../lib/util/LabelUtil');
|
2014-08-03 12:30:53 +00:00
|
|
|
|
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
describe('features/modeling - append shape', function() {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-10-30 11:06:43 +00:00
|
|
|
var testModules = [ coreModule, modelingModule ];
|
2014-08-05 06:17:22 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('shape handling', function() {
|
|
|
|
|
|
|
|
it('should execute', inject(function(elementRegistry, modeling) {
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(targetShape).to.exist;
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(target.$instanceOf('bpmn:Task')).to.be.true;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should create DI', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var startEvent = startEventShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(target.di).to.exist;
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(target.di.$parent).to.eql(startEvent.di.$parent);
|
2014-08-02 14:38:25 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
expect(target.di).to.have.bounds(targetShape);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should add to parent (sub process)', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var subProcess = subProcessShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(subProcess.get('flowElements')).to.include(target);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
describe('should add external label', function() {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
it('correctly wired and positioned', inject(function(elementRegistry, modeling, commandStack) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
// when
|
2015-09-02 12:15:45 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
var label = targetShape.label;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(label).to.exist;
|
|
|
|
expect(elementRegistry.get(label.id)).to.exist;
|
2014-08-03 12:30:53 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
expect(label).to.have.bounds(assign({ x: 441, y: 278 }, LabelUtil.DEFAULT_LABEL_SIZE));
|
2014-08-03 12:30:53 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('with di', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
2014-08-03 12:30:53 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' }),
|
2014-08-03 12:30:53 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(target.di.label).to.exist;
|
2014-08-03 12:30:53 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
expect(target.di.label).to.have.bounds(targetShape.label);
|
2014-08-03 12:30:53 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('should add connection', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
2014-07-30 14:07:43 +00:00
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(connection).to.exist;
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(connection.$instanceOf('bpmn:SequenceFlow')).to.be.true;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('undo support', function() {
|
|
|
|
|
|
|
|
it('should undo add to parent', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2015-09-02 12:15:45 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var subProcess = subProcessShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(subProcess.get('flowElements')).not.to.include(target);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.to.include(target.di);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo add shape label', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2015-09-02 12:15:45 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1'),
|
|
|
|
subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:EndEvent' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
2014-07-30 14:07:43 +00:00
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(connection.sourceRef).to.be.null;
|
|
|
|
expect(connection.targetRef).to.be.null;
|
|
|
|
expect(connection.$parent).to.be.null;
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(targetShape.label).not.to.exist;
|
|
|
|
expect(elementRegistry.get(target.id + '_label')).not.to.exist;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo add connection', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
2014-07-30 14:07:43 +00:00
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(connection.sourceRef).to.be.null;
|
|
|
|
expect(connection.targetRef).to.be.null;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(startEvent.get('outgoing')).not.to.include(connection);
|
|
|
|
expect(target.get('incoming')).not.to.include(connection);
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(connection.$parent).to.be.null;
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(elementRegistry.get(targetShape.id)).not.to.exist;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo add connection label', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
2014-07-30 14:07:43 +00:00
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(connection.sourceRef).to.be.null;
|
|
|
|
expect(connection.targetRef).to.be.null;
|
|
|
|
expect(connection.$parent).to.be.null;
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(elementRegistry.get(connection.id + '_label')).not.to.exist;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should redo appending multiple shapes', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape2 = modeling.appendShape(targetShape, { type: 'bpmn:UserTask' });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
// expect redo to work on original target object
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(targetShape.parent).to.eql(subProcessShape);
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(targetShape2.parent).to.be.null;
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(elementRegistry.get(targetShape2.id)).not.to.exist;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should redo add connection', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:Task' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
2015-02-02 13:46:21 +00:00
|
|
|
var connection = find(subProcess.get('flowElements'), function(e) {
|
2014-07-30 14:07:43 +00:00
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(connection.sourceRef).to.be.null;
|
|
|
|
expect(connection.targetRef).to.be.null;
|
|
|
|
expect(connection.$parent).to.be.null;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.to.include(connection.di);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('bpmn element support', function() {
|
|
|
|
|
|
|
|
describe('ExclusiveGateway', function() {
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
it('should append', inject(function(elementRegistry, modeling) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:ExclusiveGateway' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(targetShape).to.exist;
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(target.$instanceOf('bpmn:ExclusiveGateway')).to.be.true;
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
it('should add to parent (sub process)', inject(function(elementRegistry, modeling) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var subProcess = subProcessShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:ExclusiveGateway' }),
|
2015-09-02 12:15:45 +00:00
|
|
|
target = targetShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(subProcess.get('flowElements')).to.include(target);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
it('should undo append', inject(function(elementRegistry, modeling, commandStack) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var startEventShape = elementRegistry.get('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.get('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2015-09-02 12:15:45 +00:00
|
|
|
var subProcess = subProcessShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-12-07 12:08:50 +00:00
|
|
|
var targetShape = modeling.appendShape(startEventShape, { type: 'bpmn:ExclusiveGateway' }),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(subProcess.get('flowElements')).not.to.include(target);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.to.include(target.di);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-10-27 11:07:57 +00:00
|
|
|
});
|