Skip to content
Snippets Groups Projects
Commit 0800f8d1 authored by Chris Beer's avatar Chris Beer
Browse files

Get the manifest title for each window to display in the window list

parent 850b48d6
Branches
Tags
No related merge requests found
import React from 'react';
import { shallow } from 'enzyme';
import MenuItem from '@material-ui/core/MenuItem';
import { WindowList } from '../../../src/components/WindowList';
describe('WindowList', () => {
let wrapper;
let handleClose;
let focusWindow;
let manifests;
let windows;
beforeEach(() => {
handleClose = jest.fn();
focusWindow = jest.fn();
manifests = {};
windows = {};
wrapper = shallow(
<WindowList
anchorEl={{}}
manifests={manifests}
windows={windows}
handleClose={handleClose}
focusWindow={focusWindow}
/>,
);
});
it('renders without an error', () => {
expect(wrapper.find('WithStyles(Menu)').length).toBe(1);
});
describe('with a window without a matching manifest', () => {
beforeEach(() => {
windows = { xyz: { id: 'xyz', manifestId: 'abc' } };
wrapper = shallow(
<WindowList
anchorEl={{}}
manifests={manifests}
windows={windows}
handleClose={handleClose}
focusWindow={focusWindow}
/>,
);
});
it('renders without an error', () => {
expect(wrapper.find('WithStyles(MenuItem)').length).toBe(1);
expect(wrapper.find('WithStyles(MenuItem)').key()).toBe('xyz');
expect(
wrapper.find('WithStyles(MenuItem)').matchesElement(<MenuItem>[Untitled]</MenuItem>),
).toBe(true);
wrapper.find('WithStyles(MenuItem)').simulate('click', {});
expect(handleClose).toBeCalled();
expect(focusWindow).toBeCalledWith('xyz');
});
});
describe('with a window with a matching manifest', () => {
beforeEach(() => {
windows = { xyz: { id: 'xyz', manifestId: 'abc' } };
manifests = { abc: { manifestation: { getLabel: jest.fn(() => [{ value: 'Some title' }]) } } };
wrapper = shallow(
<WindowList
anchorEl={{}}
manifests={manifests}
windows={windows}
handleClose={handleClose}
focusWindow={focusWindow}
/>,
);
});
it('renders without an error', () => {
expect(wrapper.find('WithStyles(MenuItem)').length).toBe(1);
expect(wrapper.find('WithStyles(MenuItem)').key()).toBe('xyz');
expect(
wrapper.find('WithStyles(MenuItem)').matchesElement(<MenuItem>Some title</MenuItem>),
).toBe(true);
});
});
});
......@@ -12,6 +12,21 @@ import { actions } from '../store';
/**
*/
export class WindowList extends Component {
/**
* Get the title for a window from its manifest title
* @private
*/
titleContent(window) {
const { manifests } = this.props;
if (window.manifestId
&& manifests[window.manifestId]
&& manifests[window.manifestId].manifestation) {
return manifests[window.manifestId].manifestation.getLabel().map(label => label.value)[0];
}
return '[Untitled]';
}
/**
* render
* @return
......@@ -33,7 +48,7 @@ export class WindowList extends Component {
onClick={(e) => { focusWindow(window.id); handleClose(e); }}
>
{
window.id
this.titleContent(window)
}
</MenuItem>
))
......@@ -46,8 +61,13 @@ export class WindowList extends Component {
WindowList.propTypes = {
focusWindow: PropTypes.func.isRequired,
handleClose: PropTypes.func.isRequired,
anchorEl: PropTypes.string.isRequired,
anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types
windows: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
manifests: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
};
WindowList.defaultProps = {
anchorEl: null,
};
/**
......@@ -67,6 +87,7 @@ const mapDispatchToProps = {
const mapStateToProps = state => (
{
windows: state.windows,
manifests: state.manifests,
}
);
......
......@@ -77,7 +77,11 @@ export class WorkspaceMenu extends Component {
WorkspaceMenu.propTypes = {
handleClose: PropTypes.func.isRequired,
anchorEl: PropTypes.string.isRequired,
anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types
};
WorkspaceMenu.defaultProps = {
anchorEl: null,
};
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment