From 8896209d8278c17289d6b0b64fff794f7e64cd5c Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 25 Nov 2019 22:45:45 +0100 Subject: [PATCH] fix(drd): correct append behavior + test cover dat stuff Related to https://github.com/camunda/camunda-modeler/issues/1604 --- .../context-pad/ContextPadProvider.js | 5 +- .../context-pad/ContextPadProviderSpec.js | 51 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/dmn-js-drd/src/features/context-pad/ContextPadProvider.js b/packages/dmn-js-drd/src/features/context-pad/ContextPadProvider.js index e7ac2aabc..616ce1e62 100644 --- a/packages/dmn-js-drd/src/features/context-pad/ContextPadProvider.js +++ b/packages/dmn-js-drd/src/features/context-pad/ContextPadProvider.js @@ -136,7 +136,10 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) { function appendListener(event, element) { var shape = elementFactory.createShape(assign({ type: type }, options)); - create.start(event, shape, element); + + create.start(event, shape, { + source: element + }); } return { diff --git a/packages/dmn-js-drd/test/spec/features/context-pad/ContextPadProviderSpec.js b/packages/dmn-js-drd/test/spec/features/context-pad/ContextPadProviderSpec.js index 62c069af8..dae8989d1 100644 --- a/packages/dmn-js-drd/test/spec/features/context-pad/ContextPadProviderSpec.js +++ b/packages/dmn-js-drd/test/spec/features/context-pad/ContextPadProviderSpec.js @@ -20,6 +20,10 @@ import modelingModule from 'src/features/modeling'; import createModule from 'diagram-js/lib/features/create'; import customRulesModule from '../../../util/custom-rules'; +import { + createCanvasEvent as canvasEvent +} from '../../../util/MockEvents'; + describe('features - context-pad', function() { @@ -260,6 +264,7 @@ describe('features - context-pad', function() { }); + describe('replace', function() { var diagramXML = require('./ContextPad.dmn'); @@ -329,9 +334,55 @@ describe('features - context-pad', function() { }); + + describe('append', function() { + + var diagramXML = require('./ContextPad.dmn'); + + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); + + + it('should append decision', inject(function(dragging, contextPad, elementRegistry) { + + // given + var decision = elementRegistry.get('guestCount'); + + var decisionTargets = decision.outgoing.length; + + // when + contextPad.open(decision); + + contextPad.trigger('dragstart', padEvent('append.decision')); + + dragging.move(canvasEvent({ x: decision.x, y: decision.y })); + dragging.hover({ element: decision.parent }); + dragging.move(canvasEvent({ x: decision.x - 100, y: decision.y - 90 })); + dragging.end(); + + // then + expect(decision.outgoing).to.have.length(decisionTargets + 1); + })); + + }); + }); function padEntry(element, name) { return domQuery('[data-action="' + name + '"]', element); } + +function padEvent(entry) { + + return getDrdJS().invoke(function(overlays) { + + var target = padEntry(overlays._overlayRoot, entry); + + return { + target: target, + preventDefault: function() {}, + clientX: 100, + clientY: 100 + }; + }); +} \ No newline at end of file