Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(commands): add setRoot command #42

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ jobs:
matrix:
os: [ ubuntu-latest ]
node-version: [ 14 ]
integration-deps:
- [email protected] [email protected]
- "" # as defined in package.json

runs-on: ${{ matrix.os }}

Expand All @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 2 additions & 0 deletions lib/Initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
RedoCommand,
SaveCommand,
SetLabelCommand,
SetRootCommand,
UndoCommand,
RemoveShapeCommand,
RemoveConnectionCommand,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
17 changes: 17 additions & 0 deletions lib/commands/set-root.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"author": "Nico Rehwaldt<[email protected]>",
"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",
Expand All @@ -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"
}
}
41 changes: 41 additions & 0 deletions resources/collapsed.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0kpp76a" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0-alpha.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.16.0">
<bpmn:process id="Process_1iuh5bs" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_0yhvali</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_0yhvali" sourceRef="StartEvent_1" targetRef="SubProcess_1" />
<bpmn:endEvent id="Event_194iflk">
<bpmn:incoming>Flow_1r6lyrj</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1r6lyrj" sourceRef="SubProcess_1" targetRef="Event_194iflk" />
<bpmn:subProcess id="SubProcess_1">
<bpmn:incoming>Flow_0yhvali</bpmn:incoming>
<bpmn:outgoing>Flow_1r6lyrj</bpmn:outgoing>
</bpmn:subProcess>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1iuh5bs">
<bpmndi:BPMNEdge id="Flow_0yhvali_di" bpmnElement="Flow_0yhvali">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r6lyrj_di" bpmnElement="Flow_1r6lyrj">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_194iflk_di" bpmnElement="Event_194iflk">
<dc:Bounds x="432" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1j7cjqv_di" bpmnElement="SubProcess_1">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmndi:BPMNDiagram id="BPMNDiagram_02zcyi4">
<bpmndi:BPMNPlane id="BPMNPlane_0twaovm" bpmnElement="SubProcess_1" />
</bpmndi:BPMNDiagram>
</bpmn:definitions>
32 changes: 31 additions & 1 deletion test/TestHelper.js
Original file line number Diff line number Diff line change
@@ -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')
);
);

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 });
}
40 changes: 39 additions & 1 deletion test/spec/CliSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
bootstrapModeler,
inject
inject,
withBpmnJs
} from '../TestHelper';

import {
Expand All @@ -18,6 +19,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,
Expand Down Expand Up @@ -214,6 +216,42 @@ describe('cli', function() {
});


describe('set root', function() {

// given that
beforeEach(bootstrapModeler(collapsedDiagramXML, {
modules: testModules
}));


withBpmnJs('>=9')('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);
}));


withBpmnJs('>=9')('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
Expand Down