From 4afefcb83842aea02ef45e41bbb0571fe6a2b5f8 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Tue, 11 Aug 2015 14:46:17 +0200 Subject: [PATCH] feat(rules): add lane rules * add create / move rules * add resize rules Related to #316 --- lib/features/modeling/rules/BpmnRules.js | 11 +- .../features/modeling/rules/BpmnRulesSpec.js | 162 +++++++++++++++++- .../rules/BpmnRules.collaboration-lanes.bpmn | 80 +++++++++ 3 files changed, 245 insertions(+), 8 deletions(-) create mode 100644 test/spec/features/rules/BpmnRules.collaboration-lanes.bpmn diff --git a/lib/features/modeling/rules/BpmnRules.js b/lib/features/modeling/rules/BpmnRules.js index d2d03c78..3a4d7f53 100644 --- a/lib/features/modeling/rules/BpmnRules.js +++ b/lib/features/modeling/rules/BpmnRules.js @@ -301,6 +301,11 @@ function canDrop(element, target) { return is(target, 'bpmn:Process') || is(target, 'bpmn:Collaboration'); } + // allow creating lanes on participants and other lanes only + if (is(element, 'bpmn:Lane')) { + return is(target, 'bpmn:Participant') || is(target, 'bpmn:Lane'); + } + if (is(element, 'bpmn:BoundaryEvent')) { return false; } @@ -312,7 +317,7 @@ function canDrop(element, target) { return isExpanded(target) !== false; } - return is(target, 'bpmn:Participant'); + return is(target, 'bpmn:Participant') || is(target, 'bpmn:Lane'); } if (is(element, 'bpmn:Artifact')) { @@ -493,6 +498,10 @@ function canResize(shape, newBounds) { ); } + if (is(shape, 'bpmn:Lane')) { + return !newBounds || (newBounds.width >= 130 && newBounds.height >= 60); + } + if (is(shape, 'bpmn:Participant')) { return !newBounds || (newBounds.width >= 100 && newBounds.height >= 80); } diff --git a/test/spec/features/modeling/rules/BpmnRulesSpec.js b/test/spec/features/modeling/rules/BpmnRulesSpec.js index 7a8de5b2..b1fccfad 100644 --- a/test/spec/features/modeling/rules/BpmnRulesSpec.js +++ b/test/spec/features/modeling/rules/BpmnRulesSpec.js @@ -677,7 +677,7 @@ describe('features/modeling/rules - BpmnRules', function() { var canAttach = bpmnRules.canAttach([ eventShape ], subProcessElement, null, position); // then - expect(canAttach).to.equal(false); + expect(canAttach).to.be.false; })); @@ -722,8 +722,8 @@ describe('features/modeling/rules - BpmnRules', function() { canCreate = bpmnRules.canCreate(eventShape, subProcessElement, null, position); // then - expect(canAttach).to.equal(false); - expect(canCreate).to.equal(true); + expect(canAttach).to.be.false; + expect(canCreate).to.be.true; })); }); @@ -757,8 +757,8 @@ describe('features/modeling/rules - BpmnRules', function() { canCreate = bpmnRules.canCreate(eventShape, subProcessElement, taskElement, position); // then - expect(canAttach).to.equal(false); - expect(canCreate).to.equal(true); + expect(canAttach).to.be.false; + expect(canCreate).to.be.true; })); @@ -778,10 +778,158 @@ describe('features/modeling/rules - BpmnRules', function() { canCreate = bpmnRules.canCreate(eventShape, taskElement, boundaryElement); // then - expect(canAttach).to.equal(false); - expect(canCreate).to.equal(false); + expect(canAttach).to.be.false; + expect(canCreate).to.be.false; })); }); + + describe('lanes', function() { + + var testXML = require('./BpmnRules.collaboration-lanes.bpmn'); + + beforeEach(bootstrapModeler(testXML, { modules: testModules })); + + + describe('should add', function() { + + it('Lane -> Participant', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var participantElement = elementRegistry.get('Participant'); + + var laneShape = elementFactory.createShape({ + type: 'bpmn:Lane', + x: 413, y: 250 + }); + + // when + var canCreate = bpmnRules.canCreate(laneShape, participantElement); + + // then + expect(canCreate).to.be.true; + })); + + + it('Lane -> Participant_Lane', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var participantElement = elementRegistry.get('Participant_Lane'); + + var laneShape = elementFactory.createShape({ + type: 'bpmn:Lane', + x: 413, y: 250 + }); + + // when + var canCreate = bpmnRules.canCreate(laneShape, participantElement); + + // then + expect(canCreate).to.be.true; + })); + + + it('[not] Lane -> SubProcess', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var subProcessElement = elementRegistry.get('SubProcess'); + + var laneShape = elementFactory.createShape({ + type: 'bpmn:Lane', + x: 413, y: 250 + }); + + // when + var canCreate = bpmnRules.canCreate(laneShape, subProcessElement); + + // then + expect(canCreate).to.be.false; + })); + + }); + + + describe('should move', function() { + + it('Lane -> Participant', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var participantElement = elementRegistry.get('Participant'), + laneElement = elementRegistry.get('Lane'); + + // when + var canMove = bpmnRules.canMove([ laneElement ], participantElement); + + // then + expect(canMove).to.be.true; + })); + + + it('[not] Lane -> SubProcess', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var subProcessElement = elementRegistry.get('SubProcess'), + laneElement = elementRegistry.get('Lane'); + + // when + var canMove = bpmnRules.canMove([ laneElement ], subProcessElement); + + // then + expect(canMove).to.be.false; + })); + + }); + + + describe('should resize', function() { + + it('Lane', inject(function(bpmnRules) { + + // given + var laneElement = elementRegistry.get('Lane'); + + // when + var canResize = bpmnRules.canResize(laneElement); + + // then + expect(canResize).to.be.true; + })); + + }); + + + describe('should allow drop', function() { + + it('SubProcess -> Lane', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var element = elementRegistry.get('SubProcess'), + laneElement = elementRegistry.get('Lane'); + + // when + var canMove = bpmnRules.canMove([ element ], laneElement); + + // then + expect(canMove).to.be.true; + })); + + + it('Task_in_SubProcess -> Lane', inject(function(elementFactory, elementRegistry, bpmnRules) { + + // given + var element = elementRegistry.get('Task_in_SubProcess'), + laneElement = elementRegistry.get('Lane'); + + // when + var canMove = bpmnRules.canMove([ element ], laneElement); + + // then + expect(canMove).to.be.true; + })); + + }); + + }); + }); diff --git a/test/spec/features/rules/BpmnRules.collaboration-lanes.bpmn b/test/spec/features/rules/BpmnRules.collaboration-lanes.bpmn new file mode 100644 index 00000000..2fb45355 --- /dev/null +++ b/test/spec/features/rules/BpmnRules.collaboration-lanes.bpmn @@ -0,0 +1,80 @@ + + + + + + + + + + Boundary + Task_Boundary + Task + + + + SequenceFlow_from_Boundary + + + + SequenceFlow + + + + SequenceFlow_from_Boundary + SequenceFlow + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file