Skip to content

Commit 2ebcd85

Browse files
author
Christopher Willis-Ford
committed
add unit tests for About button on menu bar
1 parent 9d307f0 commit 2ebcd85

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

src/components/menu-bar/menu-bar.jsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ MenuItemTooltip.propTypes = {
141141
isRtl: PropTypes.bool
142142
};
143143

144+
const AboutButton = props => (
145+
<Button
146+
className={classNames(styles.menuBarItem, styles.hoverable)}
147+
iconClassName={styles.aboutIcon}
148+
iconSrc={aboutIcon}
149+
onClick={props.onClick}
150+
/>
151+
);
152+
153+
AboutButton.propTypes = {
154+
onClick: PropTypes.func.isRequired
155+
};
156+
144157
class MenuBar extends React.Component {
145158
constructor (props) {
146159
super(props);
@@ -311,17 +324,8 @@ class MenuBar extends React.Component {
311324
{remixMessage}
312325
</Button>
313326
);
314-
const handleClickAbout = this.props.onClickAbout;
315327
// Show the About button only if we have a handler for it (like in the desktop app)
316-
const aboutButton = handleClickAbout ? (
317-
<div className={classNames(styles.menuBarItem, styles.hoverable)}>
318-
<img
319-
className={styles.aboutIcon}
320-
onClick={handleClickAbout}
321-
src={aboutIcon}
322-
/>
323-
</div>
324-
) : null;
328+
const aboutButton = this.props.onClickAbout ? <AboutButton onClick={this.props.onClickAbout} /> : null;
325329
return (
326330
<Box
327331
className={classNames(
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import {mountWithIntl} from '../../helpers/intl-helpers';
3+
import MenuBar from '../../../src/components/menu-bar/menu-bar';
4+
import {menuInitialState} from '../../../src/reducers/menus';
5+
import {LoadingState} from '../../../src/reducers/project-state';
6+
7+
import configureStore from 'redux-mock-store';
8+
import {Provider} from 'react-redux';
9+
import VM from 'scratch-vm';
10+
11+
12+
describe('MenuBar Component', () => {
13+
const store = configureStore()({
14+
locales: {
15+
isRtl: false,
16+
locale: 'en-US'
17+
},
18+
scratchGui: {
19+
menus: menuInitialState,
20+
projectState: {
21+
loadingState: LoadingState.NOT_LOADED
22+
},
23+
vm: new VM()
24+
}
25+
});
26+
27+
const getComponent = function (props = {}) {
28+
return <Provider store={store}><MenuBar {...props} /></Provider>;
29+
};
30+
31+
test('menu bar with no About handler has no About button', () => {
32+
const menuBar = mountWithIntl(getComponent());
33+
const button = menuBar.find('AboutButton');
34+
expect(button.exists()).toBe(false);
35+
});
36+
37+
test('menu bar with an About handler has an About button', () => {
38+
const onClickAbout = jest.fn();
39+
const menuBar = mountWithIntl(getComponent({onClickAbout}));
40+
const button = menuBar.find('AboutButton');
41+
expect(button.exists()).toBe(true);
42+
});
43+
44+
test('clicking on About button calls the handler', () => {
45+
const onClickAbout = jest.fn();
46+
const menuBar = mountWithIntl(getComponent({onClickAbout}));
47+
const button = menuBar.find('AboutButton');
48+
expect(onClickAbout).toHaveBeenCalledTimes(0);
49+
button.simulate('click');
50+
expect(onClickAbout).toHaveBeenCalledTimes(1);
51+
});
52+
});

0 commit comments

Comments
 (0)