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
|
|
|
|
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
var LabelUtil = require('../../../../lib/util/Label');
|
|
|
|
|
|
|
|
|
2014-07-30 14:07:43 +00:00
|
|
|
describe('features/modeling - append 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
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(targetShape).toBeDefined();
|
|
|
|
expect(target.$instanceOf('bpmn:Task')).toBe(true);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should create DI', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(target.di).toBeDefined();
|
|
|
|
expect(target.di.$parent).toBe(startEvent.di.$parent);
|
2014-08-02 14:38:25 +00:00
|
|
|
|
|
|
|
expect(target.di.bounds.x).toBe(targetShape.x);
|
|
|
|
expect(target.di.bounds.y).toBe(targetShape.y);
|
|
|
|
expect(target.di.bounds.width).toBe(targetShape.width);
|
|
|
|
expect(target.di.bounds.height).toBe(targetShape.height);
|
2014-07-30 14:07:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should add to parent (sub process)', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcess.get('flowElements')).toContain(target);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
describe('should add external label', function() {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
it('correctly wired and positioned', inject(function(elementRegistry, modeling, commandStack) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'),
|
|
|
|
target = targetShape.businessObject;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
var label = targetShape.label;
|
2014-07-30 14:07:43 +00:00
|
|
|
|
2014-08-03 12:30:53 +00:00
|
|
|
// then
|
|
|
|
expect(label).toBeDefined();
|
|
|
|
expect(elementRegistry.getById(label.id)).toBeDefined();
|
|
|
|
|
|
|
|
expect(label.x).toBe(443);
|
|
|
|
expect(label.y).toBe(273);
|
|
|
|
expect(label.width).toBe(LabelUtil.DEFAULT_LABEL_SIZE.width);
|
|
|
|
expect(label.height).toBe(LabelUtil.DEFAULT_LABEL_SIZE.height);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('with di', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(target.di.label).toBeDefined();
|
|
|
|
|
|
|
|
expect(target.di.label.bounds.x).toBe(targetShape.label.x);
|
|
|
|
expect(target.di.label.bounds.y).toBe(targetShape.label.y);
|
|
|
|
expect(target.di.label.bounds.width).toBe(targetShape.label.width);
|
|
|
|
expect(target.di.label.bounds.height).toBe(targetShape.label.height);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
it('should add connection', inject(function(elementRegistry, modeling) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
var connection = _.find(subProcess.get('flowElements'), function(e) {
|
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connection).toBeDefined();
|
|
|
|
expect(connection.$instanceOf('bpmn:SequenceFlow')).toBe(true);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('undo support', function() {
|
|
|
|
|
|
|
|
it('should undo add to parent', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcess.get('flowElements')).not.toContain(target);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.toContain(target.di);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo add shape label', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:EndEvent'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
var connection = _.find(subProcess.get('flowElements'), function(e) {
|
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connection.sourceRef).toBe(null);
|
|
|
|
expect(connection.targetRef).toBe(null);
|
|
|
|
expect(connection.$parent).toBe(null);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.toContain(connection.di);
|
|
|
|
|
|
|
|
expect(targetShape.label).not.toBeDefined();
|
|
|
|
expect(elementRegistry.getById(target.id + '_label')).not.toBeDefined();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo add connection', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
var connection = _.find(subProcess.get('flowElements'), function(e) {
|
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connection.sourceRef).toBe(null);
|
|
|
|
expect(connection.targetRef).toBe(null);
|
|
|
|
|
|
|
|
expect(startEvent.get('outgoing')).not.toContain(connection);
|
|
|
|
expect(target.get('incoming')).not.toContain(connection);
|
|
|
|
|
|
|
|
expect(connection.$parent).toBe(null);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.toContain(connection.di);
|
|
|
|
|
|
|
|
expect(elementRegistry.getById(targetShape.id)).not.toBeDefined();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo add connection label', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
var connection = _.find(subProcess.get('flowElements'), function(e) {
|
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connection.sourceRef).toBe(null);
|
|
|
|
expect(connection.targetRef).toBe(null);
|
|
|
|
expect(connection.$parent).toBe(null);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.toContain(connection.di);
|
|
|
|
|
|
|
|
expect(elementRegistry.getById(connection.id + '_label')).not.toBeDefined();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should redo appending multiple shapes', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape2 = modeling.appendFlowNode(targetShape, 'bpmn:UserTask');
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.redo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
// expect redo to work on original target object
|
|
|
|
expect(targetShape.parent).toBe(subProcessShape);
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(targetShape2.parent).toBe(null);
|
|
|
|
expect(elementRegistry.getById(targetShape2.id)).not.toBeDefined();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should redo add connection', inject(function(elementRegistry, modeling, commandStack) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:Task'),
|
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
var connection = _.find(subProcess.get('flowElements'), function(e) {
|
|
|
|
return e.sourceRef === startEvent && e.targetRef === target;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
commandStack.redo();
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(connection.sourceRef).toBe(null);
|
|
|
|
expect(connection.targetRef).toBe(null);
|
|
|
|
expect(connection.$parent).toBe(null);
|
|
|
|
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.toContain(connection.di);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('bpmn element support', function() {
|
|
|
|
|
|
|
|
describe('ExclusiveGateway', function() {
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
it('should append', inject(function(elementRegistry, modeling) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
2014-07-30 14:06:32 +00:00
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:ExclusiveGateway'),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(targetShape).toBeDefined();
|
|
|
|
expect(target.$instanceOf('bpmn:ExclusiveGateway')).toBe(true);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
it('should add to parent (sub process)', inject(function(elementRegistry, modeling) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
2014-07-30 14:06:32 +00:00
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:ExclusiveGateway'),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcess.get('flowElements')).toContain(target);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
it('should undo append', inject(function(elementRegistry, modeling, commandStack) {
|
2014-07-30 14:07:43 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
var startEventShape = elementRegistry.getById('StartEvent_1');
|
|
|
|
var subProcessShape = elementRegistry.getById('SubProcess_1');
|
|
|
|
|
|
|
|
var startEvent = startEventShape.businessObject,
|
|
|
|
subProcess = subProcessShape.businessObject;
|
|
|
|
|
2014-07-30 14:06:32 +00:00
|
|
|
var targetShape = modeling.appendFlowNode(startEventShape, 'bpmn:ExclusiveGateway'),
|
2014-07-30 14:07:43 +00:00
|
|
|
target = targetShape.businessObject;
|
|
|
|
|
|
|
|
// when
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(subProcess.get('flowElements')).not.toContain(target);
|
|
|
|
expect(subProcess.di.$parent.get('planeElement')).not.toContain(target.di);
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|