chore(test): adjust test cases to fit popup menu provider concept

Related to #426
This commit is contained in:
pedesen 2016-01-06 10:34:12 +01:00 committed by Nico Rehwaldt
parent eb7b5d7bb4
commit f619a06cae
2 changed files with 109 additions and 89 deletions

View File

@ -10,7 +10,8 @@ var coreModule = require('../../../../lib/core'),
popupMenuModule = require('diagram-js/lib/features/popup-menu'),
modelingModule = require('../../../../lib/features/modeling'),
replaceModule = require('../../../../lib/features/replace'),
replaceMenuProviderModule = require('../../../../lib/features/popup-menu');
replaceMenuProviderModule = require('../../../../lib/features/popup-menu'),
customRulesModule = require('../../../util/custom-rules');
var domQuery = require('min-dom/lib/query'),
domClasses = require('min-dom/lib/classes');
@ -45,7 +46,14 @@ describe('features/replace-menu', function() {
var diagramXMLMarkers = require('../../../fixtures/bpmn/draw/activity-markers-simple.bpmn'),
diagramXMLReplace = require('../../../fixtures/bpmn/features/replace/01_replace.bpmn');
var testModules = [ coreModule, modelingModule, popupMenuModule, replaceModule, replaceMenuProviderModule ];
var testModules = [
coreModule,
modelingModule,
popupMenuModule,
replaceModule,
replaceMenuProviderModule,
customRulesModule
];
var openPopup = function(element, offset) {
offset = offset || 100;
@ -1337,4 +1345,102 @@ describe('features/replace-menu', function() {
});
describe('rules', function () {
var diagramXML = require('../../../fixtures/bpmn/basic.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules.concat([ customRulesModule ]) }));
it('should get entries by default', inject(function(elementRegistry, popupMenu) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
// when
openPopup(startEvent);
var entries = getEntries(popupMenu);
// then
expect(entries).to.have.length.above(0);
}));
it('should get entries when custom rule returns true',
inject(function(elementRegistry, popupMenu, customRules) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
customRules.addRule('shape.replace', function () {
return true;
});
//when
openPopup(startEvent);
var entries = getEntries(popupMenu);
// then
expect(entries).to.have.length.above(0);
}));
it('should get no entries when custom rule returns false',
inject(function(elementRegistry, popupMenu, customRules) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
customRules.addRule('shape.replace', function () {
return false;
});
// when
openPopup(startEvent);
var entries = getEntries(popupMenu);
// then
expect(entries).to.have.length(0);
}));
it('should provide element to custom rules', inject(function(elementRegistry, popupMenu, customRules) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
var actual;
customRules.addRule('shape.replace', function (context) {
actual = context.element;
});
// when
openPopup(startEvent);
// then
expect(actual).to.equal(startEvent);
}));
it('should evaluate rule once', inject(function(elementRegistry, popupMenu, customRules) {
// given
var callCount = 0;
var startEvent = elementRegistry.get('StartEvent_1');
customRules.addRule('shape.replace', function () {
callCount++;
});
// when
openPopup(startEvent);
// then
expect(callCount).to.equal(1);
}));
});
});

View File

@ -7,8 +7,7 @@ var TestHelper = require('../../../TestHelper');
var modelingModule = require('../../../../lib/features/modeling'),
replaceModule = require('../../../../lib/features/replace'),
moveModule = require('diagram-js/lib/features/move'),
coreModule = require('../../../../lib/core'),
customRulesModule = require('../../../util/custom-rules');
coreModule = require('../../../../lib/core');
var is = require('../../../../lib/util/ModelUtil').is,
isExpanded = require('../../../../lib/util/DiUtil').isExpanded,
@ -903,89 +902,4 @@ describe('features/replace', function() {
}));
});
describe('getReplaceOptions', function () {
var diagramXML = require('../../../fixtures/bpmn/basic.bpmn');
beforeEach(bootstrapModeler(diagramXML, { modules: testModules.concat([ customRulesModule ]) }));
it('should get replacement options by default', inject(function(elementRegistry, bpmnReplace) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
// when
var options = bpmnReplace.getReplaceOptions(startEvent);
// then
expect(options).to.have.length.above(0);
}));
it('should get replacement options when custom rule returns true', inject(function(elementRegistry, bpmnReplace, customRules) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
customRules.addRule('shape.replace', function () {
return true;
});
// when
var options = bpmnReplace.getReplaceOptions(startEvent);
// then
expect(options).to.have.length.above(0);
}));
it('should get no replacement options when custom rule returns false', inject(function(elementRegistry, bpmnReplace, customRules) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
customRules.addRule('shape.replace', function () {
return false;
});
// when
var options = bpmnReplace.getReplaceOptions(startEvent);
// then
expect(options).to.have.length(0);
}));
it('should provide element to custom rules', inject(function(elementRegistry, bpmnReplace, customRules) {
// given
var startEvent = elementRegistry.get('StartEvent_1');
var actual;
customRules.addRule('shape.replace', function (context) {
actual = context.element;
});
// when
bpmnReplace.getReplaceOptions(startEvent);
// then
expect(actual).to.equal(startEvent);
}));
it('should evaluate rule once', inject(function(elementRegistry, bpmnReplace, customRules) {
// given
var callCount = 0;
var startEvent = elementRegistry.get('StartEvent_1');
customRules.addRule('shape.replace', function () {
callCount++;
});
// when
bpmnReplace.getReplaceOptions(startEvent);
// then
expect(callCount).to.equal(1);
}));
});
});