bpmn-js/test/spec/features/modeling/BpmnFactorySpec.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

'use strict';
var Matchers = require('../../../Matchers'),
TestHelper = require('../../../TestHelper');
/* global bootstrapModeler, inject */
var fs = require('fs');
var modelingModule = require('../../../../lib/features/modeling');
describe('features - bpmn-factory', function() {
beforeEach(Matchers.addDeepEquals);
var diagramXML = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf-8');
var testModules = [ modelingModule ];
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('create element', function() {
it('element should be created', inject(function(bpmnFactory) {
var task = bpmnFactory.create('bpmn:Task');
expect(task).toBeDefined();
expect(task.$type).toEqual('bpmn:Task');
}));
it('element id should have semantic prefix', inject(function(bpmnFactory) {
var task = bpmnFactory.create('bpmn:ServiceTask');
expect(task.$type).toEqual('bpmn:ServiceTask');
expect(task.id).toMatch(/^ServiceTask_/g);
}));
});
describe('create di', function() {
it('should create waypoints', inject(function(bpmnFactory) {
// given
var waypoints = [
{ original: { x: 0, y: 0 }, x: 0, y: 0 },
{ original: { x: 0, y: 0 }, x: 0, y: 0 }
];
// when
var result = bpmnFactory.createDiWaypoints(waypoints);
// then
expect(result).toDeepEqual([
{ $type: 'dc:Point', x: 0, y: 0 },
{ $type: 'dc:Point', x: 0, y: 0 }
]);
// expect original not to have been accidently serialized
expect(result[0].$attrs).toEqual({});
}));
});
});