'use strict'; var Matchers = require('../Matchers'), TestHelper = require('../TestHelper'); /* global bootstrapViewer, inject */ var fs = require('fs'); var Viewer = require('../../lib/Viewer'); describe('Viewer', function() { beforeEach(Matchers.addDeepEquals); var container; beforeEach(function() { container = jasmine.getEnv().getTestContainer(); }); function createViewer(xml, done) { var viewer = new Viewer({ container: container }); viewer.importXML(xml, function(err, warnings) { done(err, warnings, viewer); }); } it('should import simple process', function(done) { var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8'); createViewer(xml, done); }); it('should import empty definitions', function(done) { var xml = fs.readFileSync('test/fixtures/bpmn/empty-definitions.bpmn', 'utf8'); createViewer(xml, done); }); describe('import events', function() { it('should fire events', function(done) { // given var viewer = new Viewer({ container: container }); var xml = fs.readFileSync('test/fixtures/bpmn/empty-definitions.bpmn', 'utf8'); 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 expect(events).toEqual([ 'import.start', 'import.success' ]); done(err); }); }); }); describe('overlay support', function() { it('should allow to add overlays', function(done) { var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8'); createViewer(xml, function(err, warnings, viewer) { // when var overlays = viewer.get('overlays'), elementRegistry = viewer.get('elementRegistry'); // then expect(overlays).toBeDefined(); expect(elementRegistry).toBeDefined(); // given var subProcessShape = elementRegistry.get('SubProcess_1'); // when overlays.add('SubProcess_1', { position: { bottom: 0, right: 0 }, html: '
YUP GREAT STUFF!
' }); // then expect(overlays.get({ element: 'SubProcess_1' }).length).toBe(1); done(err); }); }); }); describe('error handling', function() { it('should handle non-bpmn input', function(done) { var xml = 'invalid stuff'; createViewer(xml, function(err) { expect(err).toBeDefined(); done(); }); }); it('should handle invalid BPMNPlane#bpmnElement', function(done) { var xml = fs.readFileSync('test/fixtures/bpmn/error/di-plane-no-bpmn-element.bpmn', 'utf8'); createViewer(xml, function(err, warnings) { expect(err).not.toBeDefined(); expect(warnings.length).toBe(2); expect(warnings[0].message).toEqual('no bpmnElement referenced in '); expect(warnings[1].message).toEqual('correcting missing bpmnElement on to '); done(); }); }); it('should handle missing namespace', function(done) { var xml = fs.readFileSync('test/fixtures/bpmn/error/missing-namespace.bpmn', 'utf8'); createViewer(xml, function(err) { expect(err).toBeDefined(); expect(err.message).toEqual( 'unparsable content detected; this may indicate an invalid BPMN 2.0 diagram file\n' + '\tline: 2\n' + '\tcolumn: 29\n' + '\tnested error: unrecognized element '); done(); }); }); }); describe('dependency injection', function() { it('should be available via di as ', function(done) { var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8'); createViewer(xml, function(err, warnings, viewer) { expect(viewer.get('bpmnjs')).toBe(viewer); done(err); }); }); }); describe('export', function() { function currentTime() { return new Date().getTime(); } function isValid(svg) { var expectedStart = ''; var expectedEnd = ''; expect(svg.indexOf(expectedStart)).toEqual(0); expect(svg.indexOf(expectedEnd)).toEqual(svg.length - expectedEnd.length); // ensure correct rendering of SVG contents expect(svg.indexOf('undefined')).toBe(-1); // expect header to be written only once expect(svg.indexOf('')).toBe(-1); expect(svg.indexOf('