From 59835fefb05313b6b1596c47163c9bfbbfd63e73 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 28 Feb 2022 09:16:52 +0100 Subject: [PATCH 1/2] feat(commands): add `setRoot` command --- README.md | 1 + lib/Initializer.js | 2 ++ lib/commands/index.js | 1 + lib/commands/set-root.js | 17 +++++++++++++++++ package-lock.json | 14 +++++++------- package.json | 4 ++-- resources/collapsed.bpmn | 41 ++++++++++++++++++++++++++++++++++++++++ test/spec/CliSpec.js | 37 ++++++++++++++++++++++++++++++++++++ 8 files changed, 108 insertions(+), 9 deletions(-) create mode 100644 lib/commands/set-root.js create mode 100644 resources/collapsed.bpmn diff --git a/README.md b/README.md index 4827629..b363fd1 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Out of the box, the cli supports the following commands: * `redo` * `save svg|bpmn` * `setLabel element label` + * `setRoot element|elementId` * `removeShape shape|elementId` * `removeConnection connection|connectionId` diff --git a/lib/Initializer.js b/lib/Initializer.js index 80abda8..88f3fe6 100644 --- a/lib/Initializer.js +++ b/lib/Initializer.js @@ -17,6 +17,7 @@ import { RedoCommand, SaveCommand, SetLabelCommand, + SetRootCommand, UndoCommand, RemoveShapeCommand, RemoveConnectionCommand, @@ -49,6 +50,7 @@ export default function Initializer(cli) { cli._registerCommand('redo', RedoCommand); cli._registerCommand('save', SaveCommand); cli._registerCommand('setLabel', SetLabelCommand); + cli._registerCommand('setRoot', SetRootCommand); cli._registerCommand('undo', UndoCommand); cli._registerCommand('removeShape', RemoveShapeCommand); cli._registerCommand('removeConnection', RemoveConnectionCommand); diff --git a/lib/commands/index.js b/lib/commands/index.js index f2aafcd..0d9491d 100644 --- a/lib/commands/index.js +++ b/lib/commands/index.js @@ -8,6 +8,7 @@ export { default as MoveCommand } from './move'; export { default as RedoCommand } from './redo'; export { default as SaveCommand } from './save'; export { default as SetLabelCommand } from './set-label'; +export { default as SetRootCommand } from './set-root'; export { default as UndoCommand } from './undo'; export { default as RemoveShapeCommand } from './removeShape'; export { default as RemoveConnectionCommand } from './removeConnection'; diff --git a/lib/commands/set-root.js b/lib/commands/set-root.js new file mode 100644 index 0000000..ef24aff --- /dev/null +++ b/lib/commands/set-root.js @@ -0,0 +1,17 @@ +'use strict'; + + +function SetRootCommand(params, canvas) { + + return { + args: [ params.element('element') ], + exec: function(element) { + canvas.setRootElement(element); + return element; + } + }; +} + +SetRootCommand.$inject = [ 'cli._params', 'canvas' ]; + +module.exports = SetRootCommand; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1595de2..73b3403 100644 --- a/package-lock.json +++ b/package-lock.json @@ -867,14 +867,14 @@ } }, "bpmn-js": { - "version": "8.10.0", - "resolved": "https://registry.npmjs.org/bpmn-js/-/bpmn-js-8.10.0.tgz", - "integrity": "sha512-NozeOi01qL0ZdVq8+5hWZcikyEvgrP1yzCBqlhSufJdHFsnEMBCwn2bJJ0B/6JgX+IBwy1sk/Uw+Ds8rQ8vfrw==", + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/bpmn-js/-/bpmn-js-9.0.2.tgz", + "integrity": "sha512-dl6sErP3tTBSJAvCGcu/v7xw+QCp8UCXSVlAoCA1lSrBkfdVOcHuxyy2svGPv4nJKOUMqFAK3xcemZYyztCwoA==", "dev": true, "requires": { "bpmn-moddle": "^7.1.2", "css.escape": "^1.5.1", - "diagram-js": "^7.8.2", + "diagram-js": "^8.1.2", "diagram-js-direct-editing": "^1.6.3", "ids": "^1.0.0", "inherits": "^2.0.4", @@ -1287,9 +1287,9 @@ "dev": true }, "diagram-js": { - "version": "7.8.2", - "resolved": "https://registry.npmjs.org/diagram-js/-/diagram-js-7.8.2.tgz", - "integrity": "sha512-+lzXUccgEYf9T5/1t2Y4MZyYirw47x8VEPyQ2RmDcZKO3m2iwEgyyFTOR7u6RuiVjusq7AnzgS+MVW0FhLd68A==", + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/diagram-js/-/diagram-js-8.1.2.tgz", + "integrity": "sha512-l0UWjWA9zcO3bwGg2C3sybNEWiICdXdkFy4JRjWdPyOcO00v3T0whuNhLwz9kaS5ht67awnPyKr+RWgsx3H0Rw==", "dev": true, "requires": { "css.escape": "^1.5.1", diff --git a/package.json b/package.json index 3fca68d..5242dde 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "author": "Nico Rehwaldt", "license": "MIT", "devDependencies": { - "bpmn-js": "^8.10.0", + "bpmn-js": "^9.0.2", "chai": "^4.3.0", "eslint": "^7.21.0", "eslint-plugin-bpmn-io": "^0.12.0", @@ -42,6 +42,6 @@ "min-dash": "^3.1.0" }, "peerDependencies": { - "bpmn-js": "^1.x || ^2.x || ^3.x || ^4.x || ^5.x || ^6.x || ^7.x || ^8.x" + "bpmn-js": "^1.x || ^2.x || ^3.x || ^4.x || ^5.x || ^6.x || ^7.x || ^8.x || ^9.x" } } diff --git a/resources/collapsed.bpmn b/resources/collapsed.bpmn new file mode 100644 index 0000000..0873912 --- /dev/null +++ b/resources/collapsed.bpmn @@ -0,0 +1,41 @@ + + + + + Flow_0yhvali + + + + Flow_1r6lyrj + + + + Flow_0yhvali + Flow_1r6lyrj + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/CliSpec.js b/test/spec/CliSpec.js index a357d9b..f3ca544 100644 --- a/test/spec/CliSpec.js +++ b/test/spec/CliSpec.js @@ -18,6 +18,7 @@ describe('cli', function() { var startDiagramXML = require('resources/start.bpmn'); var simpleDiagramXML = require('resources/simple.bpmn'); + var collapsedDiagramXML = require('resources/collapsed.bpmn'); var testModules = [ coreModule, @@ -214,6 +215,42 @@ describe('cli', function() { }); + describe('set root', function() { + + // given that + beforeEach(bootstrapModeler(collapsedDiagramXML, { + modules: testModules + })); + + + it('should set Root Element', inject(function(cli, canvas) { + + // given + var rootElement = cli.element('SubProcess_1_plane'); + + // when + cli.setRoot(rootElement); + + // then + expect(canvas.getRootElement()).to.eql(rootElement); + })); + + + it('should set Root Element using IDs', inject(function(cli, canvas) { + + // given + var rootElementId = 'SubProcess_1_plane'; + + // when + cli.setRoot(rootElementId); + + // then + expect(canvas.getRootElement().id).to.eql(rootElementId); + })); + + }); + + describe('help', function() { // given that From 8881843c1b339ea91ecff93d2dfde345a85a7df9 Mon Sep 17 00:00:00 2001 From: Martin Stamm Date: Mon, 28 Feb 2022 09:21:46 +0100 Subject: [PATCH 2/2] CI: integration test with `bpmn-js@8` --- .github/workflows/CI.yml | 6 ++++++ test/TestHelper.js | 32 +++++++++++++++++++++++++++++++- test/spec/CliSpec.js | 7 ++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0bd9649..826aae4 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,6 +7,9 @@ jobs: matrix: os: [ ubuntu-latest ] node-version: [ 14 ] + integration-deps: + - diagram-js@7.x bpmn-js@8.x + - "" # as defined in package.json runs-on: ${{ matrix.os }} @@ -28,5 +31,8 @@ jobs: ${{ runner.OS }}- - name: Install dependencies run: npm ci + - name: Install dependencies for integration test + if: ${{ matrix.integration-deps != '' }} + run: npm install ${{ matrix.integration-deps }} - name: Build run: npm run all diff --git a/test/TestHelper.js b/test/TestHelper.js index b1f0d24..dce0904 100644 --- a/test/TestHelper.js +++ b/test/TestHelper.js @@ -1,11 +1,41 @@ export * from 'bpmn-js/test/helper'; +import semver from 'semver'; + import { insertCSS } from 'bpmn-js/test/helper'; + // insert diagram.css insertCSS( 'diagram-js.css', require('diagram-js/assets/diagram-js.css') -); \ No newline at end of file +); + +if (bpmnJsSatisfies('>=9')) { + insertCSS( + 'bpmn-js.css', + require('bpmn-js/dist/assets/bpmn-js.css').default + ); +} + +/** + * Execute test only if currently installed bpmn-js is of given version. + * + * @param {string} versionRange + * @param {boolean} only + */ +export function withBpmnJs(versionRange, only = false) { + if (bpmnJsSatisfies(versionRange)) { + return only ? it.only : it; + } else { + return it.skip; + } +} + +function bpmnJsSatisfies(versionRange) { + const bpmnJsVersion = require('bpmn-js/package.json').version; + + return semver.satisfies(bpmnJsVersion, versionRange, { includePrerelease: true }); +} diff --git a/test/spec/CliSpec.js b/test/spec/CliSpec.js index f3ca544..9976d99 100644 --- a/test/spec/CliSpec.js +++ b/test/spec/CliSpec.js @@ -1,6 +1,7 @@ import { bootstrapModeler, - inject + inject, + withBpmnJs } from '../TestHelper'; import { @@ -223,7 +224,7 @@ describe('cli', function() { })); - it('should set Root Element', inject(function(cli, canvas) { + withBpmnJs('>=9')('should set Root Element', inject(function(cli, canvas) { // given var rootElement = cli.element('SubProcess_1_plane'); @@ -236,7 +237,7 @@ describe('cli', function() { })); - it('should set Root Element using IDs', inject(function(cli, canvas) { + withBpmnJs('>=9')('should set Root Element using IDs', inject(function(cli, canvas) { // given var rootElementId = 'SubProcess_1_plane';