From a66d85018a71af016210e0a5696d8c7e1fab7304 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 27 May 2024 13:17:51 +0200 Subject: [PATCH] fix(drilldown): gracefully handle missing BPMNDiagram#plane --- .../drilldown/SubprocessCompatibility.js | 8 ++-- test/spec/features/drilldown/DrilldownSpec.js | 38 ++++++++++++++++++- .../missing-di-bpmndiagram-plane.bpmn | 17 +++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 test/spec/features/drilldown/missing-di-bpmndiagram-plane.bpmn diff --git a/lib/features/drilldown/SubprocessCompatibility.js b/lib/features/drilldown/SubprocessCompatibility.js index 3cfcda8730..c190a0e0e9 100644 --- a/lib/features/drilldown/SubprocessCompatibility.js +++ b/lib/features/drilldown/SubprocessCompatibility.js @@ -57,11 +57,9 @@ SubprocessCompatibility.prototype._handleImport = function(definitions) { self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram; }); - var newDiagrams = []; - definitions.diagrams.forEach(function(diagram) { - var createdDiagrams = self._createNewDiagrams(diagram.plane); - Array.prototype.push.apply(newDiagrams, createdDiagrams); - }); + var newDiagrams = definitions.diagrams + .filter(diagram => diagram.plane) + .flatMap(diagram => self._createNewDiagrams(diagram.plane)); newDiagrams.forEach(function(diagram) { self._movePlaneElementsToOrigin(diagram.plane); diff --git a/test/spec/features/drilldown/DrilldownSpec.js b/test/spec/features/drilldown/DrilldownSpec.js index acab91e50e..0fc9ff251c 100644 --- a/test/spec/features/drilldown/DrilldownSpec.js +++ b/test/spec/features/drilldown/DrilldownSpec.js @@ -400,7 +400,7 @@ describe('features - drilldown', function() { }); - describe('Legacy Processes', function() { + describe('features - drilldown - Legacy Processes', function() { beforeEach(bootstrapViewer(legacyXML, { modules: testModules })); @@ -454,6 +454,42 @@ describe('features - drilldown', function() { }); +describe('features/drilldown - integration', function() { + + var testModules = [ + coreModule, + DrilldownModule + ]; + + var missingDiXML = require('./missing-di-bpmndiagram-plane.bpmn'); + + var multiLayerXML = require('./nested-subprocesses.bpmn'); + + beforeEach(bootstrapViewer(multiLayerXML, { modules: testModules })); + + + describe('error handling', function() { + + it('should import diagram with missing BPMNDiagram#plane', inject( + async function(bpmnjs) { + + let error; + + try { + await bpmnjs.importXML(missingDiXML); + } catch (_error) { + error = _error; + } + + expect(error).not.to.exist; + } + )); + + }); + +}); + + // helpers function getBreadcrumbs() { diff --git a/test/spec/features/drilldown/missing-di-bpmndiagram-plane.bpmn b/test/spec/features/drilldown/missing-di-bpmndiagram-plane.bpmn new file mode 100644 index 0000000000..2825032133 --- /dev/null +++ b/test/spec/features/drilldown/missing-di-bpmndiagram-plane.bpmn @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + +