From b9d237e300c87b2a61ad02d00d3fdff8c006f1ec Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Fri, 20 Mar 2020 13:21:13 +0100 Subject: [PATCH] test(modeling): verify re-layout of message flows when lane added Related to #1289 Related to https://github.com/camunda/camunda-modeler/issues/655 --- .../features/modeling/lanes/AddLaneSpec.js | 102 +++++++++++++++--- .../modeling/lanes/lanes-flow-nodes.bpmn | 81 +++++++++----- 2 files changed, 138 insertions(+), 45 deletions(-) diff --git a/test/spec/features/modeling/lanes/AddLaneSpec.js b/test/spec/features/modeling/lanes/AddLaneSpec.js index e5397e51..6c98dfe6 100644 --- a/test/spec/features/modeling/lanes/AddLaneSpec.js +++ b/test/spec/features/modeling/lanes/AddLaneSpec.js @@ -5,6 +5,7 @@ import { } from 'test/TestHelper'; import { + map, pick } from 'min-dash'; @@ -329,19 +330,32 @@ describe('features/modeling - add Lane', function() { }); } + function addLaneBelow(laneId) { + + return getBpmnJS().invoke(function(elementRegistry, modeling) { + var existingLane = elementRegistry.get(laneId); + + expect(existingLane).to.exist; + + return modeling.addLane(existingLane, 'bottom'); + }); + } + it('should move flow nodes', inject(function(elementRegistry, modeling) { // given var task_Boundary = elementRegistry.get('Task_Boundary'), - boundary = elementRegistry.get('Boundary'); + taskPosition = getPosition(task_Boundary), + boundary = elementRegistry.get('Boundary'), + boundaryPosition = getPosition(boundary); // when addLaneAbove('Nested_Lane_B'); // then - expect(task_Boundary).to.have.position({ x: 344, y: -7 }); - expect(boundary).to.have.position({ x: 391, y: 55 }); + expect(task_Boundary).to.have.position({ x: taskPosition.x, y: taskPosition.y - 120 }); + expect(boundary).to.have.position({ x: boundaryPosition.x, y: boundaryPosition.y - 120 }); })); @@ -349,22 +363,54 @@ describe('features/modeling - add Lane', function() { // given var sequenceFlow = elementRegistry.get('SequenceFlow'), - sequenceFlow_From_Boundary = elementRegistry.get('SequenceFlow_From_Boundary'); + sequenceFlowWaypoints = sequenceFlow.waypoints, + sequenceFlow_From_Boundary = elementRegistry.get('SequenceFlow_From_Boundary'), + sequenceFlow_From_BoundaryWaypoints = sequenceFlow_From_Boundary.waypoints; // when addLaneAbove('Nested_Lane_B'); // then - expect(sequenceFlow_From_Boundary).to.have.waypoints([ - { x: 409, y: 91 }, - { x: 409, y: 118 }, - { x: 562, y: 118 }, - { x: 562, y: 73 } - ]); + expect(sequenceFlow_From_Boundary).to.have.waypoints( + moveWaypoints(sequenceFlow_From_BoundaryWaypoints, 0, -120) + ); - expect(sequenceFlow).to.have.waypoints([ - { x: 444, y: 33 }, - { x: 512, y: 33 } + expect(sequenceFlow).to.have.waypoints( + moveWaypoints(sequenceFlowWaypoints, 0, -120) + ); + })); + + + it('should move message flows when lane added above', inject(function(elementRegistry) { + + // given + var messageFlow = elementRegistry.get('MessageFlowAbove'), + messageFlowWaypoints = messageFlow.waypoints; + + // when + addLaneAbove('Nested_Lane_B'); + + // then + expect(messageFlow).to.have.waypoints([ + movePosition(messageFlowWaypoints[0], 0, -120), + messageFlowWaypoints[1] + ]); + })); + + + it('should move message flows when lane added below', inject(function(elementRegistry) { + + // given + var messageFlow = elementRegistry.get('MessageFlowBelow'), + messageFlowWaypoints = messageFlow.waypoints; + + // when + addLaneBelow('Nested_Lane_B'); + + // then + expect(messageFlow).to.have.waypoints([ + messageFlowWaypoints[0], + movePosition(messageFlowWaypoints[1], 0, 120) ]); })); @@ -373,7 +419,8 @@ describe('features/modeling - add Lane', function() { // given var event = elementRegistry.get('Event'), - label = event.label; + label = event.label, + labelPosition = getPosition(label); // TODO(nikku): consolidate import + editing behavior => not consistent right now @@ -384,7 +431,10 @@ describe('features/modeling - add Lane', function() { addLaneAbove('Nested_Lane_B'); // then - expect(label.y).to.eql(58); + expect(label).to.have.position({ + x: labelPosition.x, + y: labelPosition.y - 120 + }); })); }); @@ -447,4 +497,24 @@ function padEvent(entry) { clientY: 100 }; }); -} \ No newline at end of file +} + +function getPosition(element) { + return { + x: element.x, + y: element.y + }; +} + +function moveWaypoints(waypoints, deltaX, deltaY) { + return map(waypoints, function(waypoint) { + return movePosition(waypoint, deltaX, deltaY); + }); +} + +function movePosition(point, deltaX, deltaY) { + return { + x: point.x + deltaX, + y: point.y + deltaY + }; +} diff --git a/test/spec/features/modeling/lanes/lanes-flow-nodes.bpmn b/test/spec/features/modeling/lanes/lanes-flow-nodes.bpmn index dce2514e..85d74419 100644 --- a/test/spec/features/modeling/lanes/lanes-flow-nodes.bpmn +++ b/test/spec/features/modeling/lanes/lanes-flow-nodes.bpmn @@ -1,7 +1,11 @@ - + + + + + @@ -11,13 +15,13 @@ Event Boundary - Task_Boundary Task Event Boundary + @@ -32,57 +36,76 @@ SequenceFlow_From_Boundary - + + + - + - - + + - - - - - + + - - + + - - - - + + + + - - + + - + - - + + - - - - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + +