From cb5098242d7911c50d1d2d6f257abf1a6681d128 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 20 Jan 2020 15:02:44 +0100 Subject: [PATCH] test(space-tool): rewrite and improve specs --- .../features/modeling/SpaceTool.basic.bpmn | 61 ++++ test/spec/features/modeling/SpaceToolSpec.js | 300 ++++++++---------- 2 files changed, 201 insertions(+), 160 deletions(-) create mode 100644 test/spec/features/modeling/SpaceTool.basic.bpmn diff --git a/test/spec/features/modeling/SpaceTool.basic.bpmn b/test/spec/features/modeling/SpaceTool.basic.bpmn new file mode 100644 index 00000000..f9ec5d4e --- /dev/null +++ b/test/spec/features/modeling/SpaceTool.basic.bpmn @@ -0,0 +1,61 @@ + + + + + SequenceFlow_3 + SequenceFlow_2 + + SequenceFlow_1 + + + SequenceFlow_1 + + + + + SequenceFlow_2 + + + + SequenceFlow_3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/spec/features/modeling/SpaceToolSpec.js b/test/spec/features/modeling/SpaceToolSpec.js index afb49911..e6235b32 100644 --- a/test/spec/features/modeling/SpaceToolSpec.js +++ b/test/spec/features/modeling/SpaceToolSpec.js @@ -1,249 +1,229 @@ import { bootstrapModeler, + getBpmnJS, inject } from 'test/TestHelper'; +import { + createCanvasEvent as canvasEvent +} from '../../../util/MockEvents'; + +import { + pick +} from 'min-dash'; + import modelingModule from 'lib/features/modeling'; import coreModule from 'lib/core'; +import { isMac } from 'diagram-js/lib/util/Platform'; + +var invertModifier = isMac() ? { metaKey: true } : { ctrlKey: true }; + describe('features/modeling - create/remove space', function() { - var diagramXML = require('../../../fixtures/bpmn/simple.bpmn'); - - var testModules = [ coreModule, modelingModule ]; - - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); - - describe('create space', function() { + var diagramXML = require('./SpaceTool.basic.bpmn'); - it('should create space to the right', inject(function(elementRegistry, modeling, bpmnFactory) { + var testModules = [ coreModule, modelingModule ]; + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should create space to the right', inject(function(elementRegistry, spaceTool) { // given - var sequenceFlowElement = elementRegistry.get('SequenceFlow_3'), - sequenceFlow = sequenceFlowElement.businessObject; + var sequenceFlow = elementRegistry.get('SequenceFlow_3'), + subProcess = elementRegistry.get('SubProcess_1'), + endEvent = elementRegistry.get('EndEvent_1'); - var subProcessElement = elementRegistry.get('SubProcess_1'), - subProcess = subProcessElement.businessObject; - - var endEventElement = elementRegistry.get('EndEvent_1'), - endEvent = endEventElement.businessObject; - - - var subProcOldPos = { - x: subProcessElement.x, - y: subProcessElement.y - }; - - var endEventOldPos = { - x: endEventElement.x, - y: endEventElement.y - }; - - var delta = { x: 50, y: 0 }, - direction = 'e'; + var subProcessPosition_old = getPosition(subProcess), + endEventPosition_old = getPosition(endEvent); // when - modeling.createSpace([subProcessElement, endEventElement], [], delta, direction); + makeSpace({ x: 270, y: 80 }, { dx: 50 }); // then - expect(subProcess.di).to.have.position({ - x: subProcOldPos.x + 50, - y: subProcOldPos.y + expect(subProcess).to.have.diPosition({ + x: subProcessPosition_old.x + 50, + y: subProcessPosition_old.y }); - expect(endEvent.di).to.have.position({ - x: endEventOldPos.x + 50, - y: endEventOldPos.y + expect(endEvent).to.have.diPosition({ + x: endEventPosition_old.x + 50, + y: endEventPosition_old.y }); - var diWaypoints = bpmnFactory.createDiWaypoints([ + expect(sequenceFlow).to.have.diWaypoints([ { x: 144, y: 230 }, { x: 350, y: 230 } ]); - - expect(sequenceFlow.di.waypoint).eql(diWaypoints); })); it('should create space downwards', inject(function(elementRegistry, modeling, bpmnFactory) { // given - var startEventElement = elementRegistry.get('StartEvent_2'), - startEvent = startEventElement.businessObject; + var startEvent = elementRegistry.get('StartEvent_2'), + sequenceFlow = elementRegistry.get('SequenceFlow_3'), + subProcess = elementRegistry.get('SubProcess_1'), + endEvent = elementRegistry.get('EndEvent_1'); - var sequenceFlowElement = elementRegistry.get('SequenceFlow_3'), - sequenceFlow = sequenceFlowElement.businessObject; - - var subProcessElement = elementRegistry.get('SubProcess_1'), - subProcess = subProcessElement.businessObject; - - var endEventElement = elementRegistry.get('EndEvent_1'), - endEvent = endEventElement.businessObject; - - var startEventOldPos = { - x: startEventElement.x, - y: startEventElement.y - }; - - var subProcOldPos = { - x: subProcessElement.x, - y: subProcessElement.y - }; - - var endEventOldPos = { - x: endEventElement.x, - y: endEventElement.y - }; - - var delta = { x: 0, y: 50 }, - direction = 's'; + var startEventPosition_old = getPosition(startEvent), + subProcessPosition_old = getPosition(subProcess), + endEventPosition_old = getPosition(endEvent); // when - modeling.createSpace([startEventElement ,subProcessElement, endEventElement], [], delta, direction); + makeSpace({ x: 330, y: 50 }, { dy: 50 }); // then - expect(startEvent.di).to.have.position({ - x: startEventOldPos.x, - y: startEventOldPos.y + 50 + expect(startEvent).to.have.diPosition({ + x: startEventPosition_old.x, + y: startEventPosition_old.y + 50 }); - expect(subProcess.di).to.have.position({ - x: subProcOldPos.x, - y: subProcOldPos.y + 50 + expect(subProcess).to.have.diPosition({ + x: subProcessPosition_old.x, + y: subProcessPosition_old.y + 50 }); - expect(endEvent.di).to.have.position({ - x: endEventOldPos.x, - y: endEventOldPos.y + 50 + expect(endEvent).to.have.diPosition({ + x: endEventPosition_old.x, + y: endEventPosition_old.y + 50 }); - var diWaypoints = bpmnFactory.createDiWaypoints([ + expect(sequenceFlow).to.have.diWaypoints([ { x: 144, y: 280 }, { x: 300, y: 280 } ]); - - expect(sequenceFlow.di.waypoint).eql(diWaypoints); })); it('should remove space to the left', inject(function(elementRegistry, modeling, bpmnFactory) { // given - var sequenceFlowElement = elementRegistry.get('SequenceFlow_3'), - sequenceFlow = sequenceFlowElement.businessObject; + var sequenceFlow = elementRegistry.get('SequenceFlow_3'), + subProcess = elementRegistry.get('SubProcess_1'), + endEvent = elementRegistry.get('EndEvent_1'); - var subProcessElement = elementRegistry.get('SubProcess_1'), - subProcess = subProcessElement.businessObject; - - var endEventElement = elementRegistry.get('EndEvent_1'), - endEvent = endEventElement.businessObject; - - var subProcOldPos = { - x: subProcessElement.x, - y: subProcessElement.y - }; - - var endEventOldPos = { - x: endEventElement.x, - y: endEventElement.y - }; - - var delta = { x: -50, y: 0 }, - direction = 'w'; + var subProcessPosition_old = getPosition(subProcess), + endEventPosition_old = getPosition(endEvent); // when - modeling.createSpace([subProcessElement, endEventElement], [], delta, direction); + makeSpace({ x: 280, y: 100 }, { dx: -50 }); // then - expect(subProcess.di).to.have.position({ - x: subProcOldPos.x - 50, - y: subProcOldPos.y + expect(subProcess).to.have.diPosition({ + x: subProcessPosition_old.x - 50, + y: subProcessPosition_old.y }); - expect(endEvent.di).to.have.position({ - x: endEventOldPos.x - 50, - y: endEventOldPos.y + expect(endEvent).to.have.diPosition({ + x: endEventPosition_old.x - 50, + y: endEventPosition_old.y }); - var diWaypoints = bpmnFactory.createDiWaypoints([ + expect(sequenceFlow).to.have.diWaypoints([ { x: 144, y: 230 }, { x: 250, y: 230 } ]); - - expect(sequenceFlow.di.waypoint).eql(diWaypoints); })); it('should resize to the right', inject(function(elementRegistry, modeling) { // given - var taskElement = elementRegistry.get('Task_1'), - task = taskElement.businessObject; + var task = elementRegistry.get('Task_1'), + subProcess = elementRegistry.get('SubProcess_1'), + endEvent = elementRegistry.get('EndEvent_1'); - var subProcessElement = elementRegistry.get('SubProcess_1'), - subProcess = subProcessElement.businessObject; - - var startEventElement = elementRegistry.get('StartEvent_1'), - startEvent = startEventElement.businessObject; - - var startEventElement2 = elementRegistry.get('StartEvent_2'), - startEvent2 = startEventElement2.businessObject; - - var subProcOldPos = { - x: subProcessElement.x, - y: subProcessElement.y, - width: subProcessElement.width, - height: subProcessElement.height - }; - - var startEventOldPos2 = { - x: startEventElement2.x, - y: startEventElement2.y - }; - - var startEventOldPos = { - x: startEventElement.x, - y: startEventElement.y - }; - - var taskOldPos = { - x: taskElement.x, - y: taskElement.y - }; - - var delta = { x: 50, y: 0 }, - direction = 'w'; + var subProcessBounds_old = getBounds(subProcess), + endEventPosition_old = getPosition(endEvent), + taskPosition_old = getPosition(task); // when - modeling.createSpace([startEventElement, startEventElement2, taskElement], [subProcessElement], delta, direction); + makeSpace({ x: 450, y: 100 }, { dx: 50 }); // then - expect(subProcess.di).to.have.bounds({ - x: subProcOldPos.x + 50, - y: subProcOldPos.y, - width: subProcOldPos.width - 50, - height: subProcOldPos.height + expect(subProcess).to.have.diBounds({ + x: subProcessBounds_old.x, + y: subProcessBounds_old.y, + width: subProcessBounds_old.width + 50, + height: subProcessBounds_old.height }); - expect(startEvent.di).to.have.position({ - x: startEventOldPos.x + 50, - y: startEventOldPos.y + expect(endEvent).to.have.diPosition({ + x: endEventPosition_old.x + 50, + y: endEventPosition_old.y }); - expect(startEvent2.di).to.have.position({ - x: startEventOldPos2.x + 50, - y: startEventOldPos2.y + expect(task).to.have.diPosition(taskPosition_old); + })); + + + it('should create space to the left', inject(function(elementRegistry, modeling) { + + // given + var startEvent = elementRegistry.get('StartEvent_2'), + sequenceFlow = elementRegistry.get('SequenceFlow_3'), + sequenceFlowLabel = sequenceFlow.label; + + var startEventBounds_old = getBounds(startEvent), + sequenceFlowLabelBounds_old = getPosition(sequenceFlowLabel); + + // when + makeSpace({ x: 250, y: 100 }, { dx: -50 }, true); + + // then + expect(startEvent).to.have.diBounds({ + x: startEventBounds_old.x - 50, + y: startEventBounds_old.y, + width: startEventBounds_old.width, + height: startEventBounds_old.height }); - expect(task.di).to.have.position({ - x: taskOldPos.x + 50, - y: taskOldPos.y + expect(sequenceFlowLabel).to.have.position({ + x: sequenceFlowLabelBounds_old.x - 50, + y: sequenceFlowLabelBounds_old.y }); })); }); }); + + + +// helpers //////////////// + +function makeSpace(start, delta, invert) { + + if (delta.dx && delta.dy) { + throw new Error('must define either or '); + } + + 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' ]); +} \ No newline at end of file