From 8eced8a3fb232dfacff2e4f1e9322b53d1572323 Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Tue, 9 Apr 2019 14:35:48 +0200 Subject: [PATCH] test(modeling): ensure layout is done after element removal * adjust test suite to pass with diagram-js@3.2 * verify new cropping behavior * verify #940 is fixed --- .../modeling/DeleteShape.cropping.bpmn | 38 +++++++++++++ .../spec/features/modeling/DeleteShapeSpec.js | 37 +++++++++++-- .../behavior/DropOnFlowBehaviorSpec.js | 26 ++++----- .../RemoveElementBehavior.diagonal.bpmn | 54 +++++++++++++++++++ .../behavior/RemoveElementBehaviorSpec.js | 38 +++++++++++++ 5 files changed, 177 insertions(+), 16 deletions(-) create mode 100644 test/spec/features/modeling/DeleteShape.cropping.bpmn create mode 100644 test/spec/features/modeling/behavior/RemoveElementBehavior.diagonal.bpmn diff --git a/test/spec/features/modeling/DeleteShape.cropping.bpmn b/test/spec/features/modeling/DeleteShape.cropping.bpmn new file mode 100644 index 00000000..052c00b7 --- /dev/null +++ b/test/spec/features/modeling/DeleteShape.cropping.bpmn @@ -0,0 +1,38 @@ + + + + + SequenceFlow_1 + + + SequenceFlow_2 + + + + SequenceFlow_1 + SequenceFlow_2 + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/DeleteShapeSpec.js b/test/spec/features/modeling/DeleteShapeSpec.js index 62213ac8..002a8b9f 100644 --- a/test/spec/features/modeling/DeleteShapeSpec.js +++ b/test/spec/features/modeling/DeleteShapeSpec.js @@ -7,15 +7,15 @@ import modelingModule from 'lib/features/modeling'; import coreModule from 'lib/core'; +var testModules = [ coreModule, modelingModule ]; + + describe('features/modeling - #removeShape', function() { var diagramXML = require('../../../fixtures/bpmn/sequence-flows.bpmn'); - var testModules = [ coreModule, modelingModule ]; - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); - describe('shape handling', function() { it('should execute', inject(function(elementRegistry, modeling) { @@ -71,3 +71,34 @@ describe('features/modeling - #removeShape', function() { }); }); + + +describe('features/modeling - #removeShape', function() { + + var diagramXML = require('./DeleteShape.cropping.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should crop waypoints on undo/redo', inject( + function(elementRegistry, commandStack, modeling) { + + // given + var taskShape = elementRegistry.get('Task_A'), + sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'), + incomingFlow = taskShape.incoming[0], + outgoingFlow = taskShape.outgoing[0], + expectedStart = incomingFlow.waypoints[0], + expectedEnd = outgoingFlow.waypoints[1]; + + // when + modeling.removeShape(taskShape); + commandStack.undo(); + commandStack.redo(); + + // then + expect(sequenceFlowConnection).to.have.waypoints([ expectedStart, expectedEnd ]); + } + )); + +}); \ No newline at end of file diff --git a/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js b/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js index bb9652b0..37383b29 100644 --- a/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/DropOnFlowBehaviorSpec.js @@ -246,7 +246,7 @@ describe('modeling/behavior - drop on connection', function() { gfx: sequenceFlowGfx }); - dragging.move(canvasEvent({ x: 150, y: 0 })); + dragging.move(canvasEvent({ x: 149, y: 0 })); dragging.end(); @@ -268,17 +268,17 @@ describe('modeling/behavior - drop on connection', function() { // split target at insertion point expect(sequenceFlow).to.have.waypoints(flatten([ originalWaypoints.slice(0, 2), - { x: 341, y: 192 } + { x: 340, y: 192 } ])); - expect(sequenceFlow).to.have.endDocking({ x: 341, y: 210 }); + expect(sequenceFlow).to.have.endDocking({ x: 340, y: 210 }); expect(targetConnection).to.have.waypoints(flatten([ - { x: 341, y: 228 }, + { x: 340, y: 228 }, originalWaypoints.slice(2) ])); - expect(targetConnection).to.have.startDocking({ x: 341, y: 210 }); + expect(targetConnection).to.have.startDocking({ x: 340, y: 210 }); } )); @@ -307,7 +307,7 @@ describe('modeling/behavior - drop on connection', function() { gfx: rootElementGfx }); - dragging.move(canvasEvent({ x: 150, y: 0 })); + dragging.move(canvasEvent({ x: 149, y: 0 })); dragging.end(); // then @@ -328,17 +328,17 @@ describe('modeling/behavior - drop on connection', function() { // split target at insertion point expect(sequenceFlow).to.have.waypoints(flatten([ originalWaypoints.slice(0, 2), - { x: 341, y: 192 } + { x: 340, y: 192 } ])); - expect(sequenceFlow).to.have.endDocking({ x: 341, y: 210 }); + expect(sequenceFlow).to.have.endDocking({ x: 340, y: 210 }); expect(targetConnection).to.have.waypoints(flatten([ - { x: 341, y: 228 }, + { x: 340, y: 228 }, originalWaypoints.slice(2) ])); - expect(targetConnection).to.have.startDocking({ x: 341, y: 210 }); + expect(targetConnection).to.have.startDocking({ x: 340, y: 210 }); } )); @@ -361,17 +361,17 @@ describe('modeling/behavior - drop on connection', function() { gfx: sequenceFlowGfx }); - dragging.move(canvasEvent({ x: 150, y: -130 })); + dragging.move(canvasEvent({ x: 149, y: -130 })); dragging.end(); // then // split target but don't keep insertion point expect(sequenceFlow).to.have.waypoints(flatten([ originalWaypoints.slice(0, 2), - { x: 341, y: 241 } + { x: 340, y: 241 } ])); - expect(sequenceFlow).to.have.endDocking({ x: 341, y: 281 }); + expect(sequenceFlow).to.have.endDocking({ x: 340, y: 281 }); } )); diff --git a/test/spec/features/modeling/behavior/RemoveElementBehavior.diagonal.bpmn b/test/spec/features/modeling/behavior/RemoveElementBehavior.diagonal.bpmn new file mode 100644 index 00000000..83a44808 --- /dev/null +++ b/test/spec/features/modeling/behavior/RemoveElementBehavior.diagonal.bpmn @@ -0,0 +1,54 @@ + + + + + SequenceFlow1 + + + SequenceFlow1 + SequenceFlow2 + + + + SequenceFlow2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/behavior/RemoveElementBehaviorSpec.js b/test/spec/features/modeling/behavior/RemoveElementBehaviorSpec.js index ae82f05d..624ce4eb 100644 --- a/test/spec/features/modeling/behavior/RemoveElementBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/RemoveElementBehaviorSpec.js @@ -187,6 +187,44 @@ describe('features/modeling - remove element behavior', function() { }); + + describe('connections layout', function() { + + var processDiagramXML = require('./RemoveElementBehavior.diagonal.bpmn'); + + beforeEach(bootstrapModeler(processDiagramXML, { modules: testModules })); + + + it('should layout connection', inject(function(modeling, elementRegistry) { + + // given + var task = elementRegistry.get('Task1'); + var sequenceFlow1 = elementRegistry.get('SequenceFlow1'); + + // when + modeling.removeShape(task); + + // then + var waypoints = sequenceFlow1.waypoints; + + // SequenceFlow2 should be deleted + expect(elementRegistry.get('SequenceFlow2')).to.be.undefined; + expect(elementRegistry.get(task.id)).to.be.undefined; + + // source and target have one connection each + expect(elementRegistry.get('StartEvent1').outgoing.length).to.be.equal(1); + expect(elementRegistry.get('EndEvent1').incoming.length).to.be.equal(1); + + // connection has Manhattan layout + expect(waypoints).to.have.length(4); + expect(waypoints[0].y).to.eql(waypoints[1].y); + expect(waypoints[1].x).to.eql(waypoints[2].x); + expect(waypoints[2].y).to.eql(waypoints[3].y); + + })); + + }); + });