chore(tests): convert BpmnTreeWalker test to ES5

This commit is contained in:
Nico Rehwaldt 2018-07-13 15:48:34 +02:00
parent 46e7aea642
commit 311e5d7bc7
1 changed files with 33 additions and 30 deletions

View File

@ -14,7 +14,7 @@ describe('import - BpmnTreeWalker', function() {
it('should expose functions', function() { it('should expose functions', function() {
// when // when
const walker = createWalker(); var walker = createWalker();
// then // then
expect(walker.handleDeferred).to.exist; expect(walker.handleDeferred).to.exist;
@ -27,17 +27,17 @@ describe('import - BpmnTreeWalker', function() {
it('should walk bpmn:Definitions', function(done) { it('should walk bpmn:Definitions', function(done) {
// given // given
const elementSpy = sinon.spy(), var elementSpy = sinon.spy(),
rootSpy = sinon.spy(), rootSpy = sinon.spy(),
errorSpy = sinon.spy(); errorSpy = sinon.spy();
const walker = createWalker({ var walker = createWalker({
element: elementSpy, element: elementSpy,
root: rootSpy, root: rootSpy,
error: errorSpy error: errorSpy
}); });
createModdle(simpleXML, (err, definitions, context, moddle) => { createModdle(simpleXML, function(err, definitions, context, moddle) {
// when // when
walker.handleDefinitions(definitions); walker.handleDefinitions(definitions);
@ -55,20 +55,20 @@ describe('import - BpmnTreeWalker', function() {
it('should walk bpmn:SubProcess', function(done) { it('should walk bpmn:SubProcess', function(done) {
// given // given
const elementSpy = sinon.spy(), var elementSpy = sinon.spy(),
rootSpy = sinon.spy(), rootSpy = sinon.spy(),
errorSpy = sinon.spy(); errorSpy = sinon.spy();
const walker = createWalker({ var walker = createWalker({
element: elementSpy, element: elementSpy,
root: rootSpy, root: rootSpy,
error: errorSpy error: errorSpy
}); });
createModdle(simpleXML, (err, definitions, context, moddle) => { createModdle(simpleXML, function(err, definitions, context, moddle) {
const subProcess = findElementWithId(definitions, 'SubProcess_1'); var subProcess = findElementWithId(definitions, 'SubProcess_1');
const plane = definitions.diagrams[0].plane, var plane = definitions.diagrams[0].plane,
planeElements = plane.planeElement; planeElements = plane.planeElement;
// register DI // register DI
@ -92,19 +92,19 @@ describe('import - BpmnTreeWalker', function() {
it('should error', function(done) { it('should error', function(done) {
// given // given
const elementSpy = sinon.spy(), var elementSpy = sinon.spy(),
rootSpy = sinon.spy(), rootSpy = sinon.spy(),
errorSpy = sinon.spy(); errorSpy = sinon.spy();
const walker = createWalker({ var walker = createWalker({
element: elementSpy, element: elementSpy,
root: rootSpy, root: rootSpy,
error: errorSpy error: errorSpy
}); });
createModdle(simpleXML, (err, definitions, context, moddle) => { createModdle(simpleXML, function(err, definitions, context, moddle) {
const element = findElementWithId(definitions, 'SubProcess_1'); var element = findElementWithId(definitions, 'SubProcess_1');
// will error // will error
element.di = 'DI'; element.di = 'DI';
@ -127,22 +127,25 @@ describe('import - BpmnTreeWalker', function() {
// helpers ////////// // helpers //////////
function createModdle(xml, done) { function createModdle(xml, done) {
const moddle = new BpmnModdle(); var moddle = new BpmnModdle();
moddle.fromXML(xml, 'bpmn:Definitions', (err, definitions, context) => { moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
done(err, definitions, context, moddle); done(err, definitions, context, moddle);
}); });
} }
function createWalker(listeners = {}) { function createWalker(listeners) {
const visitor = {
element(element, parent) { listeners = listeners || {};
var visitor = {
element: function(element, parent) {
listeners.element && listeners.element(element, parent); listeners.element && listeners.element(element, parent);
}, },
root(root) { root: function(root) {
listeners.root && listeners.root(root); listeners.root && listeners.root(root);
}, },
error(message, context) { error: function(message, context) {
listeners.error && listeners.error(message, context); listeners.error && listeners.error(message, context);
} }
}; };
@ -158,15 +161,15 @@ function findElementWithId(definitions, id) {
} }
if (element.flowElements) { if (element.flowElements) {
return find(element.flowElements, flowElement => { return find(element.flowElements, function(flowElement) {
const foundElement = findElement(flowElement); var foundElement = findElement(flowElement);
return foundElement && foundElement.id === id; return foundElement && foundElement.id === id;
}); });
} }
} }
return definitions.rootElements.reduce((foundElement, rootElement) => { return definitions.rootElements.reduce(function(foundElement, rootElement) {
if (rootElement.id === id) { if (rootElement.id === id) {
return rootElement; return rootElement;
} else { } else {