diff --git a/lib/features/drilldown/DrilldownCentering.js b/lib/features/drilldown/DrilldownCentering.js index 6c1ffc46..3a7d81bd 100644 --- a/lib/features/drilldown/DrilldownCentering.js +++ b/lib/features/drilldown/DrilldownCentering.js @@ -1,3 +1,5 @@ +import { is } from '../../util/ModelUtil'; + /** * Move collapsed subprocesses into view when drilling down. * @@ -21,7 +23,14 @@ export default function DrilldownCentering(eventBus, canvas) { }); var newRoot = event.element; - var storedViewbox = positionMap.get(newRoot) || { x: 0, y: 0, zoom: 1 }; + var storedViewbox = positionMap.get(newRoot); + + // current root was replaced with a collaboration, we don't update the viewbox + if (is(newRoot, 'bpmn:Collaboration') && !storedViewbox) { + return; + } + + storedViewbox = storedViewbox || { x: 0, y: 0, zoom: 1 }; var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale, dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale; diff --git a/test/spec/features/drilldown/DrilldownIntegrationSpec.js b/test/spec/features/drilldown/DrilldownIntegrationSpec.js new file mode 100644 index 00000000..f2b560a8 --- /dev/null +++ b/test/spec/features/drilldown/DrilldownIntegrationSpec.js @@ -0,0 +1,94 @@ +import { + inject +} from 'test/TestHelper'; + +import coreModule from 'lib/core'; +import modelingModule from 'lib/features/modeling'; +import DrilldownModule from 'lib/features/drilldown'; +import { bootstrapModeler, getBpmnJS } from '../../../helper'; + + +describe('features - drilldown', function() { + + var testModules = [ + coreModule, + modelingModule, + DrilldownModule + ]; + + var multiLayerXML = require('./nested-subprocesses.bpmn'); + + beforeEach(bootstrapModeler(multiLayerXML, { modules: testModules })); + + describe('Navigation', function() { + + it('should not reset scroll on create collaboration', + inject(function(canvas, modeling) { + + // given + canvas.scroll({ dx: 500, dy: 500 }); + canvas.zoom(0.5); + var zoomedAndScrolledViewbox = canvas.viewbox(); + + // when + modeling.makeCollaboration(); + + // then + expectViewbox(zoomedAndScrolledViewbox); + }) + ); + + + it('should not reset scroll on create collaboration - undo', + inject(function(canvas, modeling, commandStack) { + + // given + canvas.scroll({ dx: 500, dy: 500 }); + canvas.zoom(0.5); + var zoomedAndScrolledViewbox = canvas.viewbox(); + + // when + modeling.makeCollaboration(); + commandStack.undo(); + + // then + expectViewbox(zoomedAndScrolledViewbox); + }) + ); + + + it('should not reset scroll on create collaboration - redo', + inject(function(canvas, modeling, commandStack) { + + // given + canvas.scroll({ dx: 500, dy: 500 }); + canvas.zoom(0.5); + var zoomedAndScrolledViewbox = canvas.viewbox(); + + // when + modeling.makeCollaboration(); + commandStack.undo(); + commandStack.redo(); + + // then + expectViewbox(zoomedAndScrolledViewbox); + }) + ); + + }); + +}); + + +// helpers ////////// + +function expectViewbox(expectedViewbox) { + return getBpmnJS().invoke(function(canvas) { + + var viewbox = canvas.viewbox(); + + expect(viewbox.x).to.eql(expectedViewbox.x); + expect(viewbox.y).to.eql(expectedViewbox.y); + expect(viewbox.scale).to.eql(expectedViewbox.scale); + }); +} \ No newline at end of file