2018-04-02 19:01:53 +00:00
|
|
|
import TestContainer from 'mocha-test-container-support';
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import Diagram from 'diagram-js/lib/Diagram';
|
2016-03-16 22:11:05 +00:00
|
|
|
|
2018-04-05 07:47:37 +00:00
|
|
|
import ViewerDefaultExport from '../../';
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import Viewer from 'lib/Viewer';
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import inherits from 'inherits';
|
2016-02-25 13:07:23 +00:00
|
|
|
|
2019-04-04 14:17:43 +00:00
|
|
|
import {
|
2020-04-29 09:02:42 +00:00
|
|
|
createViewer
|
2019-07-19 11:49:24 +00:00
|
|
|
} from 'test/TestHelper';
|
|
|
|
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
describe('Viewer', function() {
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
var container;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2016-06-07 06:46:45 +00:00
|
|
|
container = TestContainer.get(this);
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should import simple process', function() {
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2017-11-23 08:48:21 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
var viewer = result.viewer;
|
2017-11-23 08:48:21 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
var definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
expect(definitions).to.eql(viewer._definitions);
|
|
|
|
});
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should re-import simple process', function() {
|
2015-02-17 11:03:27 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2015-02-17 11:03:27 +00:00
|
|
|
|
|
|
|
// given
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var viewer = result.viewer;
|
2015-02-17 11:03:27 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
// mimic re-import of same diagram
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2015-02-17 11:03:27 +00:00
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(result.warnings).to.be.empty;
|
2015-02-17 11:03:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
it('should be instance of Diagram', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(viewer).to.be.instanceof(Diagram);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-05 15:02:03 +00:00
|
|
|
describe('overlay support', function() {
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should allow to add overlays', function() {
|
2014-08-05 15:02:03 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-08-05 15:02:03 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
var overlays = viewer.get('overlays'),
|
|
|
|
elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(overlays).to.exist;
|
|
|
|
expect(elementRegistry).to.exist;
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
overlays.add('SubProcess_1', {
|
|
|
|
position: {
|
|
|
|
bottom: 0,
|
|
|
|
right: 0
|
|
|
|
},
|
|
|
|
html: '<div style="max-width: 50px">YUP GREAT STUFF!</div>'
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(overlays.get({ element: 'SubProcess_1' }).length).to.equal(1);
|
2014-08-05 15:02:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-10-26 22:52:10 +00:00
|
|
|
describe('editor actions support', function() {
|
|
|
|
|
|
|
|
it('should not ship per default', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer();
|
|
|
|
|
|
|
|
// when
|
|
|
|
var editorActions = viewer.get('editorActions', false);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(editorActions).not.to.exist;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
describe('error handling', function() {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
function expectMessage(e, expectedMessage) {
|
|
|
|
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(e).to.exist;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
if (expectedMessage instanceof RegExp) {
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(e.message).to.match(expectedMessage);
|
2015-02-17 09:55:28 +00:00
|
|
|
} else {
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(e.message).to.equal(expectedMessage);
|
2015-02-17 09:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectWarnings(warnings, expected) {
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(warnings.length).to.equal(expected.length);
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
warnings.forEach(function(w, idx) {
|
|
|
|
expectMessage(w, expected[idx]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle non-bpmn input', function() {
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
var xml = 'invalid stuff';
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
2014-04-03 19:20:13 +00:00
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).to.exist;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
expectMessage(err, /missing start tag/);
|
2014-04-03 19:20:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-23 14:31:28 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle invalid BPMNPlane#bpmnElement', function() {
|
2014-05-23 14:31:28 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn');
|
2014-05-23 14:31:28 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).not.to.exist;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
expectWarnings(warnings, [
|
|
|
|
'unresolved reference <Collaboration_2>',
|
|
|
|
'no bpmnElement referenced in <bpmndi:BPMNPlane id="BPMNPlane_1" />',
|
|
|
|
'correcting missing bpmnElement ' +
|
|
|
|
'on <bpmndi:BPMNPlane id="BPMNPlane_1" /> ' +
|
|
|
|
'to <bpmn:Process id="Process_1" />'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle invalid namespaced element', function() {
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/error/categoryValue.bpmn');
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
2014-10-28 14:09:17 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).not.to.exist;
|
2014-10-28 14:09:17 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
expectWarnings(warnings, [
|
|
|
|
/unparsable content <categoryValue> detected/,
|
|
|
|
'unresolved reference <sid-afd7e63e-916e-4bd0-a9f0-98cbff749193>'
|
|
|
|
]);
|
2014-05-23 14:31:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-30 17:04:40 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle missing namespace', function() {
|
2014-06-30 17:04:40 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/error/missing-namespace.bpmn');
|
2014-06-30 17:04:40 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).to.exist;
|
2017-11-15 13:03:36 +00:00
|
|
|
expect(err.message).to.eql('failed to parse document as <bpmn:Definitions>');
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
expect(warnings).to.have.length(1);
|
|
|
|
expect(warnings[0].message).to.match(/unparsable content <definitions> detected/);
|
2016-07-26 08:53:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle duplicate ids', function() {
|
2016-07-26 08:53:45 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/error/duplicate-ids.bpmn');
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
2016-07-26 08:53:45 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
expectWarnings(warnings, [
|
|
|
|
/duplicate ID <test>/
|
|
|
|
]);
|
2014-06-30 17:04:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-02-10 18:33:50 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should throw error due to missing diagram', function() {
|
2020-02-10 18:33:50 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/empty-definitions.bpmn');
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
2020-02-10 18:33:50 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err.message).to.eql('no diagram to display');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
|
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
describe('dependency injection', function() {
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should provide self as <bpmnjs>', function() {
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var viewer = result.viewer;
|
|
|
|
var err = result.error;
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(viewer.get('bpmnjs')).to.equal(viewer);
|
|
|
|
expect(err).not.to.exist;
|
2014-06-17 09:19:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
it('should allow Diagram#get before import', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
// then
|
|
|
|
var eventBus = viewer.get('eventBus');
|
|
|
|
|
|
|
|
expect(eventBus).to.exist;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should keep references to services across re-import', function() {
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var someXML = require('../fixtures/bpmn/simple.bpmn'),
|
|
|
|
otherXML = require('../fixtures/bpmn/basic.bpmn');
|
|
|
|
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var eventBus = viewer.get('eventBus'),
|
|
|
|
canvas = viewer.get('canvas');
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(someXML).then(function() {
|
2016-03-16 22:11:05 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(viewer.get('canvas')).to.equal(canvas);
|
|
|
|
expect(viewer.get('eventBus')).to.equal(eventBus);
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(otherXML);
|
|
|
|
}).then(function() {
|
2016-03-16 22:11:05 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(viewer.get('canvas')).to.equal(canvas);
|
|
|
|
expect(viewer.get('eventBus')).to.equal(eventBus);
|
2016-03-16 22:11:05 +00:00
|
|
|
});
|
|
|
|
});
|
2014-06-17 09:19:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
describe('creation', function() {
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
var testModules = [
|
|
|
|
{ logger: [ 'type', function() { this.called = true; } ] }
|
|
|
|
];
|
|
|
|
|
|
|
|
// given
|
2015-11-24 11:53:18 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-08-01 05:55:47 +00:00
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
var viewer;
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
viewer.destroy();
|
|
|
|
});
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should override default modules', function() {
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// given
|
2014-12-18 08:45:45 +00:00
|
|
|
viewer = new Viewer({ container: container, modules: testModules });
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).catch(function(err) {
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(err.message).to.equal('No provider for "bpmnImporter"! (Resolving: bpmnImporter)');
|
2014-08-01 05:55:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should add module to default modules', function() {
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// given
|
2014-12-18 08:45:45 +00:00
|
|
|
viewer = new Viewer({ container: container, additionalModules: testModules });
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
var logger = viewer.get('logger');
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(logger.called).to.be.true;
|
2014-08-01 05:55:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
|
|
|
|
it('should use custom size and position', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer = new Viewer({
|
|
|
|
container: container,
|
|
|
|
width: 200,
|
|
|
|
height: 100,
|
|
|
|
position: 'fixed'
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2017-11-20 13:48:38 +00:00
|
|
|
expect(viewer._container.style.position).to.equal('fixed');
|
|
|
|
expect(viewer._container.style.width).to.equal('200px');
|
|
|
|
expect(viewer._container.style.height).to.equal('100px');
|
2014-12-18 08:45:45 +00:00
|
|
|
});
|
|
|
|
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
var camundaPackage = require('../fixtures/json/model/camunda');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should provide custom moddle extensions', function() {
|
2015-02-12 14:50:23 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/extension/camunda.bpmn');
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
viewer = new Viewer({
|
|
|
|
container: container,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
var taskShape = elementRegistry.get('send'),
|
|
|
|
sendTask = taskShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(sendTask).to.exist;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
var extensionElements = sendTask.extensionElements;
|
|
|
|
|
|
|
|
// receive task should be moddle extended
|
2016-02-25 13:55:00 +00:00
|
|
|
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
// extension elements should provide typed element
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(extensionElements).to.exist;
|
2017-11-15 13:03:36 +00:00
|
|
|
expect(extensionElements.values).to.exist;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
2017-11-15 13:03:36 +00:00
|
|
|
expect(extensionElements.values).to.have.length(1);
|
2016-02-25 13:55:00 +00:00
|
|
|
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true;
|
2015-02-12 14:50:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should allow to add default custom moddle extensions', function() {
|
2016-02-18 00:16:10 +00:00
|
|
|
|
2016-02-25 13:07:23 +00:00
|
|
|
// given
|
2016-02-18 00:16:10 +00:00
|
|
|
var xml = require('../fixtures/bpmn/extension/custom.bpmn'),
|
|
|
|
additionalModdleDescriptors = {
|
|
|
|
custom: require('../fixtures/json/model/custom')
|
|
|
|
};
|
|
|
|
|
2016-02-25 13:07:23 +00:00
|
|
|
function CustomViewer(options) {
|
|
|
|
Viewer.call(this, options);
|
|
|
|
}
|
2016-02-18 00:16:10 +00:00
|
|
|
|
2016-02-25 13:07:23 +00:00
|
|
|
inherits(CustomViewer, Viewer);
|
|
|
|
|
|
|
|
CustomViewer.prototype._moddleExtensions = additionalModdleDescriptors;
|
|
|
|
|
|
|
|
viewer = new CustomViewer({
|
2016-02-18 00:16:10 +00:00
|
|
|
container: container,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2016-02-18 00:16:10 +00:00
|
|
|
|
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
var taskShape = elementRegistry.get('send'),
|
|
|
|
sendTask = taskShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(sendTask).to.exist;
|
|
|
|
|
|
|
|
var extensionElements = sendTask.extensionElements;
|
|
|
|
|
|
|
|
// receive task should be moddle extended
|
2016-02-25 13:55:00 +00:00
|
|
|
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true;
|
|
|
|
expect(sendTask.$instanceOf('custom:ServiceTaskGroup')).to.be.true;
|
2016-02-18 00:16:10 +00:00
|
|
|
|
|
|
|
// extension elements should provide typed element
|
|
|
|
expect(extensionElements).to.exist;
|
|
|
|
|
|
|
|
expect(extensionElements.values.length).to.equal(2);
|
2016-02-25 13:55:00 +00:00
|
|
|
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true;
|
2016-02-18 00:16:10 +00:00
|
|
|
|
2016-02-25 13:55:00 +00:00
|
|
|
expect(extensionElements.values[1].$instanceOf('custom:CustomSendElement')).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should allow user to override default custom moddle extensions', function() {
|
2016-02-25 13:55:00 +00:00
|
|
|
|
|
|
|
// given
|
2018-04-02 19:01:53 +00:00
|
|
|
var xml = require('../fixtures/bpmn/extension/custom-override.bpmn');
|
|
|
|
|
|
|
|
var additionalModdleDescriptors = {
|
|
|
|
custom: require('../fixtures/json/model/custom')
|
|
|
|
};
|
|
|
|
|
|
|
|
var customOverride = require('../fixtures/json/model/custom-override');
|
2016-02-25 13:55:00 +00:00
|
|
|
|
|
|
|
function CustomViewer(options) {
|
|
|
|
Viewer.call(this, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
inherits(CustomViewer, Viewer);
|
|
|
|
|
|
|
|
CustomViewer.prototype._moddleExtensions = additionalModdleDescriptors;
|
|
|
|
|
|
|
|
viewer = new CustomViewer({
|
|
|
|
container: container,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage,
|
|
|
|
custom : customOverride
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2016-02-25 13:55:00 +00:00
|
|
|
|
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
var taskShape = elementRegistry.get('send'),
|
|
|
|
sendTask = taskShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(sendTask).to.exist;
|
|
|
|
|
|
|
|
var extensionElements = sendTask.extensionElements;
|
|
|
|
|
|
|
|
// receive task should be moddle extended
|
|
|
|
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.be.true;
|
|
|
|
expect(sendTask.$instanceOf('custom:ServiceTaskGroupOverride')).to.be.true;
|
|
|
|
|
|
|
|
// extension elements should provide typed element
|
|
|
|
expect(extensionElements).to.exist;
|
|
|
|
|
|
|
|
expect(extensionElements.values.length).to.equal(2);
|
|
|
|
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true;
|
|
|
|
|
|
|
|
expect(extensionElements.values[1].$instanceOf('custom:CustomSendElementOverride')).to.be.true;
|
2016-02-18 00:16:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-08 13:41:58 +00:00
|
|
|
describe('configuration', function() {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should configure Canvas', function() {
|
2016-01-08 13:41:58 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({
|
|
|
|
container: container,
|
|
|
|
canvas: {
|
|
|
|
deferUpdate: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2016-01-08 13:41:58 +00:00
|
|
|
|
|
|
|
var canvasConfig = viewer.get('config.canvas');
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(canvasConfig.deferUpdate).to.be.true;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2019-04-12 09:57:57 +00:00
|
|
|
describe('container', function() {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should attach if provided', function() {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2019-04-12 09:57:57 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer = new Viewer({ container: container });
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2019-04-12 09:57:57 +00:00
|
|
|
expect(viewer._container.parentNode).to.equal(container);
|
|
|
|
});
|
2017-01-27 09:09:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should not attach if absent', function() {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2019-04-12 09:57:57 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2019-04-12 09:57:57 +00:00
|
|
|
var viewer = new Viewer();
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2019-04-12 09:57:57 +00:00
|
|
|
expect(viewer._container.parentNode).to.equal(null);
|
|
|
|
});
|
2017-01-27 09:09:34 +00:00
|
|
|
});
|
2019-04-12 09:57:57 +00:00
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
});
|
2019-04-12 09:57:57 +00:00
|
|
|
|
2016-01-08 13:41:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
describe('#importXML', function() {
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should emit <import.*> events', function() {
|
2016-03-17 08:39:43 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'import.parse.start',
|
|
|
|
'import.parse.complete',
|
|
|
|
'import.render.start',
|
|
|
|
'import.render.complete',
|
|
|
|
'import.done'
|
|
|
|
], function(e) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2016-03-17 08:39:43 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'import.parse.start', [ 'xml' ] ],
|
2020-04-27 05:57:45 +00:00
|
|
|
[ 'import.parse.complete', [ 'error', 'definitions', 'elementsById', 'references', 'warnings', 'context' ] ],
|
2016-03-17 08:39:43 +00:00
|
|
|
[ 'import.render.start', [ 'definitions' ] ],
|
|
|
|
[ 'import.render.complete', [ 'error', 'warnings' ] ],
|
|
|
|
[ 'import.done', [ 'error', 'warnings' ] ]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-17 09:42:14 +00:00
|
|
|
|
|
|
|
it('should work without callback', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml);
|
|
|
|
|
|
|
|
// then
|
|
|
|
viewer.on('import.done', function(event) {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
describe('multiple BPMNDiagram elements', function() {
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 11:41:54 +00:00
|
|
|
var multipleXML = require('../fixtures/bpmn/multiple-diagrams.bpmn');
|
2019-04-04 14:17:43 +00:00
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should import default without bpmnDiagram specified', function() {
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, multipleXML).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(err).not.to.exist;
|
2019-04-12 09:56:29 +00:00
|
|
|
});
|
|
|
|
});
|
2019-04-04 14:17:43 +00:00
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should import bpmnDiagram specified by id', function() {
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, multipleXML, 'BpmnDiagram_2').then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
2019-04-12 09:56:29 +00:00
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(err).not.to.exist;
|
2019-04-12 09:56:29 +00:00
|
|
|
});
|
2019-04-04 14:17:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle diagram not found', function() {
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/multiple-diagrams.bpmn');
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml, 'Diagram_IDontExist').then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('BPMNDiagram <Diagram_IDontExist> not found');
|
|
|
|
});
|
2019-04-04 14:17:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
describe('without callback', function() {
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
it('should open default', function(done) {
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
2019-04-04 14:17:43 +00:00
|
|
|
|
2019-04-12 09:56:29 +00:00
|
|
|
// when
|
2019-04-12 11:41:54 +00:00
|
|
|
viewer.importXML(multipleXML);
|
2019-04-12 09:56:29 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
viewer.on('import.done', function(event) {
|
2019-06-27 15:13:19 +00:00
|
|
|
done(event.error);
|
2019-04-12 09:56:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should open specified BPMNDiagram', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
// when
|
2019-06-27 15:13:19 +00:00
|
|
|
viewer.importXML(multipleXML, 'BpmnDiagram_2');
|
2019-04-12 09:56:29 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
viewer.on('import.done', function(event) {
|
2019-06-27 15:13:19 +00:00
|
|
|
done(event.error);
|
2019-04-12 09:56:29 +00:00
|
|
|
});
|
|
|
|
});
|
2019-04-04 14:17:43 +00:00
|
|
|
|
|
|
|
});
|
2019-04-12 09:56:29 +00:00
|
|
|
|
2019-04-04 14:17:43 +00:00
|
|
|
});
|
|
|
|
|
2016-03-17 08:39:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-06-27 15:15:57 +00:00
|
|
|
describe('#importDefinitions', function() {
|
|
|
|
|
|
|
|
describe('single diagram', function() {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn'),
|
|
|
|
viewer,
|
|
|
|
definitions;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
return createViewer(container, Viewer, xml, null).then(function(result) {
|
|
|
|
|
|
|
|
var error = result.error;
|
|
|
|
var tmpViewer = result.viewer;
|
|
|
|
|
2019-06-27 15:15:57 +00:00
|
|
|
if (error) {
|
2020-04-29 09:02:42 +00:00
|
|
|
throw error;
|
2019-06-27 15:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
definitions = tmpViewer.getDefinitions();
|
|
|
|
|
|
|
|
tmpViewer.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
viewer = new Viewer({ container: container });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
viewer.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should emit <import.*> events', function() {
|
2019-06-27 15:15:57 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'import.parse.start',
|
|
|
|
'import.parse.complete',
|
|
|
|
'import.render.start',
|
|
|
|
'import.render.complete',
|
|
|
|
'import.done'
|
|
|
|
], function(e) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2019-06-27 15:15:57 +00:00
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importDefinitions(definitions).then(function() {
|
2019-06-27 15:15:57 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'import.render.start', [ 'definitions' ] ],
|
|
|
|
[ 'import.render.complete', [ 'error', 'warnings' ] ]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should work without callback', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
viewer.on('import.render.complete', function(context) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2019-06-27 15:15:57 +00:00
|
|
|
// then
|
|
|
|
done(context.error);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('multiple BPMNDiagram elements', function() {
|
|
|
|
|
|
|
|
var multipleXML = require('../fixtures/bpmn/multiple-diagrams.bpmn'),
|
|
|
|
viewer,
|
|
|
|
definitions;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
beforeEach(function() {
|
|
|
|
return createViewer(container, Viewer, multipleXML).then(function(result) {
|
|
|
|
|
|
|
|
var error = result.error;
|
|
|
|
var tmpViewer = result.viewer;
|
|
|
|
|
2019-06-27 15:15:57 +00:00
|
|
|
if (error) {
|
2020-04-29 09:02:42 +00:00
|
|
|
throw error;
|
2019-06-27 15:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
definitions = tmpViewer.getDefinitions();
|
|
|
|
|
|
|
|
tmpViewer.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
viewer = new Viewer({ container: container });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
viewer.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should import default without bpmnDiagram specified', function() {
|
2019-06-27 15:15:57 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importDefinitions(definitions);
|
2019-06-27 15:15:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should import bpmnDiagram specified by id', function() {
|
2019-06-27 15:15:57 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importDefinitions(definitions, 'BpmnDiagram_2');
|
2019-06-27 15:15:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should handle diagram not found', function() {
|
2019-06-27 15:15:57 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importDefinitions(definitions, 'Diagram_IDontExist').catch(function(err) {
|
2019-06-27 15:15:57 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('BPMNDiagram <Diagram_IDontExist> not found');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('without callback', function() {
|
|
|
|
|
|
|
|
it('should open default', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
viewer.on('import.render.complete', function(event) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
done(event.error);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should open specified BPMNDiagram', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
viewer.on('import.render.complete', function(event) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
done(event.error);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions, 'BpmnDiagram_2');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-11 12:05:26 +00:00
|
|
|
describe('#open', function() {
|
|
|
|
|
2019-04-16 12:53:06 +00:00
|
|
|
var multipleXMLSimple = require('../fixtures/bpmn/multiple-diagrams.bpmn'),
|
|
|
|
multipleXMLOverlappingDI = require('../fixtures/bpmn/multiple-diagrams-overlapping-di.bpmn'),
|
|
|
|
multipleXMLWithLaneSet = require('../fixtures/bpmn/multiple-diagrams-lanesets.bpmn'),
|
|
|
|
diagram1 = 'BpmnDiagram_1',
|
|
|
|
diagram2 = 'BpmnDiagram_2';
|
2019-04-12 11:41:54 +00:00
|
|
|
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should open the first diagram if id was not provided', function() {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var viewer, renderedDiagram;
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// when
|
|
|
|
return createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var err = result.error;
|
|
|
|
viewer = result.viewer;
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(err).not.to.exist;
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di;
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open();
|
|
|
|
}).then(function() {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram);
|
2019-04-11 12:05:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should switch between diagrams', function() {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
2019-04-12 11:05:59 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
2019-04-12 11:05:59 +00:00
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
2019-04-12 11:05:59 +00:00
|
|
|
|
2019-04-12 11:41:54 +00:00
|
|
|
expect(warnings).to.be.empty;
|
2019-04-12 11:05:59 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
definitions = viewer.getDefinitions();
|
2019-04-12 11:41:54 +00:00
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open(diagram2);
|
|
|
|
}).then(function(result) {
|
2019-04-12 11:41:54 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
var warnings = result.warnings;
|
2019-04-12 11:05:59 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(warnings).to.be.empty;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(definitions).to.equal(viewer.getDefinitions());
|
2019-04-15 11:22:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
2019-04-12 11:42:29 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(elementRegistry.get('Task_A')).to.not.exist;
|
|
|
|
expect(elementRegistry.get('Task_B')).to.exist;
|
2019-04-12 11:05:59 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should switch between diagrams with overlapping DI', function() {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
2019-04-15 11:23:21 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, multipleXMLOverlappingDI, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
2019-04-15 11:23:21 +00:00
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(err).not.to.exist;
|
2019-04-15 11:23:21 +00:00
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
definitions = viewer.getDefinitions();
|
2019-04-15 11:23:21 +00:00
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open(diagram2);
|
|
|
|
}).then(function(result) {
|
2019-04-15 11:23:21 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var warnings = result.warnings;
|
2019-04-15 11:23:21 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(warnings).to.be.empty;
|
2019-04-15 11:23:21 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(definitions).to.equal(viewer.getDefinitions());
|
2019-04-15 11:23:21 +00:00
|
|
|
});
|
2019-04-16 12:53:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should switch between diagrams with laneSets', function() {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, multipleXMLWithLaneSet, diagram2).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(err).not.to.exist;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
definitions = viewer.getDefinitions();
|
2019-04-16 12:53:06 +00:00
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open(diagram1);
|
|
|
|
}).then(function(result) {
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
var warnings = result.warnings;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(warnings).to.be.empty;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(definitions).to.equal(viewer.getDefinitions());
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(elementRegistry.get('Task_A')).to.exist;
|
|
|
|
expect(elementRegistry.get('Task_B')).to.not.exist;
|
2019-04-16 12:53:06 +00:00
|
|
|
});
|
2019-04-15 11:23:21 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should complete with error if xml was not imported', function() {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer();
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open().catch(function(err) {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('no XML imported');
|
|
|
|
|
|
|
|
var definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.not.exist;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should open with error if diagram does not exist', function() {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
2019-04-11 12:05:26 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
2019-04-11 12:05:26 +00:00
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
expect(err).not.to.exist;
|
2019-04-16 12:53:06 +00:00
|
|
|
|
2019-04-11 12:05:26 +00:00
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
definitions = viewer.getDefinitions();
|
2019-04-11 12:05:26 +00:00
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open('Diagram_IDontExist');
|
|
|
|
}).catch(function(err) {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('BPMNDiagram <Diagram_IDontExist> not found');
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// definitions stay the same
|
|
|
|
expect(viewer.getDefinitions()).to.eql(definitions);
|
2019-04-11 12:05:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should emit <import.*> events', function() {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(multipleXMLSimple, diagram1).then(function(result) {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2019-04-12 11:41:54 +00:00
|
|
|
// given
|
2019-04-11 12:05:26 +00:00
|
|
|
viewer.on([
|
|
|
|
'import.parse.start',
|
|
|
|
'import.parse.complete',
|
|
|
|
'import.render.start',
|
|
|
|
'import.render.complete',
|
|
|
|
'import.done'
|
|
|
|
], function(e) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2019-04-11 12:05:26 +00:00
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2019-04-12 11:41:54 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.open(diagram2);
|
|
|
|
}).then(function() {
|
2019-04-11 12:05:26 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'import.render.start', [ 'definitions' ] ],
|
|
|
|
[ 'import.render.complete', [ 'error', 'warnings' ] ]
|
|
|
|
]);
|
2019-04-11 12:05:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-06-12 07:27:00 +00:00
|
|
|
describe('#saveXML', function() {
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should export XML', function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.saveXML({ format: true });
|
|
|
|
}).then(function(result) {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var xml = result.xml;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(xml).to.contain('<?xml version="1.0" encoding="UTF-8"?>');
|
|
|
|
expect(xml).to.contain('<bpmn2:definitions');
|
|
|
|
expect(xml).to.contain(' ');
|
2018-06-12 07:27:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should emit <saveXML.*> events', function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var viewer;
|
|
|
|
var events = [];
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'saveXML.start',
|
|
|
|
'saveXML.serialized',
|
|
|
|
'saveXML.done'
|
|
|
|
], function(e) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2018-06-12 07:27:00 +00:00
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml);
|
|
|
|
}).then(function(result) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// when
|
|
|
|
return viewer.saveXML();
|
|
|
|
}).then(function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'saveXML.start', [ 'definitions' ] ],
|
|
|
|
[ 'saveXML.serialized', ['error', 'xml' ] ],
|
|
|
|
[ 'saveXML.done', ['error', 'xml' ] ]
|
|
|
|
]);
|
2018-06-12 07:27:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#saveSVG', function() {
|
|
|
|
|
|
|
|
function currentTime() {
|
|
|
|
return new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
function validSVG(svg) {
|
|
|
|
var expectedStart = '<?xml version="1.0" encoding="utf-8"?>';
|
|
|
|
var expectedEnd = '</svg>';
|
|
|
|
|
|
|
|
expect(svg.indexOf(expectedStart)).to.equal(0);
|
|
|
|
expect(svg.indexOf(expectedEnd)).to.equal(svg.length - expectedEnd.length);
|
|
|
|
|
|
|
|
// ensure correct rendering of SVG contents
|
|
|
|
expect(svg.indexOf('undefined')).to.equal(-1);
|
|
|
|
|
|
|
|
// expect header to be written only once
|
|
|
|
expect(svg.indexOf('<svg width="100%" height="100%">')).to.equal(-1);
|
|
|
|
expect(svg.indexOf('<g class="viewport"')).to.equal(-1);
|
|
|
|
|
|
|
|
var parser = new DOMParser();
|
|
|
|
var svgNode = parser.parseFromString(svg, 'image/svg+xml');
|
|
|
|
|
|
|
|
// [comment, <!DOCTYPE svg>, svg]
|
|
|
|
expect(svgNode.childNodes).to.have.length(3);
|
|
|
|
|
|
|
|
// no error body
|
|
|
|
expect(svgNode.body).not.to.exist;
|
|
|
|
|
|
|
|
// FIXME(nre): make matcher
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should export svg', function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
if (err) {
|
2020-04-29 09:02:42 +00:00
|
|
|
throw err;
|
2018-06-12 07:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.saveSVG();
|
|
|
|
}).then(function(result) {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var svg = result.svg;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(validSVG(svg)).to.be.true;
|
2018-06-12 07:27:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should export huge svg', function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
this.timeout(5000);
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/complex.bpmn');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
if (err) {
|
2020-04-29 09:02:42 +00:00
|
|
|
throw err;
|
2018-06-12 07:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.saveSVG();
|
|
|
|
}).then(function(result) {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var svg = result.svg;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var time = currentTime();
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(validSVG(svg)).to.be.true;
|
|
|
|
|
|
|
|
// no svg export should not take too long
|
|
|
|
expect(currentTime() - time).to.be.below(1000);
|
2018-06-12 07:27:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should remove outer-makers on export', function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
function appendTestRect(svgDoc) {
|
|
|
|
var rect = document.createElementNS(svgDoc.namespaceURI, 'rect');
|
|
|
|
rect.setAttribute('class', 'outer-bound-marker');
|
|
|
|
rect.setAttribute('width', 500);
|
|
|
|
rect.setAttribute('height', 500);
|
|
|
|
rect.setAttribute('x', 10000);
|
|
|
|
rect.setAttribute('y', 10000);
|
|
|
|
svgDoc.appendChild(rect);
|
|
|
|
}
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
if (err) {
|
2020-04-29 09:02:42 +00:00
|
|
|
throw err;
|
2018-06-12 07:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var svgDoc = viewer._container.childNodes[1].childNodes[1];
|
|
|
|
|
|
|
|
appendTestRect(svgDoc);
|
|
|
|
appendTestRect(svgDoc);
|
|
|
|
|
|
|
|
expect(svgDoc.querySelectorAll('.outer-bound-marker')).to.exist;
|
|
|
|
|
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.saveSVG();
|
|
|
|
}).then(function(result) {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var svg = result.svg;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
|
|
svgDoc.innerHTML = svg;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(validSVG(svg)).to.be.true;
|
|
|
|
expect(svgDoc.querySelector('.outer-bound-marker')).to.be.null;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should emit <saveSVG.*> events', function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
var viewer;
|
|
|
|
var events = [];
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
2018-06-12 07:27:00 +00:00
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'saveSVG.start',
|
|
|
|
'saveSVG.done'
|
|
|
|
], function(e) {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2018-06-12 07:27:00 +00:00
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml);
|
|
|
|
}).then(function() {
|
2019-08-19 08:39:20 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// when
|
|
|
|
return viewer.saveSVG();
|
|
|
|
}).then(function() {
|
2018-06-12 07:27:00 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'saveSVG.start', [ ] ],
|
|
|
|
[ 'saveSVG.done', ['error', 'svg' ] ]
|
|
|
|
]);
|
2018-06-12 07:27:00 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-08 13:41:58 +00:00
|
|
|
describe('#on', function() {
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should fire with given three', function() {
|
2016-01-08 13:41:58 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.on('foo', 1000, function() {
|
|
|
|
return 'bar';
|
|
|
|
}, viewer);
|
|
|
|
|
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function() {
|
2016-01-08 13:41:58 +00:00
|
|
|
var eventBus = viewer.get('eventBus');
|
|
|
|
|
|
|
|
var result = eventBus.fire('foo');
|
|
|
|
|
|
|
|
expect(result).to.equal('bar');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-02-22 10:47:25 +00:00
|
|
|
describe('#off', function() {
|
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should remove listener permanently', function() {
|
2016-02-16 09:31:12 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var handler = function() {
|
|
|
|
return 'bar';
|
|
|
|
};
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
viewer.on('foo', 1000, handler);
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.off('foo');
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
// then
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function() {
|
2016-02-16 09:31:12 +00:00
|
|
|
var eventBus = viewer.get('eventBus');
|
|
|
|
|
|
|
|
var result = eventBus.fire('foo');
|
|
|
|
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
});
|
|
|
|
});
|
2016-02-22 10:47:25 +00:00
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should remove listener on existing diagram instance', function() {
|
2016-02-16 09:31:12 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var handler = function() {
|
|
|
|
return 'bar';
|
|
|
|
};
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
viewer.on('foo', 1000, handler);
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
// when
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function() {
|
2016-02-16 09:31:12 +00:00
|
|
|
var eventBus = viewer.get('eventBus');
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
// when
|
|
|
|
viewer.off('foo', handler);
|
2016-02-22 10:47:25 +00:00
|
|
|
|
2016-02-16 09:31:12 +00:00
|
|
|
var result = eventBus.fire('foo');
|
|
|
|
|
|
|
|
expect(result).not.to.exist;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-02-22 10:47:25 +00:00
|
|
|
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
describe('#destroy', function() {
|
|
|
|
|
|
|
|
it('should remove traces in document tree', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({
|
|
|
|
container: container
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.destroy();
|
|
|
|
|
|
|
|
// then
|
2017-11-20 13:48:38 +00:00
|
|
|
expect(viewer._container.parentNode).not.to.exist;
|
2014-12-18 08:45:45 +00:00
|
|
|
});
|
|
|
|
|
2014-08-01 05:55:47 +00:00
|
|
|
});
|
|
|
|
|
2017-01-27 09:09:34 +00:00
|
|
|
|
|
|
|
describe('#attachTo', function() {
|
2017-11-23 10:00:23 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should attach the viewer', function() {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer = new Viewer();
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2017-11-23 10:00:23 +00:00
|
|
|
// assume
|
|
|
|
expect(viewer._container.parentNode).not.to.exist;
|
|
|
|
|
2017-12-07 10:58:41 +00:00
|
|
|
var resizedSpy = sinon.spy();
|
|
|
|
|
|
|
|
viewer.on('canvas.resized', resizedSpy);
|
|
|
|
|
2017-11-23 10:00:23 +00:00
|
|
|
// when
|
2017-01-27 09:09:34 +00:00
|
|
|
viewer.attachTo(container);
|
2017-11-23 10:00:23 +00:00
|
|
|
|
|
|
|
// then
|
2017-11-20 13:48:38 +00:00
|
|
|
expect(viewer._container.parentNode).to.equal(container);
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2017-12-07 10:58:41 +00:00
|
|
|
// should trigger resized
|
|
|
|
expect(resizedSpy).to.have.been.called;
|
2017-01-27 09:09:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#detach', function() {
|
2017-11-23 10:00:23 +00:00
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should detach the viewer', function() {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2017-01-27 09:09:34 +00:00
|
|
|
|
2017-11-23 10:00:23 +00:00
|
|
|
// assume
|
2017-11-20 13:48:38 +00:00
|
|
|
expect(viewer._container.parentNode).to.equal(container);
|
2017-11-23 10:00:23 +00:00
|
|
|
|
|
|
|
// when
|
2017-01-27 09:09:34 +00:00
|
|
|
viewer.detach();
|
2017-11-23 10:00:23 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(viewer._container.parentNode).not.to.exist;
|
2017-01-27 09:09:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-11-23 10:00:23 +00:00
|
|
|
|
2018-04-05 07:47:37 +00:00
|
|
|
|
2019-04-16 06:59:33 +00:00
|
|
|
describe('#clear', function() {
|
|
|
|
|
2019-09-20 10:55:20 +00:00
|
|
|
it('should NOT clear if no diagram', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var eventBus = viewer.get('eventBus');
|
|
|
|
|
|
|
|
var spy = sinon.spy();
|
|
|
|
|
|
|
|
eventBus.on('diagram.clear', spy);
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.clear();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(spy).not.to.have.been.called;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-16 06:59:33 +00:00
|
|
|
it('should not throw if diagram is already empty', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
function clearDiagram() {
|
|
|
|
viewer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(clearDiagram).to.not.throw();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
it('should remove di property', function() {
|
2019-04-16 06:59:33 +00:00
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer = new Viewer({ container: container }),
|
|
|
|
elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
return viewer.importXML(xml).then(function(result) {
|
2019-04-16 06:59:33 +00:00
|
|
|
|
|
|
|
var elements = elementRegistry.getAll();
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.clear();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(elements.some(function(el) {
|
|
|
|
return el && el.businessObject && el.businessObject.di;
|
|
|
|
}), 'at least one element still has di').to.be.false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2018-04-05 07:47:37 +00:00
|
|
|
it('default export', function() {
|
|
|
|
expect(ViewerDefaultExport).to.equal(Viewer);
|
|
|
|
});
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
|
|
|
|
describe('Legacy callback support', function() {
|
|
|
|
|
|
|
|
describe('#importXML', function() {
|
|
|
|
|
|
|
|
it('should emit <import.*> events', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'import.parse.start',
|
|
|
|
'import.parse.complete',
|
|
|
|
'import.render.start',
|
|
|
|
'import.render.complete',
|
|
|
|
'import.done'
|
|
|
|
], function(e) {
|
|
|
|
|
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'import.parse.start', [ 'xml' ] ],
|
2020-04-27 05:57:45 +00:00
|
|
|
[ 'import.parse.complete', ['error', 'definitions', 'elementsById', 'references', 'warnings', 'context' ] ],
|
2020-04-29 09:02:42 +00:00
|
|
|
[ 'import.render.start', [ 'definitions' ] ],
|
|
|
|
[ 'import.render.complete', [ 'error', 'warnings' ] ],
|
|
|
|
[ 'import.done', [ 'error', 'warnings' ] ]
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-27 05:57:45 +00:00
|
|
|
|
|
|
|
it('should emit <import.parse.complete> event', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'import.parse.complete'
|
|
|
|
], function(event) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
var context = event.context;
|
|
|
|
|
|
|
|
expect(context).to.exist;
|
|
|
|
|
|
|
|
expect(context.warnings).to.equal(event.warnings);
|
|
|
|
expect(context.elementsById).to.equal(event.elementsById);
|
|
|
|
expect(context.references).to.equal(event.references);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
return viewer.importXML(xml);
|
|
|
|
});
|
|
|
|
|
2020-04-29 09:02:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#importDefinitions', function() {
|
|
|
|
|
|
|
|
describe('single diagram', function() {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn'),
|
|
|
|
viewer,
|
|
|
|
definitions;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
return createViewer(container, Viewer, xml, null).then(function(result) {
|
|
|
|
|
|
|
|
var error = result.error;
|
|
|
|
var tmpViewer = result.viewer;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
definitions = tmpViewer.getDefinitions();
|
|
|
|
|
|
|
|
tmpViewer.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
viewer = new Viewer({ container: container });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
viewer.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should emit <import.*> events', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'import.parse.start',
|
|
|
|
'import.parse.complete',
|
|
|
|
'import.render.start',
|
|
|
|
'import.render.complete',
|
|
|
|
'import.done'
|
|
|
|
], function(e) {
|
|
|
|
|
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions, function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'import.render.start', [ 'definitions' ] ],
|
|
|
|
[ 'import.render.complete', [ 'error', 'warnings' ] ]
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('multiple BPMNDiagram elements', function() {
|
|
|
|
|
|
|
|
var multipleXML = require('../fixtures/bpmn/multiple-diagrams.bpmn'),
|
|
|
|
viewer,
|
|
|
|
definitions;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
return createViewer(container, Viewer, multipleXML).then(function(result) {
|
|
|
|
|
|
|
|
var error = result.error;
|
|
|
|
var tmpViewer = result.viewer;
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
definitions = tmpViewer.getDefinitions();
|
|
|
|
|
|
|
|
tmpViewer.destroy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
viewer = new Viewer({ container: container });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
viewer.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should import default without bpmnDiagram specified', function(done) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions, function(err) {
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should import bpmnDiagram specified by id', function(done) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions, 'BpmnDiagram_2', function(err) {
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should handle diagram not found', function(done) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importDefinitions(definitions, 'Diagram_IDontExist', function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('BPMNDiagram <Diagram_IDontExist> not found');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#open', function() {
|
|
|
|
|
|
|
|
var multipleXMLSimple = require('../fixtures/bpmn/multiple-diagrams.bpmn'),
|
|
|
|
multipleXMLOverlappingDI = require('../fixtures/bpmn/multiple-diagrams-overlapping-di.bpmn'),
|
|
|
|
multipleXMLWithLaneSet = require('../fixtures/bpmn/multiple-diagrams-lanesets.bpmn'),
|
|
|
|
diagram1 = 'BpmnDiagram_1',
|
|
|
|
diagram2 = 'BpmnDiagram_2';
|
|
|
|
|
|
|
|
|
|
|
|
it('should open the first diagram if id was not provided', function(done) {
|
|
|
|
|
|
|
|
var viewer, renderedDiagram;
|
|
|
|
|
|
|
|
// when
|
|
|
|
createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di;
|
|
|
|
|
|
|
|
viewer.open(function(err) {
|
|
|
|
|
|
|
|
expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should switch between diagrams', function(done) {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
|
|
|
|
|
|
|
// when
|
|
|
|
createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
// then
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
|
|
|
viewer.open(diagram2, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
expect(definitions).to.equal(viewer.getDefinitions());
|
|
|
|
|
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
expect(elementRegistry.get('Task_A')).to.not.exist;
|
|
|
|
expect(elementRegistry.get('Task_B')).to.exist;
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should switch between diagrams with overlapping DI', function(done) {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
|
|
|
|
|
|
|
// when
|
|
|
|
createViewer(container, Viewer, multipleXMLOverlappingDI, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
|
|
|
viewer.open(diagram2, function(err, warnings) {
|
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
expect(definitions).to.equal(viewer.getDefinitions());
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should switch between diagrams with laneSets', function(done) {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
|
|
|
|
|
|
|
// when
|
|
|
|
createViewer(container, Viewer, multipleXMLWithLaneSet, diagram2).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
|
|
|
viewer.open(diagram1, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
expect(definitions).to.equal(viewer.getDefinitions());
|
|
|
|
|
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
expect(elementRegistry.get('Task_A')).to.exist;
|
|
|
|
expect(elementRegistry.get('Task_B')).to.not.exist;
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should complete with error if xml was not imported', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer();
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.open(function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('no XML imported');
|
|
|
|
|
|
|
|
var definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.not.exist;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should open with error if diagram does not exist', function(done) {
|
|
|
|
|
|
|
|
var viewer, definitions;
|
|
|
|
|
|
|
|
// when
|
|
|
|
createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var warnings = result.warnings;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
expect(warnings).to.be.empty;
|
|
|
|
|
|
|
|
definitions = viewer.getDefinitions();
|
|
|
|
|
|
|
|
expect(definitions).to.exist;
|
|
|
|
|
|
|
|
viewer.open('Diagram_IDontExist', function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('BPMNDiagram <Diagram_IDontExist> not found');
|
|
|
|
|
|
|
|
// definitions stay the same
|
|
|
|
expect(viewer.getDefinitions()).to.eql(definitions);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should emit <import.*> events', function(done) {
|
|
|
|
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
viewer.importXML(multipleXMLSimple, diagram1).then(function(result) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
viewer.on([
|
|
|
|
'import.parse.start',
|
|
|
|
'import.parse.complete',
|
|
|
|
'import.render.start',
|
|
|
|
'import.render.complete',
|
|
|
|
'import.done'
|
|
|
|
], function(e) {
|
|
|
|
|
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.open(diagram2, function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'import.render.start', [ 'definitions' ] ],
|
|
|
|
[ 'import.render.complete', [ 'error', 'warnings' ] ]
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#saveXML', function() {
|
|
|
|
|
|
|
|
it('should export XML', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveXML({ format: true }, function(err, xml) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(xml).to.contain('<?xml version="1.0" encoding="UTF-8"?>');
|
|
|
|
expect(xml).to.contain('<bpmn2:definitions');
|
|
|
|
expect(xml).to.contain(' ');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should emit <saveXML.*> events', function(done) {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer;
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'saveXML.start',
|
|
|
|
'saveXML.serialized',
|
|
|
|
'saveXML.done'
|
|
|
|
], function(e) {
|
|
|
|
|
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
return viewer.importXML(xml);
|
|
|
|
}).then(function(result) {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveXML(function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'saveXML.start', [ 'definitions' ] ],
|
|
|
|
[ 'saveXML.serialized', ['error', 'xml' ] ],
|
|
|
|
[ 'saveXML.done', ['error', 'xml' ] ]
|
|
|
|
]);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#saveSVG', function() {
|
|
|
|
|
|
|
|
function currentTime() {
|
|
|
|
return new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
function validSVG(svg) {
|
|
|
|
var expectedStart = '<?xml version="1.0" encoding="utf-8"?>';
|
|
|
|
var expectedEnd = '</svg>';
|
|
|
|
|
|
|
|
expect(svg.indexOf(expectedStart)).to.equal(0);
|
|
|
|
expect(svg.indexOf(expectedEnd)).to.equal(svg.length - expectedEnd.length);
|
|
|
|
|
|
|
|
// ensure correct rendering of SVG contents
|
|
|
|
expect(svg.indexOf('undefined')).to.equal(-1);
|
|
|
|
|
|
|
|
// expect header to be written only once
|
|
|
|
expect(svg.indexOf('<svg width="100%" height="100%">')).to.equal(-1);
|
|
|
|
expect(svg.indexOf('<g class="viewport"')).to.equal(-1);
|
|
|
|
|
|
|
|
var parser = new DOMParser();
|
|
|
|
var svgNode = parser.parseFromString(svg, 'image/svg+xml');
|
|
|
|
|
|
|
|
// [comment, <!DOCTYPE svg>, svg]
|
|
|
|
expect(svgNode.childNodes).to.have.length(3);
|
|
|
|
|
|
|
|
// no error body
|
|
|
|
expect(svgNode.body).not.to.exist;
|
|
|
|
|
|
|
|
// FIXME(nre): make matcher
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
it('should export svg', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveSVG(function(err, svg) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(validSVG(svg)).to.be.true;
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should export huge svg', function(done) {
|
|
|
|
|
|
|
|
this.timeout(5000);
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/complex.bpmn');
|
|
|
|
|
|
|
|
createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveSVG(function(err, svg) {
|
|
|
|
|
|
|
|
var time = currentTime();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(validSVG(svg)).to.be.true;
|
|
|
|
|
|
|
|
// no svg export should not take too long
|
|
|
|
expect(currentTime() - time).to.be.below(1000);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should remove outer-makers on export', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
function appendTestRect(svgDoc) {
|
|
|
|
var rect = document.createElementNS(svgDoc.namespaceURI, 'rect');
|
|
|
|
rect.setAttribute('class', 'outer-bound-marker');
|
|
|
|
rect.setAttribute('width', 500);
|
|
|
|
rect.setAttribute('height', 500);
|
|
|
|
rect.setAttribute('x', 10000);
|
|
|
|
rect.setAttribute('y', 10000);
|
|
|
|
svgDoc.appendChild(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
var viewer = result.viewer;
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
var svgDoc = viewer._container.childNodes[1].childNodes[1];
|
|
|
|
|
|
|
|
appendTestRect(svgDoc);
|
|
|
|
appendTestRect(svgDoc);
|
|
|
|
|
|
|
|
expect(svgDoc.querySelectorAll('.outer-bound-marker')).to.exist;
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveSVG(function(err, svg) {
|
|
|
|
|
|
|
|
var svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
|
|
svgDoc.innerHTML = svg;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(validSVG(svg)).to.be.true;
|
|
|
|
expect(svgDoc.querySelector('.outer-bound-marker')).to.be.null;
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should emit <saveSVG.*> events', function(done) {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer;
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
createViewer(container, Viewer, xml).then(function(result) {
|
|
|
|
|
|
|
|
var err = result.error;
|
|
|
|
viewer = result.viewer;
|
|
|
|
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
|
|
|
|
viewer.on([
|
|
|
|
'saveSVG.start',
|
|
|
|
'saveSVG.done'
|
|
|
|
], function(e) {
|
|
|
|
|
|
|
|
// log event type + event arguments
|
|
|
|
events.push([
|
|
|
|
e.type,
|
|
|
|
Object.keys(e).filter(function(key) {
|
|
|
|
return key !== 'type';
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
return viewer.importXML(xml);
|
|
|
|
}).then(function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveSVG(function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(events).to.eql([
|
|
|
|
[ 'saveSVG.start', [ ] ],
|
|
|
|
[ 'saveSVG.done', ['error', 'svg' ] ]
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2015-07-15 15:22:19 +00:00
|
|
|
});
|