From 51620a441794f822f345b2da82ee681d548eaac1 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Thu, 12 Nov 2020 16:24:15 +0100 Subject: [PATCH] fix(element-templates-modal): get local and global element templates Closes #2012 --- client/src/app/plugins/PluginsRoot.js | 2 + .../app/plugins/__tests__/PluginsRootSpec.js | 73 +++++++++++++++++++ .../components/ElementTemplatesModalView.js | 4 +- .../ElementTemplatesModalViewSpec.js | 32 +++----- 4 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 client/src/app/plugins/__tests__/PluginsRootSpec.js diff --git a/client/src/app/plugins/PluginsRoot.js b/client/src/app/plugins/PluginsRoot.js index f44be445a0..be46038264 100644 --- a/client/src/app/plugins/PluginsRoot.js +++ b/client/src/app/plugins/PluginsRoot.js @@ -85,6 +85,8 @@ export default class PluginsRoot extends PureComponent { ', function() { + + it('should render', function() { + createPluginsRoot(); + }); + + + it('should pass props to plugin', function() { + createPluginsRoot({ + plugins: [ + props => { + expect(props.triggerAction).to.exist; + expect(props.config).to.exist; + expect(props.getConfig).to.exist; + expect(props.setConfig).to.exist; + expect(props.subscribe).to.exist; + expect(props.log).to.exist; + expect(props.displayNotification).to.exist; + expect(props._getGlobal).to.exist; + + return null; + } + ] + }); + }); + +}); + +// helpers ////////// + +function createPluginsRoot(props = {}) { + const defaultProps = { + app: new App(), + plugins: [] + }; + + return TestRenderer.create(); +} + +class App { + getConfig = () => {} + + setConfig = () => {} + + getGlobal = name => { + if (name === 'config') { + return new Config(); + } + } + + triggerAction = () => {} +} + +class Config { + get = () => {} +} diff --git a/client/src/plugins/element-templates-modal/components/ElementTemplatesModalView.js b/client/src/plugins/element-templates-modal/components/ElementTemplatesModalView.js index 19aae82c31..fa755b1e67 100644 --- a/client/src/plugins/element-templates-modal/components/ElementTemplatesModalView.js +++ b/client/src/plugins/element-templates-modal/components/ElementTemplatesModalView.js @@ -52,11 +52,11 @@ class ElementTemplatesView extends PureComponent { getElementTemplates = async () => { const { - config, + getConfig, triggerAction } = this.props; - let elementTemplates = await config.get('bpmn.elementTemplates'); + let elementTemplates = await getConfig('bpmn.elementTemplates'); const selectedElement = await triggerAction('getSelectedElement'); diff --git a/client/src/plugins/element-templates-modal/components/__tests__/ElementTemplatesModalViewSpec.js b/client/src/plugins/element-templates-modal/components/__tests__/ElementTemplatesModalViewSpec.js index 6f23ea5230..671e0203c5 100644 --- a/client/src/plugins/element-templates-modal/components/__tests__/ElementTemplatesModalViewSpec.js +++ b/client/src/plugins/element-templates-modal/components/__tests__/ElementTemplatesModalViewSpec.js @@ -315,15 +315,13 @@ describe('', function() { // when const { wrapper } = await createElementTemplatesModalView({ - config: new Config({ - get(key, ...args) { - if (key === 'bpmn.elementTemplates') { - return Promise.resolve([]); - } - - throw Error('Unknown key'); + getConfig: (key, ...args) => { + if (key === 'bpmn.elementTemplates') { + return Promise.resolve([]); } - }) + + throw Error('Unknown key'); + } }); // then @@ -491,8 +489,8 @@ async function createElementTemplatesModalView(props = {}) { } const defaultProps = { - config: new Config(), displayNotification() {}, + getConfig: defaultGetConfig, onApply() {}, onClose() {}, subscribe() {}, @@ -511,18 +509,10 @@ async function createElementTemplatesModalView(props = {}) { }; } -class Config { - constructor(overrides = {}) { - this.elementTemplates = DEFAULT_ELEMENT_TEMPLATES; - - Object.assign(this, overrides); +function defaultGetConfig(key, ...args) { + if (key === 'bpmn.elementTemplates') { + return Promise.resolve(DEFAULT_ELEMENT_TEMPLATES); } - get(key, ...args) { - if (key === 'bpmn.elementTemplates') { - return Promise.resolve(this.elementTemplates); - } - - throw Error('Unknown key'); - } + throw Error('Unknown key'); } \ No newline at end of file