Skip to content
Snippets Groups Projects
Commit b0a90cb6 authored by Mathias Maaß's avatar Mathias Maaß
Browse files

Add plugin hook to window menu. Closes #2298

parent 670caadf
No related branches found
No related tags found
No related merge requests found
import React from 'react';
import { shallow } from 'enzyme';
import { WindowPluginButtons } from '../../../src/components/WindowPluginButtons';
/** create wrapper */
function createWrapper(props) {
return shallow(
<WindowPluginButtons
windowId="xyz"
t={key => key}
{...props}
/>,
);
}
it('renders nothing if no plugin component was passed', () => {
const wrapper = createWrapper();
expect(wrapper.find('*').length).toBe(0);
});
it('renders the plugin component if it was passed', () => {
/** */
const PluginComponent = props => <span>woooot!</span>;
const wrapper = createWrapper({ PluginComponent });
expect(wrapper.find(PluginComponent).length).toBe(1);
});
it('passes windowId to the plugin component', () => {
/** */
const PluginComponent = props => <span>woooot!</span>;
const wrapper = createWrapper({ PluginComponent });
expect(wrapper.find(PluginComponent).first().props().windowId).toBe('xyz');
});
...@@ -3,6 +3,7 @@ import { shallow } from 'enzyme'; ...@@ -3,6 +3,7 @@ import { shallow } from 'enzyme';
import Menu from '@material-ui/core/Menu'; import Menu from '@material-ui/core/Menu';
import WindowThumbnailSettings from '../../../src/containers/WindowThumbnailSettings'; import WindowThumbnailSettings from '../../../src/containers/WindowThumbnailSettings';
import WindowViewSettings from '../../../src/containers/WindowViewSettings'; import WindowViewSettings from '../../../src/containers/WindowViewSettings';
import WindowPluginButtons from '../../../src/containers/WindowPluginButtons';
import { WindowTopMenu } from '../../../src/components/WindowTopMenu'; import { WindowTopMenu } from '../../../src/components/WindowTopMenu';
/** create wrapper */ /** create wrapper */
...@@ -24,6 +25,7 @@ describe('WindowTopMenu', () => { ...@@ -24,6 +25,7 @@ describe('WindowTopMenu', () => {
expect(wrapper.find(Menu).length).toBe(1); expect(wrapper.find(Menu).length).toBe(1);
expect(wrapper.find(WindowThumbnailSettings).length).toBe(1); expect(wrapper.find(WindowThumbnailSettings).length).toBe(1);
expect(wrapper.find(WindowViewSettings).length).toBe(1); expect(wrapper.find(WindowViewSettings).length).toBe(1);
expect(wrapper.find(WindowPluginButtons).length).toBe(1);
}); });
it('passes windowId to <WindowThumbnailSettings/>', () => { it('passes windowId to <WindowThumbnailSettings/>', () => {
...@@ -48,4 +50,9 @@ describe('WindowTopMenu', () => { ...@@ -48,4 +50,9 @@ describe('WindowTopMenu', () => {
expect(wrapper.find(Menu).first().props().open).toBe(true); expect(wrapper.find(Menu).first().props().open).toBe(true);
expect(wrapper.find(Menu).first().props().onClose).toBe(handleClose); expect(wrapper.find(Menu).first().props().onClose).toBe(handleClose);
}); });
it('passes windowId to <WindowPluginButtons/>', () => {
const wrapper = createWrapper();
expect(wrapper.find(WindowPluginButtons).first().props().windowId).toBe('xyz');
});
}); });
import React from 'react';
import PropTypes from 'prop-types';
import ListSubheader from '@material-ui/core/ListSubheader';
/** */
export function WindowPluginButtons(props) {
const {
PluginComponent,
t,
} = props;
return PluginComponent && (
<>
<ListSubheader role="presentation" tabIndex="-1">{t('windowPluginButtons')}</ListSubheader>
<PluginComponent {...props} />
</>
);
}
WindowPluginButtons.propTypes = {
PluginComponent: PropTypes.func,
t: PropTypes.func.isRequired,
windowId: PropTypes.string.isRequired,
};
WindowPluginButtons.defaultProps = {
PluginComponent: null,
};
...@@ -3,6 +3,7 @@ import Menu from '@material-ui/core/Menu'; ...@@ -3,6 +3,7 @@ import Menu from '@material-ui/core/Menu';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import WindowThumbnailSettings from '../containers/WindowThumbnailSettings'; import WindowThumbnailSettings from '../containers/WindowThumbnailSettings';
import WindowViewSettings from '../containers/WindowViewSettings'; import WindowViewSettings from '../containers/WindowViewSettings';
import WindowPluginButtons from '../containers/WindowPluginButtons';
import ns from '../config/css-ns'; import ns from '../config/css-ns';
/** /**
...@@ -39,6 +40,7 @@ export class WindowTopMenu extends Component { ...@@ -39,6 +40,7 @@ export class WindowTopMenu extends Component {
> >
<WindowViewSettings windowId={windowId} handleClose={handleClose} /> <WindowViewSettings windowId={windowId} handleClose={handleClose} />
<WindowThumbnailSettings windowId={windowId} handleClose={handleClose} /> <WindowThumbnailSettings windowId={windowId} handleClose={handleClose} />
<WindowPluginButtons windowId={windowId} />
</Menu> </Menu>
</> </>
); );
......
import { compose } from 'redux';
import { withTranslation } from 'react-i18next';
import { withPlugins } from '../extend';
import { WindowPluginButtons } from '../components/WindowPluginButtons';
export default compose(
withTranslation(),
withPlugins('WindowPluginButtons'),
)(WindowPluginButtons);
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
"view": "Ansicht", "view": "Ansicht",
"window": "Fenster: {{label}}", "window": "Fenster: {{label}}",
"windowMenu": "Fenstermenü", "windowMenu": "Fenstermenü",
"windowPluginButtons": "Plugins",
"workspace": "Arbeitsfläche", "workspace": "Arbeitsfläche",
"workspaceFullScreen": "Vollbild", "workspaceFullScreen": "Vollbild",
"workspaceMenu": "Arbeitsflächenmenü", "workspaceMenu": "Arbeitsflächenmenü",
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
"view": "View items as", "view": "View items as",
"window": "Window: {{label}}", "window": "Window: {{label}}",
"windowMenu": "Window options", "windowMenu": "Window options",
"windowPluginButtons": "Plugins",
"workspace": "Workspace", "workspace": "Workspace",
"workspaceFullScreen": "Full screen", "workspaceFullScreen": "Full screen",
"workspaceMenu": "Workspace options", "workspaceMenu": "Workspace options",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment