chore(resize-behavior): move resize behavior to seperate behavior

* setting minimum bounds and resize constraints moved to ResizeBehavior

Related to #1290
This commit is contained in:
Philipp Fromme 2019-05-20 14:54:48 +02:00 committed by Nico Rehwaldt
parent 5e199694a1
commit d42d5e3448
14 changed files with 467 additions and 413 deletions

View File

@ -0,0 +1,44 @@
import { is } from '../../../util/ModelUtil';
import { isExpanded } from '../../../util/DiUtil';
import { getParticipantResizeConstraints } from './util/ResizeUtil';
var HIGH_PRIORITY = 1500;
var PARTICIPANT_MIN_DIMENSIONS = { width: 300, height: 150 },
SUB_PROCESS_MIN_DIMENSIONS = { width: 140, height: 120 },
TEXT_ANNOTATION_MIN_DIMENSIONS = { width: 50, height: 30 };
/**
* Set minimum bounds/resize constraints on resize.
*
* @param {EventBus} eventBus
*/
export default function ResizeBehavior(eventBus) {
eventBus.on('resize.start', HIGH_PRIORITY, function(event) {
var context = event.context,
shape = context.shape,
direction = context.direction,
balanced = context.balanced;
if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
context.resizeConstraints = getParticipantResizeConstraints(shape, direction, balanced);
}
if (is(shape, 'bpmn:Participant')) {
context.minDimensions = PARTICIPANT_MIN_DIMENSIONS;
}
if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
context.minDimensions = SUB_PROCESS_MIN_DIMENSIONS;
}
if (is(shape, 'bpmn:TextAnnotation')) {
context.minDimensions = TEXT_ANNOTATION_MIN_DIMENSIONS;
}
});
}
ResizeBehavior.$inject = [ 'eventBus' ];

View File

@ -20,6 +20,7 @@ import ModelingFeedback from './ModelingFeedback';
import ReplaceConnectionBehavior from './ReplaceConnectionBehavior';
import RemoveParticipantBehavior from './RemoveParticipantBehavior';
import ReplaceElementBehaviour from './ReplaceElementBehaviour';
import ResizeBehavior from './ResizeBehavior';
import ResizeLaneBehavior from './ResizeLaneBehavior';
import RemoveElementBehavior from './RemoveElementBehavior';
import SubProcessStartEventBehavior from './SubProcessStartEventBehavior';
@ -53,6 +54,7 @@ export default {
'removeParticipantBehavior',
'replaceConnectionBehavior',
'replaceElementBehaviour',
'resizeBehavior',
'resizeLaneBehavior',
'toggleElementCollapseBehaviour',
'subProcessStartEventBehavior',
@ -82,6 +84,7 @@ export default {
replaceConnectionBehavior: [ 'type', ReplaceConnectionBehavior ],
removeParticipantBehavior: [ 'type', RemoveParticipantBehavior ],
replaceElementBehaviour: [ 'type', ReplaceElementBehaviour ],
resizeBehavior: [ 'type', ResizeBehavior ],
resizeLaneBehavior: [ 'type', ResizeLaneBehavior ],
removeElementBehavior: [ 'type', RemoveElementBehavior ],
toggleElementCollapseBehaviour : [ 'type', ToggleElementCollapseBehaviour ],

View File

@ -0,0 +1,132 @@
import { is } from '../../../../util/ModelUtil';
import {
asTRBL
} from 'diagram-js/lib/layout/LayoutUtil';
import {
collectLanes,
getLanesRoot
} from '../../../modeling/util/LaneUtil';
var abs = Math.abs,
min = Math.min,
max = Math.max;
function addToTrbl(trbl, attr, value, choice) {
var current = trbl[attr];
// make sure to set the value if it does not exist
// or apply the correct value by comparing against
// choice(value, currentValue)
trbl[attr] = current === undefined ? value : choice(value, current);
}
function addMin(trbl, attr, value) {
return addToTrbl(trbl, attr, value, min);
}
function addMax(trbl, attr, value) {
return addToTrbl(trbl, attr, value, max);
}
var LANE_MIN_HEIGHT = 60,
LANE_MIN_WIDTH = 300,
LANE_RIGHT_PADDING = 20,
LANE_LEFT_PADDING = 50,
LANE_TOP_PADDING = 20,
LANE_BOTTOM_PADDING = 20;
export function getParticipantResizeConstraints(laneShape, resizeDirection, balanced) {
var lanesRoot = getLanesRoot(laneShape);
var isFirst = true,
isLast = true;
// max top/bottom size for lanes
var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
var laneTrbl = asTRBL(laneShape);
var maxTrbl = {},
minTrbl = {};
if (/e/.test(resizeDirection)) {
minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH;
} else
if (/w/.test(resizeDirection)) {
minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH;
}
allLanes.forEach(function(other) {
var otherTrbl = asTRBL(other);
if (/n/.test(resizeDirection)) {
if (otherTrbl.top < (laneTrbl.top - 10)) {
isFirst = false;
}
// max top size (based on next element)
if (balanced && abs(laneTrbl.top - otherTrbl.bottom) < 10) {
addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT);
}
// min top size (based on self or nested element)
if (abs(laneTrbl.top - otherTrbl.top) < 5) {
addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT);
}
}
if (/s/.test(resizeDirection)) {
if (otherTrbl.bottom > (laneTrbl.bottom + 10)) {
isLast = false;
}
// max bottom size (based on previous element)
if (balanced && abs(laneTrbl.bottom - otherTrbl.top) < 10) {
addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT);
}
// min bottom size (based on self or nested element)
if (abs(laneTrbl.bottom - otherTrbl.bottom) < 5) {
addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT);
}
}
});
// max top/bottom/left/right size based on flow nodes
var flowElements = lanesRoot.children.filter(function(s) {
return !s.hidden && !s.waypoints && (is(s, 'bpmn:FlowElement') || is(s, 'bpmn:Artifact'));
});
flowElements.forEach(function(flowElement) {
var flowElementTrbl = asTRBL(flowElement);
if (isFirst && /n/.test(resizeDirection)) {
addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING);
}
if (/e/.test(resizeDirection)) {
addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING);
}
if (isLast && /s/.test(resizeDirection)) {
addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING);
}
if (/w/.test(resizeDirection)) {
addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING);
}
});
return {
min: minTrbl,
max: maxTrbl
};
}

View File

@ -11,8 +11,6 @@ import { is } from '../../util/ModelUtil';
import { isAny } from '../modeling/util/ModelingUtil';
import { isExpanded } from '../../util/DiUtil';
import {
bottomRight,
isSnapped,
@ -23,10 +21,7 @@ import {
import { asTRBL } from 'diagram-js/lib/layout/LayoutUtil';
import {
getBoundaryAttachment,
getParticipantSizeConstraints
} from './BpmnSnappingUtil';
import { getBoundaryAttachment } from './BpmnSnappingUtil';
import { getLanesRoot } from '../modeling/util/LaneUtil';
@ -150,33 +145,6 @@ export default function BpmnSnapping(bpmnRules, elementRegistry, eventBus, injec
}
});
eventBus.on('resize.start', HIGH_PRIORITY, function(event) {
var context = event.context,
shape = context.shape;
if (is(shape, 'bpmn:SubProcess') && isExpanded(shape)) {
context.minDimensions = { width: 140, height: 120 };
}
if (is(shape, 'bpmn:Participant')) {
context.minDimensions = { width: 300, height: 150 };
}
if (is(shape, 'bpmn:Lane') || is(shape, 'bpmn:Participant')) {
context.resizeConstraints = getParticipantSizeConstraints(
shape,
context.direction,
context.balanced
);
}
if (is(shape, 'bpmn:TextAnnotation')) {
context.minDimensions = { width: 50, height: 30 };
}
});
}
inherits(BpmnSnapping, Snapping);
@ -261,7 +229,6 @@ BpmnSnapping.prototype.initSnap = function(event) {
}
};
BpmnSnapping.prototype.addTargetSnaps = function(snapPoints, shape, target) {
// snap shape to itself

View File

@ -1,7 +1,4 @@
import {
getOrientation
} from 'diagram-js/lib/layout/LayoutUtil';
import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil';
export function getBoundaryAttachment(position, targetBounds) {
@ -13,146 +10,3 @@ export function getBoundaryAttachment(position, targetBounds) {
return null;
}
}
// participant snapping box implementation //////////////////////
import { is } from '../../util/ModelUtil';
import {
asTRBL
} from 'diagram-js/lib/layout/LayoutUtil';
import {
collectLanes,
getLanesRoot
} from '../modeling/util/LaneUtil';
var abs = Math.abs,
min = Math.min,
max = Math.max;
function addToTrbl(trbl, attr, value, choice) {
var current = trbl[attr];
// make sure to set the value if it does not exist
// or apply the correct value by comparing against
// choice(value, currentValue)
trbl[attr] = current === undefined ? value : choice(value, current);
}
function addMin(trbl, attr, value) {
return addToTrbl(trbl, attr, value, min);
}
function addMax(trbl, attr, value) {
return addToTrbl(trbl, attr, value, max);
}
var LANE_MIN_HEIGHT = 60,
LANE_MIN_WIDTH = 300,
LANE_RIGHT_PADDING = 20,
LANE_LEFT_PADDING = 50,
LANE_TOP_PADDING = 20,
LANE_BOTTOM_PADDING = 20;
export function getParticipantSizeConstraints(laneShape, resizeDirection, balanced) {
var lanesRoot = getLanesRoot(laneShape);
var isFirst = true,
isLast = true;
// max top/bottom size for lanes
var allLanes = collectLanes(lanesRoot, [ lanesRoot ]);
var laneTrbl = asTRBL(laneShape);
var maxTrbl = {},
minTrbl = {};
if (/e/.test(resizeDirection)) {
minTrbl.right = laneTrbl.left + LANE_MIN_WIDTH;
} else
if (/w/.test(resizeDirection)) {
minTrbl.left = laneTrbl.right - LANE_MIN_WIDTH;
}
allLanes.forEach(function(other) {
var otherTrbl = asTRBL(other);
if (/n/.test(resizeDirection)) {
if (otherTrbl.top < (laneTrbl.top - 10)) {
isFirst = false;
}
// max top size (based on next element)
if (balanced && abs(laneTrbl.top - otherTrbl.bottom) < 10) {
addMax(maxTrbl, 'top', otherTrbl.top + LANE_MIN_HEIGHT);
}
// min top size (based on self or nested element)
if (abs(laneTrbl.top - otherTrbl.top) < 5) {
addMin(minTrbl, 'top', otherTrbl.bottom - LANE_MIN_HEIGHT);
}
}
if (/s/.test(resizeDirection)) {
if (otherTrbl.bottom > (laneTrbl.bottom + 10)) {
isLast = false;
}
// max bottom size (based on previous element)
if (balanced && abs(laneTrbl.bottom - otherTrbl.top) < 10) {
addMin(maxTrbl, 'bottom', otherTrbl.bottom - LANE_MIN_HEIGHT);
}
// min bottom size (based on self or nested element)
if (abs(laneTrbl.bottom - otherTrbl.bottom) < 5) {
addMax(minTrbl, 'bottom', otherTrbl.top + LANE_MIN_HEIGHT);
}
}
});
// max top/bottom/left/right size based on flow nodes
var flowElements = lanesRoot.children.filter(function(s) {
return !s.hidden && !s.waypoints && (is(s, 'bpmn:FlowElement') || is(s, 'bpmn:Artifact'));
});
flowElements.forEach(function(flowElement) {
var flowElementTrbl = asTRBL(flowElement);
if (isFirst && /n/.test(resizeDirection)) {
addMin(minTrbl, 'top', flowElementTrbl.top - LANE_TOP_PADDING);
}
if (/e/.test(resizeDirection)) {
addMax(minTrbl, 'right', flowElementTrbl.right + LANE_RIGHT_PADDING);
}
if (isLast && /s/.test(resizeDirection)) {
addMax(minTrbl, 'bottom', flowElementTrbl.bottom + LANE_BOTTOM_PADDING);
}
if (/w/.test(resizeDirection)) {
addMin(minTrbl, 'left', flowElementTrbl.left - LANE_LEFT_PADDING);
}
});
return {
min: minTrbl,
max: maxTrbl
};
}

View File

@ -0,0 +1,258 @@
import {
bootstrapModeler,
inject
} from 'test/TestHelper';
import coreModule from 'lib/core';
import modelingModule from 'lib/features/modeling';
import resizeModule from 'diagram-js/lib/features/resize';
import rulesModule from 'lib/features/rules';
import snappingModule from 'lib/features/snapping';
import {
createCanvasEvent as canvasEvent
} from '../../../../util/MockEvents';
var testModules = [
coreModule,
modelingModule,
resizeModule,
rulesModule,
snappingModule
];
describe('features/modeling - resize behavior', function() {
describe('participant', function() {
describe('minimum dimensions', function() {
var diagramXML = require('./ResizeBehavior.participant.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should snap to children from <se>', inject(function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant_2');
// when
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
// then
expect(participant.width).to.equal(482);
expect(participant.height).to.equal(252);
}));
it('should snap to children from <nw>', inject(function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant_2');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
// then
expect(participant.width).to.equal(467);
expect(participant.height).to.equal(287);
}));
it('should snap to min dimensions from <se>', inject(
function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant_1');
// when
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
// then
expect(participant.width).to.equal(300);
expect(participant.height).to.equal(60);
})
);
it('should snap to min dimensions from <nw>', inject(
function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant_1');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
// then
expect(participant.width).to.equal(300);
expect(participant.height).to.equal(60);
})
);
it('should snap to min dimensions + children from <se>', inject(
function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant_3');
// when
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
// then
expect(participant.width).to.equal(305);
expect(participant.height).to.equal(143);
})
);
it('should snap to min dimensions + children from <nw>', inject(
function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant_3');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
// then
expect(participant.width).to.equal(353);
expect(participant.height).to.equal(177);
})
);
});
describe('resize constraints', function() {
var diagramXML = require('./ResizeBehavior.lanes.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should snap to child lanes from <nw>', inject(
function(dragging, elementRegistry, resize) {
// given
var participant = elementRegistry.get('Participant');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
// then
expect(participant.width).to.equal(563);
expect(participant.height).to.equal(223);
})
);
it('should snap to nested child lanes from <se>', inject(
function(dragging, elementRegistry, resize) {
// given
var lane = elementRegistry.get('Lane_B_0');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), lane, 'se');
dragging.move(canvasEvent({ x: -500, y: -500 }));
dragging.end();
// then
expect(lane.width).to.equal(313);
expect(lane.height).to.equal(122);
})
);
});
});
describe('sub process', function() {
var diagramXML = require('./ResizeBehavior.subProcess.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should set minimum dimensions', inject(function(dragging, elementRegistry, resize) {
// given
var subProcess = elementRegistry.get('SubProcess');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), subProcess, 'se');
dragging.move(canvasEvent({ x: -400, y: -400 }));
dragging.end();
// then
expect(subProcess.width).to.equal(140);
expect(subProcess.height).to.equal(120);
}));
});
describe('text annotation', function() {
var diagramXML = require('./ResizeBehavior.textAnnotation.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should set minimum dimensions', inject(function(dragging, elementRegistry, resize) {
// given
var textAnnotation = elementRegistry.get('TextAnnotation');
// when
resize.activate(canvasEvent({ x: 0, y: 0 }), textAnnotation, 'se');
dragging.move(canvasEvent({ x: -400, y: -400 }));
dragging.end();
// then
expect(textAnnotation.width).to.equal(50);
expect(textAnnotation.height).to.equal(30);
}));
});
});

View File

@ -3,7 +3,7 @@ import {
inject
} from 'test/TestHelper';
var getParticipantSizeConstraints = require('lib/features/snapping/BpmnSnappingUtil').getParticipantSizeConstraints;
import { getParticipantResizeConstraints } from 'lib/features/modeling/behavior/util/ResizeUtil';
import coreModule from 'lib/core';
@ -14,13 +14,13 @@ var LANE_MIN_HEIGHT = 60,
LANE_BOTTOM_PADDING = 20;
describe('features/snapping - BpmnSnappingUtil', function() {
describe('modeling/behavior/util - Resize', function() {
describe('#getParticipantSizeConstraints', function() {
describe('#getParticipantResizeConstraints', function() {
describe('lanes', function() {
var diagramXML = require('./BpmnSnappingUtil.lanes.bpmn');
var diagramXML = require('./ResizeUtil.lanes.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: [ coreModule ] }));
@ -32,7 +32,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherLaneShape = elementRegistry.get('Lane_B');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 's');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 's');
// then
expect(sizeConstraints).to.eql({
@ -52,7 +52,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherLaneShape = elementRegistry.get('Lane_B');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 's');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 's');
// then
expect(sizeConstraints).to.eql({
@ -72,7 +72,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherLaneShape = elementRegistry.get('Nested_Lane_A');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'n');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'n');
// then
expect(sizeConstraints).to.eql({
@ -92,7 +92,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherLaneShape = elementRegistry.get('Nested_Lane_A');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'n');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'n');
// then
expect(sizeConstraints).to.eql({
@ -112,7 +112,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
aboveLaneShape = elementRegistry.get('Nested_Lane_A');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'n', true);
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'n', true);
// then
expect(sizeConstraints).to.eql({
@ -134,7 +134,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherLaneShape = elementRegistry.get('Lane_B');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 's', true);
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 's', true);
// then
expect(sizeConstraints).to.eql({
@ -153,7 +153,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
describe('flowNodes', function() {
var diagramXML = require('./BpmnSnappingUtil.lanes-flowNodes.bpmn');
var diagramXML = require('./ResizeUtil.lanes-flowNodes.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: [ coreModule ] }));
@ -165,7 +165,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
taskShape = elementRegistry.get('Task');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 's');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 's');
// then
expect(sizeConstraints).to.eql({
@ -185,7 +185,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
taskShape = elementRegistry.get('Task');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 's');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 's');
// then
expect(sizeConstraints).to.eql({
@ -205,7 +205,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
taskShape = elementRegistry.get('Task_Boundary');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'n');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'n');
// then
expect(sizeConstraints).to.eql({
@ -225,7 +225,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
taskShape = elementRegistry.get('Task_Boundary');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'n');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'n');
// then
expect(sizeConstraints).to.eql({
@ -245,7 +245,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherShape = elementRegistry.get('Boundary_label');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'w');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'w');
// then
expect(sizeConstraints).to.eql({
@ -265,7 +265,7 @@ describe('features/snapping - BpmnSnappingUtil', function() {
otherShape = elementRegistry.get('Task');
// when
var sizeConstraints = getParticipantSizeConstraints(resizeShape, 'e');
var sizeConstraints = getParticipantResizeConstraints(resizeShape, 'e');
// then
expect(sizeConstraints).to.eql({

View File

@ -13,7 +13,6 @@ import coreModule from 'lib/core';
import snappingModule from 'lib/features/snapping';
import modelingModule from 'lib/features/modeling';
import createModule from 'diagram-js/lib/features/create';
import resizeModule from 'diagram-js/lib/features/resize';
import moveModule from 'diagram-js/lib/features/move';
import rulesModule from 'lib/features/rules';
import connectModule from 'diagram-js/lib/features/connect';
@ -449,216 +448,13 @@ describe('features/snapping - BpmnSnapping', function() {
});
describe('on Participant resize', function() {
describe('snap min bounds', function() {
var diagramXML = require('./BpmnSnapping.participant-resize.bpmn');
var testResizeModules = [
coreModule,
resizeModule,
modelingModule,
rulesModule,
snappingModule
];
beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));
it('should snap to children from <se>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_2');
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
expect(participant.width).to.equal(482);
expect(participant.height).to.equal(252);
}));
it('should snap to children from <nw>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_2');
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
expect(participant.width).to.equal(467);
expect(participant.height).to.equal(287);
}));
it('should snap to min dimensions from <se>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_1');
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
expect(participant.width).to.equal(300);
expect(participant.height).to.equal(60);
}));
it('should snap to min dimensions from <nw>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_1');
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
expect(participant.width).to.equal(300);
expect(participant.height).to.equal(60);
}));
it('should snap to min dimensions + children from <se>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_3');
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
dragging.move(canvasEvent({ x: 0, y: 0 }));
dragging.end();
expect(participant.width).to.equal(305);
// snap to children rather than min dimensions
expect(participant.height).to.equal(143);
}));
it('should snap to min dimensions + children from <nw>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant_3');
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
expect(participant.width).to.equal(353);
expect(participant.height).to.equal(177);
}));
});
describe('snap child lanes', function() {
var diagramXML = require('./BpmnSnapping.lanes-resize.bpmn');
var testResizeModules = [
coreModule,
resizeModule,
modelingModule,
rulesModule,
snappingModule
];
beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));
it('should snap to child lanes from <nw>', inject(function(elementRegistry, resize, dragging) {
var participant = elementRegistry.get('Participant');
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
dragging.move(canvasEvent({ x: 500, y: 500 }));
dragging.end();
expect(participant.width).to.equal(563);
expect(participant.height).to.equal(223);
}));
it('should snap to nested child lanes from <se>', inject(function(elementRegistry, resize, dragging) {
var lane = elementRegistry.get('Lane_B_0');
resize.activate(canvasEvent({ x: 0, y: 0 }), lane, 'se');
dragging.move(canvasEvent({ x: -500, y: -500 }));
dragging.end();
expect(lane.width).to.equal(313);
expect(lane.height).to.equal(122);
}));
});
});
describe('on SubProcess resize', function() {
var diagramXML = require('./BpmnSnapping.subProcess-resize.bpmn');
var testResizeModules = [
coreModule,
modelingModule,
resizeModule,
rulesModule,
snappingModule
];
beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));
it('should snap to minimum bounds', inject(function(elementRegistry, resize, dragging) {
var subProcess = elementRegistry.get('SubProcess');
resize.activate(canvasEvent({ x: 0, y: 0 }), subProcess, 'se');
dragging.move(canvasEvent({ x: -400, y: -400 }));
dragging.end();
expect(subProcess.width).to.equal(140);
expect(subProcess.height).to.equal(120);
}));
});
describe('on TextAnnotation resize', function() {
var diagramXML = require('./BpmnSnapping.textAnnotation-resize.bpmn');
var testResizeModules = [
coreModule,
modelingModule,
resizeModule,
rulesModule,
snappingModule
];
beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));
it('should snap to minimum bounds', inject(function(elementRegistry, resize, dragging) {
var textAnnotation = elementRegistry.get('TextAnnotation');
resize.activate(canvasEvent({ x: 0, y: 0 }), textAnnotation, 'se');
dragging.move(canvasEvent({ x: -400, y: -400 }));
dragging.end();
expect(textAnnotation.width).to.equal(50);
expect(textAnnotation.height).to.equal(30);
}));
});
describe('labels', function() {
var diagramXML = require('./BpmnSnapping.labels.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should snap to start events', inject(function(canvas, elementRegistry, move, dragging) {
var label = elementRegistry.get('StartEvent_1_label'),