fix(auto-place): complete direct editing on auto place

Related to camunda/camunda-modeler#1502
This commit is contained in:
Niklas Kiefer 2019-09-11 11:29:32 +02:00 committed by Philipp Fromme
parent 86c61b0c0d
commit dcf440b076
3 changed files with 147 additions and 13 deletions

View File

@ -25,6 +25,11 @@ export default function AutoPlace(eventBus, modeling) {
*/ */
this.append = function(source, shape) { this.append = function(source, shape) {
emit('autoPlace.start', {
source: source,
shape: shape
});
// allow others to provide the position // allow others to provide the position
var position = emit('autoPlace', { var position = emit('autoPlace', {
source: source, source: source,
@ -37,8 +42,8 @@ export default function AutoPlace(eventBus, modeling) {
var newShape = modeling.appendShape(source, shape, position, source.parent); var newShape = modeling.appendShape(source, shape, position, source.parent);
// notify interested parties on new shape placed
emit('autoPlace.end', { emit('autoPlace.end', {
source: source,
shape: newShape shape: newShape
}); });

View File

@ -44,10 +44,10 @@ export default function LabelEditingProvider(
// complete on followup canvas operation // complete on followup canvas operation
eventBus.on([ eventBus.on([
'element.mousedown', 'autoPlace.start',
'drag.init',
'canvas.viewbox.changing', 'canvas.viewbox.changing',
'autoPlace', 'drag.init',
'element.mousedown',
'popupMenu.open' 'popupMenu.open'
], function(event) { ], function(event) {

View File

@ -1,13 +1,19 @@
/* global sinon */
import { import {
bootstrapModeler, bootstrapModeler,
inject inject
} from 'test/TestHelper'; } from 'test/TestHelper';
import autoPlaceModule from 'lib/features/auto-place'; import autoPlaceModule from 'lib/features/auto-place';
import coreModule from 'lib/core';
import labelEditingModule from 'lib/features/label-editing';
import modelingModule from 'lib/features/modeling'; import modelingModule from 'lib/features/modeling';
import selectionModule from 'diagram-js/lib/features/selection'; import selectionModule from 'diagram-js/lib/features/selection';
import labelEditingModule from 'lib/features/label-editing';
import coreModule from 'lib/core'; import { getBusinessObject } from '../../../../lib/util/ModelUtil';
import { getMid } from 'diagram-js/lib/layout/LayoutUtil';
describe('features/auto-place', function() { describe('features/auto-place', function() {
@ -110,31 +116,52 @@ describe('features/auto-place', function() {
}); });
describe('modeling flow', function() { describe('integration', function() {
var diagramXML = require('./AutoPlace.bpmn'); var diagramXML = require('./AutoPlace.bpmn');
before(bootstrapModeler(diagramXML, { before(bootstrapModeler(diagramXML, {
modules: [ modules: [
coreModule,
modelingModule,
autoPlaceModule, autoPlaceModule,
selectionModule, coreModule,
labelEditingModule labelEditingModule,
modelingModule,
selectionModule
] ]
})); }));
it('should complete direct edit on autoPlace', inject(
function(autoPlace, directEditing, elementFactory, elementRegistry) {
// given
var element = elementFactory.createShape({ type: 'bpmn:Task' });
var source = elementRegistry.get('TASK_2');
directEditing.activate(source);
directEditing._textbox.content.textContent = 'foo';
// when
autoPlace.append(source, element);
// then
expect(getBusinessObject(source).name).to.equal('foo');
}
));
it('should select + direct edit on autoPlace', inject( it('should select + direct edit on autoPlace', inject(
function(autoPlace, elementRegistry, elementFactory, selection, directEditing) { function(autoPlace, elementRegistry, elementFactory, selection, directEditing) {
// given // given
var el = elementFactory.createShape({ type: 'bpmn:Task' }); var element = elementFactory.createShape({ type: 'bpmn:Task' });
var source = elementRegistry.get('TASK_2'); var source = elementRegistry.get('TASK_2');
// when // when
var newShape = autoPlace.append(source, el); var newShape = autoPlace.append(source, element);
// then // then
expect(selection.get()).to.eql([ newShape ]); expect(selection.get()).to.eql([ newShape ]);
@ -230,6 +257,108 @@ describe('features/auto-place', function() {
}); });
describe('eventbus integration', function() {
var diagramXML = require('./AutoPlace.bpmn');
beforeEach(bootstrapModeler(diagramXML, {
modules: [
autoPlaceModule,
coreModule,
labelEditingModule,
modelingModule,
selectionModule
]
}));
it('<autoPlace.start>', inject(
function(autoPlace, elementFactory, elementRegistry, eventBus) {
// given
var element = elementFactory.createShape({ type: 'bpmn:Task' });
var source = elementRegistry.get('TASK_2');
var listener = sinon.spy(function(event) {
// then
expect(event.shape).to.equal(element);
expect(event.source).to.equal(source);
});
eventBus.on('autoPlace.start', listener);
// when
autoPlace.append(source, element);
expect(listener).to.have.been.called;
}
));
it('<autoPlace>', inject(
function(autoPlace, elementFactory, elementRegistry, eventBus) {
// given
var element = elementFactory.createShape({ type: 'bpmn:Task' });
var source = elementRegistry.get('TASK_2');
var listener = sinon.spy(function(event) {
// then
expect(event.shape).to.equal(element);
expect(event.source).to.equal(source);
return {
x: 0,
y: 0
};
});
eventBus.on('autoPlace', listener);
// when
autoPlace.append(source, element);
expect(listener).to.have.been.called;
expect(getMid(element)).to.eql({
x: 0,
y: 0
});
}
));
it('<autoPlace.end>', inject(
function(autoPlace, elementFactory, elementRegistry, eventBus) {
// given
var element = elementFactory.createShape({ type: 'bpmn:Task' });
var source = elementRegistry.get('TASK_2');
var listener = sinon.spy(function(event) {
// then
expect(event.shape).to.equal(element);
expect(event.source).to.equal(source);
});
eventBus.on('autoPlace.end', listener);
// when
autoPlace.append(source, element);
expect(listener).to.have.been.called;
}
));
});
}); });