Skip to content

Commit 952a584

Browse files
authored
Merge pull request scratchfoundation#5434 from cwillisf/add-about-menu-button
Add about menu button
2 parents 501caf7 + 8c6b52f commit 952a584

File tree

8 files changed

+87
-1
lines changed

8 files changed

+87
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*.svg binary
1313

1414
# Prefer LF for most file types
15+
*.css text eol=lf
1516
*.frag text eol=lf
1617
*.htm text eol=lf
1718
*.html text eol=lf

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@
139139
],
140140
"moduleNameMapper": {
141141
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/__mocks__/fileMock.js",
142-
"\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js"
142+
"\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js",
143+
"editor-msgs(\\.js)?$": "<rootDir>/test/__mocks__/editor-msgs-mock.js"
143144
}
144145
}
145146
}

src/components/gui/gui.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ const GUIComponent = props => {
8989
loading,
9090
logo,
9191
renderLogin,
92+
onClickAbout,
9293
onClickAccountNav,
9394
onCloseAccountNav,
9495
onLogOut,
@@ -220,6 +221,7 @@ const GUIComponent = props => {
220221
logo={logo}
221222
renderLogin={renderLogin}
222223
showComingSoon={showComingSoon}
224+
onClickAbout={onClickAbout}
223225
onClickAccountNav={onClickAccountNav}
224226
onClickLogo={onClickLogo}
225227
onCloseAccountNav={onCloseAccountNav}
@@ -390,6 +392,7 @@ GUIComponent.propTypes = {
390392
onActivateCostumesTab: PropTypes.func,
391393
onActivateSoundsTab: PropTypes.func,
392394
onActivateTab: PropTypes.func,
395+
onClickAbout: PropTypes.func,
393396
onClickAccountNav: PropTypes.func,
394397
onClickLogo: PropTypes.func,
395398
onCloseAccountNav: PropTypes.func,
Lines changed: 1 addition & 0 deletions
Loading

src/components/menu-bar/menu-bar.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,9 @@
218218
.mystuff > a {
219219
background-image: url("/images/mystuff.png");
220220
}
221+
222+
.about-icon {
223+
height: 1.25rem;
224+
margin: 0.5rem;
225+
vertical-align: middle;
226+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import profileIcon from './icon--profile.png';
6969
import remixIcon from './icon--remix.svg';
7070
import dropdownCaret from './dropdown-caret.svg';
7171
import languageIcon from '../language-selector/language-icon.svg';
72+
import aboutIcon from './icon--about.svg';
7273

7374
import scratchLogo from './scratch-logo.svg';
7475

@@ -141,6 +142,19 @@ MenuItemTooltip.propTypes = {
141142
isRtl: PropTypes.bool
142143
};
143144

145+
const AboutButton = props => (
146+
<Button
147+
className={classNames(styles.menuBarItem, styles.hoverable)}
148+
iconClassName={styles.aboutIcon}
149+
iconSrc={aboutIcon}
150+
onClick={props.onClick}
151+
/>
152+
);
153+
154+
AboutButton.propTypes = {
155+
onClick: PropTypes.func.isRequired
156+
};
157+
144158
class MenuBar extends React.Component {
145159
constructor (props) {
146160
super(props);
@@ -311,6 +325,8 @@ class MenuBar extends React.Component {
311325
{remixMessage}
312326
</Button>
313327
);
328+
// Show the About button only if we have a handler for it (like in the desktop app)
329+
const aboutButton = this.props.onClickAbout ? <AboutButton onClick={this.props.onClickAbout} /> : null;
314330
return (
315331
<Box
316332
className={classNames(
@@ -689,6 +705,8 @@ class MenuBar extends React.Component {
689705
</React.Fragment>
690706
)}
691707
</div>
708+
709+
{aboutButton}
692710
</Box>
693711
);
694712
}
@@ -722,6 +740,7 @@ MenuBar.propTypes = {
722740
locale: PropTypes.string.isRequired,
723741
loginMenuOpen: PropTypes.bool,
724742
logo: PropTypes.string,
743+
onClickAbout: PropTypes.func,
725744
onClickAccount: PropTypes.func,
726745
onClickEdit: PropTypes.func,
727746
onClickFile: PropTypes.func,

test/__mocks__/editor-msgs-mock.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
en: {}
3+
};
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)