2015-04-15 07:06:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var TestHelper = require('../../../TestHelper');
|
|
|
|
|
|
|
|
/* global bootstrapModeler, inject */
|
|
|
|
|
|
|
|
var Events = require('diagram-js/test/util/Events');
|
|
|
|
|
|
|
|
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-04-15 07:06:34 +00:00
|
|
|
rulesModule = require('../../../../lib/features/modeling/rules');
|
|
|
|
|
|
|
|
var pick = require('lodash/object/pick');
|
|
|
|
|
|
|
|
|
|
|
|
function bounds(element) {
|
|
|
|
return pick(element, [ 'width', 'height', 'x', 'y' ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('features/snapping - BpmnSnapping', function() {
|
|
|
|
|
|
|
|
var testModules = [ coreModule, snappingModule, modelingModule, createModule, rulesModule ];
|
|
|
|
|
|
|
|
|
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-06-10 13:58:52 +00:00
|
|
|
var createEvent;
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
beforeEach(inject(function(canvas, dragging) {
|
|
|
|
createEvent = Events.scopedCreate(canvas);
|
|
|
|
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
|
|
|
|
create.start(createEvent({ 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-06-10 13:58:52 +00:00
|
|
|
dragging.move(createEvent({ x: 65, y: 65 }));
|
|
|
|
dragging.end(createEvent({ x: 65, y: 65 }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// then
|
|
|
|
expect(bounds(participantShape)).toEqual({
|
|
|
|
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
|
|
|
|
create.start(createEvent({ 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-06-10 13:58:52 +00:00
|
|
|
dragging.move(createEvent({ x: 400, y: 400 }));
|
|
|
|
dragging.end(createEvent({ x: 400, y: 400 }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// then
|
|
|
|
expect(bounds(participantShape)).toEqual({
|
|
|
|
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-06-10 13:58:52 +00:00
|
|
|
var createEvent;
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
beforeEach(inject(function(canvas, dragging) {
|
|
|
|
createEvent = Events.scopedCreate(canvas);
|
|
|
|
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
|
|
|
|
create.start(createEvent({ 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-06-10 13:58:52 +00:00
|
|
|
dragging.move(createEvent({ x: 400, y: 400 }));
|
|
|
|
dragging.end(createEvent({ x: 400, y: 400 }));
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
// then
|
|
|
|
expect(bounds(participantShape)).toEqual({
|
|
|
|
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-06-10 13:58:52 +00:00
|
|
|
var createEvent;
|
2015-04-15 07:06:34 +00:00
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
beforeEach(inject(function(canvas, dragging) {
|
|
|
|
createEvent = Events.scopedCreate(canvas);
|
|
|
|
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
|
|
|
|
create.start(createEvent({ 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-06-10 13:58:52 +00:00
|
|
|
dragging.move(createEvent({ x: 400, y: 400 }));
|
|
|
|
dragging.end(createEvent({ x: 400, y: 400 }));
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(bounds(participantShape)).toEqual({
|
|
|
|
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 }));
|
|
|
|
|
|
|
|
var createEvent;
|
|
|
|
|
|
|
|
beforeEach(inject(function(canvas, dragging) {
|
|
|
|
createEvent = Events.scopedCreate(canvas);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
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-06-10 13:58:52 +00:00
|
|
|
resize.activate(createEvent({ x: 500, y: 500 }), participant, 'se');
|
|
|
|
dragging.move(createEvent({ x: 0, y: 0 }));
|
2015-06-03 15:47:24 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
expect(participant.width).toEqual(497);
|
|
|
|
expect(participant.height).toEqual(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-06-10 13:58:52 +00:00
|
|
|
resize.activate(createEvent({ x: 0, y: 0 }), participant, 'nw');
|
|
|
|
dragging.move(createEvent({ x: 500, y: 500 }));
|
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
expect(participant.width).toEqual(467);
|
|
|
|
expect(participant.height).toEqual(287);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions from <se>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_1');
|
|
|
|
|
|
|
|
resize.activate(createEvent({ x: 500, y: 500 }), participant, 'se');
|
|
|
|
dragging.move(createEvent({ x: 0, y: 0 }));
|
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
expect(participant.width).toEqual(300);
|
|
|
|
expect(participant.height).toEqual(150);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions from <nw>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_1');
|
|
|
|
|
|
|
|
resize.activate(createEvent({ x: 0, y: 0 }), participant, 'nw');
|
|
|
|
dragging.move(createEvent({ x: 500, y: 500 }));
|
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
expect(participant.width).toEqual(300);
|
|
|
|
expect(participant.height).toEqual(150);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions + children from <se>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_3');
|
|
|
|
|
|
|
|
resize.activate(createEvent({ x: 500, y: 500 }), participant, 'se');
|
|
|
|
dragging.move(createEvent({ x: 0, y: 0 }));
|
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
expect(participant.width).toEqual(320);
|
|
|
|
expect(participant.height).toEqual(150);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap to min dimensions + children from <nw>', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_3');
|
|
|
|
|
|
|
|
resize.activate(createEvent({ x: 0, y: 0 }), participant, 'nw');
|
|
|
|
dragging.move(createEvent({ x: 500, y: 500 }));
|
2015-06-03 15:47:24 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
expect(participant.width).toEqual(353);
|
|
|
|
expect(participant.height).toEqual(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-06-10 13:58:52 +00:00
|
|
|
resize.activate(createEvent({ x: 453, y: 624 }), subProcess, 'se');
|
|
|
|
dragging.move(createEvent({ x: -453, y: -624 }));
|
2015-04-28 11:24:55 +00:00
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
expect(subProcess.width).toEqual(140);
|
|
|
|
expect(subProcess.height).toEqual(120);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should snap a Participant to minimum bounds', inject(function(canvas, elementRegistry, resize, dragging) {
|
|
|
|
|
|
|
|
var participant = elementRegistry.get('Participant_1');
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
resize.activate(createEvent({ x: 614, y: 310 }), participant, 'se');
|
|
|
|
dragging.move(createEvent({ x: -614, y: -310 }));
|
2015-04-28 11:24:55 +00:00
|
|
|
dragging.end();
|
|
|
|
|
2015-06-10 13:58:52 +00:00
|
|
|
expect(participant.width).toEqual(300);
|
|
|
|
expect(participant.height).toEqual(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-06-10 13:58:52 +00:00
|
|
|
resize.activate(createEvent({ x: 592, y: 452 }), textAnnotation, 'se');
|
|
|
|
dragging.move(createEvent({ x: -592, y: -452 }));
|
2015-04-28 11:24:55 +00:00
|
|
|
dragging.end();
|
|
|
|
|
|
|
|
expect(textAnnotation.width).toEqual(50);
|
|
|
|
expect(textAnnotation.height).toEqual(50);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-05-28 07:30:50 +00:00
|
|
|
});
|