test: verify copy and paste between Modeler instances

This commit is contained in:
Nico Rehwaldt 2021-10-20 10:03:13 +02:00 committed by Maciej Barelkowski
parent 289c074ecc
commit 97e1ad14ba
3 changed files with 134 additions and 5 deletions

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1q7lgbo" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.151.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="A" name="A" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Event_083mmcb_di" bpmnElement="A">
<dc:Bounds x="152" y="82" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="167" y="125" width="7" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1q7lgbo" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.151.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="B" name="B" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Event_083mmcb_di" bpmnElement="B">
<dc:Bounds x="102" y="82" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="117" y="125" width="7" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -2,10 +2,12 @@ import Modeler from 'lib/Modeler';
import Viewer from 'lib/Viewer'; import Viewer from 'lib/Viewer';
import NavigatedViewer from 'lib/NavigatedViewer'; import NavigatedViewer from 'lib/NavigatedViewer';
import Clipboard from 'diagram-js/lib/features/clipboard/Clipboard';
import TestContainer from 'mocha-test-container-support'; import TestContainer from 'mocha-test-container-support';
import { import {
createEvent createCanvasEvent
} from '../util/MockEvents'; } from '../util/MockEvents';
import { import {
@ -304,19 +306,18 @@ describe('Modeler', function() {
// given // given
var bendpointMove = modeler.get('bendpointMove'), var bendpointMove = modeler.get('bendpointMove'),
dragging = modeler.get('dragging'), dragging = modeler.get('dragging'),
elementRegistry = modeler.get('elementRegistry'), elementRegistry = modeler.get('elementRegistry');
canvas = modeler.get('canvas');
// assume // assume
expect(bendpointMove).to.exist; expect(bendpointMove).to.exist;
// when // when
bendpointMove.start( bendpointMove.start(
createEvent(canvas, { x: 0, y: 0 }), createCanvasEvent({ x: 0, y: 0 }),
elementRegistry.get('SequenceFlow_1'), elementRegistry.get('SequenceFlow_1'),
1 1
); );
dragging.move(createEvent(canvas, { x: 200, y: 200 })); dragging.move(createCanvasEvent({ x: 200, y: 200 }));
}); });
}); });
@ -544,6 +545,7 @@ describe('Modeler', function() {
}); });
it('should inject mandatory modules', function() { it('should inject mandatory modules', function() {
// given // given
@ -588,6 +590,101 @@ describe('Modeler', function() {
}); });
describe('copy and paste', function() {
var m1, m2;
afterEach(function() {
if (m1) {
m1.destroy();
}
if (m2) {
m2.destroy();
}
});
function isNamedA(element) {
return element.type !== 'label' && element.businessObject.name === 'A';
}
it('should share Clipboard', function() {
var aXML = require('./Modeler.copy-paste.a.bpmn');
var bXML = require('./Modeler.copy-paste.b.bpmn');
var clipboardModule = {
'clipboard': [ 'value', new Clipboard() ]
};
m2 = new Modeler({
container: container,
additionalModules: [
clipboardModule
]
});
m1 = new Modeler({
container: container,
additionalModules: [
clipboardModule
]
});
return Promise.all([
m1.importXML(aXML),
m2.importXML(bXML)
]).then(function() {
// given
// copy element <A> from m1
m1.invoke(function(selection, elementRegistry, editorActions) {
selection.select(elementRegistry.get('A'));
editorActions.trigger('copy');
});
// TODO(nikku): needed for our canvas utilities to work
setBpmnJS(m2);
m2.invoke(function(dragging, editorActions, elementRegistry) {
var processElement = elementRegistry.get('Process_1');
// when
// paste element <A> to m2, first try
editorActions.trigger('paste');
dragging.move(createCanvasEvent({ x: 150, y: 150 }));
dragging.move(createCanvasEvent({ x: 170, y: 150 }));
dragging.hover({ element: processElement });
dragging.end();
// then
expect(elementRegistry.get('A')).to.exist;
expect(elementRegistry.filter(isNamedA)).to.have.lengthOf(1);
// but when
// paste element <A> to m2, second try
editorActions.trigger('paste');
dragging.move(createCanvasEvent({ x: 150, y: 150 }));
dragging.move(createCanvasEvent({ x: 300, y: 150 }));
dragging.hover({ element: processElement });
dragging.end();
// then
expect(elementRegistry.filter(isNamedA)).to.have.lengthOf(2);
});
});
});
});
it('should expose Viewer and NavigatedViewer', function() { it('should expose Viewer and NavigatedViewer', function() {
expect(Modeler.Viewer).to.equal(Viewer); expect(Modeler.Viewer).to.equal(Viewer);
expect(Modeler.NavigatedViewer).to.equal(NavigatedViewer); expect(Modeler.NavigatedViewer).to.equal(NavigatedViewer);