Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

1431 no create on group and label #1131

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/features/rules/BpmnRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ function canCreate(shape, target, source, position) {
return false;
}

if (isLabel(target) || isGroup(target)) {
if (isLabel(shape) || isGroup(shape)) {
return true;
}

Expand Down
23 changes: 17 additions & 6 deletions test/helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
);
}

// clean up old bpmn-js instance
if (BPMN_JS) {
BPMN_JS.destroy();
}
clearBpmnJS();

var instance = new BpmnJS(_options);

BPMN_JS = new BpmnJS(_options);
setBpmnJS(instance);

BPMN_JS.importXML(diagram, done);
instance.importXML(diagram, done);
};
}

Expand Down Expand Up @@ -226,6 +225,18 @@ export function getBpmnJS() {
return BPMN_JS;
}

export function clearBpmnJS() {
// clean up old bpmn-js instance
if (BPMN_JS) {
BPMN_JS.destroy();

BPMN_JS = null;
}
}

export function setBpmnJS(instance) {
BPMN_JS = instance;
}

export function insertCSS(name, css) {
if (document.querySelector('[data-css-file="' + name + '"]')) {
Expand Down
9 changes: 9 additions & 0 deletions test/spec/ModelerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
createEvent
} from '../util/MockEvents';

import {
setBpmnJS,
clearBpmnJS
} from 'test/TestHelper';


describe('Modeler', function() {

Expand All @@ -21,13 +26,17 @@ describe('Modeler', function() {

function createModeler(xml, done) {

clearBpmnJS();

modeler = new Modeler({
container: container,
keyboard: {
bindTo: document
}
});

setBpmnJS(modeler);

modeler.importXML(xml, function(err, warnings) {
done(err, warnings, modeler);
});
Expand Down
10 changes: 10 additions & 0 deletions test/spec/NavigatedViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import EditorActionsModule from 'lib/features/editor-actions';

import TestContainer from 'mocha-test-container-support';

import {
setBpmnJS,
clearBpmnJS
} from 'test/TestHelper';


describe('NavigatedViewer', function() {

Expand All @@ -14,10 +19,15 @@ describe('NavigatedViewer', function() {
});

function createViewer(xml, done) {

clearBpmnJS();

var viewer = new NavigatedViewer({
container: container
});

setBpmnJS(viewer);

viewer.importXML(xml, function(err, warnings) {
done(err, warnings, viewer);
});
Expand Down
9 changes: 9 additions & 0 deletions test/spec/ViewerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import {
isFunction
} from 'min-dash';

import {
setBpmnJS,
clearBpmnJS
} from 'test/TestHelper';


describe('Viewer', function() {

Expand All @@ -28,8 +33,12 @@ describe('Viewer', function() {
diagramId = null;
}

clearBpmnJS();

var viewer = new Viewer({ container: container });

setBpmnJS(viewer);

viewer.importXML(xml, diagramId, function(err, warnings) {
done(err, warnings, viewer);
});
Expand Down
108 changes: 107 additions & 1 deletion test/spec/features/rules/BpmnRulesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
expectCanConnect,
expectCanDrop,
expectCanMove,
expectCanInsert
expectCanInsert,
expectCanCreate
} from './Helper';

import modelingModule from 'lib/features/modeling';
Expand Down Expand Up @@ -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);
}));

});

});


Expand Down
10 changes: 10 additions & 0 deletions test/spec/features/rules/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down