2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import coreModule from 'lib/core';
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2019-04-09 12:06:49 +00:00
|
|
|
/* global sinon */
|
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
var testModules = [ modelingModule, coreModule ];
|
|
|
|
|
2016-10-28 15:42:42 +00:00
|
|
|
|
|
|
|
describe('features - bpmn-updater', function() {
|
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
describe('connection di', function() {
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
var diagramXML = require('./BpmnUpdater.bpmn');
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: testModules
|
|
|
|
}));
|
2016-10-28 15:42:42 +00:00
|
|
|
|
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
it('should update after deleting intermediate element', inject(
|
|
|
|
function(modeling, elementRegistry) {
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// given
|
|
|
|
// sequence flow with existing sourceElement and targetElement di information
|
|
|
|
var task = elementRegistry.get('Task_1'),
|
|
|
|
sequenceFlowDi = elementRegistry.get('SequenceFlow_1').businessObject.di,
|
|
|
|
startEventDi = elementRegistry.get('StartEvent_1').businessObject.di,
|
|
|
|
endEventDi = elementRegistry.get('EndEvent_1').businessObject.di;
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// when
|
|
|
|
modeling.removeElements([ task ]);
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// then
|
|
|
|
expect(sequenceFlowDi.sourceElement).to.equal(startEventDi);
|
|
|
|
expect(sequenceFlowDi.targetElement).to.equal(endEventDi);
|
|
|
|
}
|
|
|
|
));
|
2016-10-28 15:42:42 +00:00
|
|
|
|
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
it('should update on drop on flow', inject(
|
|
|
|
function(modeling, elementRegistry, elementFactory) {
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// given
|
|
|
|
// sequence flow with existing sourceElement and targetElement di information
|
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_3'),
|
|
|
|
startEventDi = elementRegistry.get('StartEvent_2').businessObject.di;
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
var intermediateThrowEvent = elementFactory.createShape({
|
|
|
|
type: 'bpmn:IntermediateThrowEvent'
|
|
|
|
});
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
var dropPosition = { x: 320, y: 260 };
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// when
|
|
|
|
var event = modeling.createShape(intermediateThrowEvent, dropPosition, sequenceFlow);
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// then
|
|
|
|
expect(sequenceFlow.businessObject.di.sourceElement).to.equal(startEventDi);
|
|
|
|
expect(sequenceFlow.businessObject.di.targetElement).to.equal(event.businessObject.di);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
it('should not create new di refs', inject(
|
|
|
|
function(modeling, elementRegistry, elementFactory) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
// sequence flow without any sourceElement and targetElement di information
|
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_4');
|
|
|
|
|
|
|
|
var intermediateThrowEvent = elementFactory.createShape({
|
|
|
|
type: 'bpmn:IntermediateThrowEvent'
|
|
|
|
});
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
var dropPosition = { x: 320, y: 260 };
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// when
|
|
|
|
modeling.createShape(intermediateThrowEvent, dropPosition, sequenceFlow);
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
// then
|
|
|
|
expect(sequenceFlow.businessObject.di.sourceElement).not.to.exist;
|
|
|
|
expect(sequenceFlow.businessObject.di.targetElement).not.to.exist;
|
|
|
|
}
|
|
|
|
));
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-09 12:06:49 +00:00
|
|
|
describe('connection cropping', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('./BpmnUpdater.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: testModules
|
|
|
|
}));
|
|
|
|
|
|
|
|
afterEach(sinon.restore);
|
|
|
|
|
|
|
|
|
|
|
|
it('should crop connection only once per reconnect', inject(
|
|
|
|
function(modeling, elementRegistry, connectionDocking) {
|
|
|
|
// given
|
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_1'),
|
|
|
|
target = elementRegistry.get('EndEvent_2'),
|
|
|
|
cropSpy = sinon.spy(connectionDocking, 'getCroppedWaypoints');
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.reconnectEnd(sequenceFlow, target, { x: 418, y: 260 });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(cropSpy).to.have.been.calledOnce;
|
|
|
|
expect(cropSpy).to.have.been.calledWith(sequenceFlow);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-05-16 11:12:18 +00:00
|
|
|
describe('incomplete DI', function() {
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 11:12:18 +00:00
|
|
|
var diagramXML = require('./BpmnUpdater.incompleteDi.bpmn');
|
2016-10-28 15:42:42 +00:00
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, {
|
|
|
|
modules: testModules
|
2016-10-28 15:42:42 +00:00
|
|
|
}));
|
|
|
|
|
2018-05-16 06:57:33 +00:00
|
|
|
|
2018-05-16 11:12:18 +00:00
|
|
|
it('should add missing label bpmndi:Bounds', inject(
|
2018-05-16 06:57:33 +00:00
|
|
|
function(modeling, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var event = elementRegistry.get('StartEvent'),
|
|
|
|
label = event.label,
|
|
|
|
di = event.businessObject.di;
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements([ label ], { x: 20, y: 20 });
|
|
|
|
|
|
|
|
var labelBounds = di.label.bounds;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(labelBounds).to.exist;
|
|
|
|
|
|
|
|
expect(labelBounds).to.include.keys(
|
|
|
|
'x', 'y',
|
|
|
|
'width', 'height'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2018-05-16 11:12:18 +00:00
|
|
|
|
|
|
|
it('should add missing bpmndi:BPMNLabel', inject(
|
|
|
|
function(modeling, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var event = elementRegistry.get('StartEvent_2'),
|
|
|
|
label = event.label,
|
|
|
|
di = event.businessObject.di;
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveElements([ label ], { x: 20, y: 20 });
|
|
|
|
|
|
|
|
var diLabel = di.label;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(diLabel).to.exist;
|
|
|
|
|
|
|
|
expect(diLabel.bounds).to.exist;
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
2016-10-28 15:42:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|