bpmn-js/test/spec/features/modeling/layout/LayoutConnectionSpec.js

99 lines
2.5 KiB
JavaScript

'use strict';
require('../../../../TestHelper');
/* global bootstrapModeler, inject */
var modelingModule = require('../../../../../lib/features/modeling'),
coreModule = require('../../../../../lib/core');
describe('features/modeling - layout connection', function() {
var diagramXML = require('../../../../fixtures/bpmn/sequence-flows.bpmn');
var testModules = [ coreModule, modelingModule ];
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('connection handling', function() {
it('should execute', inject(function(elementRegistry, modeling, bpmnFactory) {
// given
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
sequenceFlow = sequenceFlowConnection.businessObject;
var expectedWaypoints = sequenceFlowConnection.waypoints;
// when
modeling.layoutConnection(sequenceFlowConnection);
// then
// expect cropped, repaired connection
// that was not actually modified
expect(sequenceFlowConnection.waypoints).to.eql(expectedWaypoints);
// expect cropped waypoints in di
var diWaypoints = bpmnFactory.createDiWaypoints(expectedWaypoints);
expect(sequenceFlow.di.waypoint).eql(diWaypoints);
}));
});
describe('undo support', function() {
it('should undo', inject(function(elementRegistry, commandStack, modeling) {
// given
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
sequenceFlow = sequenceFlowConnection.businessObject;
var oldWaypoints = sequenceFlowConnection.waypoints,
oldDiWaypoints = sequenceFlow.di.waypoint;
modeling.layoutConnection(sequenceFlowConnection);
// when
commandStack.undo();
// then
expect(sequenceFlowConnection.waypoints).eql(oldWaypoints);
expect(sequenceFlow.di.waypoint).eql(oldDiWaypoints);
}));
});
describe('redo support', function() {
it('should redo', inject(function(elementRegistry, commandStack, modeling) {
// given
var sequenceFlowConnection = elementRegistry.get('SequenceFlow_1'),
sequenceFlow = sequenceFlowConnection.businessObject;
modeling.layoutConnection(sequenceFlowConnection);
var newWaypoints = sequenceFlowConnection.waypoints,
newDiWaypoints = sequenceFlow.di.waypoint;
// when
commandStack.undo();
commandStack.redo();
// then
expect(sequenceFlowConnection.waypoints).eql(newWaypoints);
expect(sequenceFlow.di.waypoint).eql(newDiWaypoints);
}));
});
});