feat(lib): Promisify public APIs

This commit promisifies following APIs:

   BaseViewer#importXML
   BaseViewer#importDefinitions
   BaseViewer#open
   BaseViewer#saveXML
   BaseViewer#saveSVG
   Modeler#createDiagram

Related to https://github.com/bpmn-io/bpmn-js/issues/812

BREAKING CHANGES:

* Users are now expected to have Promises either by default or
polyfilled as the APIs return a Promise now.
This commit is contained in:
Nico Rehwaldt 2020-04-29 11:02:42 +02:00 committed by Nico Rehwaldt
parent ef2a6d0cd0
commit 04ca31fac9
23 changed files with 1961 additions and 1049 deletions

View File

@ -24,14 +24,14 @@ var viewer = new BpmnJS({
container: 'body'
});
viewer.importXML(xml, function(err) {
try {
if (err) {
console.log('error rendering', err);
} else {
console.log('rendered');
}
});
const { warnings } = await viewer.importXML(xml);
console.log('rendered');
} catch (err) {
console.log('error rendering', err);
}
```
Checkout our [examples](https://github.com/bpmn-io/bpmn-js-examples) for many

View File

@ -7,7 +7,6 @@
import {
assign,
find,
isFunction,
isNumber,
omit
} from 'min-dash';
@ -68,6 +67,21 @@ export default function BaseViewer(options) {
inherits(BaseViewer, Diagram);
/**
* The importXML result.
*
* @typedef {Object} ImportXMLResult
*
* @property {Array<string>} warnings
*/
/**
* The importXML error.
*
* @typedef {Error} ImportXMLError
*
* @property {Array<string>} warnings
*/
/**
* Parse and render a BPMN 2.0 diagram.
@ -89,65 +103,83 @@ inherits(BaseViewer, Diagram);
*
* @param {string} xml the BPMN 2.0 xml
* @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
* @param {Function} [done] invoked with (err, warnings=[])
*
* Returns {Promise<ImportXMLResult, ImportXMLError>}
*/
BaseViewer.prototype.importXML = wrapForCompatibility(function importXML(xml, bpmnDiagram, done) {
if (isFunction(bpmnDiagram)) {
done = bpmnDiagram;
bpmnDiagram = null;
}
// done is optional
done = done || function() {};
BaseViewer.prototype.importXML = wrapForCompatibility(function importXML(xml, bpmnDiagram) {
var self = this;
// hook in pre-parse listeners +
// allow xml manipulation
xml = this._emit('import.parse.start', { xml: xml }) || xml;
return new Promise(function(resolve, reject) {
this._moddle.fromXML(xml, 'bpmn:Definitions').then(function(result) {
var definitions = result.rootElement;
var references = result.references;
var parseWarnings = result.warnings;
var elementsById = result.elementsById;
// hook in pre-parse listeners +
// allow xml manipulation
xml = self._emit('import.parse.start', { xml: xml }) || xml;
var context = {
elementsById: elementsById,
references: references,
warnings: parseWarnings
};
self._moddle.fromXML(xml, 'bpmn:Definitions').then(function(result) {
var definitions = result.rootElement;
var references = result.references;
var parseWarnings = result.warnings;
var elementsById = result.elementsById;
// hook in post parse listeners +
// allow definitions manipulation
definitions = self._emit('import.parse.complete', {
error: null,
definitions: definitions,
context: context
}) || definitions;
var context = {
elementsById: elementsById,
references: references,
warnings: parseWarnings
};
self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
var allWarnings = [].concat(parseWarnings, importWarnings || []);
// hook in post parse listeners +
// allow definitions manipulation
definitions = self._emit('import.parse.complete', {
error: null,
definitions: definitions,
context: context
}) || definitions;
self._emit('import.done', { error: err, warnings: allWarnings });
self.importDefinitions(definitions, bpmnDiagram).then(function(result) {
var allWarnings = [].concat(parseWarnings, result.warnings || []);
done(err, allWarnings);
self._emit('import.done', { error: null, warnings: allWarnings });
return resolve({ warnings: allWarnings });
}).catch(function(err) {
var allWarnings = [].concat(parseWarnings, err.warnings || []);
self._emit('import.done', { error: err, warnings: allWarnings });
return reject(addWarningsToError(err, allWarnings));
});
}).catch(function(err) {
self._emit('import.parse.complete', {
error: err
});
err = checkValidationError(err);
self._emit('import.done', { error: err, warnings: err.warnings });
return reject(err);
});
}).catch(function(err) {
self._emit('import.parse.complete', {
error: err
});
err = checkValidationError(err);
self._emit('import.done', { error: err, warnings: err.warnings });
return done(err, err.warnings);
});
});
/**
* The importDefinitions result.
*
* @typedef {Object} ImportDefinitionsResult
*
* @property {Array<string>} warnings
*/
/**
* The importDefinitions error.
*
* @typedef {Error} ImportDefinitionsError
*
* @property {Array<string>} warnings
*/
/**
* Import parsed definitions and render a BPMN 2.0 diagram.
*
@ -165,23 +197,45 @@ BaseViewer.prototype.importXML = wrapForCompatibility(function importXML(xml, bp
*
* @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
* @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
* @param {Function} [done] invoked with (err, warnings=[])
*
* Returns {Promise<ImportDefinitionsResult, ImportDefinitionsError>}
*/
BaseViewer.prototype.importDefinitions = wrapForCompatibility(function importDefinitions(definitions, bpmnDiagram, done) {
BaseViewer.prototype.importDefinitions = wrapForCompatibility(function importDefinitions(definitions, bpmnDiagram) {
if (isFunction(bpmnDiagram)) {
done = bpmnDiagram;
bpmnDiagram = null;
}
var self = this;
// done is optional
done = done || function() {};
return new Promise(function(resolve, reject) {
this._setDefinitions(definitions);
self._setDefinitions(definitions);
return this.open(bpmnDiagram, done);
self.open(bpmnDiagram).then(function(result) {
var warnings = result.warnings;
return resolve({ warnings: warnings });
}).catch(function(err) {
return reject(err);
});
});
});
/**
* The open result.
*
* @typedef {Object} OpenResult
*
* @property {Array<string>} warnings
*/
/**
* The open error.
*
* @typedef {Error} OpenError
*
* @property {Array<string>} warnings
*/
/**
* Open diagram of previously imported XML.
*
@ -198,45 +252,63 @@ BaseViewer.prototype.importDefinitions = wrapForCompatibility(function importDef
* You can use these events to hook into the life-cycle.
*
* @param {string|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
* @param {Function} [done] invoked with (err, warnings=[])
*
* Returns {Promise<OpenResult, OpenError>}
*/
BaseViewer.prototype.open = wrapForCompatibility(function open(bpmnDiagramOrId, done) {
if (isFunction(bpmnDiagramOrId)) {
done = bpmnDiagramOrId;
bpmnDiagramOrId = null;
}
BaseViewer.prototype.open = wrapForCompatibility(function open(bpmnDiagramOrId) {
var definitions = this._definitions;
var bpmnDiagram = bpmnDiagramOrId;
// done is optional
done = done || function() {};
var self = this;
if (!definitions) {
return done(new Error('no XML imported'));
}
return new Promise(function(resolve, reject) {
if (!definitions) {
var err1 = new Error('no XML imported');
if (typeof bpmnDiagramOrId === 'string') {
bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
if (!bpmnDiagram) {
return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
return reject(addWarningsToError(err1, []));
}
}
// clear existing rendered diagram
// catch synchronous exceptions during #clear()
try {
this.clear();
} catch (error) {
return done(error);
}
if (typeof bpmnDiagramOrId === 'string') {
bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
// perform graphical import
return importBpmnDiagram(this, definitions, bpmnDiagram, done);
if (!bpmnDiagram) {
var err2 = new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found');
return reject(addWarningsToError(err2, []));
}
}
// clear existing rendered diagram
// catch synchronous exceptions during #clear()
try {
self.clear();
} catch (error) {
return reject(addWarningsToError(error, []));
}
// perform graphical import
importBpmnDiagram(self, definitions, bpmnDiagram).then(function(result) {
var warnings = result.warnings;
return resolve({ warnings: warnings });
}).catch(function(err) {
return reject(err);
});
});
});
/**
* The saveXML result.
*
* @typedef {Object} SaveXMLResult
*
* @property {string} xml
*/
/**
* Export the currently displayed BPMN 2.0 diagram as
* a BPMN 2.0 XML document.
@ -255,52 +327,63 @@ BaseViewer.prototype.open = wrapForCompatibility(function open(bpmnDiagramOrId,
* @param {boolean} [options.format=false] output formatted XML
* @param {boolean} [options.preamble=true] output preamble
*
* @param {Function} done invoked with (err, xml)
* Returns {Promise<SaveXMLResult, Error>}
*/
BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options, done) {
BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) {
if (!done) {
done = options;
options = {};
}
options = options || {};
var self = this;
var definitions = this._definitions;
if (!definitions) {
return done(new Error('no definitions loaded'));
}
return new Promise(function(resolve, reject) {
// allow to fiddle around with definitions
definitions = this._emit('saveXML.start', {
definitions: definitions
}) || definitions;
if (!definitions) {
var err = new Error('no definitions loaded');
this._moddle.toXML(definitions, options).then(function(result) {
var xml = result.xml;
try {
xml = self._emit('saveXML.serialized', {
error: null,
xml: xml
}) || xml;
self._emit('saveXML.done', {
error: null,
xml: xml
});
} catch (e) {
console.error('error in saveXML life-cycle listener', e);
return reject(err);
}
done(null, xml);
}).catch(function(err) {
done(err);
// allow to fiddle around with definitions
definitions = self._emit('saveXML.start', {
definitions: definitions
}) || definitions;
self._moddle.toXML(definitions, options).then(function(result) {
var xml = result.xml;
try {
xml = self._emit('saveXML.serialized', {
error: null,
xml: xml
}) || xml;
self._emit('saveXML.done', {
error: null,
xml: xml
});
} catch (e) {
console.error('error in saveXML life-cycle listener', e);
}
return resolve({ xml: xml });
}).catch(function(err) {
return reject(err);
});
});
});
/**
* The saveSVG result.
*
* @typedef {Object} SaveSVGResult
*
* @property {string} svg
*/
/**
* Export the currently displayed BPMN 2.0 diagram as
* an SVG image.
@ -315,49 +398,56 @@ BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options, do
* You can use these events to hook into the life-cycle.
*
* @param {Object} [options]
* @param {Function} done invoked with (err, svgStr)
*
* Returns {Promise<SaveSVGResult, Error>}
*/
BaseViewer.prototype.saveSVG = wrapForCompatibility(function saveSVG(options, done) {
BaseViewer.prototype.saveSVG = wrapForCompatibility(function saveSVG(options) {
if (!done) {
done = options;
options = {};
}
options = options || {};
this._emit('saveSVG.start');
var self = this;
var svg, err;
return new Promise(function(resolve, reject) {
try {
var canvas = this.get('canvas');
self._emit('saveSVG.start');
var contentNode = canvas.getDefaultLayer(),
defsNode = domQuery('defs', canvas._svg);
var svg, err;
var contents = innerSVG(contentNode),
defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
try {
var canvas = self.get('canvas');
var bbox = contentNode.getBBox();
var contentNode = canvas.getDefaultLayer(),
defsNode = domQuery('defs', canvas._svg);
svg =
'<?xml version="1.0" encoding="utf-8"?>\n' +
'<!-- created with bpmn-js / http://bpmn.io -->\n' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
'width="' + bbox.width + '" height="' + bbox.height + '" ' +
'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
defs + contents +
'</svg>';
} catch (e) {
err = e;
}
var contents = innerSVG(contentNode),
defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
this._emit('saveSVG.done', {
error: err,
svg: svg
var bbox = contentNode.getBBox();
svg =
'<?xml version="1.0" encoding="utf-8"?>\n' +
'<!-- created with bpmn-js / http://bpmn.io -->\n' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
'width="' + bbox.width + '" height="' + bbox.height + '" ' +
'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
defs + contents +
'</svg>';
} catch (e) {
err = e;
}
self._emit('saveSVG.done', {
error: err,
svg: svg
});
if (!err) {
return resolve({ svg: svg });
}
return reject(err);
});
done(err, svg);
});
/**
@ -574,6 +664,11 @@ BaseViewer.prototype._modules = [];
// helpers ///////////////
function addWarningsToError(err, warningsAry) {
err.warnings = warningsAry;
return err;
}
function checkValidationError(err) {
// check if we can help the user by indicating wrong BPMN 2.0 xml

View File

@ -35,6 +35,9 @@ import ResizeModule from 'diagram-js/lib/features/resize';
import SnappingModule from './features/snapping';
import SearchModule from './features/search';
import {
wrapForCompatibility
} from './util/CompatibilityUtil';
var initialDiagram =
'<?xml version="1.0" encoding="UTF-8"?>' +
@ -139,14 +142,30 @@ inherits(Modeler, BaseModeler);
Modeler.Viewer = Viewer;
Modeler.NavigatedViewer = NavigatedViewer;
/**
* The createDiagram result.
*
* @typedef {Object} CreateDiagramResult
*
* @property {Array<string>} warnings
*/
/**
* The createDiagram error.
*
* @typedef {Error} CreateDiagramError
*
* @property {Array<string>} warnings
*/
/**
* Create a new diagram to start modeling.
*
* @param {Function} [done]
* Returns {Promise<CreateDiagramResult, CreateDiagramError>}
*/
Modeler.prototype.createDiagram = function(done) {
return this.importXML(initialDiagram, done);
};
Modeler.prototype.createDiagram = wrapForCompatibility(function createDiagram() {
return this.importXML(initialDiagram);
});
Modeler.prototype._interactionModules = [

View File

@ -1,8 +1,21 @@
import BpmnTreeWalker from './BpmnTreeWalker';
import {
isFunction
} from 'min-dash';
/**
* The importBpmnDiagram result.
*
* @typedef {Object} ImportBPMNDiagramResult
*
* @property {Array<string>} warnings
*/
/**
* The importBpmnDiagram error.
*
* @typedef {Error} ImportBPMNDiagramError
*
* @property {Array<string>} warnings
*/
/**
* Import the definitions into a diagram.
@ -13,14 +26,10 @@ import {
* @param {ModdleElement<Definitions>} definitions
* @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
* (if not provided, the first one will be rendered)
* @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
*
* Returns {Promise<ImportBPMNDiagramResult, ImportBPMNDiagramError>}
*/
export function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
if (isFunction(bpmnDiagram)) {
done = bpmnDiagram;
bpmnDiagram = null;
}
export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
var importer,
eventBus,
@ -60,22 +69,26 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
walker.handleDefinitions(definitions, bpmnDiagram);
}
try {
importer = diagram.get('bpmnImporter');
eventBus = diagram.get('eventBus');
translate = diagram.get('translate');
return new Promise(function(resolve, reject) {
try {
importer = diagram.get('bpmnImporter');
eventBus = diagram.get('eventBus');
translate = diagram.get('translate');
eventBus.fire('import.render.start', { definitions: definitions });
eventBus.fire('import.render.start', { definitions: definitions });
render(definitions, bpmnDiagram);
render(definitions, bpmnDiagram);
eventBus.fire('import.render.complete', {
error: error,
warnings: warnings
});
} catch (e) {
error = e;
}
eventBus.fire('import.render.complete', {
error: error,
warnings: warnings
});
done(error, warnings);
}
return resolve({ warnings: warnings });
} catch (e) {
e.warnings = warnings;
return reject(e);
}
});
}

View File

@ -15,7 +15,7 @@ export function wrapForCompatibility(api) {
return function() {
if (!window.Promise) {
throw new Error('Promises is not supported in this environment. Consider polyfilling.');
throw new Error('Promises is not supported in this environment. Please polyfill Promise.');
}
var argLen = arguments.length;

View File

@ -48,7 +48,7 @@ import translationModule from './TranslationCollector';
export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
return function(done) {
return function() {
var testContainer;
// Make sure the test container is an optional dependency and we fall back
@ -118,7 +118,11 @@ export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
setBpmnJS(instance);
instance.importXML(diagram, done);
return instance.importXML(diagram).then(function(result) {
return { error: null, warnings: result.warnings };
}).catch(function(err) {
return { error: err, warnings: err.warnings };
});
};
}
@ -236,6 +240,23 @@ export function clearBpmnJS() {
}
}
// This method always resolves.
// It helps us to do done(err) within the same block.
export function createViewer(container, viewerInstance, xml, diagramId) {
clearBpmnJS();
var viewer = new viewerInstance({ container: container });
setBpmnJS(viewer);
return viewer.importXML(xml, diagramId).then(function(result) {
return { warnings: result.warnings, viewer: viewer };
}).catch(function(err) {
return { error: err, viewer: viewer, warnings: err.warnings };
});
}
export function setBpmnJS(instance) {
BPMN_JS = instance;
}
@ -257,4 +278,4 @@ export function insertCSS(name, css) {
}
head.appendChild(style);
}
}

View File

@ -68,15 +68,12 @@ describe.skip('scenario - successive reopening', function() {
var xml = allDiagrams[i];
// when
modeler.importXML(xml, function(err) {
modeler.importXML(xml).then(function() {
count++;
if (err) {
return finish(err);
}
delay(importNext);
}).catch(function(err) {
return finish(err);
});
}

View File

@ -12,16 +12,13 @@ describe('scenario - simple modeling', function() {
});
it('should build process from start to end event', function(done) {
it('should build process from start to end event', function() {
// given
var modeler = new Modeler({ container: container });
// when
modeler.createDiagram(function(err) {
done(err);
});
return modeler.createDiagram();
});
});

View File

@ -11,7 +11,7 @@ describe('bpmn-moddle', function() {
describe('browser support', function() {
it('should parse simple xml', function(done) {
it('should parse simple xml', function() {
var xml =
'<?xml version="1.0" encoding="UTF-8"?>' +
@ -22,7 +22,7 @@ describe('bpmn-moddle', function() {
'</bpmn2:definitions>';
// when
parse(xml).then(function(result) {
return parse(xml).then(function(result) {
var definitions = result.rootElement;
@ -32,29 +32,22 @@ describe('bpmn-moddle', function() {
expect(definitions.rootElements.length).to.equal(1);
expect(definitions.rootElements[0].id).to.equal('Process_1');
done();
}).catch(function(err) {
done(err);
});
});
it('should parse complex xml', function(done) {
it('should parse complex xml', function() {
var xml = require('../../fixtures/bpmn/complex.bpmn');
var start = new Date().getTime();
// when
parse(xml).then(function() {
return parse(xml).then(function() {
// then
// parsing a XML document should not take too long
expect((new Date().getTime() - start)).to.be.below(1000);
done();
}).catch(function(err) {
done(err);
});
});

View File

@ -24,7 +24,7 @@ describe('Modeler', function() {
container = TestContainer.get(this);
});
function createModeler(xml, done) {
function createModeler(xml) {
clearBpmnJS();
@ -37,108 +37,122 @@ describe('Modeler', function() {
setBpmnJS(modeler);
modeler.importXML(xml, function(err, warnings) {
done(err, warnings, modeler);
return modeler.importXML(xml).then(function(result) {
return { error: null, warnings: result.warnings, modeler: modeler };
}).catch(function(err) {
return { error: err, warnings: err.warnings, modeler: modeler };
});
}
it('should import simple process', function(done) {
it('should import simple process', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
it('should import collaboration', function(done) {
it('should import collaboration', function() {
var xml = require('../fixtures/bpmn/collaboration-message-flows.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
it('should import nested lanes', function(done) {
it('should import nested lanes', function() {
var xml = require('./features/modeling/lanes/lanes.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
it('should import ioSpecification', function(done) {
it('should import ioSpecification', function() {
var xml = require('./features/modeling/input-output/DataInputOutput.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
it.skip('should import complex', function(done) {
it.skip('should import complex', function() {
var xml = require('../fixtures/bpmn/complex.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
it('should not import empty definitions', function(done) {
it('should not import empty definitions', function() {
var xml = require('../fixtures/bpmn/empty-definitions.bpmn');
// given
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
// when
modeler.importXML(xml, function(err, warnings) {
// then
expect(err.message).to.equal('no diagram to display');
done();
});
return modeler.importXML(xml);
}).catch(function(err) {
// then
expect(err.message).to.equal('no diagram to display');
});
});
it('should re-import simple process', function(done) {
it('should re-import simple process', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
// given
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
// when
// mimic re-import of same diagram
modeler.importXML(xml, function(err, warnings) {
return modeler.importXML(xml);
}).then(function(result) {
// then
expect(warnings).to.be.empty;
done();
});
var warnings = result.warnings;
// then
expect(warnings).to.be.empty;
});
});
it('should switch between diagrams', function(done) {
it('should switch between diagrams', function() {
var multipleXML = require('../fixtures/bpmn/multiple-diagrams.bpmn');
// given
createModeler(multipleXML, function(err, warnings, modeler) {
return createModeler(multipleXML).then(function(result) {
var modeler = result.modeler;
var err = result.error;
if (err) {
return done(err);
throw err;
}
// when
modeler.open('BpmnDiagram_2', function(err, warnings) {
return modeler.open('BpmnDiagram_2');
}).then(function(result) {
if (err) {
return done(err);
}
// then
expect(warnings).to.be.empty;
done();
});
var warnings = result.warnings;
// then
expect(warnings).to.be.empty;
});
});
@ -146,9 +160,16 @@ describe('Modeler', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
it('should allow translation of multi-lingual strings', function(done) {
it('should allow translation of multi-lingual strings', function() {
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
var err = result.error;
if (err) {
throw err;
}
// given
var translate = modeler.get('translate');
@ -161,8 +182,6 @@ describe('Modeler', function() {
// then
expect(interpolatedString).to.eql('HELLO WALT!');
done(err);
});
});
@ -172,11 +191,18 @@ describe('Modeler', function() {
describe('overlay support', function() {
it('should allow to add overlays', function(done) {
it('should allow to add overlays', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
var err = result.error;
if (err) {
throw err;
}
// given
var overlays = modeler.get('overlays'),
@ -207,8 +233,6 @@ describe('Modeler', function() {
// then
expect(overlays.get({ element: 'SubProcess_1', type: 'badge' })).to.have.length(1);
expect(overlays.get({ element: 'StartEvent_1', type: 'badge' })).to.have.length(1);
done(err);
});
});
@ -260,11 +284,18 @@ describe('Modeler', function() {
describe('bendpoint editing support', function() {
it('should allow to edit bendpoints', function(done) {
it('should allow to edit bendpoints', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
var err = result.error;
if (err) {
throw err;
}
// given
var bendpointMove = modeler.get('bendpointMove'),
@ -282,8 +313,6 @@ describe('Modeler', function() {
1
);
dragging.move(createEvent(canvas, { x: 200, y: 200 }));
done(err);
});
});
@ -293,11 +322,13 @@ describe('Modeler', function() {
describe('color support', function() {
it('should allow color changes', function(done) {
it('should allow color changes', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
// given
var modeling = modeler.get('modeling'),
@ -312,14 +343,13 @@ describe('Modeler', function() {
});
// test saving process to get XML
modeler.saveXML({ format: true }, function(err, xml) {
expect(xml).not.to.contain('di="[object Object]"');
return modeler.saveXML({ format: true });
}).then(function(result) {
var xml = result.xml;
done();
});
expect(xml).not.to.contain('di="[object Object]"');
});
});
});
@ -328,7 +358,7 @@ describe('Modeler', function() {
// given
var xml = require('../fixtures/bpmn/simple.bpmn');
it('should configure Canvas', function(done) {
it('should configure Canvas', function() {
// given
var modeler = new Modeler({
@ -339,18 +369,14 @@ describe('Modeler', function() {
});
// when
modeler.importXML(xml, function(err) {
return modeler.importXML(xml).then(function() {
var canvasConfig = modeler.get('config.canvas');
// then
expect(canvasConfig.deferUpdate).to.be.true;
done();
});
});
});
@ -369,7 +395,7 @@ describe('Modeler', function() {
});
it('should populate ids on import', function(done) {
it('should populate ids on import', function() {
// given
var xml = require('../fixtures/bpmn/simple.bpmn');
@ -380,7 +406,7 @@ describe('Modeler', function() {
var elementRegistry = modeler.get('elementRegistry');
// when
modeler.importXML(xml, function(err) {
return modeler.importXML(xml).then(function() {
var subProcess = elementRegistry.get('SubProcess_1').businessObject;
var bpmnEdge = elementRegistry.get('SequenceFlow_3').businessObject.di;
@ -388,14 +414,12 @@ describe('Modeler', function() {
// then
expect(moddle.ids.assigned('SubProcess_1')).to.eql(subProcess);
expect(moddle.ids.assigned('BPMNEdge_SequenceFlow_3')).to.eql(bpmnEdge);
done();
});
});
it('should clear ids before re-import', function(done) {
it('should clear ids before re-import', function() {
// given
var someXML = require('../fixtures/bpmn/simple.bpmn'),
@ -407,60 +431,71 @@ describe('Modeler', function() {
var elementRegistry = modeler.get('elementRegistry');
// when
modeler.importXML(someXML, function() {
return modeler.importXML(someXML).then(function() {
modeler.importXML(otherXML, function() {
return modeler.importXML(otherXML);
}).then(function() {
var task = elementRegistry.get('Task_1').businessObject;
var task = elementRegistry.get('Task_1').businessObject;
// then
// not in other.bpmn
expect(moddle.ids.assigned('SubProcess_1')).to.be.false;
// then
// not in other.bpmn
expect(moddle.ids.assigned('SubProcess_1')).to.be.false;
// in other.bpmn
expect(moddle.ids.assigned('Task_1')).to.eql(task);
done();
});
// in other.bpmn
expect(moddle.ids.assigned('Task_1')).to.eql(task);
});
});
});
it('should handle errors', function(done) {
it('should handle errors', function() {
var xml = 'invalid stuff';
var modeler = new Modeler({ container: container });
modeler.importXML(xml, function(err) {
return modeler.importXML(xml).catch(function(err) {
expect(err).to.exist;
done();
});
});
it('should create new diagram', function(done) {
it('should create new diagram', function() {
var modeler = new Modeler({ container: container });
modeler.createDiagram(done);
return modeler.createDiagram();
});
it('should create new diagram - Legacy', function(done) {
var modeler = new Modeler({ container: container });
modeler.createDiagram(function(err, warnings) {
expect(warnings).to.exist;
expect(warnings).to.have.length(0);
done(err);
});
});
describe('dependency injection', function() {
it('should provide self as <bpmnjs>', function(done) {
it('should provide self as <bpmnjs>', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
var err = result.error;
if (err) {
throw err;
}
expect(modeler.get('bpmnjs')).to.equal(modeler);
done(err);
});
});
@ -477,7 +512,7 @@ describe('Modeler', function() {
});
it('should keep references to services across re-import', function(done) {
it('should keep references to services across re-import', function() {
// given
var someXML = require('../fixtures/bpmn/simple.bpmn'),
@ -489,33 +524,39 @@ describe('Modeler', function() {
canvas = modeler.get('canvas');
// when
modeler.importXML(someXML, function() {
return modeler.importXML(someXML).then(function() {
// then
expect(modeler.get('canvas')).to.equal(canvas);
expect(modeler.get('eventBus')).to.equal(eventBus);
modeler.importXML(otherXML, function() {
return modeler.importXML(otherXML);
}).then(function() {
// then
expect(modeler.get('canvas')).to.equal(canvas);
expect(modeler.get('eventBus')).to.equal(eventBus);
done();
});
// then
expect(modeler.get('canvas')).to.equal(canvas);
expect(modeler.get('eventBus')).to.equal(eventBus);
});
});
it('should inject mandatory modules', function(done) {
it('should inject mandatory modules', function() {
// given
var xml = require('../fixtures/bpmn/simple.bpmn');
// when
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var modeler = result.modeler;
var err = result.error;
// then
if (err) {
throw err;
}
expect(modeler.get('alignElements')).to.exist;
expect(modeler.get('autoPlace')).to.exist;
expect(modeler.get('bpmnAutoResize')).to.exist;
@ -536,8 +577,6 @@ describe('Modeler', function() {
expect(modeler.get('paletteProvider')).to.exist;
expect(modeler.get('resize')).to.exist;
expect(modeler.get('snapping')).to.exist;
done(err);
});
});

View File

@ -5,8 +5,7 @@ import EditorActionsModule from 'lib/features/editor-actions';
import TestContainer from 'mocha-test-container-support';
import {
setBpmnJS,
clearBpmnJS
createViewer
} from 'test/TestHelper';
@ -18,25 +17,13 @@ describe('NavigatedViewer', function() {
container = TestContainer.get(this);
});
function createViewer(xml, done) {
clearBpmnJS();
var viewer = new NavigatedViewer({
container: container
});
setBpmnJS(viewer);
viewer.importXML(xml, function(err, warnings) {
done(err, warnings, viewer);
});
}
it('should import simple process', function(done) {
it('should import simple process', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
createViewer(xml, done);
return createViewer(container, NavigatedViewer, xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
@ -79,7 +66,6 @@ describe('NavigatedViewer', function() {
expect(actualActions).to.eql(expectedActions);
});
});
@ -87,24 +73,28 @@ describe('NavigatedViewer', function() {
var xml = require('../fixtures/bpmn/simple.bpmn');
it('should include zoomScroll', function(done) {
it('should include zoomScroll', function() {
createViewer(xml, function(err, warnings, viewer) {
return createViewer(container, NavigatedViewer, xml).then(function(result) {
var viewer = result.viewer;
var err = result.error;
expect(err).not.to.exist;
expect(viewer.get('zoomScroll')).to.exist;
done(err);
});
});
it('should include moveCanvas', function(done) {
createViewer(xml, function(err, warnings, viewer) {
it('should include moveCanvas', function() {
return createViewer(container, NavigatedViewer, xml).then(function(result) {
var viewer = result.viewer;
var err = result.error;
expect(err).not.to.exist;
expect(viewer.get('moveCanvas')).to.exist;
done(err);
});
});
});
});

File diff suppressed because it is too large Load Diff

View File

@ -22,177 +22,256 @@ import {
getDi
} from 'lib/draw/BpmnRenderUtil';
function checkErrors(done) {
return function(err, warnings) {
expect(warnings).to.be.empty;
expect(err).not.to.exist;
done();
};
function checkErrors(err, warnings) {
expect(warnings).to.be.empty;
expect(err).not.to.exist;
}
describe('draw - bpmn renderer', function() {
it('should render labels', function(done) {
it('should render labels', function() {
var xml = require('./BpmnRenderer.labels.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render activity markers', function(done) {
it('should render activity markers', function() {
var xml = require('../../fixtures/bpmn/draw/activity-markers.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render association markers', function(done) {
it('should render association markers', function() {
var xml = require('../../fixtures/bpmn/draw/associations.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render activity markers (combination)', function(done) {
it('should render activity markers (combination)', function() {
var xml = require('../../fixtures/bpmn/draw/activity-markers-combination.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render conditional flows', function(done) {
it('should render conditional flows', function() {
var xml = require('../../fixtures/bpmn/draw/conditional-flow.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render conditional default flows', function(done) {
it('should render conditional default flows', function() {
var xml = require('../../fixtures/bpmn/draw/conditional-flow-default.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
return checkErrors(result.error, result.warnings);
});
});
it('should render NO conditional flow (gateway)', function(done) {
it('should render NO conditional flow (gateway)', function() {
var xml = require('../../fixtures/bpmn/draw/conditional-flow-gateways.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render conditional flow (typed task)', function(done) {
it('should render conditional flow (typed task)', function() {
var xml = require('../../fixtures/bpmn/draw/conditional-flow-typed-task.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render data objects', function(done) {
it('should render data objects', function() {
var xml = require('../../fixtures/bpmn/draw/data-objects.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render events', function(done) {
it('should render events', function() {
var xml = require('../../fixtures/bpmn/draw/events.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render events (interrupting)', function(done) {
it('should render events (interrupting)', function() {
var xml = require('../../fixtures/bpmn/draw/events-interrupting.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render event subprocesses (collapsed)', function(done) {
it('should render event subprocesses (collapsed)', function() {
var xml = require('../../fixtures/bpmn/draw/event-subprocesses-collapsed.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render event subprocesses (expanded)', function(done) {
it('should render event subprocesses (expanded)', function() {
var xml = require('../../fixtures/bpmn/draw/event-subprocesses-expanded.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render gateways', function(done) {
it('should render gateways', function() {
var xml = require('../../fixtures/bpmn/draw/gateways.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render group', function(done) {
it('should render group', function() {
var xml = require('../../fixtures/bpmn/draw/group.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render message marker', function(done) {
it('should render message marker', function() {
var xml = require('../../fixtures/bpmn/draw/message-marker.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render pools', function(done) {
it('should render pools', function() {
var xml = require('../../fixtures/bpmn/draw/pools.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render pool collection marker', function(done) {
it('should render pool collection marker', function() {
var xml = require('../../fixtures/bpmn/draw/pools-with-collection-marker.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render task types', function(done) {
it('should render task types', function() {
var xml = require('../../fixtures/bpmn/draw/task-types.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render text annotations', function(done) {
it('should render text annotations', function() {
var xml = require('../../fixtures/bpmn/draw/text-annotation.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render flow markers', function(done) {
it('should render flow markers', function() {
var xml = require('../../fixtures/bpmn/flow-markers.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render xor gateways blank and with X', function(done) {
it('should render xor gateways blank and with X', function() {
var xml = require('../../fixtures/bpmn/draw/xor.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render boundary events with correct z-index', function(done) {
it('should render boundary events with correct z-index', function() {
var xml = require('../../fixtures/bpmn/draw/boundary-event-z-index.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render boundary events without flowNodeRef', function(done) {
it('should render boundary events without flowNodeRef', function() {
var xml = require('../../fixtures/bpmn/draw/boundary-event-without-refnode.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render boundary event only once if referenced incorrectly via flowNodeRef (robustness)', function(done) {
it('should render boundary event only once if referenced incorrectly via flowNodeRef (robustness)', function() {
var xml = require('../../fixtures/bpmn/draw/boundary-event-with-refnode.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render gateway event if attribute is missing in XML', function(done) {
it('should render gateway event if attribute is missing in XML', function() {
var xml = require('../../fixtures/bpmn/draw/gateway-type-default.bpmn');
bootstrapViewer(xml).call(this, checkErrors(done));
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render call activity', function(done) {
it('should render call activity', function() {
var xml = require('../../fixtures/bpmn/draw/call-activity.bpmn');
bootstrapViewer(xml).call(this, function(err) {
return bootstrapViewer(xml).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
inject(function(elementRegistry) {
@ -200,18 +279,20 @@ describe('draw - bpmn renderer', function() {
// make sure the + marker is shown
expect(domQuery('[data-marker=sub-process]', callActivityGfx)).to.exist;
done(err);
})();
});
});
it('should render adhoc sub process', function(done) {
it('should render adhoc sub process', function() {
var xml = require('../../fixtures/bpmn/draw/activity-markers-simple.bpmn');
bootstrapViewer(xml).call(this, function(err) {
return bootstrapViewer(xml).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
inject(function(elementRegistry) {
@ -219,18 +300,20 @@ describe('draw - bpmn renderer', function() {
// make sure the + marker is shown
expect(domQuery('[data-marker=adhoc]', callActivityGfx)).to.exist;
done(err);
})();
});
});
it('should add random ID suffix to marker ID', function(done) {
it('should add random ID suffix to marker ID', function() {
var xml = require('../../fixtures/bpmn/simple.bpmn');
bootstrapViewer(xml).call(this, function(err) {
return bootstrapViewer(xml).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
inject(function(canvas) {
var svg = canvas._svg;
@ -238,16 +321,19 @@ describe('draw - bpmn renderer', function() {
expect(markers[0].id).to.match(/^sequenceflow-end-white-black-[A-Za-z0-9]+$/);
})();
done(err);
});
});
it('should properly render colored markers', function(done) {
it('should properly render colored markers', function() {
var xml = require('./BpmnRenderer.colors.bpmn');
bootstrapViewer(xml).call(this, function(err) {
return bootstrapViewer(xml).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
inject(function(canvas) {
var svg = canvas._svg,
markers = svg.querySelectorAll('marker');
@ -261,16 +347,19 @@ describe('draw - bpmn renderer', function() {
expect(markers[5].id).to.match(/^messageflow-end-_FFE0B2-_FB8C00-[A-Za-z0-9]{25}$/);
expect(markers[6].id).to.match(/^messageflow-start-_FFE0B2-_FB8C00-[A-Za-z0-9]{25}$/);
})();
done(err);
});
});
it('should properly render connection markers (2)', function(done) {
it('should properly render connection markers (2)', function() {
var xml = require('./BpmnRenderer.connection-colors.bpmn');
bootstrapViewer(xml).call(this, function(err) {
return bootstrapViewer(xml).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
inject(function(canvas) {
var svg = canvas._svg,
markers = svg.querySelectorAll('marker');
@ -281,22 +370,24 @@ describe('draw - bpmn renderer', function() {
expect(markers[2].id).to.match(/^messageflow-end-rgb_23_100_344_-rgb_23_100_344_-[A-Za-z0-9]{25}$/);
expect(markers[3].id).to.match(/^messageflow-start-rgb_23_100_344_-rgb_23_100_344_-[A-Za-z0-9]{25}$/);
})();
done(err);
});
});
it('should render sequenceFlows without source', function(done) {
it('should render sequenceFlows without source', function() {
var xml = require('./BpmnRenderer.sequenceFlow-no-source.bpmn');
bootstrapModeler(xml, {
return bootstrapModeler(xml, {
modules: [
coreModule,
rendererModule,
modelingModule
]
}).call(this, function(err) {
}).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
inject(function(elementFactory, graphicsFactory) {
@ -315,8 +406,6 @@ describe('draw - bpmn renderer', function() {
expect(gfx).to.exist;
})();
done(err);
});
});
@ -328,13 +417,19 @@ describe('draw - bpmn renderer', function() {
var groupXML = require('./BpmnRenderer.group-colors.bpmn');
it('should render colors without warnings and errors', function(done) {
bootstrapViewer(xml).call(this, checkErrors(done));
it('should render colors without warnings and errors', function() {
return bootstrapViewer(xml).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});
it('should render group colors', function(done) {
bootstrapViewer(groupXML).call(this, checkErrors(done));
it('should render group colors', function() {
return bootstrapViewer(groupXML).call(this).then(function(result) {
checkErrors(result.error, result.warnings);
});
});

View File

@ -12,24 +12,30 @@ describe('direct editing - touch integration', function() {
});
function createModeler(xml, done) {
function createModeler(xml) {
var modeler = new Modeler({ container: container });
modeler.importXML(xml, function(err) {
done(err, modeler);
return modeler.importXML(xml).then(function(result) {
return { error: null, modeler: modeler };
}).catch(function(err) {
return { error: err, modeler: modeler };
});
}
it('should work on modeler (manual test)', function(done) {
it('should work on modeler (manual test)', function() {
var xml = require('../../../fixtures/bpmn/simple.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
it('should edit labels via double tap (manual test)', function(done) {
it('should edit labels via double tap (manual test)', function() {
var xml = require('./LabelEditing.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
});

View File

@ -12,11 +12,13 @@ var DELTA = 2;
describe('label bounds', function() {
function createModeler(xml, done) {
function createModeler(xml) {
var modeler = new Modeler({ container: container });
modeler.importXML(xml, function(err, warnings) {
done(err, warnings, modeler);
return modeler.importXML(xml).then(function(result) {
return { error: null, warnings: result.warnings, modeler: modeler };
}).catch(function(err) {
return { error: err, warnings: err.warnings, modeler: modeler };
});
}
@ -28,9 +30,12 @@ describe('label bounds', function() {
describe('on import', function() {
it('should import simple label process', function(done) {
it('should import simple label process', function() {
var xml = require('./LabelBoundsSpec.simple.bpmn');
createModeler(xml, done);
return createModeler(xml).then(function(result) {
expect(result.error).not.to.exist;
});
});
});
@ -228,107 +233,116 @@ describe('label bounds', function() {
describe('on export', function() {
it('should create DI when label has changed', function(done) {
it('should create DI when label has changed', function() {
var xml = require('./LabelBoundsSpec.simple.bpmn');
createModeler(xml, function(err, warnings, modeler) {
var shape;
return createModeler(xml).then(function(result) {
var err = result.error;
var modeler = result.modeler;
if (err) {
return done(err);
throw err;
}
var elementRegistry = modeler.get('elementRegistry'),
directEditing = modeler.get('directEditing');
var shape = elementRegistry.get('StartEvent_1');
shape = elementRegistry.get('StartEvent_1');
directEditing.activate(shape);
directEditing._textbox.content.innerText = 'BARBAZ';
directEditing.complete();
modeler.saveXML({ format: true }, function(err, result) {
return modeler.saveXML({ format: true });
}).then(function(result) {
// strip spaces and line breaks after '>'
result = result.replace(/>\s+/g,'>');
var xml = result.xml;
// get label width and height from XML
var matches = result.match(/StartEvent_1_di.*?BPMNLabel.*?width="(\d*).*?height="(\d*)/);
// strip spaces and line breaks after '>'
xml = xml.replace(/>\s+/g,'>');
var width = parseInt(matches[1]),
height = parseInt(matches[2]);
// get label width and height from XML
var matches = xml.match(/StartEvent_1_di.*?BPMNLabel.*?width="(\d*).*?height="(\d*)/);
expect(width).to.equal(shape.label.width);
expect(height).to.equal(shape.label.height);
var width = parseInt(matches[1]),
height = parseInt(matches[2]);
done(err);
});
expect(width).to.equal(shape.label.width);
expect(height).to.equal(shape.label.height);
});
});
it('should update existing DI when label has changed', function(done) {
it('should update existing DI when label has changed', function() {
var xml = require('./LabelBoundsSpec.simple.bpmn');
createModeler(xml, function(err, warnings, modeler) {
var shape;
return createModeler(xml).then(function(result) {
var err = result.error;
var modeler = result.modeler;
if (err) {
return done(err);
throw err;
}
var elementRegistry = modeler.get('elementRegistry'),
directEditing = modeler.get('directEditing');
var shape = elementRegistry.get('StartEvent_3');
shape = elementRegistry.get('StartEvent_3');
directEditing.activate(shape);
directEditing._textbox.content.innerText = 'BARBAZ';
directEditing.complete();
modeler.saveXML({ format: true }, function(err, result) {
return modeler.saveXML({ format: true });
}).then(function(result) {
// strip spaces and line breaks after '>'
result = result.replace(/>\s+/g,'>');
var xml = result.xml;
// get label width and height from XML
var matches = result.match(/StartEvent_3_di.*?BPMNLabel.*?width="(\d*).*?height="(\d*)/);
// strip spaces and line breaks after '>'
xml = xml.replace(/>\s+/g,'>');
var width = parseInt(matches[1]),
height = parseInt(matches[2]);
// get label width and height from XML
var matches = xml.match(/StartEvent_3_di.*?BPMNLabel.*?width="(\d*).*?height="(\d*)/);
expect(width).to.equal(shape.label.width);
expect(height).to.equal(shape.label.height);
var width = parseInt(matches[1]),
height = parseInt(matches[2]);
done(err);
});
expect(width).to.equal(shape.label.width);
expect(height).to.equal(shape.label.height);
});
});
it('should not update DI of untouched labels', function(done) {
it('should not update DI of untouched labels', function() {
var xml = require('./LabelBoundsSpec.simple.bpmn');
// strip windows line breaks (if any)
xml = xml.replace(/\r/g, '');
createModeler(xml, function(err, warnings, modeler) {
return createModeler(xml).then(function(result) {
var err = result.error;
var modeler = result.modeler;
if (err) {
return done(err);
throw err;
}
modeler.saveXML({ format: true }, function(err, result) {
return modeler.saveXML({ format: true });
}).then(function(result) {
if (err) {
return done(err);
}
var savedXML = result.xml;
expect(result).to.equal(xml);
done(err);
});
expect(savedXML).to.equal(xml);
});
});

View File

@ -23,7 +23,7 @@ describe('features/modeling - di ordering', function() {
beforeEach(bootstrapModeler(emptyProcessXML, { modules: testModules }));
it('should place after tasks', function(done) {
it('should place after tasks', function() {
// when
var task1 = add({ type: 'bpmn:Task' }, { x: 100, y: 100 }),
@ -35,7 +35,7 @@ describe('features/modeling - di ordering', function() {
task2 = add({ type: 'bpmn:Task' }, { x: 300, y: 100 });
// then
expectDiOrder([ 'Process_1', task1.id, task2.id, event.id ], done);
return expectDiOrder([ 'Process_1', task1.id, task2.id, event.id ]);
});
});
@ -45,7 +45,7 @@ describe('features/modeling - di ordering', function() {
beforeEach(bootstrapModeler(emptyProcessXML, { modules: testModules }));
it('should place di elements in correct order', function(done) {
it('should place di elements in correct order', function() {
// given
var canvas = getBpmnJS().get('canvas'),
@ -66,7 +66,7 @@ describe('features/modeling - di ordering', function() {
sequenceFlow = connect(task2, task1);
// then
expectDiOrder([
return expectDiOrder([
root.id,
participant1.id,
sequenceFlow.id,
@ -75,7 +75,7 @@ describe('features/modeling - di ordering', function() {
participant2.id,
messageFlow1.id,
messageFlow2.id
], done);
]);
});
});
@ -85,7 +85,7 @@ describe('features/modeling - di ordering', function() {
beforeEach(bootstrapModeler(emptyProcessXML, { modules: testModules }));
it('should place di elements in correct order', function(done) {
it('should place di elements in correct order', function() {
// given
var canvas = getBpmnJS().get('canvas'),
@ -102,12 +102,12 @@ describe('features/modeling - di ordering', function() {
root = canvas.getRootElement();
// then
expectDiOrder([
return expectDiOrder([
root.id,
participant.id,
subProcess.id,
task1.id,
], done);
]);
});
});
@ -117,10 +117,10 @@ describe('features/modeling - di ordering', function() {
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
it('should correctly order di elements on export', function(done) {
it('should correctly order di elements on export', function() {
// then
expectDiOrder(
return expectDiOrder(
[
'Page1Process',
'SequenceFlow_13g7fzw',
@ -176,19 +176,17 @@ describe('features/modeling - di ordering', function() {
'NotifyCustomerOfferExpiredTask',
'UpdateCustomerRecordTask',
'ReceiveTravelRequestStartEvent'
],
done
]
);
});
});
});
// helper
function expectDiOrder(expectedOrder, done) {
getBpmnJS().saveXML({ format: true }, function(error, xml) {
if (error) {
return done(error);
}
function expectDiOrder(expectedOrder) {
return getBpmnJS().saveXML({ format: true }).then(function(result) {
var xml = result.xml;
var pattern = /bpmnElement="([^"]+)"/g,
exportedOrder = [],
@ -200,12 +198,6 @@ function expectDiOrder(expectedOrder, done) {
match = pattern.exec(xml);
}
try {
expect(exportedOrder).to.eql(expectedOrder);
done();
} catch (err) {
return done(err);
}
expect(exportedOrder).to.eql(expectedOrder);
});
}

View File

@ -59,7 +59,7 @@ describe('features/snapping - BpmnCreateMoveSnapping', function() {
bootstrapModeler(diagramXML, {
container: TestContainer.get(this),
modules: testModules
})(function() {
})().then(function() {
// when
inject(function(canvas, create, dragging, elementFactory, eventBus) {
@ -107,7 +107,7 @@ describe('features/snapping - BpmnCreateMoveSnapping', function() {
bootstrapModeler(diagramXML, {
container: container,
modules: testModules
})(function() {
})().then(function() {
// when
inject(function(create, dragging, elementFactory, elementRegistry, eventBus) {

View File

@ -22,7 +22,7 @@ describe('import - BpmnTreeWalker', function() {
});
it('should walk bpmn:Definitions', function(done) {
it('should walk bpmn:Definitions', function() {
// given
var elementSpy = sinon.spy(),
@ -35,7 +35,7 @@ describe('import - BpmnTreeWalker', function() {
error: errorSpy
});
createModdle(simpleXML).then(function(result) {
return createModdle(simpleXML).then(function(result) {
var definitions = result.rootElement;
@ -46,16 +46,11 @@ describe('import - BpmnTreeWalker', function() {
expect(elementSpy.callCount).to.equal(8);
expect(rootSpy.calledOnce).to.be.true;
expect(errorSpy.notCalled).to.be.true;
done();
}).catch(function(err) {
done(err);
});
});
it('should walk bpmn:SubProcess', function(done) {
it('should walk bpmn:SubProcess', function() {
// given
var elementSpy = sinon.spy(),
@ -68,7 +63,7 @@ describe('import - BpmnTreeWalker', function() {
error: errorSpy
});
createModdle(simpleXML).then(function(result) {
return createModdle(simpleXML).then(function(result) {
var definitions = result.rootElement;
@ -90,15 +85,11 @@ describe('import - BpmnTreeWalker', function() {
expect(rootSpy.notCalled).to.be.true;
expect(errorSpy.notCalled).to.be.true;
done();
}).catch(function(err) {
done(err);
});
});
it('should error', function(done) {
it('should error', function() {
// given
var elementSpy = sinon.spy(),
@ -111,7 +102,7 @@ describe('import - BpmnTreeWalker', function() {
error: errorSpy
});
createModdle(simpleXML).then(function(result) {
return createModdle(simpleXML).then(function(result) {
var definitions = result.rootElement;
@ -127,11 +118,6 @@ describe('import - BpmnTreeWalker', function() {
expect(elementSpy.callCount).to.equal(8);
expect(rootSpy.calledOnce).to.be.true;
expect(errorSpy.calledOnce).to.be.true;
done();
}).catch(function(err) {
done(err);
});
});
@ -140,7 +126,7 @@ describe('import - BpmnTreeWalker', function() {
// helpers //////////
function createModdle(xml, done) {
function createModdle(xml) {
var moddle = new BpmnModdle();
return moddle.fromXML(xml, 'bpmn:Definitions');

View File

@ -18,8 +18,7 @@ import {
} from 'diagram-js/lib/util/GraphicsUtil';
import {
find,
isFunction
find
} from 'min-dash';
import { is } from 'lib/util/ModelUtil';
@ -41,16 +40,11 @@ describe('import - Importer', function() {
});
function runImport(diagram, xml, diagramId, done) {
if (isFunction(diagramId)) {
done = diagramId;
diagramId = null;
}
function runImport(diagram, xml, diagramId) {
var moddle = new BpmnModdle();
moddle.fromXML(xml).then(function(result) {
return moddle.fromXML(xml).then(function(result) {
var definitions = result.rootElement;
@ -58,14 +52,17 @@ describe('import - Importer', function() {
return element.id === diagramId;
});
importBpmnDiagram(diagram, definitions, selectedDiagram, done);
return importBpmnDiagram(diagram, definitions, selectedDiagram);
}).then(function(result) {
return result;
});
}
describe('events', function() {
it('should fire <import.render.start> and <import.render.complete>', function(done) {
it('should fire <import.render.start> and <import.render.complete>', function() {
// given
var xml = require('../../fixtures/bpmn/import/process.bpmn');
@ -89,17 +86,15 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// then
expect(eventCount).to.equal(2);
done(err);
});
});
it('should fire <bpmnElement.added> during import', function(done) {
it('should fire <bpmnElement.added> during import', function() {
// given
var xml = require('../../fixtures/bpmn/import/process.bpmn');
@ -112,12 +107,10 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// then
expect(eventCount).to.equal(9);
done(err);
});
});
@ -126,7 +119,7 @@ describe('import - Importer', function() {
describe('basics', function() {
it('should import process', function(done) {
it('should import process', function() {
// given
var xml = require('../../fixtures/bpmn/import/process.bpmn');
@ -144,7 +137,7 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// then
expect(events).to.eql([
@ -158,13 +151,11 @@ describe('import - Importer', function() {
{ type: 'add', semantic: 'SequenceFlow_2', di: 'BPMNEdge_SequenceFlow_2', diagramElement: 'SequenceFlow_2' },
{ type: 'add', semantic: 'SequenceFlow_3', di: 'BPMNEdge_SequenceFlow_3', diagramElement: 'SequenceFlow_3' }
]);
done(err);
});
});
it('should import collaboration', function(done) {
it('should import collaboration', function() {
// given
var xml = require('../../fixtures/bpmn/import/collaboration.bpmn');
@ -182,7 +173,7 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// then
expect(events).to.eql([
@ -195,8 +186,6 @@ describe('import - Importer', function() {
{ type: 'add', semantic: 'Lane_2', di: '_BPMNShape_Lane_3', diagramElement: 'Lane_2' },
{ type: 'add', semantic: 'Lane_3', di: '_BPMNShape_Lane_4', diagramElement: 'Lane_3' }
]);
done(err);
});
});
@ -208,7 +197,7 @@ describe('import - Importer', function() {
var xml = require('../../fixtures/bpmn/import/position/position-testcase.bpmn');
it('should round shape coordinates', function(done) {
it('should round shape coordinates', function() {
// given
var events = {};
@ -219,7 +208,7 @@ describe('import - Importer', function() {
events[e.element.id] = e.element;
});
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// round up
expect(events.ID_End.x).to.equal(Math.round(340.6));
@ -228,13 +217,11 @@ describe('import - Importer', function() {
// round down
expect(events.ID_Start.x).to.equal(Math.round(120.4));
expect(events.ID_Start.y).to.equal(Math.round(135.4));
done(err);
});
});
it('should round shape dimensions', function(done) {
it('should round shape dimensions', function() {
// given
var events = {};
@ -245,13 +232,12 @@ describe('import - Importer', function() {
events[e.element.id] = e.element;
});
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// round down
expect(events.ID_Start.height).to.equal(Math.round(30.4));
expect(events.ID_Start.width).to.equal(Math.round(30.4));
done(err);
});
});
@ -260,7 +246,7 @@ describe('import - Importer', function() {
describe('order', function() {
it('should import sequence flows and lanes behind other flow nodes', function(done) {
it('should import sequence flows and lanes behind other flow nodes', function() {
var xml = require('./sequenceFlow-ordering.bpmn');
@ -268,7 +254,7 @@ describe('import - Importer', function() {
var elementRegistry = diagram.get('elementRegistry');
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// when
var processShape = elementRegistry.get('Participant_1jxpy8o');
@ -287,7 +273,6 @@ describe('import - Importer', function() {
// then
expectChildren(diagram, processShape, correctlyOrdered);
done(err);
});
});
@ -296,7 +281,7 @@ describe('import - Importer', function() {
describe('elements', function() {
it('should import boundary events', function(done) {
it('should import boundary events', function() {
// given
var xml = require('../../fixtures/bpmn/import/boundaryEvent.bpmn');
@ -314,7 +299,7 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
// then
expect(events).to.eql([
@ -325,12 +310,11 @@ describe('import - Importer', function() {
{ type: 'add', semantic: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' }
]);
done(err);
});
});
it('should import data store as child of participant', function(done) {
it('should import data store as child of participant', function() {
// given
var xml = require('../../fixtures/bpmn/import/data-store.inside-participant.bpmn');
@ -343,16 +327,15 @@ describe('import - Importer', function() {
events[e.element.id] = e.element;
});
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
expect(events.DataStoreReference.parent).to.equal(events.Participant);
done(err);
});
});
it('should import data store in participant as child of collaboration', function(done) {
it('should import data store in participant as child of collaboration', function() {
// given
var xml = require('../../fixtures/bpmn/import/data-store.outside-participant.participant.bpmn');
@ -365,15 +348,14 @@ describe('import - Importer', function() {
events[e.element.id] = e.element;
});
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
expect(events.DataStoreReference.parent).to.equal(events.Collaboration);
done(err);
});
});
it('should import data store in subprocess as child of collaboration', function(done) {
it('should import data store in subprocess as child of collaboration', function() {
// given
var xml = require('../../fixtures/bpmn/import/data-store.outside-participant.subprocess.bpmn');
@ -386,31 +368,31 @@ describe('import - Importer', function() {
events[e.element.id] = e.element;
});
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
expect(events.DataStoreReference.parent).to.equal(events.Collaboration);
done(err);
});
});
it('should import data store outside of participant without warnings', function(done) {
it('should import data store outside of participant without warnings', function() {
// given
var xml = require('../../fixtures/bpmn/import/data-store.outside-participant.dangling.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
// then
expect(warnings).to.be.empty;
done(err);
});
});
it('should import single diagram from multiple diagrams 2', function(done) {
it('should import single diagram from multiple diagrams 2', function() {
// given
var xml = require('../../fixtures/bpmn/import/multiple-diagrams.bpmn');
@ -428,7 +410,7 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, 'BPMNDiagram_2', function(err, warnings) {
return runImport(diagram, xml, 'BPMNDiagram_2').then(function() {
// then
expect(events).to.eql([
@ -440,12 +422,11 @@ describe('import - Importer', function() {
{ type: 'add', semantic: 'SequenceFlow_5', di: 'BPMNEdge_SequenceFlow_5', diagramElement: 'SequenceFlow_5' }
]);
done(err);
});
});
it('should import single diagram from multiple diagrams 1', function(done) {
it('should import single diagram from multiple diagrams 1', function() {
// given
var xml = require('../../fixtures/bpmn/import/multiple-diagrams.bpmn');
@ -463,7 +444,7 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, 'BPMNDiagram_1', function(err, warnings) {
return runImport(diagram, xml, 'BPMNDiagram_1').then(function() {
// then
expect(events).to.eql([
@ -477,13 +458,11 @@ describe('import - Importer', function() {
{ type: 'add', semantic: 'SequenceFlow_3', di: 'BPMNEdge_SequenceFlow_3', diagramElement: 'SequenceFlow_3' }
]);
done(err);
});
});
it('should import groups', function(done) {
it('should import groups', function() {
// given
var xml = require('../../fixtures/bpmn/import/groups.bpmn');
@ -502,7 +481,7 @@ describe('import - Importer', function() {
});
// when
runImport(diagram, xml, function(err) {
return runImport(diagram, xml).then(function() {
// then
expect(events).to.eql([
@ -510,7 +489,6 @@ describe('import - Importer', function() {
{ type: 'add', semantic: 'Group_1', di: 'Group_1_di', diagramElement: 'Group_1', isFrame: true }
]);
done(err);
});
});
@ -519,28 +497,32 @@ describe('import - Importer', function() {
describe('forgiveness', function() {
it('should import invalid flowElement', function(done) {
it('should import invalid flowElement', function() {
// given
var xml = require('../../fixtures/bpmn/import/error/invalid-flow-element.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
// then
expect(warnings).to.have.length(0);
done(err);
});
});
it('should import multiple DIs', function(done) {
it('should import multiple DIs', function() {
// given
var xml = require('../../fixtures/bpmn/import/error/multiple-dis.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
var expectedMessage =
'multiple DI elements defined for <bpmn:InclusiveGateway id="InclusiveGateway_1" />';
@ -548,33 +530,34 @@ describe('import - Importer', function() {
expect(warnings).to.have.length(1);
expect(warnings[0].message).to.equal(expectedMessage);
done(err);
});
});
it('should import sequence flow without waypoints', function(done) {
it('should import sequence flow without waypoints', function() {
// given
var xml = require('./sequenceFlow-missingWaypoints.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
// then
expect(warnings).to.be.empty;
done(err);
});
});
it('should extend attributes with default value', function(done) {
it('should extend attributes with default value', function() {
// given
var xml = require('../../fixtures/bpmn/import/default-attrs.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
var elementRegistry = diagram.get('elementRegistry');
@ -582,20 +565,21 @@ describe('import - Importer', function() {
expect(element.businessObject.eventGatewayType).to.equal('Exclusive');
done();
});
});
describe('boundary events', function() {
it('should handle missing attachToRef', function(done) {
it('should handle missing attachToRef', function() {
// given
var xml = require('../../fixtures/bpmn/import/error/boundaryEvent-missingAttachToRef.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
// then
expect(warnings.length).to.eql(2);
@ -603,18 +587,19 @@ describe('import - Importer', function() {
expect(warnings[0].message).to.eql('missing <bpmn:BoundaryEvent id="BoundaryEvent_1" />#attachedToRef');
expect(warnings[1].message).to.eql('element <bpmn:BoundaryEvent id="BoundaryEvent_1" /> referenced by <bpmn:SequenceFlow id="SequenceFlow_1" />#sourceRef not yet drawn');
done(err);
});
});
it('should handle invalid attachToRef', function(done) {
it('should handle invalid attachToRef', function() {
// given
var xml = require('../../fixtures/bpmn/import/error/boundaryEvent-invalidAttachToRef.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
// then
expect(warnings.length).to.eql(2);
@ -622,7 +607,6 @@ describe('import - Importer', function() {
expect(warnings[0].message).to.eql('missing <bpmn:BoundaryEvent id="BoundaryEvent_1" />#attachedToRef');
expect(warnings[1].message).to.eql('element <bpmn:BoundaryEvent id="BoundaryEvent_1" /> referenced by <bpmn:SequenceFlow id="SequenceFlow_1" />#sourceRef not yet drawn');
done(err);
});
});
@ -633,13 +617,15 @@ describe('import - Importer', function() {
describe('integration', function() {
it('should import dangling process message flows', function(done) {
it('should import dangling process message flows', function() {
// given
var xml = require('../../fixtures/bpmn/import/error/dangling-process-message-flow.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function(result) {
var warnings = result.warnings;
// then
expect(warnings).to.have.length(0);
@ -647,7 +633,6 @@ describe('import - Importer', function() {
expect(diagram.get('elementRegistry').get('_b467921a-ef7b-44c5-bf78-fd624c400d17')).to.exist;
expect(diagram.get('elementRegistry').get('_c311cc87-677e-47a4-bdb1-8744c4ec3147')).to.exist;
done(err);
});
});
@ -656,13 +641,13 @@ describe('import - Importer', function() {
describe('hiding', function() {
it('should hide shapes and connections inside of collapsed subprocess', function(done) {
it('should hide shapes and connections inside of collapsed subprocess', function() {
// given
var xml = require('../../fixtures/bpmn/import/collapsed/processWithChildren.bpmn');
// when
runImport(diagram, xml, function(err, warnings) {
return runImport(diagram, xml).then(function() {
var elementRegistry = diagram.get('elementRegistry');
@ -674,7 +659,6 @@ describe('import - Importer', function() {
// then
expect(visible).to.be.undefined;
done(err);
});
});

View File

@ -8,12 +8,16 @@ describe('import - associations', function() {
describe('should import association', function() {
it('connecting task -> text annotation', function(done) {
it('connecting task -> text annotation', function() {
var xml = require('./AssociationSpec.text-annotation.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
expect(err).not.to.exist;
// when
inject(function(elementRegistry) {
@ -22,20 +26,22 @@ describe('import - associations', function() {
// then
expect(association).to.exist;
done(err);
})();
});
});
it('connecting boundary -> compensate task', function(done) {
it('connecting boundary -> compensate task', function() {
var xml = require('./AssociationSpec.compensation.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
expect(err).not.to.exist;
// when
inject(function(elementRegistry) {
@ -44,8 +50,6 @@ describe('import - associations', function() {
// then
expect(association).to.exist;
done();
})();
});
@ -74,95 +78,104 @@ describe('import - associations', function() {
}
it('task -> data object -> task', function(done) {
it('task -> data object -> task', function() {
var xml = require('./AssociationSpec.data-association.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
// then
expect(err).not.to.exist;
expectRendered([
'DataInputAssociation',
'DataOutputAssociation'
]);
done(err);
});
});
it('data input -> task -> data output', function(done) {
it('data input -> task -> data output', function() {
var xml = require('./AssociationSpec.data-input-output.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
// then
expect(err).not.to.exist;
expectRendered([
'DataInputAssociation',
'DataOutputAssociation'
]);
done(err);
});
});
it('in collaboration', function(done) {
it('in collaboration', function() {
var xml = require('./AssociationSpec.collaboration.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
// then
expect(err).not.to.exist;
expectRendered([
'DataInputAssociation',
'DataOutputAssociation'
]);
done(err);
});
});
it('catch event -> data object -> throw event', function(done) {
it('catch event -> data object -> throw event', function() {
var xml = require('./AssociationSpec.events.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
// then
expect(err).not.to.exist;
expectRendered([
'DataInputAssociation',
'DataOutputAssociation'
]);
done(err);
});
});
it('boundary event -> data object', function(done) {
it('boundary event -> data object', function() {
var xml = require('./AssociationSpec.data-association.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
// then
expect(err).not.to.exist;
expectRendered([
'DataOutputAssociation_2'
]);
done(err);
});
});
});
});
});

View File

@ -8,12 +8,16 @@ describe('import - data input/output', function() {
describe('should import external labels', function() {
it('with di', function(done) {
it('with di', function() {
var xml = require('./DataInputOutput.bpmn');
// given
bootstrapViewer(xml).call(this, function(err) {
return bootstrapViewer(xml).call(this).then(function(result) {
var err = result.error;
expect(err).not.to.exist;
// when
inject(function(elementRegistry) {
@ -34,8 +38,6 @@ describe('import - data input/output', function() {
expect(outputCenter.y).to.be.within(190, 210);
expect(outputLabel.width).to.be.above(20);
expect(outputLabel.height).to.be.above(10);
done(err);
})();
});
@ -53,4 +55,4 @@ function getCenter(element) {
x: element.x + Math.ceil(element.width / 2),
y: element.y + Math.ceil(element.height / 2)
};
}
}

View File

@ -8,11 +8,15 @@ describe('import - groups', function() {
describe('should import groups', function() {
it('with frame property set', function(done) {
it('with frame property set', function() {
var xml = require('./Groups.bpmn');
// given
bootstrapModeler(xml)(function(err) {
return bootstrapModeler(xml)().then(function(result) {
var err = result.error;
expect(err).not.to.exist;
// when
inject(function(elementRegistry) {
@ -22,8 +26,6 @@ describe('import - groups', function() {
expect(groupElement).to.exist;
expect(groupElement.isFrame).to.be.true;
done(err);
})();
});
@ -32,4 +34,4 @@ describe('import - groups', function() {
});
});
});

View File

@ -8,21 +8,27 @@ describe('import - labels', function() {
describe('should import embedded labels', function() {
it('on flow nodes', function(done) {
it('on flow nodes', function() {
var xml = require('../../../fixtures/bpmn/import/labels/embedded.bpmn');
bootstrapViewer(xml)(done);
return bootstrapViewer(xml)().then(function(result) {
expect(result.error).not.to.exist;
});
});
it('on pools and lanes', function(done) {
it('on pools and lanes', function() {
var xml = require('../../../fixtures/bpmn/import/labels/collaboration.bpmn');
bootstrapViewer(xml)(done);
return bootstrapViewer(xml)().then(function(result) {
expect(result.error).not.to.exist;
});
});
it('on message flows', function(done) {
it('on message flows', function() {
var xml = require('../../../fixtures/bpmn/import/labels/collaboration-message-flows.bpmn');
bootstrapViewer(xml)(done);
return bootstrapViewer(xml)().then(function(result) {
expect(result.error).not.to.exist;
});
});
});
@ -30,11 +36,15 @@ describe('import - labels', function() {
describe('should import external labels', function() {
it('with di', function(done) {
it('with di', function() {
var xml = require('../../../fixtures/bpmn/import/labels/external.bpmn');
// given
bootstrapViewer(xml)(function(err) {
return bootstrapViewer(xml)().then(function(result) {
var err = result.error;
expect(err).not.to.exist;
// when
inject(function(elementRegistry) {
@ -55,17 +65,17 @@ describe('import - labels', function() {
expect(sequenceFlowCenter.y).to.be.within(323, 335);
expect(sequenceFlowLabel.width).to.be.above(64);
expect(sequenceFlowLabel.height).to.be.above(11);
done(err);
})();
});
});
it('without di', function(done) {
it('without di', function() {
var xml = require('../../../fixtures/bpmn/import/labels/external-no-di.bpmn');
bootstrapViewer(xml)(done);
return bootstrapViewer(xml)().then(function(result) {
expect(result.error).not.to.exist;
});
});
});
@ -80,4 +90,4 @@ function getCenter(element) {
x: element.x + Math.ceil(element.width / 2),
y: element.y + Math.ceil(element.height / 2)
};
}
}