test(editor-actions): verify alignElements and distributeElements behavior

This commit is contained in:
Nico Rehwaldt 2021-03-03 09:03:55 +01:00 committed by fake-join[bot]
parent 58e1801f52
commit ca550a247a
1 changed files with 121 additions and 1 deletions

View File

@ -11,6 +11,9 @@ var getParent = require('lib/features/modeling/util/ModelingUtil').getParent;
import bpmnEditorActionsModule from 'lib/features/editor-actions';
import selectionModule from 'diagram-js/lib/features/selection';
import alignElementsModule from 'diagram-js/lib/features/align-elements';
import distributeElementsModule from 'diagram-js/lib/features/distribute-elements';
import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
@ -18,7 +21,6 @@ var basicXML = require('../../../fixtures/bpmn/nested-subprocesses.bpmn');
var collaborationXML = require('../../../fixtures/bpmn/collaboration.bpmn');
describe('features/editor-actions', function() {
describe('#moveToOrigin', function() {
@ -91,4 +93,122 @@ describe('features/editor-actions', function() {
});
describe('#alignElements', function() {
beforeEach(bootstrapModeler(basicXML, {
modules: [
selectionModule,
alignElementsModule,
bpmnEditorActionsModule,
modelingModule,
coreModule
]
}));
it('should align items', inject(
function(elementRegistry, selection, editorActions) {
// given
var elementIds = [ 'StartEvent_1', 'UserTask_1', 'EndEvent_1' ];
var elements = elementIds.map(function(id) {
return elementRegistry.get(id);
});
// when
selection.select(elements);
editorActions.trigger('alignElements', { type: 'middle' });
// then
expect(elements.map(function(e) {
return e.y + e.height / 2;
})).to.eql([ 311, 311, 311 ]);
}
));
it('should not align if too few elements', inject(
function(elementRegistry, eventBus, editorActions, selection) {
// given
var elementIds = [ 'StartEvent_1' ];
var elements = elementIds.map(function(id) {
return elementRegistry.get(id);
});
var changedSpy = sinon.spy();
// when
eventBus.once('commandStack.changed', changedSpy);
selection.select(elements);
editorActions.trigger('alignElements', { type: 'center' });
// then
expect(changedSpy).not.to.have.been.called;
}
));
});
describe('#distributeElements', function() {
beforeEach(bootstrapModeler(basicXML, {
modules: [
selectionModule,
distributeElementsModule,
bpmnEditorActionsModule,
modelingModule,
coreModule
]
}));
it('should distribute items', inject(
function(elementRegistry, selection, editorActions) {
// given
var elementIds = [ 'StartEvent_1', 'UserTask_1', 'EndEvent_1' ];
var elements = elementIds.map(function(id) {
return elementRegistry.get(id);
});
// when
selection.select(elements);
editorActions.trigger('distributeElements', { type: 'horizontal' });
// then
expect(elements.map(function(e) {
return e.x + e.width / 2;
})).to.eql([ 433, 574, 714 ]);
}
));
it('should not distribute if too few elements', inject(
function(elementRegistry, eventBus, editorActions, selection) {
// given
var elementIds = [ 'StartEvent_1', 'UserTask_1' ];
var elements = elementIds.map(function(id) {
return elementRegistry.get(id);
});
var changedSpy = sinon.spy();
// when
eventBus.once('commandStack.changed', changedSpy);
selection.select(elements);
editorActions.trigger('distributeElements', { type: 'horizontal' });
// then
expect(changedSpy).not.to.have.been.called;
}
));
});
});