2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
|
|
|
|
|
|
|
import autoPlaceModule from 'lib/features/auto-place';
|
2019-09-11 09:29:32 +00:00
|
|
|
import coreModule from 'lib/core';
|
|
|
|
import labelEditingModule from 'lib/features/label-editing';
|
2018-04-02 19:01:53 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import selectionModule from 'diagram-js/lib/features/selection';
|
2019-09-11 09:29:32 +00:00
|
|
|
|
|
|
|
import { getBusinessObject } from '../../../../lib/util/ModelUtil';
|
|
|
|
|
2017-12-08 20:06:08 +00:00
|
|
|
|
|
|
|
describe('features/auto-place', function() {
|
|
|
|
|
|
|
|
describe('element placement', function() {
|
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
var diagramXML = require('./BpmnAutoPlace.bpmn');
|
2017-12-15 09:16:09 +00:00
|
|
|
|
2017-12-08 20:06:08 +00:00
|
|
|
before(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
coreModule,
|
|
|
|
modelingModule,
|
|
|
|
autoPlaceModule,
|
|
|
|
selectionModule
|
|
|
|
]
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
describe('should place bpmn:FlowNode', function() {
|
|
|
|
|
|
|
|
it('at default distance after START_EVENT_1', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'START_EVENT_1',
|
|
|
|
expectedBounds: { x: 1052, y: 224, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('at incoming distance after TASK_0', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'TASK_0',
|
|
|
|
expectedBounds: { x: 262, y: 54, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('at incoming distance / quorum after TASK_5', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'TASK_5',
|
|
|
|
expectedBounds: { x: 296, y: 390, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('at existing outgoing / below TASK_2', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'TASK_1',
|
|
|
|
expectedBounds: { x: 279, y: 293, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('ignoring existing, far away outgoing of TASK_3', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'TASK_3',
|
|
|
|
expectedBounds: { x: 746, y: 127, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('behind bpmn:SubProcess', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'SUBPROCESS_1',
|
|
|
|
expectedBounds: { x: 925, y: 368, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('should place bpmn:DataStoreReference', function() {
|
|
|
|
|
|
|
|
it('bottom right of source', autoPlace({
|
2017-12-15 09:34:11 +00:00
|
|
|
element: 'bpmn:DataStoreReference',
|
|
|
|
behind: 'TASK_2',
|
|
|
|
expectedBounds: { x: 369, y: 303, width: 50, height: 50 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('next to existing', autoPlace({
|
2017-12-08 20:06:08 +00:00
|
|
|
element: 'bpmn:DataStoreReference',
|
|
|
|
behind: 'TASK_3',
|
|
|
|
expectedBounds: { x: 769, y: 247, width: 50, height: 50 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('should place bpmn:TextAnnotation', function() {
|
|
|
|
|
|
|
|
it('top right of source', autoPlace({
|
|
|
|
element: 'bpmn:TextAnnotation',
|
|
|
|
behind: 'TASK_2',
|
2017-12-15 09:34:11 +00:00
|
|
|
expectedBounds: { x: 379, y: 103, width: 100, height: 30 }
|
2017-12-08 20:06:08 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('above existing', autoPlace({
|
|
|
|
element: 'bpmn:TextAnnotation',
|
|
|
|
behind: 'TASK_3',
|
2017-12-15 09:34:11 +00:00
|
|
|
expectedBounds: { x: 696, y: -4, width: 100, height: 30 }
|
2017-12-08 20:06:08 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-09-11 09:29:32 +00:00
|
|
|
describe('integration', function() {
|
2017-12-08 20:06:08 +00:00
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
var diagramXML = require('./BpmnAutoPlace.bpmn');
|
2017-12-15 09:16:09 +00:00
|
|
|
|
2017-12-08 20:06:08 +00:00
|
|
|
before(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
2019-09-11 09:29:32 +00:00
|
|
|
autoPlaceModule,
|
2017-12-08 20:06:08 +00:00
|
|
|
coreModule,
|
2019-09-11 09:29:32 +00:00
|
|
|
labelEditingModule,
|
2017-12-08 20:06:08 +00:00
|
|
|
modelingModule,
|
2019-09-11 09:29:32 +00:00
|
|
|
selectionModule
|
2017-12-08 20:06:08 +00:00
|
|
|
]
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2019-09-11 09:29:32 +00:00
|
|
|
it('should complete direct edit on autoPlace', inject(
|
|
|
|
function(autoPlace, directEditing, elementFactory, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementFactory.createShape({ type: 'bpmn:Task' });
|
|
|
|
|
|
|
|
var source = elementRegistry.get('TASK_2');
|
|
|
|
|
|
|
|
directEditing.activate(source);
|
|
|
|
|
|
|
|
directEditing._textbox.content.textContent = 'foo';
|
|
|
|
|
|
|
|
// when
|
|
|
|
autoPlace.append(source, element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(getBusinessObject(source).name).to.equal('foo');
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
2017-12-08 20:06:08 +00:00
|
|
|
it('should select + direct edit on autoPlace', inject(
|
|
|
|
function(autoPlace, elementRegistry, elementFactory, selection, directEditing) {
|
|
|
|
|
|
|
|
// given
|
2019-09-11 09:29:32 +00:00
|
|
|
var element = elementFactory.createShape({ type: 'bpmn:Task' });
|
2017-12-08 20:06:08 +00:00
|
|
|
|
|
|
|
var source = elementRegistry.get('TASK_2');
|
|
|
|
|
|
|
|
// when
|
2019-09-11 09:29:32 +00:00
|
|
|
var newShape = autoPlace.append(source, element);
|
2017-12-08 20:06:08 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(selection.get()).to.eql([ newShape ]);
|
|
|
|
|
|
|
|
expect(directEditing.isActive()).to.be.true;
|
|
|
|
expect(directEditing._active.element).to.equal(newShape);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-12-15 09:16:09 +00:00
|
|
|
|
|
|
|
describe('multi connection handling', function() {
|
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
var diagramXML = require('./BpmnAutoPlace.multi-connection.bpmn');
|
2017-12-15 09:16:09 +00:00
|
|
|
|
|
|
|
before(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
coreModule,
|
|
|
|
modelingModule,
|
|
|
|
autoPlaceModule,
|
2018-01-24 19:25:28 +00:00
|
|
|
selectionModule,
|
|
|
|
labelEditingModule
|
2017-12-15 09:16:09 +00:00
|
|
|
]
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should ignore multiple source -> target connections', inject(
|
|
|
|
function(autoPlace, elementRegistry, elementFactory, selection, directEditing) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementFactory.createShape({ type: 'bpmn:Task' });
|
|
|
|
|
|
|
|
var source = elementRegistry.get('TASK_1');
|
|
|
|
var alignedElement = elementRegistry.get('TASK_3');
|
|
|
|
|
|
|
|
// when
|
|
|
|
var newShape = autoPlace.append(source, element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(newShape.x).to.eql(alignedElement.x);
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-12-15 13:34:05 +00:00
|
|
|
|
|
|
|
describe('boundary event connection handling', function() {
|
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
var diagramXML = require('./BpmnAutoPlace.boundary-events.bpmn');
|
2017-12-15 13:34:05 +00:00
|
|
|
|
|
|
|
before(bootstrapModeler(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
coreModule,
|
|
|
|
modelingModule,
|
|
|
|
autoPlaceModule,
|
|
|
|
selectionModule
|
|
|
|
]
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should place bottom right of BOUNDARY_BOTTOM', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'BOUNDARY_BOTTOM',
|
|
|
|
expectedBounds: { x: 241, y: 213, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should place bottom right of BOUNDARY_SUBPROCESS_BOTTOM', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'BOUNDARY_SUBPROCESS_BOTTOM',
|
|
|
|
expectedBounds: { x: 278, y: 495, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should place top right of BOUNDARY_TOP', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'BOUNDARY_TOP',
|
|
|
|
expectedBounds: { x: 242, y: -27, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
|
2018-05-03 15:29:23 +00:00
|
|
|
it('should place top right of BOUNDARY_TOP_RIGHT without infinite loop', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'BOUNDARY_TOP_RIGHT',
|
|
|
|
expectedBounds: { x: 473, y: -27, width: 100, height: 80 }
|
|
|
|
}));
|
2017-12-15 13:34:05 +00:00
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
|
2017-12-15 13:34:05 +00:00
|
|
|
it('should place top right of BOUNDARY_SUBPROCESS_TOP', autoPlace({
|
|
|
|
element: 'bpmn:Task',
|
|
|
|
behind: 'BOUNDARY_SUBPROCESS_TOP',
|
|
|
|
expectedBounds: { x: 275, y: 194, width: 100, height: 80 }
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-03-02 13:26:09 +00:00
|
|
|
// helpers //////////
|
2017-12-15 13:34:05 +00:00
|
|
|
|
|
|
|
function autoPlace(cfg) {
|
|
|
|
|
|
|
|
var element = cfg.element,
|
|
|
|
behind = cfg.behind,
|
|
|
|
expectedBounds = cfg.expectedBounds;
|
|
|
|
|
|
|
|
return inject(function(autoPlace, elementRegistry, elementFactory) {
|
|
|
|
|
|
|
|
var sourceEl = elementRegistry.get(behind);
|
|
|
|
|
|
|
|
// assume
|
|
|
|
expect(sourceEl).to.exist;
|
|
|
|
|
|
|
|
if (typeof element === 'string') {
|
|
|
|
element = { type: element };
|
|
|
|
}
|
|
|
|
|
|
|
|
var shape = elementFactory.createShape(element);
|
|
|
|
|
|
|
|
// when
|
|
|
|
var placedShape = autoPlace.append(sourceEl, shape);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(placedShape).to.have.bounds(expectedBounds);
|
|
|
|
});
|
|
|
|
}
|