diff --git a/test/spec/Modeler.copy-paste.a.bpmn b/test/spec/Modeler.copy-paste.a.bpmn new file mode 100644 index 00000000..76ee1650 --- /dev/null +++ b/test/spec/Modeler.copy-paste.a.bpmn @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/spec/Modeler.copy-paste.b.bpmn b/test/spec/Modeler.copy-paste.b.bpmn new file mode 100644 index 00000000..7fbda4de --- /dev/null +++ b/test/spec/Modeler.copy-paste.b.bpmn @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/spec/ModelerSpec.js b/test/spec/ModelerSpec.js index 2e266156..f969c99d 100644 --- a/test/spec/ModelerSpec.js +++ b/test/spec/ModelerSpec.js @@ -2,10 +2,12 @@ import Modeler from 'lib/Modeler'; import Viewer from 'lib/Viewer'; import NavigatedViewer from 'lib/NavigatedViewer'; +import Clipboard from 'diagram-js/lib/features/clipboard/Clipboard'; + import TestContainer from 'mocha-test-container-support'; import { - createEvent + createCanvasEvent } from '../util/MockEvents'; import { @@ -312,11 +314,11 @@ describe('Modeler', function() { // when bendpointMove.start( - createEvent(canvas, { x: 0, y: 0 }), + createCanvasEvent({ x: 0, y: 0 }), elementRegistry.get('SequenceFlow_1'), 1 ); - dragging.move(createEvent(canvas, { x: 200, y: 200 })); + dragging.move(createCanvasEvent({ x: 200, y: 200 })); }); }); @@ -544,6 +546,7 @@ describe('Modeler', function() { }); + it('should inject mandatory modules', function() { // given @@ -588,6 +591,91 @@ describe('Modeler', function() { }); + describe('copy and paste', function() { + + var m1, m2; + + afterEach(function() { + if (m1) { + m1.destroy(); + } + + if (m2) { + m2.destroy(); + } + }); + + + 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 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) { + + // when + // paste element to m2, first try + editorActions.trigger('paste'); + dragging.move(createCanvasEvent({ x: 150, y: 150 })); + dragging.move(createCanvasEvent({ x: 170, y: 150 })); + + dragging.end(); + + // then + expect(elementRegistry.get('A')).to.exist; + + // but when + // paste element to m2, second try + editorActions.trigger('paste'); + dragging.move(createCanvasEvent({ x: 150, y: 150 })); + dragging.move(createCanvasEvent({ x: 200, y: 150 })); + + dragging.end(); + + // TODO(nikku): assert newly created element exists + }); + + }); + + }); + + }); + + it('should expose Viewer and NavigatedViewer', function() { expect(Modeler.Viewer).to.equal(Viewer); expect(Modeler.NavigatedViewer).to.equal(NavigatedViewer);