2018-04-02 19:01:53 +00:00
|
|
|
/* global sinon */
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapViewer,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
import { forEach } from 'min-dash';
|
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import coreModule from 'lib/core';
|
|
|
|
import editorActionsModule from 'lib/features/editor-actions';
|
2018-10-26 22:57:24 +00:00
|
|
|
import searchModule from 'lib/features/search';
|
|
|
|
import globalConnectModule from 'diagram-js/lib/features/global-connect';
|
|
|
|
import spaceToolModule from 'diagram-js/lib/features/space-tool';
|
|
|
|
import lassoToolModule from 'diagram-js/lib/features/lasso-tool';
|
|
|
|
import handToolModule from 'diagram-js/lib/features/hand-tool';
|
2018-04-02 19:01:53 +00:00
|
|
|
import keyboardModule from 'lib/features/keyboard';
|
|
|
|
import modelingModule from 'lib/features/modeling';
|
2018-10-26 22:57:24 +00:00
|
|
|
import labelEditingModule from 'lib/features/label-editing';
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-11-21 08:38:11 +00:00
|
|
|
import {
|
|
|
|
createKeyEvent
|
|
|
|
} from 'test/util/KeyEvents';
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-10-26 22:57:24 +00:00
|
|
|
describe('features/keyboard', function() {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
|
|
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
var testModules = [
|
|
|
|
coreModule,
|
2016-06-21 13:18:29 +00:00
|
|
|
editorActionsModule,
|
2015-08-03 09:49:06 +00:00
|
|
|
keyboardModule,
|
2018-10-26 22:57:24 +00:00
|
|
|
modelingModule,
|
|
|
|
globalConnectModule,
|
|
|
|
spaceToolModule,
|
|
|
|
lassoToolModule,
|
|
|
|
handToolModule,
|
|
|
|
searchModule,
|
|
|
|
labelEditingModule
|
2015-07-22 16:08:53 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
|
|
|
|
2016-06-21 13:18:29 +00:00
|
|
|
|
2018-10-26 22:57:24 +00:00
|
|
|
describe('bpmn keyboard bindings', function() {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2015-10-19 06:09:58 +00:00
|
|
|
it('should include triggers inside editorActions', inject(function(editorActions) {
|
2018-10-26 22:57:24 +00:00
|
|
|
// given
|
|
|
|
var expectedActions = [
|
|
|
|
'undo',
|
|
|
|
'redo',
|
|
|
|
'zoom',
|
|
|
|
'removeSelection',
|
|
|
|
'selectElements',
|
|
|
|
'spaceTool',
|
|
|
|
'lassoTool',
|
|
|
|
'handTool',
|
|
|
|
'globalConnectTool',
|
|
|
|
'setColor',
|
|
|
|
'directEditing',
|
|
|
|
'find',
|
|
|
|
'moveToOrigin'
|
|
|
|
];
|
|
|
|
|
2015-10-19 06:09:58 +00:00
|
|
|
// then
|
2018-10-26 22:57:24 +00:00
|
|
|
expect(editorActions.getActions()).to.eql(expectedActions);
|
2016-04-13 10:36:19 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
forEach(['c', 'C'], function(key) {
|
2016-04-13 10:36:19 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
it('should global connect tool for key ' + key, inject(function(keyboard, globalConnect) {
|
2016-04-13 10:36:19 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
sinon.spy(globalConnect, 'toggle');
|
2016-04-13 10:36:19 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// given
|
2018-11-21 08:38:11 +00:00
|
|
|
var e = createKeyEvent(key);
|
2016-04-13 10:36:19 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// when
|
|
|
|
keyboard._keyHandler(e);
|
2015-10-19 06:09:58 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// then
|
2018-10-26 22:57:24 +00:00
|
|
|
expect(globalConnect.toggle).to.have.been.calledOnce;
|
2018-10-24 11:56:21 +00:00
|
|
|
}));
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
});
|
2015-07-22 16:08:53 +00:00
|
|
|
|
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
forEach(['l', 'L'], function(key) {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
it('should trigger lasso tool for key ' + key, inject(function(keyboard, lassoTool) {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
sinon.spy(lassoTool, 'activateSelection');
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// given
|
2018-11-21 08:38:11 +00:00
|
|
|
var e = createKeyEvent(key);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// when
|
|
|
|
keyboard._keyHandler(e);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// then
|
2018-10-26 22:57:24 +00:00
|
|
|
expect(lassoTool.activateSelection).to.have.been.calledOnce;
|
2018-10-24 11:56:21 +00:00
|
|
|
}));
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
});
|
2015-07-22 16:08:53 +00:00
|
|
|
|
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
forEach(['s', 'S'], function(key) {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
it('should trigger space tool', inject(function(keyboard, spaceTool) {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
sinon.spy(spaceTool, 'activateSelection');
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// given
|
2018-11-21 08:38:11 +00:00
|
|
|
var e = createKeyEvent(key);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// when
|
|
|
|
keyboard._keyHandler(e);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// then
|
2018-10-26 22:57:24 +00:00
|
|
|
expect(spaceTool.activateSelection).to.have.been.calledOnce;
|
2018-10-24 11:56:21 +00:00
|
|
|
}));
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
});
|
2015-07-22 16:08:53 +00:00
|
|
|
|
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
forEach(['e', 'E'], function(key) {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
it('should trigger direct editing', inject(function(keyboard, selection, elementRegistry, directEditing) {
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
sinon.spy(directEditing, 'activate');
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
selection.select(task);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-11-21 08:38:11 +00:00
|
|
|
var e = createKeyEvent(key);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// when
|
|
|
|
keyboard._keyHandler(e);
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// then
|
2018-10-26 22:57:24 +00:00
|
|
|
expect(directEditing.activate).to.have.been.calledOnce;
|
2018-10-24 11:56:21 +00:00
|
|
|
}));
|
2015-07-22 16:08:53 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
});
|
2016-03-27 14:04:07 +00:00
|
|
|
|
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
forEach(['a', 'A'], function(key) {
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
it('should select all elements',
|
|
|
|
inject(function(canvas, keyboard, selection, elementRegistry) {
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
// given
|
2018-11-21 08:38:11 +00:00
|
|
|
var e = createKeyEvent(key, { ctrlKey: true });
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2018-10-24 11:56:21 +00:00
|
|
|
var allElements = elementRegistry.getAll(),
|
|
|
|
rootElement = canvas.getRootElement();
|
|
|
|
|
|
|
|
// when
|
|
|
|
keyboard._keyHandler(e);
|
|
|
|
|
|
|
|
// then
|
|
|
|
var selectedElements = selection.get();
|
|
|
|
|
|
|
|
expect(selectedElements).to.have.length(allElements.length - 1);
|
|
|
|
expect(selectedElements).not.to.contain(rootElement);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
forEach(['f', 'F'], function(key) {
|
|
|
|
|
|
|
|
it('should trigger search for labels', inject(function(keyboard, searchPad) {
|
|
|
|
|
|
|
|
sinon.spy(searchPad, 'toggle');
|
|
|
|
|
|
|
|
// given
|
2018-11-21 08:38:11 +00:00
|
|
|
var e = createKeyEvent(key, { ctrlKey: true });
|
2018-10-24 11:56:21 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
keyboard._keyHandler(e);
|
|
|
|
|
|
|
|
// then
|
2018-10-26 22:57:24 +00:00
|
|
|
expect(searchPad.toggle).to.have.been.calledOnce;
|
2018-10-24 11:56:21 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2016-03-27 14:04:07 +00:00
|
|
|
|
2015-07-22 16:08:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|