test(overlays): add overlay support tests

Related to #54
This commit is contained in:
Nico Rehwaldt 2014-08-05 17:02:03 +02:00
parent c21b295ec2
commit 8116941fca
3 changed files with 80 additions and 2 deletions

View File

@ -12,7 +12,7 @@ function getSvgContents(diagram) {
var outerNode = diagram.get('canvas').getContainer();
var svg = outerNode.innerHTML;
return svg.replace(/^<svg[^>]*>|<\/svg>$/g, '')
return svg.replace(/.*<svg[^>]*>|<\/svg>.*$/g, '')
.replace('<desc>Created with Snap</desc>', '')
.replace(/<g class="viewport"( transform="[^"]*")?/, '<g');
}

View File

@ -42,6 +42,45 @@ describe('modeler', function() {
});
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) {
// when
var overlays = viewer.get('overlays'),
elementRegistry = viewer.get('elementRegistry');
// then
expect(overlays).toBeDefined();
expect(elementRegistry).toBeDefined();
// given
var subProcessShape = elementRegistry.getById('SubProcess_1');
// when
overlays.add('SubProcess_1', {
position: {
bottom: 0,
right: 0
},
html: '<div style="max-width: 50px">YUP GREAT STUFF!</div>'
});
// then
expect(overlays.get({ element: 'SubProcess_1' }).length).toBe(1);
done(err);
});
});
});
it('should handle errors', function(done) {
var xml = 'invalid stuff';

View File

@ -50,7 +50,7 @@ describe('viewer', function() {
describe('import events', function() {
iit('should fire <import.*> events', function(done) {
it('should fire <import.*> events', function(done) {
// given
var viewer = new Viewer({ container: container });
@ -87,6 +87,45 @@ describe('viewer', function() {
});
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, viewer) {
// when
var overlays = viewer.get('overlays'),
elementRegistry = viewer.get('elementRegistry');
// then
expect(overlays).toBeDefined();
expect(elementRegistry).toBeDefined();
// given
var subProcessShape = elementRegistry.getById('SubProcess_1');
// when
overlays.add('SubProcess_1', {
position: {
bottom: 0,
right: 0
},
html: '<div style="max-width: 50px">YUP GREAT STUFF!</div>'
});
// then
expect(overlays.get({ element: 'SubProcess_1' }).length).toBe(1);
done(err);
});
});
});
describe('error handling', function() {
it('should handle non-bpmn input', function(done) {