From 04ca31fac9866472138bf4f30553e21a5bebf6a8 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 29 Apr 2020 11:02:42 +0200 Subject: [PATCH] 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. --- README.md | 14 +- lib/BaseViewer.js | 389 +++-- lib/Modeler.js | 27 +- lib/import/Importer.js | 63 +- lib/util/CompatibilityUtil.js | 2 +- test/helper/index.js | 27 +- test/integration/ReimportSpec.js | 9 +- test/integration/SimpleModelingSpec.js | 7 +- test/integration/model/BpmnModdleSpec.js | 15 +- test/spec/ModelerSpec.js | 259 +-- test/spec/NavigatedViewerSpec.js | 50 +- test/spec/ViewerSpec.js | 1396 ++++++++++++----- test/spec/draw/BpmnRendererSpec.js | 269 +++- .../label-editing/TouchIntegrationSpec.js | 20 +- .../spec/features/modeling/LabelBoundsSpec.js | 106 +- .../features/ordering/BpmnDiOrderingSpec.js | 40 +- .../snapping/BpmnCreateMoveSnappingSpec.js | 4 +- test/spec/import/BpmnTreeWalkerSpec.js | 28 +- test/spec/import/ImporterSpec.js | 154 +- test/spec/import/elements/AssociationSpec.js | 71 +- .../import/elements/DataInputOutputSpec.js | 12 +- test/spec/import/elements/GroupsSpec.js | 12 +- test/spec/import/elements/LabelSpec.js | 36 +- 23 files changed, 1961 insertions(+), 1049 deletions(-) diff --git a/README.md b/README.md index e9602099..04fbc3eb 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/BaseViewer.js b/lib/BaseViewer.js index 1311490c..0622c021 100644 --- a/lib/BaseViewer.js +++ b/lib/BaseViewer.js @@ -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} warnings +*/ + +/** +* The importXML error. +* +* @typedef {Error} ImportXMLError +* +* @property {Array} 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|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} */ -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} warnings +*/ + +/** +* The importDefinitions error. +* +* @typedef {Error} ImportDefinitionsError +* +* @property {Array} 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 parsed BPMN 2.0 definitions * @param {ModdleElement|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} */ -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} warnings + */ + +/** +* The open error. +* +* @typedef {Error} OpenError +* +* @property {Array} 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} [bpmnDiagramOrId] id or the diagram to open - * @param {Function} [done] invoked with (err, warnings=[]) + * + * Returns {Promise} */ -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} */ -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} */ -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 ? '' + innerSVG(defsNode) + '' : ''; + try { + var canvas = self.get('canvas'); - var bbox = contentNode.getBBox(); + var contentNode = canvas.getDefaultLayer(), + defsNode = domQuery('defs', canvas._svg); - svg = - '\n' + - '\n' + - '\n' + - '' + - defs + contents + - ''; - } catch (e) { - err = e; - } + var contents = innerSVG(contentNode), + defs = defsNode ? '' + innerSVG(defsNode) + '' : ''; - this._emit('saveSVG.done', { - error: err, - svg: svg + var bbox = contentNode.getBBox(); + + svg = + '\n' + + '\n' + + '\n' + + '' + + defs + contents + + ''; + } 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 diff --git a/lib/Modeler.js b/lib/Modeler.js index 94d17e0f..b0ec29d8 100644 --- a/lib/Modeler.js +++ b/lib/Modeler.js @@ -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 = '' + @@ -139,14 +142,30 @@ inherits(Modeler, BaseModeler); Modeler.Viewer = Viewer; Modeler.NavigatedViewer = NavigatedViewer; +/** +* The createDiagram result. +* +* @typedef {Object} CreateDiagramResult +* +* @property {Array} warnings +*/ + +/** +* The createDiagram error. +* +* @typedef {Error} CreateDiagramError +* +* @property {Array} warnings +*/ + /** * Create a new diagram to start modeling. * - * @param {Function} [done] + * Returns {Promise} */ -Modeler.prototype.createDiagram = function(done) { - return this.importXML(initialDiagram, done); -}; +Modeler.prototype.createDiagram = wrapForCompatibility(function createDiagram() { + return this.importXML(initialDiagram); +}); Modeler.prototype._interactionModules = [ diff --git a/lib/import/Importer.js b/lib/import/Importer.js index 3a58d8c5..3974f048 100644 --- a/lib/import/Importer.js +++ b/lib/import/Importer.js @@ -1,8 +1,21 @@ import BpmnTreeWalker from './BpmnTreeWalker'; -import { - isFunction -} from 'min-dash'; + +/** + * The importBpmnDiagram result. + * + * @typedef {Object} ImportBPMNDiagramResult + * + * @property {Array} warnings + */ + +/** +* The importBpmnDiagram error. +* +* @typedef {Error} ImportBPMNDiagramError +* +* @property {Array} warnings +*/ /** * Import the definitions into a diagram. @@ -13,14 +26,10 @@ import { * @param {ModdleElement} definitions * @param {ModdleElement} [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} */ -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); -} \ No newline at end of file + return resolve({ warnings: warnings }); + } catch (e) { + + e.warnings = warnings; + return reject(e); + } + }); +} diff --git a/lib/util/CompatibilityUtil.js b/lib/util/CompatibilityUtil.js index 1f60716a..f407dc43 100644 --- a/lib/util/CompatibilityUtil.js +++ b/lib/util/CompatibilityUtil.js @@ -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; diff --git a/test/helper/index.js b/test/helper/index.js index 10bfdd8d..46c28b84 100644 --- a/test/helper/index.js +++ b/test/helper/index.js @@ -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); -} \ No newline at end of file +} diff --git a/test/integration/ReimportSpec.js b/test/integration/ReimportSpec.js index 8e221bff..4839f4fd 100644 --- a/test/integration/ReimportSpec.js +++ b/test/integration/ReimportSpec.js @@ -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); }); } diff --git a/test/integration/SimpleModelingSpec.js b/test/integration/SimpleModelingSpec.js index 19342a35..06b213cf 100644 --- a/test/integration/SimpleModelingSpec.js +++ b/test/integration/SimpleModelingSpec.js @@ -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(); }); }); diff --git a/test/integration/model/BpmnModdleSpec.js b/test/integration/model/BpmnModdleSpec.js index e13cfe05..0a94923e 100644 --- a/test/integration/model/BpmnModdleSpec.js +++ b/test/integration/model/BpmnModdleSpec.js @@ -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 = '' + @@ -22,7 +22,7 @@ describe('bpmn-moddle', function() { ''; // 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); }); }); diff --git a/test/spec/ModelerSpec.js b/test/spec/ModelerSpec.js index a77b252f..0730b4cc 100644 --- a/test/spec/ModelerSpec.js +++ b/test/spec/ModelerSpec.js @@ -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 ', function(done) { + it('should provide self as ', 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); }); }); diff --git a/test/spec/NavigatedViewerSpec.js b/test/spec/NavigatedViewerSpec.js index 4271ba36..853206b4 100644 --- a/test/spec/NavigatedViewerSpec.js +++ b/test/spec/NavigatedViewerSpec.js @@ -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); }); }); - }); - }); diff --git a/test/spec/ViewerSpec.js b/test/spec/ViewerSpec.js index fcf3ac78..2cb0fcaa 100644 --- a/test/spec/ViewerSpec.js +++ b/test/spec/ViewerSpec.js @@ -9,12 +9,7 @@ import Viewer from 'lib/Viewer'; import inherits from 'inherits'; import { - isFunction -} from 'min-dash'; - -import { - setBpmnJS, - clearBpmnJS + createViewer } from 'test/TestHelper'; @@ -27,29 +22,15 @@ describe('Viewer', function() { }); - function createViewer(xml, diagramId, done) { - if (isFunction(diagramId)) { - done = diagramId; - diagramId = null; - } - - clearBpmnJS(); - - var viewer = new Viewer({ container: container }); - - setBpmnJS(viewer); - - viewer.importXML(xml, diagramId, 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'); // when - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var warnings = result.warnings; + var viewer = result.viewer; // then expect(err).not.to.exist; @@ -59,27 +40,25 @@ describe('Viewer', function() { expect(definitions).to.exist; expect(definitions).to.eql(viewer._definitions); - - done(); }); }); - it('should re-import simple process', function(done) { + it('should re-import simple process', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); // given - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var viewer = result.viewer; // when // mimic re-import of same diagram - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { // then - expect(warnings).to.be.empty; - - done(); + expect(result.warnings).to.be.empty; }); }); @@ -98,11 +77,16 @@ describe('Viewer', 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'); - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var viewer = result.viewer; + + expect(err).not.to.exist; // when var overlays = viewer.get('overlays'), @@ -123,8 +107,6 @@ describe('Viewer', function() { // then expect(overlays.get({ element: 'SubProcess_1' }).length).to.equal(1); - - done(err); }); }); @@ -172,27 +154,30 @@ describe('Viewer', function() { } - it('should handle non-bpmn input', function(done) { + it('should handle non-bpmn input', function() { var xml = 'invalid stuff'; - createViewer(xml, function(err) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; expect(err).to.exist; expectMessage(err, /missing start tag/); - - done(); }); }); - it('should handle invalid BPMNPlane#bpmnElement', function(done) { + it('should handle invalid BPMNPlane#bpmnElement', function() { var xml = require('../fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn'); // when - createViewer(xml, function(err, warnings) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var warnings = result.warnings; // then expect(err).not.to.exist; @@ -204,18 +189,19 @@ describe('Viewer', function() { 'on ' + 'to ' ]); - - done(); }); }); - it('should handle invalid namespaced element', function(done) { + it('should handle invalid namespaced element', function() { var xml = require('../fixtures/bpmn/error/categoryValue.bpmn'); // when - createViewer(xml, function(err, warnings) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var warnings = result.warnings; // then expect(err).not.to.exist; @@ -224,18 +210,19 @@ describe('Viewer', function() { /unparsable content detected/, 'unresolved reference ' ]); - - done(); }); }); - it('should handle missing namespace', function(done) { + it('should handle missing namespace', function() { var xml = require('../fixtures/bpmn/error/missing-namespace.bpmn'); // when - createViewer(xml, function(err, warnings) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var warnings = result.warnings; // then expect(err).to.exist; @@ -243,18 +230,19 @@ describe('Viewer', function() { expect(warnings).to.have.length(1); expect(warnings[0].message).to.match(/unparsable content detected/); - - done(); }); }); - it('should handle duplicate ids', function(done) { + it('should handle duplicate ids', function() { var xml = require('../fixtures/bpmn/error/duplicate-ids.bpmn'); // when - createViewer(xml, function(err, warnings) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var warnings = result.warnings; // then expect(err).not.to.exist; @@ -262,23 +250,21 @@ describe('Viewer', function() { expectWarnings(warnings, [ /duplicate ID / ]); - - done(); }); }); - it('should throw error due to missing diagram', function(done) { + it('should throw error due to missing diagram', function() { var xml = require('../fixtures/bpmn/empty-definitions.bpmn'); // when - createViewer(xml, function(err, warnings) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; // then expect(err.message).to.eql('no diagram to display'); - - done(); }); }); @@ -287,15 +273,17 @@ describe('Viewer', function() { describe('dependency injection', function() { - it('should provide self as ', function(done) { + it('should provide self as ', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var viewer = result.viewer; + var err = result.error; expect(viewer.get('bpmnjs')).to.equal(viewer); - - done(err); + expect(err).not.to.exist; }); }); @@ -312,7 +300,7 @@ describe('Viewer', 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'), @@ -324,22 +312,19 @@ describe('Viewer', function() { canvas = viewer.get('canvas'); // when - viewer.importXML(someXML, function() { + return viewer.importXML(someXML).then(function() { // then expect(viewer.get('canvas')).to.equal(canvas); expect(viewer.get('eventBus')).to.equal(eventBus); - viewer.importXML(otherXML, function() { + return viewer.importXML(otherXML); + }).then(function() { - // then - expect(viewer.get('canvas')).to.equal(canvas); - expect(viewer.get('eventBus')).to.equal(eventBus); - - done(); - }); + // then + expect(viewer.get('canvas')).to.equal(canvas); + expect(viewer.get('eventBus')).to.equal(eventBus); }); - }); }); @@ -359,35 +344,32 @@ describe('Viewer', function() { viewer.destroy(); }); - it('should override default modules', function(done) { + it('should override default modules', function() { // given viewer = new Viewer({ container: container, modules: testModules }); // when - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).catch(function(err) { // then expect(err.message).to.equal('No provider for "bpmnImporter"! (Resolving: bpmnImporter)'); - done(); }); }); - it('should add module to default modules', function(done) { + it('should add module to default modules', function() { // given viewer = new Viewer({ container: container, additionalModules: testModules }); // when - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).then(function(result) { // then var logger = viewer.get('logger'); expect(logger.called).to.be.true; - - done(err); }); }); @@ -412,7 +394,7 @@ describe('Viewer', function() { var camundaPackage = require('../fixtures/json/model/camunda'); - it('should provide custom moddle extensions', function(done) { + it('should provide custom moddle extensions', function() { var xml = require('../fixtures/bpmn/extension/camunda.bpmn'); @@ -425,7 +407,7 @@ describe('Viewer', function() { }); // when - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { var elementRegistry = viewer.get('elementRegistry'); @@ -446,14 +428,12 @@ describe('Viewer', function() { expect(extensionElements.values).to.have.length(1); expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true; - - done(err); }); }); - it('should allow to add default custom moddle extensions', function(done) { + it('should allow to add default custom moddle extensions', function() { // given var xml = require('../fixtures/bpmn/extension/custom.bpmn'), @@ -477,7 +457,7 @@ describe('Viewer', function() { }); // when - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { var elementRegistry = viewer.get('elementRegistry'); @@ -500,14 +480,12 @@ describe('Viewer', function() { expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true; expect(extensionElements.values[1].$instanceOf('custom:CustomSendElement')).to.be.true; - - done(err); }); }); - it('should allow user to override default custom moddle extensions', function(done) { + it('should allow user to override default custom moddle extensions', function() { // given var xml = require('../fixtures/bpmn/extension/custom-override.bpmn'); @@ -535,7 +513,7 @@ describe('Viewer', function() { }); // when - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { var elementRegistry = viewer.get('elementRegistry'); @@ -558,8 +536,6 @@ describe('Viewer', function() { expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.be.true; expect(extensionElements.values[1].$instanceOf('custom:CustomSendElementOverride')).to.be.true; - - done(err); }); }); @@ -571,7 +547,7 @@ describe('Viewer', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); - it('should configure Canvas', function(done) { + it('should configure Canvas', function() { // given var viewer = new Viewer({ @@ -582,14 +558,12 @@ describe('Viewer', function() { }); // when - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).then(function(result) { var canvasConfig = viewer.get('config.canvas'); // then expect(canvasConfig.deferUpdate).to.be.true; - - done(); }); }); @@ -597,32 +571,28 @@ describe('Viewer', function() { describe('container', function() { - it('should attach if provided', function(done) { + it('should attach if provided', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); var viewer = new Viewer({ container: container }); - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { expect(viewer._container.parentNode).to.equal(container); - - done(err, warnings); }); }); - it('should not attach if absent', function(done) { + it('should not attach if absent', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); var viewer = new Viewer(); - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { expect(viewer._container.parentNode).to.equal(null); - - done(err, warnings); }); }); @@ -633,7 +603,7 @@ describe('Viewer', function() { describe('#importXML', function() { - it('should emit events', function(done) { + it('should emit events', function() { // given var viewer = new Viewer({ container: container }); @@ -660,7 +630,7 @@ describe('Viewer', function() { }); // when - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).then(function(result) { // then expect(events).to.eql([ @@ -670,8 +640,6 @@ describe('Viewer', function() { [ 'import.render.complete', [ 'error', 'warnings' ] ], [ 'import.done', [ 'error', 'warnings' ] ] ]); - - done(err); }); }); @@ -698,41 +666,45 @@ describe('Viewer', function() { var multipleXML = require('../fixtures/bpmn/multiple-diagrams.bpmn'); - it('should import default without bpmnDiagram specified', function(done) { + it('should import default without bpmnDiagram specified', function() { // when - createViewer(multipleXML, function(err) { + return createViewer(container, Viewer, multipleXML).then(function(result) { + + var err = result.error; // then - done(err); + expect(err).not.to.exist; }); }); - it('should import bpmnDiagram specified by id', function(done) { + it('should import bpmnDiagram specified by id', function() { // when - createViewer(multipleXML, 'BpmnDiagram_2', function(err) { + return createViewer(container, Viewer, multipleXML, 'BpmnDiagram_2').then(function(result) { + + var err = result.error; // then - done(err); + expect(err).not.to.exist; }); }); - it('should handle diagram not found', function(done) { + it('should handle diagram not found', function() { // given var xml = require('../fixtures/bpmn/multiple-diagrams.bpmn'); // when - createViewer(xml, 'Diagram_IDontExist', function(err) { + return createViewer(container, Viewer, xml, 'Diagram_IDontExist').then(function(result) { + + var err = result.error; // then expect(err).to.exist; expect(err.message).to.eql('BPMNDiagram not found'); - - done(); }); }); @@ -783,17 +755,19 @@ describe('Viewer', function() { viewer, definitions; - beforeEach(function(done) { - createViewer(xml, null, function(error, _, tmpViewer) { + beforeEach(function() { + return createViewer(container, Viewer, xml, null).then(function(result) { + + var error = result.error; + var tmpViewer = result.viewer; + if (error) { - return done(error); + throw error; } definitions = tmpViewer.getDefinitions(); tmpViewer.destroy(); - - done(); }); }); @@ -806,7 +780,7 @@ describe('Viewer', function() { }); - it('should emit events', function(done) { + it('should emit events', function() { // given var events = []; @@ -829,15 +803,13 @@ describe('Viewer', function() { }); // when - viewer.importDefinitions(definitions, function(err) { + return viewer.importDefinitions(definitions).then(function() { // then expect(events).to.eql([ [ 'import.render.start', [ 'definitions' ] ], [ 'import.render.complete', [ 'error', 'warnings' ] ] ]); - - done(err); }); }); @@ -864,17 +836,19 @@ describe('Viewer', function() { viewer, definitions; - beforeEach(function(done) { - createViewer(multipleXML, null, function(error, _, tmpViewer) { + beforeEach(function() { + return createViewer(container, Viewer, multipleXML).then(function(result) { + + var error = result.error; + var tmpViewer = result.viewer; + if (error) { - return done(error); + throw error; } definitions = tmpViewer.getDefinitions(); tmpViewer.destroy(); - - done(); }); }); @@ -887,38 +861,28 @@ describe('Viewer', function() { }); - it('should import default without bpmnDiagram specified', function(done) { + it('should import default without bpmnDiagram specified', function() { // when - viewer.importDefinitions(definitions, function(err) { - - // then - done(err); - }); + return viewer.importDefinitions(definitions); }); - it('should import bpmnDiagram specified by id', function(done) { + it('should import bpmnDiagram specified by id', function() { // when - viewer.importDefinitions(definitions, 'BpmnDiagram_2', function(err) { - - // then - done(err); - }); + return viewer.importDefinitions(definitions, 'BpmnDiagram_2'); }); - it('should handle diagram not found', function(done) { + it('should handle diagram not found', function() { // when - viewer.importDefinitions(definitions, 'Diagram_IDontExist', function(err) { + return viewer.importDefinitions(definitions, 'Diagram_IDontExist').catch(function(err) { // then expect(err).to.exist; expect(err.message).to.eql('BPMNDiagram not found'); - - done(); }); }); @@ -967,154 +931,146 @@ describe('Viewer', function() { diagram2 = 'BpmnDiagram_2'; - it('should open the first diagram if id was not provided', function(done) { + it('should open the first diagram if id was not provided', function() { + + var viewer, renderedDiagram; // when - createViewer(multipleXMLSimple, diagram1, function(err, warnings, viewer) { + return createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) { - if (err) { - return done(err); - } + var err = result.error; + viewer = result.viewer; + + expect(err).not.to.exist; + + renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di; + + return viewer.open(); + }).then(function() { // then - var renderedDiagram = viewer.get('canvas').getRootElement().businessObject.di; - - viewer.open(function(err) { - - if (err) { - return done(err); - } - - // then - expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram); - - done(); - }); + expect(viewer.get('canvas').getRootElement().businessObject.di).to.equal(renderedDiagram); }); }); - it('should switch between diagrams', function(done) { + it('should switch between diagrams', function() { + + var viewer, definitions; // when - createViewer(multipleXMLSimple, diagram1, function(err, warnings, viewer) { + return createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) { + + var err = result.error; + var warnings = result.warnings; + viewer = result.viewer; // then - if (err) { - return done(err); - } + + expect(err).not.to.exist; expect(warnings).to.be.empty; - var definitions = viewer.getDefinitions(); + definitions = viewer.getDefinitions(); expect(definitions).to.exist; - viewer.open(diagram2, function(err, warnings) { - - // then - if (err) { - return done(err); - } - - 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(); - }); - - }); - - }); - - - it('should switch between diagrams with overlapping DI', function(done) { - - // when - createViewer(multipleXMLOverlappingDI, diagram1, function(err, warnings, viewer) { + return viewer.open(diagram2); + }).then(function(result) { // then - if (err) { - return done(err); - } + var warnings = result.warnings; expect(warnings).to.be.empty; - var definitions = viewer.getDefinitions(); + expect(definitions).to.equal(viewer.getDefinitions()); - expect(definitions).to.exist; - - viewer.open(diagram2, function(err, warnings) { - - // then - if (err) { - return done(err); - } - - expect(warnings).to.be.empty; - - expect(definitions).to.equal(viewer.getDefinitions()); - - done(); - }); + var elementRegistry = viewer.get('elementRegistry'); + expect(elementRegistry.get('Task_A')).to.not.exist; + expect(elementRegistry.get('Task_B')).to.exist; }); }); - it('should switch between diagrams with laneSets', function(done) { + it('should switch between diagrams with overlapping DI', function() { + + var viewer, definitions; // when - createViewer(multipleXMLWithLaneSet, diagram2, function(err, warnings, viewer) { + return createViewer(container, Viewer, multipleXMLOverlappingDI, diagram1).then(function(result) { + + var err = result.error; + var warnings = result.warnings; + viewer = result.viewer; // then - if (err) { - return done(err); - } + expect(err).not.to.exist; expect(warnings).to.be.empty; - var definitions = viewer.getDefinitions(); + definitions = viewer.getDefinitions(); expect(definitions).to.exist; - viewer.open(diagram1, function(err, warnings) { + return viewer.open(diagram2); + }).then(function(result) { - // then - if (err) { - return done(err); - } + var warnings = result.warnings; - expect(warnings).to.be.empty; + expect(warnings).to.be.empty; - expect(definitions).to.equal(viewer.getDefinitions()); + 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; + it('should switch between diagrams with laneSets', function() { - done(); - }); + var viewer, definitions; + // when + return 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; + + return viewer.open(diagram1); + }).then(function(result) { + + // then + var warnings = result.warnings; + + 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; }); }); - it('should complete with error if xml was not imported', function(done) { + it('should complete with error if xml was not imported', function() { // given var viewer = new Viewer(); // when - viewer.open(function(err) { + return viewer.open().catch(function(err) { // then expect(err).to.exist; @@ -1123,51 +1079,51 @@ describe('Viewer', function() { var definitions = viewer.getDefinitions(); expect(definitions).to.not.exist; - - done(); }); }); - it('should open with error if diagram does not exist', function(done) { + it('should open with error if diagram does not exist', function() { + + var viewer, definitions; // when - createViewer(multipleXMLSimple, diagram1, function(err, warnings, viewer) { + return createViewer(container, Viewer, multipleXMLSimple, diagram1).then(function(result) { + + var err = result.error; + var warnings = result.warnings; + viewer = result.viewer; // then - if (err) { - return done(err); - } + expect(err).not.to.exist; expect(warnings).to.be.empty; - var definitions = viewer.getDefinitions(); + definitions = viewer.getDefinitions(); expect(definitions).to.exist; - viewer.open('Diagram_IDontExist', function(err) { + return viewer.open('Diagram_IDontExist'); + }).catch(function(err) { - // then - expect(err).to.exist; - expect(err.message).to.eql('BPMNDiagram not found'); + // then + expect(err).to.exist; + expect(err.message).to.eql('BPMNDiagram not found'); - // definitions stay the same - expect(viewer.getDefinitions()).to.eql(definitions); - - done(); - }); + // definitions stay the same + expect(viewer.getDefinitions()).to.eql(definitions); }); }); - it('should emit events', function(done) { + it('should emit events', function() { var viewer = new Viewer({ container: container }); var events = []; - viewer.importXML(multipleXMLSimple, diagram1, function(err) { + return viewer.importXML(multipleXMLSimple, diagram1).then(function(result) { // given viewer.on([ @@ -1188,16 +1144,14 @@ describe('Viewer', function() { }); // when - viewer.open(diagram2, function(err) { + return viewer.open(diagram2); + }).then(function() { - // then - expect(events).to.eql([ - [ 'import.render.start', [ 'definitions' ] ], - [ 'import.render.complete', [ 'error', 'warnings' ] ] - ]); - - done(err); - }); + // then + expect(events).to.eql([ + [ 'import.render.start', [ 'definitions' ] ], + [ 'import.render.complete', [ 'error', 'warnings' ] ] + ]); }); }); @@ -1206,35 +1160,45 @@ describe('Viewer', function() { describe('#saveXML', function() { - it('should export XML', function(done) { + it('should export XML', function() { // given var xml = require('../fixtures/bpmn/simple.bpmn'); - createViewer(xml, function(err, warnings, viewer) { + return 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) { + return viewer.saveXML({ format: true }); + }).then(function(result) { - // then - expect(xml).to.contain(''); - expect(xml).to.contain(''); + expect(xml).to.contain(' events', function(done) { + it('should emit events', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); - createViewer(xml, function(err, warnings, viewer) { + var viewer; + var events = []; - var events = []; + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + viewer = result.viewer; + + expect(err).not.to.exist; viewer.on([ 'saveXML.start', @@ -1251,21 +1215,19 @@ describe('Viewer', function() { ]); }); - viewer.importXML(xml, function(err) { + return viewer.importXML(xml); + }).then(function(result) { - // when - viewer.saveXML(function(err) { + // when + return viewer.saveXML(); + }).then(function() { - // then - expect(events).to.eql([ - [ 'saveXML.start', [ 'definitions' ] ], - [ 'saveXML.serialized', ['error', 'xml' ] ], - [ 'saveXML.done', ['error', 'xml' ] ] - ]); - - done(err); - }); - }); + // then + expect(events).to.eql([ + [ 'saveXML.start', [ 'definitions' ] ], + [ 'saveXML.serialized', ['error', 'xml' ] ], + [ 'saveXML.done', ['error', 'xml' ] ] + ]); }); }); @@ -1306,60 +1268,66 @@ describe('Viewer', function() { } - it('should export svg', function(done) { + it('should export svg', function() { // given var xml = require('../fixtures/bpmn/simple.bpmn'); - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var viewer = result.viewer; if (err) { - return done(err); + throw err; } // when - viewer.saveSVG(function(err, svg) { + return viewer.saveSVG(); + }).then(function(result) { - // then - expect(validSVG(svg)).to.be.true; + var svg = result.svg; - done(err); - }); + // then + expect(validSVG(svg)).to.be.true; }); }); - it('should export huge svg', function(done) { + it('should export huge svg', function() { this.timeout(5000); // given var xml = require('../fixtures/bpmn/complex.bpmn'); - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var viewer = result.viewer; if (err) { - return done(err); + throw err; } + // when + return viewer.saveSVG(); + }).then(function(result) { + + var svg = result.svg; + var time = currentTime(); - // when - viewer.saveSVG(function(err, svg) { + // then + expect(validSVG(svg)).to.be.true; - // then - expect(validSVG(svg)).to.be.true; - - // no svg export should not take too long - expect(currentTime() - time).to.be.below(1000); - - done(err); - }); + // no svg export should not take too long + expect(currentTime() - time).to.be.below(1000); }); }); - it('should remove outer-makers on export', function(done) { + it('should remove outer-makers on export', function() { // given var xml = require('../fixtures/bpmn/simple.bpmn'); @@ -1373,44 +1341,52 @@ describe('Viewer', function() { svgDoc.appendChild(rect); } - createViewer(xml, function(err, warnings, viewer) { + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + var viewer = result.viewer; if (err) { - return done(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) { + return viewer.saveSVG(); + }).then(function(result) { - var svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); - svgDoc.innerHTML = svg; + var svg = result.svg; - // then - expect(validSVG(svg)).to.be.true; - expect(svgDoc.querySelector('.outer-bound-marker')).to.be.null; + 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 events', function(done) { + it('should emit events', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); - createViewer(xml, function(err, warnings, viewer) { + var viewer; + var events = []; - var events = []; + return createViewer(container, Viewer, xml).then(function(result) { + + var err = result.error; + viewer = result.viewer; + + expect(err).not.to.exist; viewer.on([ 'saveSVG.start', @@ -1426,20 +1402,18 @@ describe('Viewer', function() { ]); }); - viewer.importXML(xml, function(err) { + return viewer.importXML(xml); + }).then(function() { - // when - viewer.saveSVG(function() { + // when + return viewer.saveSVG(); + }).then(function() { - // then - expect(events).to.eql([ - [ 'saveSVG.start', [ ] ], - [ 'saveSVG.done', ['error', 'svg' ] ] - ]); - - done(err); - }); - }); + // then + expect(events).to.eql([ + [ 'saveSVG.start', [ ] ], + [ 'saveSVG.done', ['error', 'svg' ] ] + ]); }); }); @@ -1448,7 +1422,7 @@ describe('Viewer', function() { describe('#on', function() { - it('should fire with given three', function(done) { + it('should fire with given three', function() { // given var viewer = new Viewer({ container: container }); @@ -1461,18 +1435,14 @@ describe('Viewer', function() { }, viewer); // then - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).then(function() { var eventBus = viewer.get('eventBus'); var result = eventBus.fire('foo'); expect(result).to.equal('bar'); - - done(); }); - }); - }); @@ -1480,7 +1450,7 @@ describe('Viewer', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); - it('should remove listener permanently', function(done) { + it('should remove listener permanently', function() { // given var viewer = new Viewer({ container: container }); @@ -1495,20 +1465,17 @@ describe('Viewer', function() { viewer.off('foo'); // then - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).then(function() { var eventBus = viewer.get('eventBus'); var result = eventBus.fire('foo'); expect(result).not.to.exist; - - done(); }); - }); - it('should remove listener on existing diagram instance', function(done) { + it('should remove listener on existing diagram instance', function() { // given var viewer = new Viewer({ container: container }); @@ -1520,7 +1487,7 @@ describe('Viewer', function() { viewer.on('foo', 1000, handler); // when - viewer.importXML(xml, function(err) { + return viewer.importXML(xml).then(function() { var eventBus = viewer.get('eventBus'); // when @@ -1529,12 +1496,8 @@ describe('Viewer', function() { var result = eventBus.fire('foo'); expect(result).not.to.exist; - - done(); }); - }); - }); @@ -1559,13 +1522,13 @@ describe('Viewer', function() { describe('#attachTo', function() { - it('should attach the viewer', function(done) { + it('should attach the viewer', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); var viewer = new Viewer(); - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { // assume expect(viewer._container.parentNode).not.to.exist; @@ -1582,23 +1545,20 @@ describe('Viewer', function() { // should trigger resized expect(resizedSpy).to.have.been.called; - - done(err, warnings); }); }); - }); describe('#detach', function() { - it('should detach the viewer', function(done) { + it('should detach the viewer', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); var viewer = new Viewer({ container: container }); - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { // assume expect(viewer._container.parentNode).to.equal(container); @@ -1608,11 +1568,8 @@ describe('Viewer', function() { // then expect(viewer._container.parentNode).not.to.exist; - - done(err, warnings); }); }); - }); @@ -1651,14 +1608,14 @@ describe('Viewer', function() { }); - it('should remove di property', function(done) { + it('should remove di property', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); var viewer = new Viewer({ container: container }), elementRegistry = viewer.get('elementRegistry'); - viewer.importXML(xml, function(err, warnings) { + return viewer.importXML(xml).then(function(result) { var elements = elementRegistry.getAll(); @@ -1669,8 +1626,6 @@ describe('Viewer', function() { expect(elements.some(function(el) { return el && el.businessObject && el.businessObject.di; }), 'at least one element still has di').to.be.false; - - done(err, warnings); }); }); @@ -1681,4 +1636,693 @@ describe('Viewer', function() { expect(ViewerDefaultExport).to.equal(Viewer); }); + + describe('Legacy callback support', function() { + + describe('#importXML', function() { + + it('should emit 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' ] ], + [ 'import.parse.complete', ['error', 'definitions', 'context' ] ], + [ 'import.render.start', [ 'definitions' ] ], + [ 'import.render.complete', [ 'error', 'warnings' ] ], + [ 'import.done', [ 'error', 'warnings' ] ] + ]); + + done(err); + }); + }); + + }); + + + 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 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 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 not found'); + + // definitions stay the same + expect(viewer.getDefinitions()).to.eql(definitions); + + done(); + }); + }); + }); + + + it('should emit 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(''); + expect(xml).to.contain(' 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 = ''; + var expectedEnd = ''; + + 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('')).to.equal(-1); + expect(svg.indexOf(', 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 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); + }); + }); + }); + + }); + }); }); diff --git a/test/spec/draw/BpmnRendererSpec.js b/test/spec/draw/BpmnRendererSpec.js index 535fb9e9..70c3b184 100644 --- a/test/spec/draw/BpmnRendererSpec.js +++ b/test/spec/draw/BpmnRendererSpec.js @@ -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); + }); }); diff --git a/test/spec/features/label-editing/TouchIntegrationSpec.js b/test/spec/features/label-editing/TouchIntegrationSpec.js index 5f474180..26b3513b 100644 --- a/test/spec/features/label-editing/TouchIntegrationSpec.js +++ b/test/spec/features/label-editing/TouchIntegrationSpec.js @@ -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; + }); }); }); diff --git a/test/spec/features/modeling/LabelBoundsSpec.js b/test/spec/features/modeling/LabelBoundsSpec.js index 445d525d..4e62766d 100644 --- a/test/spec/features/modeling/LabelBoundsSpec.js +++ b/test/spec/features/modeling/LabelBoundsSpec.js @@ -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); }); }); diff --git a/test/spec/features/ordering/BpmnDiOrderingSpec.js b/test/spec/features/ordering/BpmnDiOrderingSpec.js index 64579179..665cdfb0 100644 --- a/test/spec/features/ordering/BpmnDiOrderingSpec.js +++ b/test/spec/features/ordering/BpmnDiOrderingSpec.js @@ -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); }); } diff --git a/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js b/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js index 2efd904c..ecbc3b9a 100644 --- a/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js +++ b/test/spec/features/snapping/BpmnCreateMoveSnappingSpec.js @@ -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) { diff --git a/test/spec/import/BpmnTreeWalkerSpec.js b/test/spec/import/BpmnTreeWalkerSpec.js index 1bcbd804..fcd6b952 100644 --- a/test/spec/import/BpmnTreeWalkerSpec.js +++ b/test/spec/import/BpmnTreeWalkerSpec.js @@ -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'); diff --git a/test/spec/import/ImporterSpec.js b/test/spec/import/ImporterSpec.js index 2dcb80fe..84165f68 100644 --- a/test/spec/import/ImporterSpec.js +++ b/test/spec/import/ImporterSpec.js @@ -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 and ', function(done) { + it('should fire and ', 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 during import', function(done) { + it('should fire 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 '; @@ -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 #attachedToRef'); expect(warnings[1].message).to.eql('element referenced by #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 #attachedToRef'); expect(warnings[1].message).to.eql('element referenced by #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); }); }); diff --git a/test/spec/import/elements/AssociationSpec.js b/test/spec/import/elements/AssociationSpec.js index cae9bfa8..51fb2665 100644 --- a/test/spec/import/elements/AssociationSpec.js +++ b/test/spec/import/elements/AssociationSpec.js @@ -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); }); }); }); -}); \ No newline at end of file +}); diff --git a/test/spec/import/elements/DataInputOutputSpec.js b/test/spec/import/elements/DataInputOutputSpec.js index 6b8b28be..73cff07c 100644 --- a/test/spec/import/elements/DataInputOutputSpec.js +++ b/test/spec/import/elements/DataInputOutputSpec.js @@ -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) }; -} \ No newline at end of file +} diff --git a/test/spec/import/elements/GroupsSpec.js b/test/spec/import/elements/GroupsSpec.js index 0a61de07..4b42b3bd 100644 --- a/test/spec/import/elements/GroupsSpec.js +++ b/test/spec/import/elements/GroupsSpec.js @@ -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() { }); -}); \ No newline at end of file +}); diff --git a/test/spec/import/elements/LabelSpec.js b/test/spec/import/elements/LabelSpec.js index 948e0b84..fc37b5f3 100644 --- a/test/spec/import/elements/LabelSpec.js +++ b/test/spec/import/elements/LabelSpec.js @@ -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) }; -} \ No newline at end of file +}