2014-06-27 15:52:34 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var TestHelper = require('../../../TestHelper');
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2015-07-15 15:22:19 +00:00
|
|
|
var TestContainer = require('mocha-test-container-support');
|
|
|
|
|
2015-06-04 13:24:35 +00:00
|
|
|
var domQuery = require('min-dom/lib/query');
|
|
|
|
|
2016-01-06 16:36:11 +00:00
|
|
|
var is = require('../../../../lib/util/ModelUtil').is;
|
|
|
|
|
|
|
|
|
2016-01-25 20:26:46 +00:00
|
|
|
/* global bootstrapModeler, inject */
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
|
2014-08-01 05:16:59 +00:00
|
|
|
var contextPadModule = require('../../../../lib/features/context-pad'),
|
2015-04-30 08:52:34 +00:00
|
|
|
coreModule = require('../../../../lib/core'),
|
|
|
|
modelingModule = require('../../../../lib/features/modeling'),
|
2016-01-06 16:36:11 +00:00
|
|
|
replaceMenuModule = require('../../../../lib/features/popup-menu'),
|
2016-01-06 15:36:49 +00:00
|
|
|
customRulesModule = require('../../../util/custom-rules');
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features - context-pad', function() {
|
|
|
|
|
2016-01-06 16:36:11 +00:00
|
|
|
var testModules = [
|
|
|
|
coreModule,
|
|
|
|
modelingModule,
|
|
|
|
contextPadModule,
|
|
|
|
replaceMenuModule,
|
|
|
|
customRulesModule
|
|
|
|
];
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
describe('remove action rules', function () {
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
2015-05-08 12:26:05 +00:00
|
|
|
|
|
|
|
|
2015-12-02 11:12:04 +00:00
|
|
|
var deleteAction;
|
|
|
|
|
|
|
|
beforeEach(inject(function (contextPad) {
|
|
|
|
|
|
|
|
deleteAction = function(element) {
|
2016-01-06 15:36:49 +00:00
|
|
|
return padEntry(contextPad.getPad(element).html, 'delete');
|
2015-12-02 11:12:04 +00:00
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should add delete action by default', inject(function (elementRegistry, contextPad) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(deleteAction(element)).to.exist;
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
it('should include delete action when rule returns true',
|
|
|
|
inject(function (elementRegistry, contextPad, customRules) {
|
2015-12-02 11:12:04 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
customRules.addRule('elements.delete', function() {
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(deleteAction(element)).to.exist;
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
it('should NOT include delete action when rule returns false',
|
|
|
|
inject(function(elementRegistry, contextPad, customRules) {
|
2015-12-02 11:12:04 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
customRules.addRule('elements.delete', function() {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(deleteAction(element)).to.not.exist;
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should call rules with [ element ]', inject(function(elementRegistry, contextPad, customRules) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
customRules.addRule('elements.delete', function(context) {
|
|
|
|
|
|
|
|
// element array is actually passed
|
|
|
|
expect(context.elements).to.eql([ element ]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(function() {
|
|
|
|
contextPad.open(element);
|
|
|
|
}).not.to.throw;
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
it('should include delete action when [ element ] is returned from rule',
|
|
|
|
inject(function(elementRegistry, contextPad, customRules) {
|
2015-12-02 11:12:04 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
customRules.addRule('elements.delete', function(context) {
|
|
|
|
return context.elements;
|
|
|
|
});
|
|
|
|
|
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(deleteAction(element)).to.exist;
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
it('should NOT include delete action when [ ] is returned from rule',
|
|
|
|
inject(function(elementRegistry, contextPad, customRules) {
|
2015-12-02 11:12:04 +00:00
|
|
|
|
|
|
|
// given
|
|
|
|
customRules.addRule('elements.delete', function() {
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(deleteAction(element)).to.not.exist;
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
describe('available entries', function() {
|
|
|
|
|
|
|
|
var diagramXML = require('./ContextPad.activation.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
|
|
|
|
|
|
function expectContextPadEntries(elementOrId, expectedEntries) {
|
|
|
|
|
|
|
|
TestHelper.getBpmnJS().invoke(function(elementRegistry, contextPad) {
|
|
|
|
|
|
|
|
var element = typeof elementOrId === 'string' ? elementRegistry.get(elementOrId) : elementOrId;
|
|
|
|
|
|
|
|
contextPad.open(element, true);
|
|
|
|
|
|
|
|
var entries = contextPad._current.entries;
|
|
|
|
|
|
|
|
expectedEntries.forEach(function(name) {
|
|
|
|
|
|
|
|
if (name.charAt(0) === '!') {
|
|
|
|
name = name.substring(1);
|
|
|
|
|
|
|
|
expect(entries).not.to.have.property(name);
|
|
|
|
} else {
|
|
|
|
expect(entries).to.have.property(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
it('should provide Task entries', inject(function() {
|
|
|
|
|
|
|
|
expectContextPadEntries('Task_1', [
|
|
|
|
'connect',
|
|
|
|
'replace',
|
|
|
|
'append.end-event',
|
|
|
|
'append.gateway',
|
|
|
|
'append.append-task',
|
|
|
|
'append.intermediate-event',
|
|
|
|
'append.text-annotation'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should provide EventBasedGateway entries', inject(function() {
|
|
|
|
|
|
|
|
expectContextPadEntries('EventBasedGateway_1', [
|
|
|
|
'connect',
|
|
|
|
'replace',
|
|
|
|
'append.receive-task',
|
|
|
|
'append.message-intermediate-event',
|
|
|
|
'append.timer-intermediate-event',
|
|
|
|
'append.condtion-intermediate-event',
|
|
|
|
'append.signal-intermediate-event',
|
|
|
|
'append.text-annotation',
|
|
|
|
'!append.task'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should provide EndEvent entries', inject(function() {
|
|
|
|
|
|
|
|
expectContextPadEntries('EndEvent_1', [
|
|
|
|
'connect',
|
|
|
|
'replace',
|
|
|
|
'!append.task'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should provide Compensation Activity entries', inject(function() {
|
|
|
|
|
|
|
|
expectContextPadEntries('Task_2', [
|
|
|
|
'connect',
|
|
|
|
'replace',
|
|
|
|
'!append.end-event',
|
|
|
|
'append.text-annotation'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should provide Compensate Boundary entries', inject(function() {
|
|
|
|
|
|
|
|
expectContextPadEntries('BoundaryEvent_1', [
|
|
|
|
'connect',
|
|
|
|
'replace',
|
|
|
|
'append.compensation-activity',
|
|
|
|
'!append.end-event'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
2016-01-25 20:26:46 +00:00
|
|
|
|
|
|
|
it('should provide DataStoreReference entries', inject(function() {
|
|
|
|
|
|
|
|
expectContextPadEntries('DataStoreReference', [
|
|
|
|
'connect',
|
|
|
|
'!replace',
|
|
|
|
'!append.end-event',
|
|
|
|
'!append.text-annotation'
|
|
|
|
]);
|
|
|
|
}));
|
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-06 15:36:49 +00:00
|
|
|
describe('replace', function() {
|
2015-05-08 12:26:05 +00:00
|
|
|
|
2016-01-21 10:17:11 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
|
|
|
|
|
|
|
beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
|
|
|
|
|
2015-05-15 09:06:49 +00:00
|
|
|
var container;
|
2016-01-06 15:36:49 +00:00
|
|
|
|
2015-05-15 09:06:49 +00:00
|
|
|
beforeEach(function() {
|
2015-07-15 15:22:19 +00:00
|
|
|
container = TestContainer.get(this);
|
2015-05-15 09:06:49 +00:00
|
|
|
});
|
2015-05-08 12:26:05 +00:00
|
|
|
|
2016-01-06 15:36:49 +00:00
|
|
|
|
|
|
|
it('should show popup menu in the correct position', inject(function(elementRegistry, contextPad) {
|
2015-05-15 09:06:49 +00:00
|
|
|
|
2015-05-08 12:26:05 +00:00
|
|
|
// given
|
2015-06-04 13:24:35 +00:00
|
|
|
var element = elementRegistry.get('StartEvent_1'),
|
2015-05-15 09:06:49 +00:00
|
|
|
padding = 5,
|
|
|
|
replaceMenuRect,
|
|
|
|
padMenuRect;
|
2015-07-03 08:48:32 +00:00
|
|
|
|
2015-06-04 13:24:35 +00:00
|
|
|
contextPad.open(element);
|
|
|
|
padMenuRect = contextPad.getPad(element).html.getBoundingClientRect();
|
2015-05-08 12:26:05 +00:00
|
|
|
|
2015-06-04 13:24:35 +00:00
|
|
|
// mock event
|
|
|
|
var event = {
|
2016-01-06 15:36:49 +00:00
|
|
|
target: padEntry(container, 'replace'),
|
2015-06-04 13:24:35 +00:00
|
|
|
preventDefault: function(){}
|
|
|
|
};
|
2015-05-08 12:26:05 +00:00
|
|
|
|
|
|
|
// when
|
2015-06-04 13:24:35 +00:00
|
|
|
contextPad.trigger('click', event);
|
2015-12-10 11:48:40 +00:00
|
|
|
replaceMenuRect = domQuery('.bpmn-replace', container).getBoundingClientRect();
|
2015-05-08 12:26:05 +00:00
|
|
|
|
|
|
|
// then
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(replaceMenuRect.left).to.be.at.most(padMenuRect.left);
|
|
|
|
expect(replaceMenuRect.top).to.be.at.most(padMenuRect.bottom + padding);
|
2015-05-08 12:26:05 +00:00
|
|
|
}));
|
2015-12-02 11:12:04 +00:00
|
|
|
|
2016-01-06 15:36:49 +00:00
|
|
|
|
2016-01-06 16:36:11 +00:00
|
|
|
it('should not include control if replacement is disallowed',
|
2016-01-06 15:36:49 +00:00
|
|
|
inject(function(elementRegistry, contextPad, customRules) {
|
|
|
|
|
|
|
|
// given
|
2016-01-06 16:36:11 +00:00
|
|
|
var element = elementRegistry.get('StartEvent_1');
|
2016-01-06 15:36:49 +00:00
|
|
|
|
|
|
|
// disallow replacement
|
2016-01-06 16:36:11 +00:00
|
|
|
customRules.addRule('shape.replace', function(context) {
|
|
|
|
return !is(context.element, 'bpmn:StartEvent');
|
2016-01-06 15:36:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
var padNode = contextPad.getPad(element).html;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(padEntry(padNode, 'replace')).not.to.exist;
|
|
|
|
}));
|
|
|
|
|
2016-01-06 16:36:11 +00:00
|
|
|
|
|
|
|
it('should include control if replacement is allowed',
|
|
|
|
inject(function(elementRegistry, contextPad, customRules) {
|
|
|
|
|
|
|
|
// given
|
|
|
|
var element = elementRegistry.get('EndEvent_1');
|
|
|
|
|
|
|
|
// disallow replacement
|
|
|
|
customRules.addRule('shape.replace', function(context) {
|
|
|
|
return !is(context.element, 'bpmn:StartEvent');
|
|
|
|
});
|
|
|
|
|
|
|
|
// when
|
|
|
|
contextPad.open(element);
|
|
|
|
|
|
|
|
var padNode = contextPad.getPad(element).html;
|
|
|
|
|
|
|
|
// then
|
|
|
|
expect(padEntry(padNode, 'replace')).to.exist;
|
|
|
|
}));
|
|
|
|
|
2015-05-08 12:26:05 +00:00
|
|
|
});
|
2015-12-02 11:12:04 +00:00
|
|
|
|
2014-10-27 11:07:57 +00:00
|
|
|
});
|
2016-01-06 15:36:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
function padEntry(element, name) {
|
|
|
|
return domQuery('[data-action="' + name + '"]', element);
|
|
|
|
}
|