From 566f0eadaa83822b5e03c03b47dc2ac39b716216 Mon Sep 17 00:00:00 2001 From: Niklas Kiefer Date: Fri, 7 Feb 2020 09:10:39 +0100 Subject: [PATCH] fix(import): set property on import Closes #1278 --- lib/import/BpmnImporter.js | 10 +++++++-- test/fixtures/bpmn/import/groups.bpmn | 16 ++++++++++++++ test/spec/import/ImporterSpec.js | 32 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/bpmn/import/groups.bpmn diff --git a/lib/import/BpmnImporter.js b/lib/import/BpmnImporter.js index 6dafd7ee..5ef5e26c 100644 --- a/lib/import/BpmnImporter.js +++ b/lib/import/BpmnImporter.js @@ -115,7 +115,8 @@ BpmnImporter.prototype.add = function(semantic, parentElement) { // SHAPE else if (is(di, 'bpmndi:BPMNShape')) { - var collapsed = !isExpanded(semantic); + var collapsed = !isExpanded(semantic), + isFrame = isFrameElement(semantic); hidden = parentElement && (parentElement.hidden || parentElement.collapsed); var bounds = semantic.di.bounds; @@ -126,7 +127,8 @@ BpmnImporter.prototype.add = function(semantic, parentElement) { x: Math.round(bounds.x), y: Math.round(bounds.y), width: Math.round(bounds.width), - height: Math.round(bounds.height) + height: Math.round(bounds.height), + isFrame: isFrame })); if (is(semantic, 'bpmn:BoundaryEvent')) { @@ -332,4 +334,8 @@ function isPointInsideBBox(bbox, point) { x <= bbox.x + bbox.width && y >= bbox.y && y <= bbox.y + bbox.height; +} + +function isFrameElement(semantic) { + return is(semantic, 'bpmn:Group'); } \ No newline at end of file diff --git a/test/fixtures/bpmn/import/groups.bpmn b/test/fixtures/bpmn/import/groups.bpmn new file mode 100644 index 00000000..92e5d76e --- /dev/null +++ b/test/fixtures/bpmn/import/groups.bpmn @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/spec/import/ImporterSpec.js b/test/spec/import/ImporterSpec.js index b376af42..f1130d9d 100644 --- a/test/spec/import/ImporterSpec.js +++ b/test/spec/import/ImporterSpec.js @@ -480,6 +480,38 @@ describe('import - Importer', function() { }); }); + + it('should import groups', function(done) { + + // given + var xml = require('../../fixtures/bpmn/import/groups.bpmn'); + + var events = []; + + // log events + diagram.get('eventBus').on('bpmnElement.added', function(e) { + events.push({ + type: 'add', + semantic: e.element.businessObject.id, + di: e.element.businessObject.di.id, + diagramElement: e.element && e.element.id, + isFrame: e.element && e.element.isFrame + }); + }); + + // when + runImport(diagram, xml, function(err) { + + // then + expect(events).to.eql([ + { type: 'add', semantic: 'Process_1', di: 'BPMNPlane_1', diagramElement: 'Process_1', isFrame: undefined }, + { type: 'add', semantic: 'Group_1', di: 'Group_1_di', diagramElement: 'Group_1', isFrame: true } + ]); + + done(err); + }); + }); + });