From 348a0b2d9956bb96419637ee0781e3d8411f25d5 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 6 Jan 2016 17:36:11 +0100 Subject: [PATCH] test(context-pad): cleanup provider test case --- .../context-pad/ContextPadProviderSpec.js | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/test/spec/features/context-pad/ContextPadProviderSpec.js b/test/spec/features/context-pad/ContextPadProviderSpec.js index 5f0fe58a..5dd79817 100644 --- a/test/spec/features/context-pad/ContextPadProviderSpec.js +++ b/test/spec/features/context-pad/ContextPadProviderSpec.js @@ -6,15 +6,16 @@ var TestContainer = require('mocha-test-container-support'); var domQuery = require('min-dom/lib/query'); +var is = require('../../../../lib/util/ModelUtil').is; + + /* global bootstrapViewer, inject */ var contextPadModule = require('../../../../lib/features/context-pad'), coreModule = require('../../../../lib/core'), modelingModule = require('../../../../lib/features/modeling'), - popupModule = require('diagram-js/lib/features/popup-menu'), - replaceMenuProvider = require('../../../../lib/features/popup-menu'), - replaceModule = require('diagram-js/lib/features/replace'), + replaceMenuModule = require('../../../../lib/features/popup-menu'), customRulesModule = require('../../../util/custom-rules'); @@ -22,15 +23,20 @@ describe('features - context-pad', function() { var diagramXML = require('../../../fixtures/bpmn/simple.bpmn'); - var testModules = [ contextPadModule, coreModule, modelingModule, popupModule, - replaceModule, customRulesModule, replaceMenuProvider ]; + var testModules = [ + coreModule, + modelingModule, + contextPadModule, + replaceMenuModule, + customRulesModule + ]; - beforeEach(bootstrapViewer(diagramXML, { modules: testModules })); + beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); describe('bootstrap', function() { - it('should bootstrap', inject(function(contextPadProvider, replaceMenuProvider) { + it('should bootstrap', inject(function(contextPadProvider) { expect(contextPadProvider).to.exist; })); @@ -192,18 +198,15 @@ describe('features - context-pad', function() { })); - it('should not inclide control if replacement is disallowed', + it('should not include control if replacement is disallowed', inject(function(elementRegistry, contextPad, customRules) { // given - var element = elementRegistry.get('StartEvent_1'), - padding = 5, - replaceMenuRect, - padMenuRect; + var element = elementRegistry.get('StartEvent_1'); // disallow replacement - customRules.addRule('shape.replace', function() { - return false; + customRules.addRule('shape.replace', function(context) { + return !is(context.element, 'bpmn:StartEvent'); }); // when @@ -215,6 +218,27 @@ describe('features - context-pad', function() { expect(padEntry(padNode, 'replace')).not.to.exist; })); + + 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; + })); + }); });