2014-06-17 09:53:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
require('../../../TestHelper');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
/* global bootstrapViewer, inject */
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-06-18 09:45:30 +00:00
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var labelEditingModule = require('../../../../lib/features/label-editing'),
|
2014-10-30 11:06:43 +00:00
|
|
|
coreModule = require('../../../../lib/core');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var LabelUtil = require('../../../../lib/features/label-editing/LabelUtil');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
function triggerKeyEvent(element, event, code) {
|
|
|
|
var e = document.createEvent('Events');
|
|
|
|
|
|
|
|
if (e.initEvent) {
|
|
|
|
e.initEvent(event, true, true);
|
|
|
|
}
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
e.keyCode = code;
|
|
|
|
e.which = code;
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
return element.dispatchEvent(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('features - label-editing', function() {
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/features/label-editing/labels.bpmn');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-10-30 11:06:43 +00:00
|
|
|
var testModules = [ labelEditingModule, coreModule ];
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('basics', function() {
|
|
|
|
|
|
|
|
it('should register on dblclick', inject(function(elementRegistry, directEditing, eventBus) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var shape = elementRegistry.get('task-nested-embedded');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
// when
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.fire('element.dblclick', { element: shape });
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(directEditing.isActive()).to.be.true;
|
2014-06-17 09:53:07 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
it('should cancel on <ESC>', inject(function(elementRegistry, directEditing, eventBus) {
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var shape = elementRegistry.get('task-nested-embedded'),
|
2014-07-16 14:15:23 +00:00
|
|
|
task = shape.businessObject;
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
var oldName = task.name;
|
|
|
|
|
|
|
|
// activate
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.fire('element.dblclick', { element: shape });
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
// a <textarea /> element
|
2014-06-17 09:53:07 +00:00
|
|
|
var textarea = directEditing._textbox.textarea;
|
|
|
|
|
|
|
|
// when
|
|
|
|
// change + ESC is pressed
|
2015-02-05 08:24:27 +00:00
|
|
|
textarea.value = 'new value';
|
|
|
|
triggerKeyEvent(textarea, 'keydown', 27);
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(directEditing.isActive()).to.be.false;
|
|
|
|
expect(task.name).to.equal(oldName);
|
2014-06-17 09:53:07 +00:00
|
|
|
}));
|
|
|
|
|
2014-07-07 15:17:41 +00:00
|
|
|
|
2014-12-17 20:54:25 +00:00
|
|
|
it('should submit on root element click', inject(function(elementRegistry, directEditing, canvas, eventBus) {
|
2014-07-07 15:17:41 +00:00
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var shape = elementRegistry.get('task-nested-embedded'),
|
2014-07-16 14:15:23 +00:00
|
|
|
task = shape.businessObject;
|
2014-07-07 15:17:41 +00:00
|
|
|
|
|
|
|
// activate
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.fire('element.dblclick', { element: shape });
|
2014-07-07 15:17:41 +00:00
|
|
|
|
|
|
|
var newName = 'new value';
|
|
|
|
|
2015-02-05 08:24:27 +00:00
|
|
|
// a <textarea /> element
|
2014-07-07 15:17:41 +00:00
|
|
|
var textarea = directEditing._textbox.textarea;
|
|
|
|
|
|
|
|
// when
|
2014-12-23 15:49:28 +00:00
|
|
|
// change + <element.mousedown>
|
2015-02-05 08:24:27 +00:00
|
|
|
textarea.value = newName;
|
|
|
|
|
2014-12-23 15:49:28 +00:00
|
|
|
eventBus.fire('element.mousedown', { element: canvas.getRootElement() });
|
2014-07-07 15:17:41 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(directEditing.isActive()).to.be.false;
|
|
|
|
expect(task.name).to.equal(newName);
|
2014-07-07 15:17:41 +00:00
|
|
|
}));
|
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
var elementRegistry,
|
2014-06-17 09:53:07 +00:00
|
|
|
eventBus,
|
|
|
|
directEditing;
|
|
|
|
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
beforeEach(inject([ 'elementRegistry', 'eventBus', 'directEditing', function(_elementRegistry, _eventBus, _directEditing) {
|
|
|
|
elementRegistry = _elementRegistry;
|
2014-06-17 09:53:07 +00:00
|
|
|
eventBus = _eventBus;
|
|
|
|
directEditing = _directEditing;
|
|
|
|
}]));
|
|
|
|
|
|
|
|
|
|
|
|
function directEditActivate(element) {
|
|
|
|
if (element.waypoints) {
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.fire('element.dblclick', { element: element });
|
2014-06-17 09:53:07 +00:00
|
|
|
} else {
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.fire('element.dblclick', { element: element });
|
2014-06-17 09:53:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function directEditUpdate(value) {
|
2015-02-05 08:24:27 +00:00
|
|
|
directEditing._textbox.textarea.value = value;
|
2014-06-17 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function directEditComplete(value) {
|
|
|
|
directEditUpdate(value);
|
|
|
|
directEditing.complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
function directEditCancel(value) {
|
|
|
|
directEditUpdate(value);
|
|
|
|
directEditing.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
describe('command support', function() {
|
|
|
|
|
|
|
|
it('should update via command stack', function() {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var diagramElement = elementRegistry.get('user-task');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
var listenerCalled;
|
|
|
|
|
|
|
|
eventBus.on('commandStack.changed', function(e) {
|
|
|
|
listenerCalled = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
directEditActivate(diagramElement);
|
|
|
|
directEditComplete('BAR');
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(listenerCalled).to.be.true;
|
2014-06-17 09:53:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should undo via command stack', inject(function(commandStack) {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var diagramElement = elementRegistry.get('user-task');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-09-08 17:03:39 +00:00
|
|
|
var oldLabel = LabelUtil.getLabel(diagramElement);
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
// when
|
|
|
|
directEditActivate(diagramElement);
|
|
|
|
directEditComplete('BAR');
|
|
|
|
|
|
|
|
commandStack.undo();
|
|
|
|
|
|
|
|
// then
|
2014-09-08 17:03:39 +00:00
|
|
|
var label = LabelUtil.getLabel(diagramElement);
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(label).to.eql(oldLabel);
|
2014-06-17 09:53:07 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('should trigger redraw', function() {
|
|
|
|
|
|
|
|
it('on shape change', function() {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var diagramElement = elementRegistry.get('user-task');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
var listenerCalled;
|
|
|
|
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.on('element.changed', function(e) {
|
2014-06-17 09:53:07 +00:00
|
|
|
if (e.element === diagramElement) {
|
|
|
|
listenerCalled = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
directEditActivate(diagramElement);
|
|
|
|
directEditComplete('BAR');
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(listenerCalled).to.be.true;
|
2014-06-17 09:53:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('on connection on change', function() {
|
|
|
|
|
|
|
|
// given
|
2014-11-17 16:36:22 +00:00
|
|
|
var diagramElement = elementRegistry.get('sequence-flow-no');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
var listenerCalled;
|
|
|
|
|
2014-12-17 20:54:25 +00:00
|
|
|
eventBus.on('element.changed', function(e) {
|
2014-06-17 09:53:07 +00:00
|
|
|
if (e.element === diagramElement.label) {
|
|
|
|
listenerCalled = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
directEditActivate(diagramElement);
|
|
|
|
directEditComplete('BAR');
|
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(listenerCalled).to.be.true;
|
2014-06-17 09:53:07 +00:00
|
|
|
});
|
2014-06-11 13:08:45 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
describe('element support, should edit', function() {
|
|
|
|
|
|
|
|
function directEdit(elementId) {
|
|
|
|
|
2014-07-16 14:15:23 +00:00
|
|
|
return inject(function(elementRegistry, eventBus, directEditing) {
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-11-17 16:36:22 +00:00
|
|
|
var diagramElement = elementRegistry.get(elementId);
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-09-08 17:03:39 +00:00
|
|
|
var label = LabelUtil.getLabel(diagramElement);
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
directEditActivate(diagramElement);
|
|
|
|
|
|
|
|
// then
|
|
|
|
// expect editing to be active
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(directEditing.getValue()).to.eql(label);
|
|
|
|
expect(directEditing.isActive()).to.be.true;
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
directEditComplete('B');
|
|
|
|
|
|
|
|
// then
|
|
|
|
// expect update to have happened
|
2014-09-08 17:03:39 +00:00
|
|
|
label = LabelUtil.getLabel(diagramElement);
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(label).to.equal('B');
|
2014-06-17 09:53:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// when
|
|
|
|
directEditActivate(diagramElement);
|
|
|
|
directEditCancel('C');
|
|
|
|
|
|
|
|
// expect no label update to have happened
|
2014-09-08 17:03:39 +00:00
|
|
|
label = LabelUtil.getLabel(diagramElement);
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(label).to.equal('B');
|
2014-06-17 09:53:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
it('task', directEdit('user-task'));
|
|
|
|
|
|
|
|
|
|
|
|
it('gateway', directEdit('exclusive-gateway'));
|
|
|
|
|
|
|
|
it('gateway via label', directEdit('exclusive-gateway_label'));
|
|
|
|
|
|
|
|
|
|
|
|
it('event', directEdit('intermediate-throw-event'));
|
|
|
|
|
|
|
|
it('event via label', directEdit('intermediate-throw-event_label'));
|
|
|
|
|
|
|
|
it('event without label', directEdit('start-event'));
|
|
|
|
|
|
|
|
|
|
|
|
it('data store reference', directEdit('data-store-reference'));
|
|
|
|
|
|
|
|
it('data object reference', directEdit('data-object-reference'));
|
|
|
|
|
|
|
|
|
|
|
|
it('sequenceflow', directEdit('sequence-flow-yes'));
|
|
|
|
|
|
|
|
it('sequenceflow without label', directEdit('sequenceflow-unlabeled'));
|
|
|
|
|
|
|
|
it('sequenceflow via label', directEdit('sequence-flow-yes_label'));
|
|
|
|
|
|
|
|
|
|
|
|
it('message flow', directEdit('message-flow'));
|
|
|
|
|
|
|
|
it('message flow via label', directEdit('message-flow_label'));
|
|
|
|
|
|
|
|
|
|
|
|
it('pool', directEdit('expanded-pool'));
|
|
|
|
|
|
|
|
it('pool, collapsed', directEdit('collapsed-pool'));
|
|
|
|
|
|
|
|
|
|
|
|
it('lane with label', directEdit('nested-lane-1-2'));
|
|
|
|
|
|
|
|
it('lane without label', directEdit('nested-lane-no-label'));
|
2014-06-11 13:08:45 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
});
|