bpmn-js/test/spec/node/ModelSpec.js
Nico Rehwaldt 423c757f1d chore(testsuite): organize tests into node/browser
This commit introduces a clean separation of node and browser tests.

ALL tests should be organized according to where they are run

non browser (áka node tests): `test/spec/node`
browser tests: `test/spec/browser`
2014-03-13 11:33:25 +01:00

156 lines
3.5 KiB
JavaScript

var _ = require('lodash');
var BpmnModel = require('../../../lib/Model');
var Helper = require('./Helper'),
Matchers = require('../Matchers');
describe('Model', function() {
beforeEach(Matchers.add);
describe('parsing', function() {
it('should publish type', function() {
// given
var model = BpmnModel.instance();
// when
var type = model.getType('bpmn:Process');
// then
expect(type).toBeDefined();
expect(type.$descriptor).toBeDefined();
});
it('should redefine property', function() {
// given
var model = BpmnModel.instance();
// when
var type = model.getType('bpmndi:BPMNShape');
// then
expect(type).toBeDefined();
var descriptor = type.$descriptor;
expect(descriptor).toBeDefined();
expect(descriptor.propertiesByName['di:modelElement']).toEqual(descriptor.propertiesByName['bpmndi:bpmnElement']);
});
});
describe('creation', function() {
it('should create SequenceFlow', function() {
var model = BpmnModel.instance();
var sequenceFlow = model.create('bpmn:SequenceFlow');
expect(sequenceFlow.$type).toEqual('bpmn:SequenceFlow');
});
it('should create Definitions', function() {
var model = BpmnModel.instance();
var definitions = model.create('bpmn:Definitions');
expect(definitions.$type).toEqual('bpmn:Definitions');
});
});
describe('property access', function() {
describe('singleton properties', function() {
it('should set attribute', function() {
// given
var model = BpmnModel.instance();
var process = model.create('bpmn:Process');
// assume
expect(process.get('isExecutable')).not.toBeDefined();
// when
process.set('isExecutable', true);
// then
expect(process).toDeepEqual({
$type: 'bpmn:Process',
isExecutable: true
});
});
it('should set attribute (ns)', function() {
// given
var model = BpmnModel.instance();
var process = model.create('bpmn:Process');
// when
process.set('bpmn:isExecutable', true);
// then
expect(process).toDeepEqual({
$type: 'bpmn:Process',
isExecutable: true
});
});
it('should set id attribute', function() {
// given
var model = BpmnModel.instance();
var definitions = model.create('bpmn:Definitions');
// when
definitions.set('id', 10);
// then
expect(definitions).toDeepEqual({
$type: 'bpmn:Definitions',
id: 10
});
});
});
describe('builder', function() {
it('should create simple hierarchy', function() {
// given
var model = BpmnModel.instance();
var definitions = model.create('bpmn:Definitions');
var rootElements = definitions.get('bpmn:rootElements');
var process = model.create('bpmn:Process');
var collaboration = model.create('bpmn:Collaboration');
// when
rootElements.push(collaboration);
rootElements.push(process);
// then
expect(rootElements).toEqual([ collaboration, process ]);
expect(definitions.rootElements).toEqual([ collaboration, process ]);
expect(definitions).toDeepEqual({
$type: 'bpmn:Definitions',
rootElements: [
{ $type: 'bpmn:Collaboration' },
{ $type: 'bpmn:Process' }
]
});
});
});
});
});