From d42d5e34487a113a4dbf85d85042790a91aac150 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Mon, 20 May 2019 14:54:48 +0200 Subject: [PATCH] chore(resize-behavior): move resize behavior to seperate behavior * setting minimum bounds and resize constraints moved to ResizeBehavior Related to #1290 --- .../modeling/behavior/ResizeBehavior.js | 44 +++ lib/features/modeling/behavior/index.js | 3 + .../modeling/behavior/util/ResizeUtil.js | 132 +++++++++ lib/features/snapping/BpmnSnapping.js | 35 +-- lib/features/snapping/BpmnSnappingUtil.js | 168 +----------- .../behavior/ResizeBehavior.lanes.bpmn} | 0 .../behavior/ResizeBehavior.participant.bpmn} | 0 .../behavior/ResizeBehavior.subProcess.bpmn} | 0 .../ResizeBehavior.textAnnotation.bpmn} | 0 .../modeling/behavior/ResizeBehaviorSpec.js | 258 ++++++++++++++++++ .../util/ResizeUtil.lanes-flowNodes.bpmn} | 0 .../behavior/util/ResizeUtil.lanes.bpmn} | 0 .../behavior/util/ResizeUtilSpec.js} | 34 +-- .../features/snapping/BpmnSnappingSpec.js | 206 +------------- 14 files changed, 467 insertions(+), 413 deletions(-) create mode 100644 lib/features/modeling/behavior/ResizeBehavior.js create mode 100644 lib/features/modeling/behavior/util/ResizeUtil.js rename test/spec/features/{snapping/BpmnSnapping.lanes-resize.bpmn => modeling/behavior/ResizeBehavior.lanes.bpmn} (100%) rename test/spec/features/{snapping/BpmnSnapping.participant-resize.bpmn => modeling/behavior/ResizeBehavior.participant.bpmn} (100%) rename test/spec/features/{snapping/BpmnSnapping.subProcess-resize.bpmn => modeling/behavior/ResizeBehavior.subProcess.bpmn} (100%) rename test/spec/features/{snapping/BpmnSnapping.textAnnotation-resize.bpmn => modeling/behavior/ResizeBehavior.textAnnotation.bpmn} (100%) create mode 100644 test/spec/features/modeling/behavior/ResizeBehaviorSpec.js rename test/spec/features/{snapping/BpmnSnappingUtil.lanes-flowNodes.bpmn => modeling/behavior/util/ResizeUtil.lanes-flowNodes.bpmn} (100%) rename test/spec/features/{snapping/BpmnSnappingUtil.lanes.bpmn => modeling/behavior/util/ResizeUtil.lanes.bpmn} (100%) rename test/spec/features/{snapping/BpmnSnappingUtilSpec.js => modeling/behavior/util/ResizeUtilSpec.js} (80%) diff --git a/lib/features/modeling/behavior/ResizeBehavior.js b/lib/features/modeling/behavior/ResizeBehavior.js new file mode 100644 index 00000000..c2fce507 --- /dev/null +++ b/lib/features/modeling/behavior/ResizeBehavior.js @@ -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' ]; \ No newline at end of file diff --git a/lib/features/modeling/behavior/index.js b/lib/features/modeling/behavior/index.js index 99aac369..474ebf51 100644 --- a/lib/features/modeling/behavior/index.js +++ b/lib/features/modeling/behavior/index.js @@ -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 ], diff --git a/lib/features/modeling/behavior/util/ResizeUtil.js b/lib/features/modeling/behavior/util/ResizeUtil.js new file mode 100644 index 00000000..bf0bb2a9 --- /dev/null +++ b/lib/features/modeling/behavior/util/ResizeUtil.js @@ -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 + }; +} \ No newline at end of file diff --git a/lib/features/snapping/BpmnSnapping.js b/lib/features/snapping/BpmnSnapping.js index 921fdb36..37ba1c73 100644 --- a/lib/features/snapping/BpmnSnapping.js +++ b/lib/features/snapping/BpmnSnapping.js @@ -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 diff --git a/lib/features/snapping/BpmnSnappingUtil.js b/lib/features/snapping/BpmnSnappingUtil.js index 48cfc5ef..a88882b1 100644 --- a/lib/features/snapping/BpmnSnappingUtil.js +++ b/lib/features/snapping/BpmnSnappingUtil.js @@ -1,158 +1,12 @@ -import { - getOrientation -} from 'diagram-js/lib/layout/LayoutUtil'; - - -export function getBoundaryAttachment(position, targetBounds) { - - var orientation = getOrientation(position, targetBounds, -15); - - if (orientation !== 'intersect') { - return orientation; - } else { - 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 - }; +import { getOrientation } from 'diagram-js/lib/layout/LayoutUtil'; + +export function getBoundaryAttachment(position, targetBounds) { + + var orientation = getOrientation(position, targetBounds, -15); + + if (orientation !== 'intersect') { + return orientation; + } else { + return null; + } } \ No newline at end of file diff --git a/test/spec/features/snapping/BpmnSnapping.lanes-resize.bpmn b/test/spec/features/modeling/behavior/ResizeBehavior.lanes.bpmn similarity index 100% rename from test/spec/features/snapping/BpmnSnapping.lanes-resize.bpmn rename to test/spec/features/modeling/behavior/ResizeBehavior.lanes.bpmn diff --git a/test/spec/features/snapping/BpmnSnapping.participant-resize.bpmn b/test/spec/features/modeling/behavior/ResizeBehavior.participant.bpmn similarity index 100% rename from test/spec/features/snapping/BpmnSnapping.participant-resize.bpmn rename to test/spec/features/modeling/behavior/ResizeBehavior.participant.bpmn diff --git a/test/spec/features/snapping/BpmnSnapping.subProcess-resize.bpmn b/test/spec/features/modeling/behavior/ResizeBehavior.subProcess.bpmn similarity index 100% rename from test/spec/features/snapping/BpmnSnapping.subProcess-resize.bpmn rename to test/spec/features/modeling/behavior/ResizeBehavior.subProcess.bpmn diff --git a/test/spec/features/snapping/BpmnSnapping.textAnnotation-resize.bpmn b/test/spec/features/modeling/behavior/ResizeBehavior.textAnnotation.bpmn similarity index 100% rename from test/spec/features/snapping/BpmnSnapping.textAnnotation-resize.bpmn rename to test/spec/features/modeling/behavior/ResizeBehavior.textAnnotation.bpmn diff --git a/test/spec/features/modeling/behavior/ResizeBehaviorSpec.js b/test/spec/features/modeling/behavior/ResizeBehaviorSpec.js new file mode 100644 index 00000000..15139dcd --- /dev/null +++ b/test/spec/features/modeling/behavior/ResizeBehaviorSpec.js @@ -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 ', 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 ', 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 ', 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 ', 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 ', 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 ', 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 ', 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 ', 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); + })); + + }); + +}); \ No newline at end of file diff --git a/test/spec/features/snapping/BpmnSnappingUtil.lanes-flowNodes.bpmn b/test/spec/features/modeling/behavior/util/ResizeUtil.lanes-flowNodes.bpmn similarity index 100% rename from test/spec/features/snapping/BpmnSnappingUtil.lanes-flowNodes.bpmn rename to test/spec/features/modeling/behavior/util/ResizeUtil.lanes-flowNodes.bpmn diff --git a/test/spec/features/snapping/BpmnSnappingUtil.lanes.bpmn b/test/spec/features/modeling/behavior/util/ResizeUtil.lanes.bpmn similarity index 100% rename from test/spec/features/snapping/BpmnSnappingUtil.lanes.bpmn rename to test/spec/features/modeling/behavior/util/ResizeUtil.lanes.bpmn diff --git a/test/spec/features/snapping/BpmnSnappingUtilSpec.js b/test/spec/features/modeling/behavior/util/ResizeUtilSpec.js similarity index 80% rename from test/spec/features/snapping/BpmnSnappingUtilSpec.js rename to test/spec/features/modeling/behavior/util/ResizeUtilSpec.js index 822c8076..ac726c65 100644 --- a/test/spec/features/snapping/BpmnSnappingUtilSpec.js +++ b/test/spec/features/modeling/behavior/util/ResizeUtilSpec.js @@ -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({ diff --git a/test/spec/features/snapping/BpmnSnappingSpec.js b/test/spec/features/snapping/BpmnSnappingSpec.js index ebd6297a..86bbd650 100644 --- a/test/spec/features/snapping/BpmnSnappingSpec.js +++ b/test/spec/features/snapping/BpmnSnappingSpec.js @@ -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 ', 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 ', 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 ', 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 ', 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 ', 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 ', 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 ', 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 ', 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'),