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');
|
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
/* global bootstrapViewer, 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'),
|
2015-02-05 15:00:05 +00:00
|
|
|
popupModule = require('diagram-js/lib/features/popup-menu'),
|
2015-12-10 11:48:40 +00:00
|
|
|
replaceMenuProvider = require('../../../../lib/features/popup-menu'),
|
2015-12-02 11:12:04 +00:00
|
|
|
replaceModule = require('diagram-js/lib/features/replace'),
|
2015-12-02 15:47:20 +00:00
|
|
|
rulesModule = require('../../../util/custom-rules');
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('features - context-pad', function() {
|
|
|
|
|
2015-03-31 12:17:15 +00:00
|
|
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
var testModules = [ contextPadModule, coreModule, modelingModule, popupModule,
|
|
|
|
replaceModule, rulesModule, replaceMenuProvider ];
|
2014-06-27 15:52:34 +00:00
|
|
|
|
2014-08-05 06:17:22 +00:00
|
|
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
2014-06-27 15:52:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('bootstrap', function() {
|
|
|
|
|
2015-12-10 11:48:40 +00:00
|
|
|
it('should bootstrap', inject(function(contextPadProvider, replaceMenuProvider) {
|
2015-07-15 15:22:19 +00:00
|
|
|
expect(contextPadProvider).to.exist;
|
2014-06-27 15:52:34 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
2015-05-08 12:26:05 +00:00
|
|
|
|
|
|
|
|
2015-12-02 11:12:04 +00:00
|
|
|
describe('remove action rules', function () {
|
|
|
|
|
|
|
|
var deleteAction;
|
|
|
|
|
|
|
|
beforeEach(inject(function (contextPad) {
|
|
|
|
|
|
|
|
deleteAction = function(element) {
|
|
|
|
return domQuery('[data-action="delete"]', contextPad.getPad(element).html);
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-06-04 13:24:35 +00:00
|
|
|
describe('should show replace popup menu in the correct position ', function() {
|
2015-05-08 12:26:05 +00:00
|
|
|
|
2015-05-15 09:06:49 +00:00
|
|
|
var container;
|
|
|
|
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
|
|
|
|
2015-06-04 13:24:35 +00:00
|
|
|
it('for a diagram element', inject(function(elementRegistry, contextPad, popupMenu) {
|
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 = {
|
|
|
|
target: domQuery('[data-action="replace"]', container),
|
|
|
|
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
|
|
|
|
2015-05-08 12:26:05 +00:00
|
|
|
});
|
2015-12-02 11:12:04 +00:00
|
|
|
|
2014-10-27 11:07:57 +00:00
|
|
|
});
|