2014-06-18 09:45:30 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Matchers = require('../Matchers'),
|
|
|
|
TestHelper = require('../TestHelper');
|
|
|
|
|
|
|
|
|
2014-03-13 15:06:30 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var Modeler = require('../../lib/Modeler');
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
describe('modeler', function() {
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
beforeEach(Matchers.addDeepEquals);
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2014-03-13 15:06:30 +00:00
|
|
|
var container;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
2014-06-18 09:45:30 +00:00
|
|
|
container = jasmine.getEnv().getTestContainer();
|
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 });
|
|
|
|
|
|
|
|
modeler.importXML(xml, function(err) {
|
|
|
|
done(err, modeler);
|
|
|
|
});
|
|
|
|
}
|
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) {
|
2014-03-13 15:06:30 +00:00
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
2014-06-17 09:19:31 +00:00
|
|
|
createModeler(xml, done);
|
|
|
|
});
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
it('should import empty definitions', function(done) {
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/empty-definitions.bpmn', 'utf8');
|
|
|
|
createModeler(xml, done);
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
2014-04-25 11:30:10 +00:00
|
|
|
|
|
|
|
|
2014-08-05 15:02:03 +00:00
|
|
|
describe('overlay support', function() {
|
|
|
|
|
|
|
|
it('should allow to add overlays', function(done) {
|
|
|
|
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
|
|
|
|
|
|
|
createModeler(xml, function(err, viewer) {
|
|
|
|
|
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
|
2014-08-05 15:02:03 +00:00
|
|
|
expect(overlays).toBeDefined();
|
|
|
|
expect(elementRegistry).toBeDefined();
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
2014-08-12 09:53:38 +00:00
|
|
|
expect(overlays.get({ element: 'SubProcess_1', type: 'badge' }).length).toBe(1);
|
|
|
|
expect(overlays.get({ element: 'StartEvent_1', type: 'badge' }).length).toBe(1);
|
2014-08-05 15:02:03 +00:00
|
|
|
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-08 12:42:50 +00:00
|
|
|
describe('cli support', function() {
|
|
|
|
|
|
|
|
it('should ship with cli', function(done) {
|
|
|
|
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
|
|
|
|
|
|
|
createModeler(xml, function(err, viewer) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var cli = viewer.get('cli');
|
|
|
|
|
|
|
|
// assume
|
|
|
|
expect(cli).toBeDefined();
|
|
|
|
|
|
|
|
// when
|
|
|
|
var subProcessShape = cli.element('SubProcess_1');
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcessShape.id).toEqual('SubProcess_1');
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
expect(err).toBeDefined();
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
createModeler(xml, function(err, modeler) {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-06-17 09:19:31 +00:00
|
|
|
expect(modeler.get('bpmnjs')).toBe(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
|
|
|
});
|