Skip to content

Commit

Permalink
#1872: fixes and adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glefi committed Feb 20, 2019
1 parent 394263f commit 5ce995c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
37 changes: 20 additions & 17 deletions __tests__/src/components/WindowSideBarCanvasPanel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,64 @@ import { shallow } from 'enzyme';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import Typography from '@material-ui/core/Typography';
import manifesto from 'manifesto.js';
import WindowSideBarCanvasPanel from '../../../src/components/WindowSideBarCanvasPanel';
import CanvasThumbnail from '../../../src/components/CanvasThumbnail';
import manifestJson from '../../fixtures/version-2/019.json';
import { getIdAndLabelOfCanvases } from '../../../src/state/selectors';

describe('WindowSideBarCanvasPanel', () => {
let wrapper;
let setCanvas;
const canvasesIdAndLabel = [
{
id: 'testid1',
label: 'testLabel',
},
{
id: 'testid2',
label: 'testLabel2',
},
];
let canvases;

beforeEach(() => {
setCanvas = jest.fn();
canvases = manifesto.create(manifestJson).getSequences()[0].getCanvases();

wrapper = shallow(
<WindowSideBarCanvasPanel
canvasesIdAndLabel={canvasesIdAndLabel}
canvases={canvases}
classes={{}}
t={key => key}
windowId="xyz"
setCanvas={setCanvas}
config={{ canvasNavigation: { height: 100 } }}
/>,
).dive();
});

it('renders all needed elements', () => {
expect(wrapper.find(Typography).at(0).render().text()).toBe('canvasIndex');
expect(wrapper.find(List).length).toBe(1);
expect(wrapper.find(ListItem).length).toBe(canvasesIdAndLabel.length);
expect(wrapper.find(List).find(Typography).length).toBe(canvasesIdAndLabel.length);
expect(wrapper.find(ListItem).length).toBe(3);
expect(wrapper.find(List).find(Typography).length).toBe(3);
});

it('should set the correct labels', () => {
const idsAndLabels = getIdAndLabelOfCanvases(canvases);
expect(wrapper
.find(List)
.find(Typography)
.at(0)
.render()
.text()).toBe(canvasesIdAndLabel[0].label);
.text()).toBe(idsAndLabels[0].label);

expect(wrapper
.find(List)
.find(Typography)
.at(1)
.at(0)
.render()
.text()).toBe(canvasesIdAndLabel[1].label);
.text()).toBe(idsAndLabels[1].label);
});

it('should call the onClick handler', () => {
it('should call the onClick handler of a navigation item\'s label', () => {
wrapper.find(Typography).at(1).simulate('click');
expect(setCanvas).toHaveBeenCalledTimes(1);
});

it('should call the onClick handler of a navigation item\'s thumbnail', () => {
wrapper.find(CanvasThumbnail).at(0).simulate('click');
expect(setCanvas).toHaveBeenCalledTimes(1);
});
});
1 change: 0 additions & 1 deletion src/components/WindowSideBarInfoPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ WindowSideBarInfoPanel.propTypes = {
t: PropTypes.func,
};


WindowSideBarInfoPanel.defaultProps = {
canvasDescription: null,
canvasLabel: null,
Expand Down

0 comments on commit 5ce995c

Please sign in to comment.