2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapModeler,
|
2020-01-20 14:02:44 +00:00
|
|
|
getBpmnJS,
|
2018-04-02 19:01:53 +00:00
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
import {
|
|
|
|
createCanvasEvent as canvasEvent
|
|
|
|
} from '../../../util/MockEvents';
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
import {
|
|
|
|
pick
|
|
|
|
} from 'min-dash';
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
import modelingModule from 'lib/features/modeling';
|
|
|
|
import coreModule from 'lib/core';
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
import { isMac } from 'diagram-js/lib/util/Platform';
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var invertModifier = isMac() ? { metaKey: true } : { ctrlKey: true };
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
describe('features/modeling - create/remove space', function() {
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
describe('create space', function() {
|
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var diagramXML = require('./SpaceTool.basic.bpmn');
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var testModules = [ coreModule, modelingModule ];
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
it('should create space to the right', inject(function(elementRegistry, spaceTool) {
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
// given
|
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_3'),
|
|
|
|
subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
endEvent = elementRegistry.get('EndEvent_1');
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var subProcessPosition_old = getPosition(subProcess),
|
|
|
|
endEventPosition_old = getPosition(endEvent);
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// when
|
2020-01-20 14:02:44 +00:00
|
|
|
makeSpace({ x: 270, y: 80 }, { dx: 50 });
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// then
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(subProcess).to.have.diPosition({
|
|
|
|
x: subProcessPosition_old.x + 50,
|
|
|
|
y: subProcessPosition_old.y
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(endEvent).to.have.diPosition({
|
|
|
|
x: endEventPosition_old.x + 50,
|
|
|
|
y: endEventPosition_old.y
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(sequenceFlow).to.have.diWaypoints([
|
2015-07-15 15:22:19 +00:00
|
|
|
{ x: 144, y: 230 },
|
|
|
|
{ x: 350, y: 230 }
|
2015-04-15 07:43:55 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
it('should create space downwards', inject(function(elementRegistry, modeling, bpmnFactory) {
|
|
|
|
|
2015-04-15 07:43:55 +00:00
|
|
|
// given
|
2020-01-20 14:02:44 +00:00
|
|
|
var startEvent = elementRegistry.get('StartEvent_2'),
|
|
|
|
sequenceFlow = elementRegistry.get('SequenceFlow_3'),
|
|
|
|
subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
endEvent = elementRegistry.get('EndEvent_1');
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var startEventPosition_old = getPosition(startEvent),
|
|
|
|
subProcessPosition_old = getPosition(subProcess),
|
|
|
|
endEventPosition_old = getPosition(endEvent);
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// when
|
2020-01-20 14:02:44 +00:00
|
|
|
makeSpace({ x: 330, y: 50 }, { dy: 50 });
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// then
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(startEvent).to.have.diPosition({
|
|
|
|
x: startEventPosition_old.x,
|
|
|
|
y: startEventPosition_old.y + 50
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(subProcess).to.have.diPosition({
|
|
|
|
x: subProcessPosition_old.x,
|
|
|
|
y: subProcessPosition_old.y + 50
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(endEvent).to.have.diPosition({
|
|
|
|
x: endEventPosition_old.x,
|
|
|
|
y: endEventPosition_old.y + 50
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(sequenceFlow).to.have.diWaypoints([
|
2015-07-15 15:22:19 +00:00
|
|
|
{ x: 144, y: 280 },
|
|
|
|
{ x: 300, y: 280 }
|
2015-04-15 07:43:55 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
it('should remove space to the left', inject(function(elementRegistry, modeling, bpmnFactory) {
|
|
|
|
|
2015-04-15 07:43:55 +00:00
|
|
|
// given
|
2020-01-20 14:02:44 +00:00
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_3'),
|
|
|
|
subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
endEvent = elementRegistry.get('EndEvent_1');
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var subProcessPosition_old = getPosition(subProcess),
|
|
|
|
endEventPosition_old = getPosition(endEvent);
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// when
|
2020-01-20 14:02:44 +00:00
|
|
|
makeSpace({ x: 280, y: 100 }, { dx: -50 });
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// then
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(subProcess).to.have.diPosition({
|
|
|
|
x: subProcessPosition_old.x - 50,
|
|
|
|
y: subProcessPosition_old.y
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(endEvent).to.have.diPosition({
|
|
|
|
x: endEventPosition_old.x - 50,
|
|
|
|
y: endEventPosition_old.y
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(sequenceFlow).to.have.diWaypoints([
|
2015-07-15 15:22:19 +00:00
|
|
|
{ x: 144, y: 230 },
|
|
|
|
{ x: 250, y: 230 }
|
2015-04-15 07:43:55 +00:00
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should resize to the right', inject(function(elementRegistry, modeling) {
|
2015-07-15 15:22:19 +00:00
|
|
|
|
2015-04-15 07:43:55 +00:00
|
|
|
// given
|
2020-01-20 14:02:44 +00:00
|
|
|
var task = elementRegistry.get('Task_1'),
|
|
|
|
subProcess = elementRegistry.get('SubProcess_1'),
|
|
|
|
endEvent = elementRegistry.get('EndEvent_1');
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var subProcessBounds_old = getBounds(subProcess),
|
|
|
|
endEventPosition_old = getPosition(endEvent),
|
|
|
|
taskPosition_old = getPosition(task);
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
// when
|
|
|
|
makeSpace({ x: 450, y: 100 }, { dx: 50 });
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
// then
|
|
|
|
expect(subProcess).to.have.diBounds({
|
|
|
|
x: subProcessBounds_old.x,
|
|
|
|
y: subProcessBounds_old.y,
|
|
|
|
width: subProcessBounds_old.width + 50,
|
|
|
|
height: subProcessBounds_old.height
|
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(endEvent).to.have.diPosition({
|
|
|
|
x: endEventPosition_old.x + 50,
|
|
|
|
y: endEventPosition_old.y
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(task).to.have.diPosition(taskPosition_old);
|
|
|
|
}));
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
it('should create space to the left', inject(function(elementRegistry, modeling) {
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
// given
|
|
|
|
var startEvent = elementRegistry.get('StartEvent_2'),
|
|
|
|
sequenceFlow = elementRegistry.get('SequenceFlow_3'),
|
|
|
|
sequenceFlowLabel = sequenceFlow.label;
|
2015-04-15 07:43:55 +00:00
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
var startEventBounds_old = getBounds(startEvent),
|
|
|
|
sequenceFlowLabelBounds_old = getPosition(sequenceFlowLabel);
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// when
|
2020-01-20 14:02:44 +00:00
|
|
|
makeSpace({ x: 250, y: 100 }, { dx: -50 }, true);
|
2015-04-15 07:43:55 +00:00
|
|
|
|
|
|
|
// then
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(startEvent).to.have.diBounds({
|
|
|
|
x: startEventBounds_old.x - 50,
|
|
|
|
y: startEventBounds_old.y,
|
|
|
|
width: startEventBounds_old.width,
|
|
|
|
height: startEventBounds_old.height
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
|
|
|
|
2020-01-20 14:02:44 +00:00
|
|
|
expect(sequenceFlowLabel).to.have.position({
|
|
|
|
x: sequenceFlowLabelBounds_old.x - 50,
|
|
|
|
y: sequenceFlowLabelBounds_old.y
|
2015-09-02 12:15:45 +00:00
|
|
|
});
|
2015-04-15 07:43:55 +00:00
|
|
|
}));
|
2015-04-17 14:40:45 +00:00
|
|
|
|
2015-04-15 07:43:55 +00:00
|
|
|
});
|
2015-04-17 14:40:45 +00:00
|
|
|
|
2020-01-20 16:55:16 +00:00
|
|
|
|
|
|
|
describe('case 1', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('./SpaceTool.case1.bpmn');
|
|
|
|
|
|
|
|
var testModules = [ coreModule, modelingModule ];
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
|
|
|
|
|
|
|
|
|
|
it('should create space to the left', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var sequenceFlow = elementRegistry.get('SequenceFlow_C'),
|
|
|
|
sequenceFlowLabel = sequenceFlow.label;
|
|
|
|
|
|
|
|
var sequenceFlowLabelBounds_old = getPosition(sequenceFlowLabel);
|
|
|
|
|
|
|
|
// when
|
|
|
|
makeSpace({ x: 200, y: 100 }, { dx: 200 });
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
|
|
|
expect(sequenceFlowLabel).to.have.position({
|
|
|
|
x: sequenceFlowLabelBounds_old.x + 200,
|
|
|
|
y: sequenceFlowLabelBounds_old.y
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-15 07:43:55 +00:00
|
|
|
});
|
2020-01-20 14:02:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// helpers ////////////////
|
|
|
|
|
|
|
|
function makeSpace(start, delta, invert) {
|
|
|
|
|
|
|
|
if (delta.dx && delta.dy) {
|
|
|
|
throw new Error('must define either <dx> or <dy>');
|
|
|
|
}
|
|
|
|
|
|
|
|
var modifier = invert ? invertModifier : {};
|
|
|
|
|
|
|
|
var end = {
|
|
|
|
x: start.x + (delta.dx || 0),
|
|
|
|
y: start.y + (delta.dy || 0)
|
|
|
|
};
|
|
|
|
|
|
|
|
return getBpmnJS().invoke(function(spaceTool, dragging) {
|
|
|
|
spaceTool.activateMakeSpace(canvasEvent(start));
|
|
|
|
|
|
|
|
dragging.move(canvasEvent(end, modifier));
|
|
|
|
|
|
|
|
dragging.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPosition(element) {
|
|
|
|
return pick(element, [ 'x', 'y' ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBounds(element) {
|
|
|
|
return pick(element, [ 'x', 'y', 'width', 'height' ]);
|
|
|
|
}
|