diff --git a/lib/features/modeling/behavior/FixHoverBehavior.js b/lib/features/modeling/behavior/FixHoverBehavior.js index e56078e1ff..cd7076235b 100644 --- a/lib/features/modeling/behavior/FixHoverBehavior.js +++ b/lib/features/modeling/behavior/FixHoverBehavior.js @@ -44,6 +44,52 @@ export default function FixHoverBehavior(elementRegistry, eventBus, canvas) { } }); + + eventBus.on([ + 'connect.hover', + 'global-connect.hover' + ], HIGH_PRIORITY, function(event) { + var hover = event.hover; + + // ensure connections start/end on bpmn:Participant, + // not the underlying bpmn:Lane + if (is(hover, 'bpmn:Lane')) { + event.hover = getLanesRoot(hover) || hover; + event.hoverGfx = elementRegistry.getGraphics(event.hover); + } + }); + + + eventBus.on([ + 'bendpoint.move.hover' + ], HIGH_PRIORITY, function(event) { + var context = event.context, + type = context.type, + hover = event.hover; + + // ensure reconnect start/end on bpmn:Participant, + // not the underlying bpmn:Lane + if (is(hover, 'bpmn:Lane') && /reconnect/.test(type)) { + event.hover = getLanesRoot(hover) || hover; + event.hoverGfx = elementRegistry.getGraphics(event.hover); + } + }); + + + eventBus.on([ + 'connect.start' + ], HIGH_PRIORITY, function(event) { + + var context = event.context, + source = context.source; + + // ensure connect start on bpmn:Participant, + // not the underlying bpmn:Lane + if (is(source, 'bpmn:Lane')) { + context.source = getLanesRoot(source) || source; + } + }); + } FixHoverBehavior.$inject = [ diff --git a/test/spec/features/modeling/behavior/FixHoverBehavior.lane-connect.bpmn b/test/spec/features/modeling/behavior/FixHoverBehavior.lane-connect.bpmn new file mode 100644 index 0000000000..cf5f7996bd --- /dev/null +++ b/test/spec/features/modeling/behavior/FixHoverBehavior.lane-connect.bpmn @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/features/modeling/behavior/FixHoverBehaviorSpec.js b/test/spec/features/modeling/behavior/FixHoverBehaviorSpec.js index ece9583630..aa403f69a3 100644 --- a/test/spec/features/modeling/behavior/FixHoverBehaviorSpec.js +++ b/test/spec/features/modeling/behavior/FixHoverBehaviorSpec.js @@ -7,9 +7,13 @@ import coreModule from 'lib/core'; import createModule from 'diagram-js/lib/features/create'; import modelingModule from 'lib/features/modeling'; import moveModule from 'diagram-js/lib/features/move'; +import globalConnectModule from 'diagram-js/lib/features/global-connect'; +import bendpointsModule from 'diagram-js/lib/features/bendpoints'; import { createCanvasEvent as canvasEvent } from '../../../../util/MockEvents'; +/* global sinon */ +var spy = sinon.spy; var testModules = [ coreModule, @@ -18,6 +22,7 @@ var testModules = [ modelingModule ]; + describe('features/modeling/behavior - fix hover', function() { describe('drop on lane', function() { @@ -205,4 +210,176 @@ describe('features/modeling/behavior - fix hover', function() { }); + + describe('connect lane', function() { + + var diagramXML = require('./FixHoverBehavior.lane-connect.bpmn'); + + beforeEach(bootstrapModeler(diagramXML, { + modules: testModules.concat([ + globalConnectModule, + bendpointsModule + ]) + })); + + beforeEach(inject(function(dragging) { + dragging.setOptions({ manual: true }); + })); + + + it('should set global connect source to participant', inject( + function(globalConnect, elementRegistry, eventBus, dragging) { + + // given + var participant_lanes = elementRegistry.get('Participant_Lanes'); + var lane_1 = elementRegistry.get('Lane_1'); + + var connectSpy = spy(function(event) { + expect(event.context.startTarget).to.eql(participant_lanes); + }); + + eventBus.once('global-connect.end', connectSpy); + + // when + globalConnect.start(canvasEvent({ x: 0, y: 0 })); + + dragging.move(canvasEvent({ x: 150, y: 130 })); + dragging.hover(canvasEvent({ x: 150, y: 130 }, { element: lane_1 })); + dragging.end(canvasEvent({ x: 0, y: 0 })); + + // then + expect(connectSpy).to.have.been.called; + } + )); + + + describe('reconnect', function() { + + it('should set start to participant', inject( + function(bendpointMove, elementRegistry, eventBus, dragging) { + + // given + var participant_lanes = elementRegistry.get('Participant_Lanes'); + var lane_1 = elementRegistry.get('Lane_1'); + + var messageFlow = elementRegistry.get('MessageFlow_2'); + + var connectSpy = spy(function(event) { + expect(event.context.target).to.eql(participant_lanes); + }); + + eventBus.once('bendpoint.move.end', connectSpy); + + // when + bendpointMove.start(canvasEvent({ x: 240, y: 200 }), messageFlow, 0); + dragging.move(canvasEvent({ x: 240, y: 280 })); + + dragging.hover({ element: lane_1, gfx: elementRegistry.getGraphics(lane_1) }); + dragging.end(); + + // then + expect(connectSpy).to.have.been.called; + } + )); + + + it('should set end to participant', inject( + function(bendpointMove, elementRegistry, eventBus, dragging) { + + // given + var participant_lanes = elementRegistry.get('Participant_Lanes'); + var lane_1 = elementRegistry.get('Lane_1'); + + var messageFlow = elementRegistry.get('MessageFlow_1'); + + var connectSpy = spy(function(event) { + expect(event.context.target).to.eql(participant_lanes); + }); + + eventBus.once('bendpoint.move.end', connectSpy); + + // when + bendpointMove.start(canvasEvent({ x: 240, y: 200 }), messageFlow, 1); + dragging.move(canvasEvent({ x: 240, y: 280 })); + + dragging.hover({ element: lane_1, gfx: elementRegistry.getGraphics(lane_1) }); + dragging.end(); + + // then + expect(connectSpy).to.have.been.called; + } + )); + + }); + + + describe('connect', function() { + + it('should set start to participant', inject( + function(connect, dragging, elementRegistry, eventBus) { + + // given + var participant_lanes = elementRegistry.get('Participant_Lanes'); + var participant_no_lanes = elementRegistry.get('Participant_No_Lanes'); + var lane_1 = elementRegistry.get('Lane_1'); + + var connectSpy = spy(function(event) { + + var context = event.context, + source = context.source; + + expect(source).to.eql(participant_lanes); + }); + + eventBus.once('connect.end', connectSpy); + + // when + connect.start(canvasEvent({ x: 240, y: 300 }), lane_1); + + dragging.move(canvasEvent({ x: 240, y: 0 })); + + dragging.hover(canvasEvent({ x: 240, y: 0 }, { element: participant_no_lanes })); + dragging.end(); + + // then + expect(connectSpy).to.have.been.called; + } + )); + + + it('should set end to participant', inject( + function(connect, dragging, elementRegistry, eventBus) { + + // given + var participant_lanes = elementRegistry.get('Participant_Lanes'); + var participant_no_lanes = elementRegistry.get('Participant_No_Lanes'); + var lane_1 = elementRegistry.get('Lane_1'); + + var connectSpy = spy(function(event) { + + var context = event.context, + target = context.target; + + expect(target).to.eql(participant_lanes); + }); + + eventBus.once('connect.end', connectSpy); + + // when + connect.start(canvasEvent({ x: 240, y: 0 }), participant_no_lanes); + + dragging.move(canvasEvent({ x: 240, y: 300 })); + + dragging.hover(canvasEvent({ x: 240, y: 300 }, { element: lane_1 })); + dragging.end(); + + // then + expect(connectSpy).to.have.been.called; + } + )); + + }); + + }); + }); \ No newline at end of file