2014-06-11 12:41:55 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
var TestContainer = require('mocha-test-container-support');
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var Viewer = require('../../lib/Viewer');
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
describe('Viewer', function() {
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
var container;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2015-07-15 15:22:19 +00:00
|
|
|
container = TestContainer.get(this);
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2014-06-11 12:41:55 +00:00
|
|
|
function createViewer(xml, done) {
|
2014-08-01 05:55:47 +00:00
|
|
|
var viewer = new Viewer({ container: container });
|
2014-06-11 12:41:55 +00:00
|
|
|
|
2014-10-28 14:09:17 +00:00
|
|
|
viewer.importXML(xml, function(err, warnings) {
|
|
|
|
done(err, warnings, viewer);
|
2014-06-11 12:41:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-03-13 15:06:30 +00:00
|
|
|
it('should import simple process', function(done) {
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-06-11 12:41:55 +00:00
|
|
|
createViewer(xml, done);
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2015-02-17 11:03:27 +00:00
|
|
|
it('should re-import simple process', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2015-02-17 11:03:27 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
createViewer(xml, function(err, warnings, viewer) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
|
|
|
// mimic re-import of same diagram
|
|
|
|
viewer.importXML(xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).to.exist;
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(warnings.length).to.equal(0);
|
2015-02-17 11:03:27 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-05-04 12:54:56 +00:00
|
|
|
describe('defaults', function() {
|
|
|
|
|
|
|
|
it('should use <body> as default parent', function(done) {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var viewer = new Viewer();
|
|
|
|
|
|
|
|
viewer.importXML(xml, function(err, warnings) {
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(viewer.container.parentNode).to.equal(document.body);
|
2015-05-04 12:54:56 +00:00
|
|
|
|
|
|
|
done(err, warnings);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-05 06:34:54 +00:00
|
|
|
describe('import events', function() {
|
|
|
|
|
2014-08-05 15:02:03 +00:00
|
|
|
it('should fire <import.*> events', function(done) {
|
2014-08-05 06:34:54 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-08-05 06:34:54 +00:00
|
|
|
|
|
|
|
var events = [];
|
|
|
|
|
|
|
|
viewer.on('import.start', function() {
|
|
|
|
events.push('import.start');
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.on('import.success', function() {
|
|
|
|
events.push('import.success');
|
|
|
|
});
|
|
|
|
|
|
|
|
viewer.on('import.error', function() {
|
|
|
|
events.push('import.error');
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(events).to.eql([
|
2014-08-05 06:34:54 +00:00
|
|
|
'import.start',
|
|
|
|
'import.success'
|
|
|
|
]);
|
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-05 15:02:03 +00:00
|
|
|
describe('overlay support', function() {
|
|
|
|
|
|
|
|
it('should allow to add overlays', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-08-05 15:02:03 +00:00
|
|
|
|
2014-10-28 14:09:17 +00:00
|
|
|
createViewer(xml, function(err, warnings, viewer) {
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
var overlays = viewer.get('overlays'),
|
|
|
|
elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(overlays).to.exist;
|
|
|
|
expect(elementRegistry).to.exist;
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
overlays.add('SubProcess_1', {
|
|
|
|
position: {
|
|
|
|
bottom: 0,
|
|
|
|
right: 0
|
|
|
|
},
|
|
|
|
html: '<div style="max-width: 50px">YUP GREAT STUFF!</div>'
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(overlays.get({ element: 'SubProcess_1' }).length).to.equal(1);
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
describe('error handling', function() {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
function expectMessage(e, expectedMessage) {
|
|
|
|
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(e).to.exist;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
if (expectedMessage instanceof RegExp) {
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(e.message).to.match(expectedMessage);
|
2015-02-17 09:55:28 +00:00
|
|
|
} else {
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(e.message).to.equal(expectedMessage);
|
2015-02-17 09:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function expectWarnings(warnings, expected) {
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(warnings.length).to.equal(expected.length);
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
warnings.forEach(function(w, idx) {
|
|
|
|
expectMessage(w, expected[idx]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-23 14:31:28 +00:00
|
|
|
it('should handle non-bpmn input', function(done) {
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
var xml = 'invalid stuff';
|
|
|
|
|
2014-06-11 12:41:55 +00:00
|
|
|
createViewer(xml, function(err) {
|
2014-04-03 19:20:13 +00:00
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).to.exist;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
expectMessage(err, /Text data outside of root node./);
|
2014-04-03 19:20:13 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-05-23 14:31:28 +00:00
|
|
|
|
|
|
|
it('should handle invalid BPMNPlane#bpmnElement', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn');
|
2014-05-23 14:31:28 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
// when
|
|
|
|
createViewer(xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).not.to.exist;
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
expectWarnings(warnings, [
|
|
|
|
'unresolved reference <Collaboration_2>',
|
|
|
|
'no bpmnElement referenced in <bpmndi:BPMNPlane id="BPMNPlane_1" />',
|
|
|
|
'correcting missing bpmnElement ' +
|
|
|
|
'on <bpmndi:BPMNPlane id="BPMNPlane_1" /> ' +
|
|
|
|
'to <bpmn:Process id="Process_1" />'
|
|
|
|
]);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-07-20 15:13:47 +00:00
|
|
|
it('should handle invalid namespaced element', function(done) {
|
2015-02-17 09:55:28 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/error/categoryValue.bpmn');
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
// when
|
2014-10-28 14:09:17 +00:00
|
|
|
createViewer(xml, function(err, warnings) {
|
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).not.to.exist;
|
2014-10-28 14:09:17 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
expectWarnings(warnings, [
|
|
|
|
/unparsable content <categoryValue> detected/,
|
|
|
|
'unresolved reference <sid-afd7e63e-916e-4bd0-a9f0-98cbff749193>'
|
|
|
|
]);
|
2014-05-23 14:31:28 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-30 17:04:40 +00:00
|
|
|
|
|
|
|
it('should handle missing namespace', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/error/missing-namespace.bpmn');
|
2014-06-30 17:04:40 +00:00
|
|
|
|
2015-02-17 09:55:28 +00:00
|
|
|
// when
|
|
|
|
createViewer(xml, function(err, warnings) {
|
|
|
|
|
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(err).to.exist;
|
|
|
|
expect(err.message).to.eql('no process or collaboration to display');
|
2015-02-17 09:55:28 +00:00
|
|
|
|
|
|
|
expectWarnings(warnings, [
|
|
|
|
/unparsable content <collaboration> detected/,
|
|
|
|
'unresolved reference <Participant_1>',
|
|
|
|
'no bpmnElement referenced in <bpmndi:BPMNPlane id="BPMNPlane_1" />',
|
2015-11-24 11:53:18 +00:00
|
|
|
'no bpmnElement referenced in <bpmndi:BPMNShape id="BPMNShape_Participant_1" />'
|
2015-02-17 09:55:28 +00:00
|
|
|
]);
|
2014-06-30 17:04:40 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
|
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
describe('dependency injection', function() {
|
|
|
|
|
|
|
|
it('should be available via di as <bpmnjs>', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2014-10-28 14:09:17 +00:00
|
|
|
createViewer(xml, function(err, warnings, viewer) {
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(viewer.get('bpmnjs')).to.equal(viewer);
|
2014-06-17 09:19:31 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
describe('export', function() {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-08-06 13:21:55 +00:00
|
|
|
function currentTime() {
|
|
|
|
return new Date().getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
function isValid(svg) {
|
|
|
|
var expectedStart = '<?xml version="1.0" encoding="utf-8"?>';
|
|
|
|
var expectedEnd = '</svg>';
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(svg.indexOf(expectedStart)).to.equal(0);
|
|
|
|
expect(svg.indexOf(expectedEnd)).to.equal(svg.length - expectedEnd.length);
|
2014-08-06 13:21:55 +00:00
|
|
|
|
|
|
|
// ensure correct rendering of SVG contents
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(svg.indexOf('undefined')).to.equal(-1);
|
2014-08-06 13:21:55 +00:00
|
|
|
|
|
|
|
// expect header to be written only once
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(svg.indexOf('<svg width="100%" height="100%">')).to.equal(-1);
|
|
|
|
expect(svg.indexOf('<g class="viewport"')).to.equal(-1);
|
2014-08-06 13:21:55 +00:00
|
|
|
|
|
|
|
// FIXME(nre): make matcher
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
it('should export svg', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-11-24 11:53:18 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-04-03 19:20:13 +00:00
|
|
|
|
2014-10-28 14:09:17 +00:00
|
|
|
createViewer(xml, function(err, warnings, viewer) {
|
2014-04-03 19:20:13 +00:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
2014-08-01 05:55:47 +00:00
|
|
|
viewer.saveSVG(function(err, svg) {
|
2014-04-03 19:20:13 +00:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(isValid(svg)).to.be.true;
|
2014-08-06 13:21:55 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-08-25 13:45:44 +00:00
|
|
|
it('should export huge svg', function(done) {
|
2014-08-06 13:21:55 +00:00
|
|
|
|
|
|
|
// given
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/complex.bpmn');
|
2014-08-06 13:21:55 +00:00
|
|
|
|
2014-10-28 14:09:17 +00:00
|
|
|
createViewer(xml, function(err, warnings, viewer) {
|
2014-08-06 13:21:55 +00:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var time = currentTime();
|
2014-04-03 19:20:13 +00:00
|
|
|
|
2014-08-06 13:21:55 +00:00
|
|
|
// when
|
|
|
|
viewer.saveSVG(function(err, svg) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(isValid(svg)).to.be.true;
|
2014-05-23 08:58:44 +00:00
|
|
|
|
2015-07-20 15:13:47 +00:00
|
|
|
// no svg export should not take too long
|
|
|
|
expect(currentTime() - time).to.be.below(1000);
|
2014-05-28 10:19:35 +00:00
|
|
|
|
2014-08-17 10:17:15 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-02-12 14:50:23 +00:00
|
|
|
|
2014-08-17 10:17:15 +00:00
|
|
|
it('should remove outer-makers on export', function(done) {
|
|
|
|
|
|
|
|
// given
|
2015-07-20 15:13:47 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-08-17 10:17:15 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-10-28 14:09:17 +00:00
|
|
|
createViewer(xml, function(err, warnings, viewer) {
|
2014-08-17 10:17:15 +00:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var svgDoc = viewer.container.childNodes[1].childNodes[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appendTestRect(svgDoc);
|
|
|
|
appendTestRect(svgDoc);
|
|
|
|
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(svgDoc.querySelectorAll('.outer-bound-marker')).to.exist;
|
2014-08-17 10:17:15 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.saveSVG(function(err, svg) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var svgDoc = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
|
|
svgDoc.innerHTML = svg;
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(isValid(svg)).to.be.true;
|
|
|
|
expect(svgDoc.querySelector('.outer-bound-marker')).to.be.null;
|
2014-08-17 10:17:15 +00:00
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-03-17 10:11:25 +00:00
|
|
|
});
|
2014-04-03 19:20:13 +00:00
|
|
|
|
2014-03-17 10:11:25 +00:00
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
|
|
|
|
describe('creation', function() {
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
var testModules = [
|
|
|
|
{ logger: [ 'type', function() { this.called = true; } ] }
|
|
|
|
];
|
|
|
|
|
|
|
|
// given
|
2015-11-24 11:53:18 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-08-01 05:55:47 +00:00
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
var viewer;
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
viewer.destroy();
|
|
|
|
});
|
|
|
|
|
2014-08-01 05:55:47 +00:00
|
|
|
it('should override default modules', function(done) {
|
|
|
|
|
|
|
|
// given
|
2014-12-18 08:45:45 +00:00
|
|
|
viewer = new Viewer({ container: container, modules: testModules });
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(err.message).to.equal('No provider for "bpmnImporter"! (Resolving: bpmnImporter)');
|
2014-08-01 05:55:47 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should add module to default modules', function(done) {
|
|
|
|
|
|
|
|
// given
|
2014-12-18 08:45:45 +00:00
|
|
|
viewer = new Viewer({ container: container, additionalModules: testModules });
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
var logger = viewer.get('logger');
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(logger.called).to.be.true;
|
2014-08-01 05:55:47 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
|
|
|
|
it('should use custom size and position', function() {
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer = new Viewer({
|
|
|
|
container: container,
|
|
|
|
width: 200,
|
|
|
|
height: 100,
|
|
|
|
position: 'fixed'
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(viewer.container.style.position).to.equal('fixed');
|
|
|
|
expect(viewer.container.style.width).to.equal('200px');
|
|
|
|
expect(viewer.container.style.height).to.equal('100px');
|
2014-12-18 08:45:45 +00:00
|
|
|
});
|
|
|
|
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
var camundaPackage = require('../fixtures/json/model/camunda');
|
|
|
|
|
|
|
|
it('should provide custom moddle extensions', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/extension/camunda.bpmn');
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
viewer = new Viewer({
|
|
|
|
container: container,
|
|
|
|
moddleExtensions: {
|
|
|
|
camunda: camundaPackage
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err, warnings) {
|
|
|
|
|
|
|
|
var elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
|
|
|
var taskShape = elementRegistry.get('send'),
|
|
|
|
sendTask = taskShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
2015-12-01 07:27:45 +00:00
|
|
|
expect(sendTask).to.exist;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
var extensionElements = sendTask.extensionElements;
|
|
|
|
|
|
|
|
// receive task should be moddle extended
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(sendTask.$instanceOf('camunda:ServiceTaskLike')).to.exist;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
// extension elements should provide typed element
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(extensionElements).to.exist;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(extensionElements.values.length).to.equal(1);
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(extensionElements.values[0].$instanceOf('camunda:InputOutput')).to.exist;
|
2015-02-12 14:50:23 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-11-24 11:53:18 +00:00
|
|
|
|
|
|
|
it('should throw error due to missing diagram', function(done) {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/empty-definitions.bpmn');
|
|
|
|
|
|
|
|
// given
|
|
|
|
viewer = new Viewer({ container: container, additionalModules: testModules });
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(err.message).to.eql('no diagram to display');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-08 13:41:58 +00:00
|
|
|
describe('configuration', function() {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
it('should configure Canvas', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({
|
|
|
|
container: container,
|
|
|
|
canvas: {
|
|
|
|
deferUpdate: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
var canvasConfig = viewer.get('config.canvas');
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(canvasConfig.deferUpdate).to.be.true;
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('#on', function() {
|
|
|
|
|
|
|
|
it('should fire with given three', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({ container: container });
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.on('foo', 1000, function() {
|
|
|
|
return 'bar';
|
|
|
|
}, viewer);
|
|
|
|
|
|
|
|
// then
|
|
|
|
viewer.importXML(xml, function(err) {
|
|
|
|
var eventBus = viewer.get('eventBus');
|
|
|
|
|
|
|
|
var result = eventBus.fire('foo');
|
|
|
|
|
|
|
|
expect(result).to.equal('bar');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
describe('#destroy', function() {
|
|
|
|
|
|
|
|
it('should remove traces in document tree', function() {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var viewer = new Viewer({
|
|
|
|
container: container
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
viewer.destroy();
|
|
|
|
|
|
|
|
// then
|
2015-11-24 11:53:18 +00:00
|
|
|
expect(viewer.container.parentNode).not.to.exist;
|
2014-12-18 08:45:45 +00:00
|
|
|
});
|
|
|
|
|
2014-08-01 05:55:47 +00:00
|
|
|
});
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
});
|