Skip to content

Commit

Permalink
test(edit): verify missing namespace export
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku authored and fake-join[bot] committed Apr 28, 2020
1 parent 4030435 commit 1211bda
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/fixtures/bpmn/local-ns-no-di.bpmn
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="6.4.2">
<process id="Process" isExecutable="false">
<startEvent id="Start" name="hunger noticed">
<outgoing>SequenceFlow</outgoing>
</startEvent>
<task id="Task" name="choose recipe">
<incoming>SequenceFlow</incoming>
</task>
<sequenceFlow id="SequenceFlow" sourceRef="Start" targetRef="Task" />
</process>
<BPMNDiagram id="BpmnDiagram_1" xmlns="http://www.omg.org/spec/BPMN/20100524/DI">
<BPMNPlane id="BpmnPlane_1" bpmnElement="Process" xmlns="http://www.omg.org/spec/BPMN/20100524/DI">
</BPMNPlane>
</BPMNDiagram>
</definitions>
110 changes: 110 additions & 0 deletions test/spec/xml/edit.js
Expand Up @@ -6,6 +6,7 @@ import {

import {
fromFile as readFromFile,
validate,
toXML
} from '../../xml-helper';

Expand Down Expand Up @@ -73,4 +74,113 @@ describe('bpmn-moddle - edit', function() {
expect(xml).to.contain('<bpmn:dataObjectReference id="DataObjectReference_1" dataObjectRef="dataObject_2" />');
});
});


describe('generate DI', function() {

async function readAndGenerateDI(file) {

var {
rootElement: definitions
} = await fromFile(file);

var process = definitions.rootElements[0];

var flowElements = process.flowElements;

var [
start,
task,
flow
] = flowElements;

var plane = definitions.diagrams[0].plane;

var model = definitions.$model;

var planeElements = plane.get('planeElement');

// when
planeElements.push(
model.create('bpmndi:BPMNEdge', {
id: 'Flow_di',
bpmnElement: flow,
waypoint: [
model.create('dc:Point', { x: 100, y: 100 }),
model.create('dc:Point', { x: 150, y: 150 })
]
}),
model.create('bpmndi:BPMNShape', {
id: 'Start_di',
bpmnElement: start,
bounds: model.create('dc:Bounds', { x: 50, y: 50, width: 100, height: 100 })
}),
model.create('bpmndi:BPMNShape', {
id: 'Task_di',
bpmnElement: task,
bounds: model.create('dc:Bounds', { x: 100, y: 100, width: 100, height: 100 })
})
);

return {
definitions
};
}


it('should auto-add wellknown', async function() {

// given
var {
definitions
} = await readAndGenerateDI('test/fixtures/bpmn/local-ns-no-di.bpmn');

// when
var {
xml
} = await toXML(definitions, { format: true });

// then
expect(xml).to.contain(
'xmlns:di="http://www.omg.org/spec/DD/20100524/DI"'
);

expect(xml).to.contain(
'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"'
);

await validate(xml);
});


it('should reuse global namespace', async function() {

// given
var {
definitions
} = await readAndGenerateDI('test/fixtures/bpmn/local-ns-no-di.bpmn');

// when
// set global namespace information
definitions.$attrs['xmlns:di'] = 'http://www.omg.org/spec/DD/20100524/DI';
definitions.$attrs['xmlns:dc'] = 'http://www.omg.org/spec/DD/20100524/DC';

var {
xml
} = await toXML(definitions, { format: true });

// then
expect(xml).to.contain(
'xmlns:di="http://www.omg.org/spec/DD/20100524/DI"'
);

expect(xml).to.contain(
'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"'
);

await validate(xml);
});

});

});

0 comments on commit 1211bda

Please sign in to comment.