2015-04-15 07:06:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var TestHelper = require('../../../TestHelper');
|
|
|
|
|
|
|
|
/* global bootstrapModeler, inject */
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
var canvasEvent = require('../../../util/MockEvents').createCanvasEvent;
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
var coreModule = require('../../../../lib/core'),
|
|
|
|
snappingModule = require('../../../../lib/features/snapping'),
|
|
|
|
modelingModule = require('../../../../lib/features/modeling'),
|
|
|
|
createModule = require('diagram-js/lib/features/create'),
|
2015-04-28 11:24:55 +00:00
|
|
|
resizeModule = require('diagram-js/lib/features/resize'),
|
2015-07-13 08:37:43 +00:00
|
|
|
moveModule = require('diagram-js/lib/features/move'),
|
2015-08-19 15:16:21 +00:00
|
|
|
rulesModule = require('../../../../lib/features/rules');
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
var pick = require('lodash/object/pick');
|
|
|
|
|
|
|
|
|
|
|
|
function bounds(element) {
|
|
|
|
return pick(element, [ 'width', 'height', 'x', 'y' ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('features/snapping - BpmnSnapping', function() {
|
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
var testModules = [ coreModule, snappingModule, modelingModule, createModule, rulesModule, moveModule ];
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-07-13 08:37:43 +00:00
|
|
|
describe('on Boundary Events', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('../../../fixtures/bpmn/collaboration/process.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
var task, intermediateThrowEvent;
|
2015-07-13 08:37:43 +00:00
|
|
|
|
|
|
|
beforeEach(inject(function(elementFactory, elementRegistry, canvas, dragging) {
|
|
|
|
task = elementRegistry.get('Task_1');
|
|
|
|
|
|
|
|
intermediateThrowEvent = elementFactory.createShape({
|
|
|
|
type: 'bpmn:IntermediateThrowEvent',
|
|
|
|
});
|
|
|
|
|
|
|
|
dragging.setOptions({ manual: true });
|
|
|
|
}));
|
|
|
|
|
|
|
|
afterEach(inject(function(dragging) {
|
|
|
|
dragging.setOptions({ manual: false });
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should snap on create to the bottom',
|
|
|
|
inject(function(canvas, create, dragging, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var taskGfx = canvas.getGraphics(task);
|
|
|
|
|
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
create.start(canvasEvent({ x: 0, y: 0 }), intermediateThrowEvent);
|
2015-07-13 08:37:43 +00:00
|
|
|
|
|
|
|
dragging.hover({ element: task, gfx: taskGfx });
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
dragging.move(canvasEvent({ x: 382, y: 170 }));
|
2015-07-13 08:37:43 +00:00
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
var boundaryEvent = elementRegistry.get(task.attachers[0].id);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(bounds(boundaryEvent)).to.eql({ x: 364, y: 167, width: 36, height: 36 });
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap on create to the left',
|
|
|
|
inject(function(canvas, create, dragging, elementRegistry) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var taskGfx = canvas.getGraphics(task);
|
|
|
|
|
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
create.start(canvasEvent({ x: 0, y: 0 }), intermediateThrowEvent);
|
2015-07-13 08:37:43 +00:00
|
|
|
|
|
|
|
dragging.hover({ element: task, gfx: taskGfx });
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
dragging.move(canvasEvent({ x: 382, y: 115 }));
|
2015-07-13 08:37:43 +00:00
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
var boundaryEvent = elementRegistry.get(task.attachers[0].id);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(bounds(boundaryEvent)).to.eql({ x: 364, y: 87, width: 36, height: 36 });
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
describe('on Participant create', function() {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
describe('in non-empty process', function() {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/collaboration/process.bpmn');
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
beforeEach(inject(function(dragging) {
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.setOptions({ manual: true });
|
|
|
|
}));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
it('should snap to process children bounds / top left',
|
|
|
|
inject(function(canvas, create, dragging, elementFactory) {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// given
|
|
|
|
var participantShape = elementFactory.createParticipantShape(false),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
rootGfx = canvas.getGraphics(rootElement);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
create.start(canvasEvent({ x: 50, y: 50 }), participantShape);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.hover({ element: rootElement, gfx: rootGfx });
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
dragging.move(canvasEvent({ x: 65, y: 65 }));
|
|
|
|
dragging.end(canvasEvent({ x: 65, y: 65 }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(bounds(participantShape)).to.eql({
|
2015-06-10 13:58:52 +00:00
|
|
|
width: 600, height: 250, x: 18, y: -8
|
|
|
|
});
|
|
|
|
}));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
it('should snap to process children bounds / bottom right',
|
|
|
|
inject(function(canvas, create, dragging, elementFactory) {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// given
|
|
|
|
var participantShape = elementFactory.createParticipantShape(false),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
rootGfx = canvas.getGraphics(rootElement);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
create.start(canvasEvent({ x: 50, y: 50 }), participantShape);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.hover({ element: rootElement, gfx: rootGfx });
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
dragging.move(canvasEvent({ x: 400, y: 400 }));
|
|
|
|
dragging.end(canvasEvent({ x: 400, y: 400 }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(bounds(participantShape)).to.eql({
|
2015-06-10 13:58:52 +00:00
|
|
|
width: 600, height: 250, x: 100, y: 52
|
|
|
|
});
|
|
|
|
}));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
});
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
describe('in empty process', function() {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/collaboration/process-empty.bpmn');
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
beforeEach(inject(function(dragging) {
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.setOptions({ manual: true });
|
|
|
|
}));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
it('should not snap', inject(function(canvas, create, dragging, elementFactory) {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// given
|
|
|
|
var participantShape = elementFactory.createParticipantShape(false),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
rootGfx = canvas.getGraphics(rootElement);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
create.start(canvasEvent({ x: 50, y: 50 }), participantShape);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.hover({ element: rootElement, gfx: rootGfx });
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
dragging.move(canvasEvent({ x: 400, y: 400 }));
|
|
|
|
dragging.end(canvasEvent({ x: 400, y: 400 }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(bounds(participantShape)).to.eql({
|
2015-06-10 13:58:52 +00:00
|
|
|
x: 100, y: 275, width: 600, height: 250
|
|
|
|
});
|
|
|
|
}));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
});
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
describe('in collaboration', function() {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/collaboration/collaboration-participant.bpmn');
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
beforeEach(inject(function(dragging) {
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.setOptions({ manual: true });
|
|
|
|
}));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
it('should not snap', inject(function(canvas, create, dragging, elementFactory) {
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// given
|
|
|
|
var participantShape = elementFactory.createParticipantShape(false),
|
|
|
|
rootElement = canvas.getRootElement(),
|
|
|
|
rootGfx = canvas.getGraphics(rootElement);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// when
|
2015-08-24 13:31:47 +00:00
|
|
|
create.start(canvasEvent({ x: 50, y: 50 }), participantShape);
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.hover({ element: rootElement, gfx: rootGfx });
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
dragging.move(canvasEvent({ x: 400, y: 400 }));
|
|
|
|
dragging.end(canvasEvent({ x: 400, y: 400 }));
|
2015-06-10 13:58:52 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(bounds(participantShape)).to.eql({
|
2015-06-10 13:58:52 +00:00
|
|
|
x: 100, y: 275, width: 600, height: 250
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2015-04-15 07:06:34 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-05-05 11:29:28 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
describe('on Participant resize', function () {
|
2015-06-03 15:47:24 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
var diagramXML = require('./BpmnSnapping.collaboration-resize.bpmn');
|
2015-05-05 11:29:28 +00:00
|
|
|
|
2015-04-28 11:24:55 +00:00
|
|
|
var testResizeModules = [ coreModule, resizeModule, rulesModule, snappingModule ];
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));
|
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
describe('snap min bounds', function() {
|
2015-06-03 15:47:24 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
it('should snap to children from <se>', inject(function(canvas, elementRegistry, resize, dragging) {
|
2015-06-03 15:47:24 +00:00
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_2');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
|
|
|
|
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
2015-06-03 15:47:24 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(497);
|
|
|
|
expect(participant.height).to.equal(252);
|
2015-06-03 15:47:24 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
it('should snap to children from <nw>', inject(function(canvas, elementRegistry, resize, dragging) {
|
2015-06-03 15:47:24 +00:00
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_2');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
|
|
|
|
dragging.move(canvasEvent({ x: 500, y: 500 }));
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(467);
|
|
|
|
expect(participant.height).to.equal(287);
|
2015-06-10 13:58:52 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions from <se>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_1');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
|
|
|
|
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(300);
|
|
|
|
expect(participant.height).to.equal(150);
|
2015-06-10 13:58:52 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions from <nw>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_1');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
|
|
|
|
dragging.move(canvasEvent({ x: 500, y: 500 }));
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(300);
|
|
|
|
expect(participant.height).to.equal(150);
|
2015-06-10 13:58:52 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions + children from <se>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_3');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 500, y: 500 }), participant, 'se');
|
|
|
|
dragging.move(canvasEvent({ x: 0, y: 0 }));
|
2015-06-10 13:58:52 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(320);
|
|
|
|
expect(participant.height).to.equal(150);
|
2015-06-10 13:58:52 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions + children from <nw>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_3');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 0, y: 0 }), participant, 'nw');
|
|
|
|
dragging.move(canvasEvent({ x: 500, y: 500 }));
|
2015-06-03 15:47:24 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(353);
|
|
|
|
expect(participant.height).to.equal(177);
|
2015-06-03 15:47:24 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-04-28 11:24:55 +00:00
|
|
|
it('should snap a SubProcess to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
|
2015-05-05 11:29:28 +00:00
|
|
|
|
2015-04-28 11:24:55 +00:00
|
|
|
var subProcess = elementRegistry.get('SubProcess_1');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 453, y: 624 }), subProcess, 'se');
|
|
|
|
dragging.move(canvasEvent({ x: -453, y: -624 }));
|
2015-04-28 11:24:55 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(subProcess.width).to.equal(140);
|
|
|
|
expect(subProcess.height).to.equal(120);
|
2015-04-28 11:24:55 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap a Participant to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_1');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 614, y: 310 }), participant, 'se');
|
|
|
|
dragging.move(canvasEvent({ x: -614, y: -310 }));
|
2015-04-28 11:24:55 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(participant.width).to.equal(300);
|
|
|
|
expect(participant.height).to.equal(150);
|
2015-04-28 11:24:55 +00:00
|
|
|
}));
|
|
|
|
|
2015-06-03 15:47:24 +00:00
|
|
|
|
2015-04-28 11:24:55 +00:00
|
|
|
it('should snap a TextAnnotation to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
|
2015-05-05 11:29:28 +00:00
|
|
|
|
2015-04-28 11:24:55 +00:00
|
|
|
var textAnnotation = elementRegistry.get('TextAnnotation_1');
|
|
|
|
|
2015-08-24 13:31:47 +00:00
|
|
|
resize.activate(canvasEvent({ x: 592, y: 452 }), textAnnotation, 'se');
|
|
|
|
dragging.move(canvasEvent({ x: -592, y: -452 }));
|
2015-04-28 11:24:55 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(textAnnotation.width).to.equal(50);
|
|
|
|
expect(textAnnotation.height).to.equal(50);
|
2015-04-28 11:24:55 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-05-28 07:30:50 +00:00
|
|
|
});
|