2014-07-30 14:07:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Matchers = require('../../../Matchers'),
|
|
|
|
TestHelper = require('../../../TestHelper');
|
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
/* global bootstrapModeler, inject */
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var modelingModule = require('../../../../lib/features/modeling'),
|
|
|
|
drawModule = require('../../../../lib/draw');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features/modeling - move shape', function() {
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
beforeEach(Matchers.addDeepEquals);
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
var diagramXML = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf-8');
|
|
|
|
|
|
|
|
var testModules = [ drawModule, modelingModule ];
|
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('shape handling', function() {
|
|
|
|
|
|
|
|
it('should execute', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-07-31 13:46:55 +00:00
|
|
|
var startEventElement = elementRegistry.getById('StartEvent_1'),
|
|
|
|
startEvent = startEventElement.businessObject;
|
|
|
|
|
|
|
|
var sequenceFlowElement = elementRegistry.getById('SequenceFlow_1'),
|
|
|
|
sequenceFlow = sequenceFlowElement.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var oldPosition = {
|
2014-07-31 13:46:55 +00:00
|
|
|
x: startEventElement.x,
|
|
|
|
y: startEventElement.y
|
2014-07-30 14:07:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2014-08-02 14:38:40 +00:00
|
|
|
modeling.moveShape(startEventElement, { x: 0, y: 50 });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(startEvent.di.bounds.x).toBe(oldPosition.x);
|
|
|
|
expect(startEvent.di.bounds.y).toBe(oldPosition.y + 50);
|
2014-07-31 13:46:55 +00:00
|
|
|
|
2014-08-27 14:55:26 +00:00
|
|
|
// expect flow layout
|
2014-07-31 13:46:55 +00:00
|
|
|
expect(sequenceFlowElement.waypoints).toDeepEqual([
|
2014-08-27 14:55:26 +00:00
|
|
|
{ original: { x: 370, y: 310 }, x: 388, y: 310 },
|
|
|
|
{ x: 404, y: 310 },
|
|
|
|
{ x: 404, y: 260 },
|
|
|
|
{ original: { x: 470, y: 260 }, x: 420, y: 260 }
|
2014-07-31 13:46:55 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
expect(sequenceFlow.di.waypoint).toDeepEqual([
|
2014-08-27 14:55:26 +00:00
|
|
|
{ $type: 'dc:Point', x: 388, y: 310 },
|
|
|
|
{ $type: 'dc:Point', x: 404, y: 310 },
|
|
|
|
{ $type: 'dc:Point', x: 404, y: 260 },
|
|
|
|
{ $type: 'dc:Point', x: 420, y: 260 }
|
2014-07-31 13:46:55 +00:00
|
|
|
]);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should execute on label', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-07-31 13:46:55 +00:00
|
|
|
var labelElement = elementRegistry.getById('StartEvent_1_label'),
|
|
|
|
startEvent = labelElement.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var oldPosition = {
|
2014-07-31 13:46:55 +00:00
|
|
|
x: labelElement.x,
|
|
|
|
y: labelElement.y
|
2014-07-30 14:07:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
2014-08-02 14:38:40 +00:00
|
|
|
modeling.moveShape(labelElement, { x: 0, y: 50 });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// then
|
|
|
|
expect(startEvent.di.label.bounds.x).toBe(oldPosition.x);
|
|
|
|
expect(startEvent.di.label.bounds.y).toBe(oldPosition.y + 50);
|
|
|
|
}));
|
|
|
|
|
2014-09-11 15:22:59 +00:00
|
|
|
|
|
|
|
it('should move label with element', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventElement = elementRegistry.getById('StartEvent_1'),
|
|
|
|
startEvent = startEventElement.businessObject;
|
|
|
|
|
|
|
|
var label = startEventElement.label;
|
|
|
|
|
|
|
|
var labelPosition = {
|
|
|
|
x: label.x,
|
|
|
|
y: label.y
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
modeling.moveShape(startEventElement, { x: 40, y: -80 });
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(label.x).toBe(labelPosition.x + 40);
|
|
|
|
expect(label.y).toBe(labelPosition.y - 80);
|
|
|
|
}));
|
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('undo support', function() {
|
|
|
|
|
|
|
|
it('should undo', inject(function(elementRegistry, commandStack, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-07-31 13:46:55 +00:00
|
|
|
var startEventElement = elementRegistry.getById('StartEvent_1'),
|
|
|
|
startEvent = startEventElement.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var oldPosition = {
|
2014-07-31 13:46:55 +00:00
|
|
|
x: startEventElement.x,
|
|
|
|
y: startEventElement.y
|
2014-07-30 14:07:43 +00:00
|
|
|
};
|
|
|
|
|
2014-08-02 14:38:40 +00:00
|
|
|
modeling.moveShape(startEventElement, { x: 0, y: 50 });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(startEvent.di.bounds.x).toBe(oldPosition.x);
|
|
|
|
expect(startEvent.di.bounds.y).toBe(oldPosition.y);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo on label', inject(function(elementRegistry, commandStack, modeling) {
|
|
|
|
|
|
|
|
// given
|
2014-07-31 13:46:55 +00:00
|
|
|
var labelElement = elementRegistry.getById('StartEvent_1_label'),
|
|
|
|
startEvent = labelElement.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
var oldPosition = {
|
2014-07-31 13:46:55 +00:00
|
|
|
x: labelElement.x,
|
|
|
|
y: labelElement.y
|
2014-07-30 14:07:43 +00:00
|
|
|
};
|
|
|
|
|
2014-08-02 14:38:40 +00:00
|
|
|
modeling.moveShape(labelElement, { x: 0, y: 50 });
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(startEvent.di.label.bounds.x).toBe(oldPosition.x);
|
|
|
|
expect(startEvent.di.label.bounds.y).toBe(oldPosition.y);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-07-31 13:46:55 +00:00
|
|
|
|
|
|
|
describe('redo support', function() {
|
|
|
|
|
|
|
|
it('should redo', inject(function(elementRegistry, commandStack, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventElement = elementRegistry.getById('StartEvent_1'),
|
|
|
|
startEvent = startEventElement.businessObject;
|
|
|
|
|
|
|
|
|
2014-08-02 14:38:40 +00:00
|
|
|
modeling.moveShape(startEventElement, { x: 0, y: 50 });
|
2014-07-31 13:46:55 +00:00
|
|
|
|
|
|
|
var newPosition = {
|
|
|
|
x: startEventElement.x,
|
|
|
|
y: startEventElement.y
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(startEvent.di.bounds.x).toBe(newPosition.x);
|
|
|
|
expect(startEvent.di.bounds.y).toBe(newPosition.y);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should redo on label', inject(function(elementRegistry, commandStack, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var labelElement = elementRegistry.getById('StartEvent_1_label'),
|
|
|
|
startEvent = labelElement.businessObject;
|
|
|
|
|
2014-08-02 14:38:40 +00:00
|
|
|
modeling.moveShape(labelElement, { x: 0, y: 50 });
|
2014-07-31 13:46:55 +00:00
|
|
|
|
|
|
|
var newPosition = {
|
|
|
|
x: labelElement.x,
|
|
|
|
y: labelElement.y
|
|
|
|
};
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(startEvent.di.label.bounds.x).toBe(newPosition.x);
|
|
|
|
expect(startEvent.di.label.bounds.y).toBe(newPosition.y);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
});
|