From f619a06caef4f22de68a01c2725280e51f93bdfc Mon Sep 17 00:00:00 2001 From: pedesen Date: Wed, 6 Jan 2016 10:34:12 +0100 Subject: [PATCH] chore(test): adjust test cases to fit popup menu provider concept Related to #426 --- .../popup-menu/ReplaceMenuProviderSpec.js | 110 +++++++++++++++++- test/spec/features/replace/BpmnReplaceSpec.js | 88 +------------- 2 files changed, 109 insertions(+), 89 deletions(-) diff --git a/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js b/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js index 31764093..f0e2f4f8 100644 --- a/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js +++ b/test/spec/features/popup-menu/ReplaceMenuProviderSpec.js @@ -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); + })); + }); + }); diff --git a/test/spec/features/replace/BpmnReplaceSpec.js b/test/spec/features/replace/BpmnReplaceSpec.js index 228c75b1..c21d1030 100644 --- a/test/spec/features/replace/BpmnReplaceSpec.js +++ b/test/spec/features/replace/BpmnReplaceSpec.js @@ -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); - })); - }); - });