Skip to content

Commit

Permalink
fix(element-templates-modal): get local and global element templates
Browse files Browse the repository at this point in the history
Closes #2012
  • Loading branch information
philippfromme authored and nikku committed Nov 13, 2020
1 parent 155d7f0 commit 51620a4
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 23 deletions.
2 changes: 2 additions & 0 deletions client/src/app/plugins/PluginsRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export default class PluginsRoot extends PureComponent {
<PluginComponent
triggerAction={ app.triggerAction }
config={ config }
getConfig={ app.getConfig }
setConfig={ app.setConfig }
subscribe={ subscribe }
log={ this.log }
displayNotification={ this.displayNotification }
Expand Down
73 changes: 73 additions & 0 deletions client/src/app/plugins/__tests__/PluginsRootSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

import React from 'react';

import TestRenderer from 'react-test-renderer';

import PluginsRoot from '../PluginsRoot';


describe('<PluginParent>', 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(<PluginsRoot { ...{ ...defaultProps, ...props } } />);
}

class App {
getConfig = () => {}

setConfig = () => {}

getGlobal = name => {
if (name === 'config') {
return new Config();
}
}

triggerAction = () => {}
}

class Config {
get = () => {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,13 @@ describe('<ElementTemplatesView>', 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
Expand Down Expand Up @@ -491,8 +489,8 @@ async function createElementTemplatesModalView(props = {}) {
}

const defaultProps = {
config: new Config(),
displayNotification() {},
getConfig: defaultGetConfig,
onApply() {},
onClose() {},
subscribe() {},
Expand All @@ -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');
}

0 comments on commit 51620a4

Please sign in to comment.