2014-06-18 09:45:30 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var Modeler = require('../../lib/Modeler');
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
var TestContainer = require('mocha-test-container-support');
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-12-18 08:45:45 +00:00
|
|
|
describe('Modeler', 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-03-21 20:10:01 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
function createModeler(xml, done) {
|
|
|
|
var modeler = new Modeler({ container: container });
|
|
|
|
|
2015-02-17 11:03:27 +00:00
|
|
|
modeler.importXML(xml, function(err, warnings) {
|
|
|
|
done(err, warnings, modeler);
|
2014-06-17 09:19:31 +00:00
|
|
|
});
|
|
|
|
}
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2014-06-17 09:19:31 +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-17 09:19:31 +00:00
|
|
|
createModeler(xml, done);
|
|
|
|
});
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
|
2015-04-16 07:11:04 +00:00
|
|
|
it('should import collaboration', function(done) {
|
|
|
|
var xml = require('../fixtures/bpmn/collaboration-message-flows.bpmn');
|
|
|
|
createModeler(xml, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
it('should import empty definitions', function(done) {
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/empty-definitions.bpmn');
|
2014-06-17 09:19:31 +00:00
|
|
|
createModeler(xml, done);
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
2014-04-25 11:30:10 +00:00
|
|
|
|
|
|
|
|
2015-02-18 12:25:20 +00:00
|
|
|
it('should re-import simple process', function(done) {
|
2015-02-17 11:03:27 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2015-02-17 11:03:27 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
createModeler(xml, function(err, warnings, modeler) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
|
|
|
// mimic re-import of same diagram
|
|
|
|
modeler.importXML(xml, function(err, warnings) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// then
|
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:57:32 +00:00
|
|
|
describe('defaults', function() {
|
|
|
|
|
|
|
|
it('should use <body> as default parent', function(done) {
|
|
|
|
|
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var modeler = new Modeler();
|
|
|
|
|
|
|
|
modeler.importXML(xml, function(err, warnings) {
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(modeler.container.parentNode).to.equal(document.body);
|
2015-05-04 12:57:32 +00:00
|
|
|
|
|
|
|
done(err, warnings);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-17 11:03:27 +00:00
|
|
|
createModeler(xml, function(err, warnings, viewer) {
|
2014-08-05 15:02:03 +00:00
|
|
|
|
2014-08-07 20:09:12 +00:00
|
|
|
// given
|
2014-08-05 15:02:03 +00:00
|
|
|
var overlays = viewer.get('overlays'),
|
|
|
|
elementRegistry = viewer.get('elementRegistry');
|
|
|
|
|
2014-08-07 20:09:12 +00:00
|
|
|
// assume
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(overlays).to.be.defined;
|
|
|
|
expect(elementRegistry).to.be.defined;
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
// when
|
2014-08-12 09:53:38 +00:00
|
|
|
overlays.add('SubProcess_1', 'badge', {
|
2014-08-05 15:02:03 +00:00
|
|
|
position: {
|
|
|
|
bottom: 0,
|
|
|
|
right: 0
|
|
|
|
},
|
|
|
|
html: '<div style="max-width: 50px">YUP GREAT STUFF!</div>'
|
|
|
|
});
|
|
|
|
|
2014-08-12 09:53:38 +00:00
|
|
|
overlays.add('StartEvent_1', 'badge', {
|
2014-08-07 20:09:12 +00:00
|
|
|
position: {
|
|
|
|
top: 0,
|
|
|
|
left: 0
|
|
|
|
},
|
|
|
|
html: '<div style="max-width: 50px">YUP GREAT STUFF!</div>'
|
|
|
|
});
|
|
|
|
|
2014-08-05 15:02:03 +00:00
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(overlays.get({ element: 'SubProcess_1', type: 'badge' }).length).to.equal(1);
|
|
|
|
expect(overlays.get({ element: 'StartEvent_1', type: 'badge' }).length).to.equal(1);
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-01-14 17:48:06 +00:00
|
|
|
describe('bendpoint editing support', function() {
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
var createEvent = require('../util/MockEvents').createEvent;
|
|
|
|
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
it('should allow to edit bendpoints', function(done) {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2015-01-14 17:48:06 +00:00
|
|
|
|
2015-02-17 11:03:27 +00:00
|
|
|
createModeler(xml, function(err, warnings, viewer) {
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var bendpointMove = viewer.get('bendpointMove'),
|
|
|
|
dragging = viewer.get('dragging'),
|
|
|
|
elementRegistry = viewer.get('elementRegistry'),
|
2015-08-24 13:31:47 +00:00
|
|
|
canvas = viewer.get('canvas');
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
// assume
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(bendpointMove).to.be.defined;
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
bendpointMove.start(createEvent(canvas, { x: 0, y: 0 }), elementRegistry.get('SequenceFlow_1'), 1);
|
|
|
|
dragging.move(createEvent(canvas, { x: 200, y: 200 }));
|
2015-01-14 17:48:06 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
it('should handle errors', function(done) {
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
var xml = 'invalid stuff';
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
var modeler = new Modeler({ container: container });
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
modeler.importXML(xml, function(err) {
|
2014-04-03 09:47:26 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(err).to.be.defined;
|
2014-06-17 09:19:31 +00:00
|
|
|
|
|
|
|
done();
|
2014-03-21 20:10:01 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-24 13:50:51 +00:00
|
|
|
it('should create new diagram', function(done) {
|
|
|
|
var modeler = new Modeler({ container: container });
|
|
|
|
modeler.createDiagram(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
describe('dependency injection', function() {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
it('should be available via di as <bpmnjs>', function(done) {
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2015-02-17 11:03:27 +00:00
|
|
|
createModeler(xml, function(err, warnings, modeler) {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(modeler.get('bpmnjs')).to.equal(modeler);
|
2014-10-27 11:07:57 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
done(err);
|
|
|
|
});
|
2014-03-17 10:11:25 +00:00
|
|
|
});
|
2014-06-17 09:19:31 +00:00
|
|
|
|
2014-03-17 10:11:25 +00:00
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-10-27 11:07:57 +00:00
|
|
|
});
|