bpmn-js/test/spec/features/modeling/BpmnUpdaterSpec.js

148 lines
3.9 KiB
JavaScript
Raw Normal View History

import {
bootstrapModeler,
inject
} from 'test/TestHelper';
import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
var testModules = [ modelingModule, coreModule ];
describe('features - bpmn-updater', function() {
describe('connection di', function() {
var diagramXML = require('./BpmnUpdater.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: testModules
}));
it('should update after deleting intermediate element', inject(
function(modeling, elementRegistry) {
// 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;
// when
modeling.removeElements([ task ]);
// then
expect(sequenceFlowDi.sourceElement).to.equal(startEventDi);
expect(sequenceFlowDi.targetElement).to.equal(endEventDi);
}
));
it('should update on drop on flow', inject(
function(modeling, elementRegistry, elementFactory) {
// given
// sequence flow with existing sourceElement and targetElement di information
var sequenceFlow = elementRegistry.get('SequenceFlow_3'),
startEventDi = elementRegistry.get('StartEvent_2').businessObject.di;
var intermediateThrowEvent = elementFactory.createShape({
type: 'bpmn:IntermediateThrowEvent'
});
var dropPosition = { x: 320, y: 260 };
// when
var event = modeling.createShape(intermediateThrowEvent, dropPosition, sequenceFlow);
// 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'
});
var dropPosition = { x: 320, y: 260 };
// when
modeling.createShape(intermediateThrowEvent, dropPosition, sequenceFlow);
// then
expect(sequenceFlow.businessObject.di.sourceElement).not.to.exist;
expect(sequenceFlow.businessObject.di.targetElement).not.to.exist;
}
));
});
describe('incomplete DI', function() {
var diagramXML = require('./BpmnUpdater.incompleteDi.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: testModules
}));
it('should add missing label bpmndi:Bounds', inject(
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'
);
}
));
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;
}
));
});
});