From d19c4b0027bfa9f6e19601be7f7b26ccc8bba252 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 30 Aug 2021 11:19:25 +0200 Subject: [PATCH] fix(import): pass context during collaboration import --- lib/import/BpmnTreeWalker.js | 8 ++--- test/spec/import/BpmnTreeWalkerSpec.js | 44 ++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/lib/import/BpmnTreeWalker.js b/lib/import/BpmnTreeWalker.js index 2b2342b3..6a9a2ba5 100644 --- a/lib/import/BpmnTreeWalker.js +++ b/lib/import/BpmnTreeWalker.js @@ -427,15 +427,15 @@ export default function BpmnTreeWalker(handler, translate) { } } - function handleCollaboration(collaboration) { + function handleCollaboration(collaboration, context) { - forEach(collaboration.participants, contextual(handleParticipant)); + forEach(collaboration.participants, contextual(handleParticipant, context)); - handleArtifacts(collaboration.artifacts); + handleArtifacts(collaboration.artifacts, context); // handle message flows latest in the process deferred.push(function() { - handleMessageFlows(collaboration.messageFlows); + handleMessageFlows(collaboration.messageFlows, context); }); } diff --git a/test/spec/import/BpmnTreeWalkerSpec.js b/test/spec/import/BpmnTreeWalkerSpec.js index fcd6b952..8dc6d6f1 100644 --- a/test/spec/import/BpmnTreeWalkerSpec.js +++ b/test/spec/import/BpmnTreeWalkerSpec.js @@ -5,6 +5,7 @@ import BpmnModdle from 'bpmn-moddle'; import { find } from 'min-dash'; import simpleXML from 'test/fixtures/bpmn/simple.bpmn'; +import collaboration from 'test/fixtures/bpmn/collaboration.bpmn'; describe('import - BpmnTreeWalker', function() { @@ -44,8 +45,37 @@ describe('import - BpmnTreeWalker', function() { // then expect(elementSpy.callCount).to.equal(8); - expect(rootSpy.calledOnce).to.be.true; - expect(errorSpy.notCalled).to.be.true; + expect(rootSpy).to.be.calledOnce; + expect(errorSpy).not.to.be.called; + }); + }); + + + it('should always call element visitor with parent', function() { + + // given + var elementSpy = sinon.spy(), + errorSpy = sinon.spy(); + + + var walker = createWalker({ + element: elementSpy, + root: function() { + return 'root'; + }, + error: errorSpy + }); + + return createModdle(collaboration).then(function(result) { + + var definitions = result.rootElement; + + // when + walker.handleDefinitions(definitions); + + // then + expect(elementSpy).to.not.be.calledWith(sinon.match.any, sinon.match.typeOf('undefined')); + expect(errorSpy).to.not.be.called; }); }); @@ -82,8 +112,8 @@ describe('import - BpmnTreeWalker', function() { // then expect(elementSpy.callCount).to.equal(3); - expect(rootSpy.notCalled).to.be.true; - expect(errorSpy.notCalled).to.be.true; + expect(rootSpy).to.not.be.called; + expect(errorSpy).to.not.be.called; }); }); @@ -138,13 +168,13 @@ function createWalker(listeners) { var visitor = { element: function(element, parent) { - listeners.element && listeners.element(element, parent); + return listeners.element && listeners.element(element, parent); }, root: function(root) { - listeners.root && listeners.root(root); + return listeners.root && listeners.root(root); }, error: function(message, context) { - listeners.error && listeners.error(message, context); + return listeners.error && listeners.error(message, context); } };