From d865cd0717961f797db048ce75d574d38043f1a4 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Fri, 19 Jul 2019 13:48:28 +0200 Subject: [PATCH 1/3] feat(test): expose BpmnJS set and clear utilities --- test/helper/index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/test/helper/index.js b/test/helper/index.js index bce83a2dcb..54aafd0170 100644 --- a/test/helper/index.js +++ b/test/helper/index.js @@ -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); }; } @@ -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 + '"]')) { From f0d65f04c9522bfb7c0ebb302a372a88b20eeb7c Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Fri, 19 Jul 2019 13:49:24 +0200 Subject: [PATCH 2/3] test(project): register BpmnJS in integration tests --- test/spec/ModelerSpec.js | 9 +++++++++ test/spec/NavigatedViewerSpec.js | 10 ++++++++++ test/spec/ViewerSpec.js | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/test/spec/ModelerSpec.js b/test/spec/ModelerSpec.js index 7d2981b1b8..a77b252f1e 100644 --- a/test/spec/ModelerSpec.js +++ b/test/spec/ModelerSpec.js @@ -8,6 +8,11 @@ import { createEvent } from '../util/MockEvents'; +import { + setBpmnJS, + clearBpmnJS +} from 'test/TestHelper'; + describe('Modeler', function() { @@ -21,6 +26,8 @@ describe('Modeler', function() { function createModeler(xml, done) { + clearBpmnJS(); + modeler = new Modeler({ container: container, keyboard: { @@ -28,6 +35,8 @@ describe('Modeler', function() { } }); + setBpmnJS(modeler); + modeler.importXML(xml, function(err, warnings) { done(err, warnings, modeler); }); diff --git a/test/spec/NavigatedViewerSpec.js b/test/spec/NavigatedViewerSpec.js index 10612cdc4c..4271ba368a 100644 --- a/test/spec/NavigatedViewerSpec.js +++ b/test/spec/NavigatedViewerSpec.js @@ -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() { @@ -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); }); diff --git a/test/spec/ViewerSpec.js b/test/spec/ViewerSpec.js index 560102f541..9e82ffbc9c 100644 --- a/test/spec/ViewerSpec.js +++ b/test/spec/ViewerSpec.js @@ -12,6 +12,11 @@ import { isFunction } from 'min-dash'; +import { + setBpmnJS, + clearBpmnJS +} from 'test/TestHelper'; + describe('Viewer', function() { @@ -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); }); From c84611a6d0753183768df660c0cc2d1ea37d734d Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 22 Jul 2019 13:53:45 +0200 Subject: [PATCH 3/3] 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 --- lib/features/rules/BpmnRules.js | 2 +- test/spec/features/rules/BpmnRulesSpec.js | 108 +++++++++++++++++++++- test/spec/features/rules/Helper.js | 10 ++ 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/lib/features/rules/BpmnRules.js b/lib/features/rules/BpmnRules.js index 34f4d8911d..8cd834097e 100644 --- a/lib/features/rules/BpmnRules.js +++ b/lib/features/rules/BpmnRules.js @@ -768,7 +768,7 @@ function canCreate(shape, target, source, position) { return false; } - if (isLabel(target) || isGroup(target)) { + if (isLabel(shape) || isGroup(shape)) { return true; } diff --git a/test/spec/features/rules/BpmnRulesSpec.js b/test/spec/features/rules/BpmnRulesSpec.js index d3ce9ab1c3..7d9a4f7547 100644 --- a/test/spec/features/rules/BpmnRulesSpec.js +++ b/test/spec/features/rules/BpmnRulesSpec.js @@ -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); + })); + + }); + }); diff --git a/test/spec/features/rules/Helper.js b/test/spec/features/rules/Helper.js index ed02e72238..430287a27e 100644 --- a/test/spec/features/rules/Helper.js +++ b/test/spec/features/rules/Helper.js @@ -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) {