2014-03-13 15:06:30 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
|
2014-04-25 11:30:10 +00:00
|
|
|
var Viewer = require('../../../lib/Viewer');
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
var Matchers = require('../Matchers');
|
|
|
|
|
|
|
|
|
2014-04-25 11:30:10 +00:00
|
|
|
describe('Viewer', function() {
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-04-25 11:30:10 +00:00
|
|
|
beforeEach(Matchers.add);
|
2014-03-13 15:06:30 +00:00
|
|
|
|
|
|
|
var container;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
container = document.createElement('div');
|
|
|
|
document.getElementsByTagName('body')[0].appendChild(container);
|
|
|
|
});
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-03-13 15:06:30 +00:00
|
|
|
it('should import simple process', function(done) {
|
|
|
|
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
var renderer = new Viewer(container);
|
2014-03-13 15:06:30 +00:00
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
renderer.importXML(xml, function(err) {
|
|
|
|
done(err);
|
2014-03-13 15:06:30 +00:00
|
|
|
});
|
|
|
|
});
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-03-17 10:11:25 +00:00
|
|
|
it('should import empty definitions', function(done) {
|
|
|
|
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/empty-definitions.bpmn', 'utf8');
|
|
|
|
|
2014-03-21 20:10:01 +00:00
|
|
|
var renderer = new Viewer(container);
|
|
|
|
|
|
|
|
renderer.importXML(xml, function(err) {
|
|
|
|
done(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
describe('error handling', function() {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
it('should handle errors', function(done) {
|
2014-03-17 10:11:25 +00:00
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
var xml = 'invalid stuff';
|
|
|
|
|
|
|
|
var renderer = new Viewer(container);
|
|
|
|
|
|
|
|
renderer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
expect(err).toBeDefined();
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2014-03-21 20:10:01 +00:00
|
|
|
|
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
describe('export', function() {
|
2014-03-21 20:10:01 +00:00
|
|
|
|
2014-04-03 19:20:13 +00:00
|
|
|
it('should export svg', function(done) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var xml = fs.readFileSync('test/fixtures/bpmn/empty-definitions.bpmn', 'utf8');
|
|
|
|
var renderer = new Viewer(container);
|
|
|
|
|
|
|
|
renderer.importXML(xml, function(err) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// when
|
|
|
|
renderer.saveSVG(function(err, svg) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
var expectedStart = '<?xml version="1.0" encoding="utf-8"?>';
|
|
|
|
var expectedEnd = '</svg>';
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(svg.indexOf(expectedStart)).toEqual(0);
|
|
|
|
expect(svg.indexOf(expectedEnd)).toEqual(svg.length - expectedEnd.length);
|
|
|
|
|
2014-05-23 08:58:44 +00:00
|
|
|
// ensure correct rendering of SVG contents
|
|
|
|
expect(svg.indexOf('undefined')).toBe(-1);
|
|
|
|
|
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-03-13 15:06:30 +00:00
|
|
|
});
|