diff --git a/lib/features/ordering/BpmnOrderingProvider.js b/lib/features/ordering/BpmnOrderingProvider.js index f45cfbe7..6e474458 100644 --- a/lib/features/ordering/BpmnOrderingProvider.js +++ b/lib/features/ordering/BpmnOrderingProvider.js @@ -22,7 +22,8 @@ function BpmnOrderingProvider(eventBus) { OrderingProvider.call(this, eventBus); var orders = [ - { type: 'label', order: { level: 7 } }, + { type: 'label', order: { level: 10 } }, + { type: 'bpmn:SubProcess', order: { level: 6 } }, { type: 'bpmn:SequenceFlow', order: { @@ -44,8 +45,8 @@ function BpmnOrderingProvider(eventBus) { ] } }, - { type: 'bpmn:MessageFlow', order: { level: 6, containers: [ 'bpmn:Collaboration' ] } }, - { type: 'bpmn:BoundaryEvent', order: { level: 4 } }, + { type: 'bpmn:MessageFlow', order: { level: 9, containers: [ 'bpmn:Collaboration' ] } }, + { type: 'bpmn:BoundaryEvent', order: { level: 8 } }, { type: 'bpmn:Participant', order: { level: -2 } }, { type: 'bpmn:Lane', order: { level: -1 } } ]; @@ -135,4 +136,4 @@ BpmnOrderingProvider.$inject = [ 'eventBus' ]; inherits(BpmnOrderingProvider, OrderingProvider); -module.exports = BpmnOrderingProvider; \ No newline at end of file +module.exports = BpmnOrderingProvider; diff --git a/test/spec/features/ordering/BpmnOrderingProviderSpec.js b/test/spec/features/ordering/BpmnOrderingProviderSpec.js index e15e9d59..e87cf80c 100644 --- a/test/spec/features/ordering/BpmnOrderingProviderSpec.js +++ b/test/spec/features/ordering/BpmnOrderingProviderSpec.js @@ -13,40 +13,88 @@ var modelingModule = require('../../../../lib/features/modeling'), describe('features/modeling - ordering', function() { - var diagramXML = require('./ordering.bpmn'); - var testModules = [ coreModule, modelingModule ]; - beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + describe('boundary events', function() { + + var diagramXML = require('./ordering.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + it('should stay in front of Task', inject(function() { + + // when + move('Task_With_Boundary'); + + // then + expectZOrder('Task_With_Boundary', 'BoundaryEvent'); + })); - it('should keep Task behind BoundaryEvent', inject(function() { + it('should stay in front of Task, moving both', inject(function() { - // when - move('Task_With_Boundary'); + // when + move([ 'BoundaryEvent', 'Task_With_Boundary' ], 'Participant_StartEvent'); - // then - expectZOrder('Task_With_Boundary', 'BoundaryEvent'); - })); + // then + expectZOrder('Task_With_Boundary', 'BoundaryEvent'); + })); + + }); + + describe('participants', function() { + + var diagramXML = require('./ordering.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + it('should stay behind MessageFlow', inject(function() { + + // when + move('Participant', 'Collaboration'); + + // then + expectZOrder('Participant_StartEvent', 'Participant', 'MessageFlow'); + })); + + }); - it('should keep Task behind BoundaryEvent, moving both', inject(function() { + describe('sub processes', function() { - // when - move([ 'BoundaryEvent', 'Task_With_Boundary' ], 'Participant_StartEvent'); + var diagramXML = require('./ordering-subprocesses.bpmn'); - // then - expectZOrder('Task_With_Boundary', 'BoundaryEvent'); - })); + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + it('should stay behind boundary events', inject(function() { + + // when + move('BoundaryEvent_1', { x: 50, y: 0 }, 'SubProcess_1', true); + + // then + expectZOrder('SubProcess_1', 'BoundaryEvent_1'); + })); - it('should keep Participant behind MessageFlow', inject(function() { + it('should stay behind tasks', inject(function() { - // when - move('Participant', 'Collaboration'); + // when + move(['Task_1', 'Task_2'], { x: 50, y: 0 }, 'SubProcess_1'); - // then - expectZOrder('Participant_StartEvent', 'Participant', 'MessageFlow'); - })); + // then + expectZOrder('SubProcess_1', 'Task_1', 'Task_2'); + })); -}); \ No newline at end of file + + it('should be in front of tasks if task is not a child', inject(function() { + + // when + move(['Task_1', 'Task_2'], { x: 200, y: 0 }, 'Root'); + + // then + expectZOrder('Task_1', 'Task_2', 'SubProcess_1'); + })); + + }); + +}); diff --git a/test/spec/features/ordering/Helper.js b/test/spec/features/ordering/Helper.js index 4ced59ce..6a6f3011 100644 --- a/test/spec/features/ordering/Helper.js +++ b/test/spec/features/ordering/Helper.js @@ -4,6 +4,16 @@ var TestHelper = require('../../../TestHelper'); var map = require('lodash/collection/map'); +// polyfill, because Math.sign is not available in PhantomJS, IE and Safari +// https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/sign +Math.sign = Math.sign || function(x) { + x = +x; // convert to a number + if (x === 0 || isNaN(x)) { + return x; + } + return x > 0 ? 1 : -1; +}; + function move(elementIds, delta, targetId, isAttach) { if (typeof elementIds === 'string') { @@ -21,18 +31,25 @@ function move(elementIds, delta, targetId, isAttach) { targetId = null; } - return TestHelper.getBpmnJS().invoke(function(elementRegistry, modeling) { + return TestHelper.getBpmnJS().invoke(function(canvas, elementRegistry, modeling) { function getElement(id) { var element = elementRegistry.get(id); + expect(element).to.exist; return element; } var elements = map(elementIds, getElement), - target = targetId && getElement(targetId); + target; + + if (targetId === 'Root') { + target = canvas.getRootElement(); + } else { + target = targetId && getElement(targetId); + } return modeling.moveElements(elements, delta, target, isAttach); }); @@ -93,7 +110,7 @@ function compareZOrder(aId, bId) { parent: aAncestor }; } - }); + }, false); // b contained in a if (!sharedRoot.a) { @@ -105,8 +122,8 @@ function compareZOrder(aId, bId) { return 1; } - var aIndex = sharedRoot.parent.indexOf(sharedRoot.a), - bIndex = sharedRoot.parent.indexOf(sharedRoot.b); + var aIndex = sharedRoot.parent.children.indexOf(sharedRoot.a), + bIndex = sharedRoot.parent.children.indexOf(sharedRoot.b); return Math.sign(aIndex - bIndex); } @@ -122,7 +139,7 @@ function expectZOrder() { forEach(elements, function(e, idx) { - next = elements[idx]; + next = elements[idx + 1]; if (next) { expect(compareZOrder(e, next)).to.eql(-1); @@ -132,4 +149,4 @@ function expectZOrder() { return true; } -module.exports.expectZOrder = expectZOrder; \ No newline at end of file +module.exports.expectZOrder = expectZOrder; diff --git a/test/spec/features/ordering/ordering-subprocesses.bpmn b/test/spec/features/ordering/ordering-subprocesses.bpmn new file mode 100644 index 00000000..95e94fbc --- /dev/null +++ b/test/spec/features/ordering/ordering-subprocesses.bpmn @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +