fix(rules): disallow dropping on labels and groups

* test create
* disallow drop on label
* disallow drop on group
* verify create group everywhere

Required by https://github.com/camunda/camunda-modeler/issues/1431
This commit is contained in:
Nico Rehwaldt 2019-07-22 13:53:45 +02:00 committed by Maciej Barelkowski
parent 1a6b6dc46a
commit e7d66b4461
3 changed files with 118 additions and 2 deletions

View File

@ -768,7 +768,7 @@ function canCreate(shape, target, source, position) {
return false;
}
if (isLabel(target) || isGroup(target)) {
if (isLabel(shape) || isGroup(shape)) {
return true;
}

View File

@ -7,7 +7,8 @@ import {
expectCanConnect,
expectCanDrop,
expectCanMove,
expectCanInsert
expectCanInsert,
expectCanCreate
} from './Helper';
import modelingModule from 'lib/features/modeling';
@ -1055,6 +1056,111 @@ describe('features/modeling/rules - BpmnRules', function() {
});
describe('create Group', function() {
var group;
beforeEach(inject(function(elementFactory) {
group = elementFactory.createShape({
type: 'bpmn:Group',
x: 413, y: 254
});
}));
it('-> MessageFlow', function() {
expectCanCreate(group, 'MessageFlow_labeled', true);
});
it('-> CollapsedParticipant', function() {
expectCanCreate(group, 'CollapsedParticipant', true);
});
it('-> Collaboration', function() {
// then
expectCanCreate(group, 'Collaboration', true);
});
it('-> Task_in_SubProcess', function() {
expectCanCreate(group, 'Task_in_SubProcess', true);
});
it('-> SequenceFlow', function() {
expectCanCreate(group, 'SequenceFlow', true);
});
it('-> DataOutputAssociation', function() {
expectCanCreate(group, 'DataOutputAssociation', true);
});
it('-> Group', function() {
expectCanCreate(group, 'Group', true);
});
});
describe('reject create on Group', function() {
it('DataStoreReference ->', inject(function(elementFactory) {
var dataStoreReference = elementFactory.createShape({
type: 'bpmn:DataStoreReference',
x: 413, y: 254
});
expectCanCreate(dataStoreReference, 'Group', false);
}));
it('Task ->', inject(function(elementFactory) {
var task = elementFactory.createShape({
type: 'bpmn:Task',
x: 413, y: 254
});
expectCanCreate(task, 'Group', false);
}));
});
describe('reject create on label', function() {
var label;
beforeEach(inject(function(elementRegistry) {
label = elementRegistry.get('MessageFlow_labeled').label;
}));
it('DataStoreReference ->', inject(function(elementFactory) {
var dataStoreReference = elementFactory.createShape({
type: 'bpmn:DataStoreReference',
x: 413, y: 254
});
expectCanCreate(dataStoreReference, label, false);
}));
it('Task ->', inject(function(elementFactory) {
var task = elementFactory.createShape({
type: 'bpmn:Task',
x: 413, y: 254
});
expectCanCreate(task, label, false);
}));
});
});

View File

@ -47,6 +47,16 @@ export function expectCanDrop(element, target, expectedResult) {
}
export function expectCanCreate(element, target, expectedResult) {
var result = getBpmnJS().invoke(function(bpmnRules) {
return bpmnRules.canCreate(get(element), get(target));
});
expect(result).to.eql(expectedResult);
}
export function expectCanInsert(element, target, expectedResult) {
var result = getBpmnJS().invoke(function(bpmnRules) {