Skip to content

Commit 9639265

Browse files
authored
Merge pull request scratchfoundation#5291 from benjiwheeler/standalone-new-project-title-fix
reset title on transitioning to isShowingWithoutId
2 parents 3d1205e + f244da7 commit 9639265

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/lib/titled-hoc.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import React from 'react';
33
import {connect} from 'react-redux';
44
import {defineMessages, injectIntl, intlShape} from 'react-intl';
55

6-
import {getIsShowingWithoutId} from '../reducers/project-state';
6+
import {
7+
getIsAnyCreatingNewState,
8+
getIsShowingWithoutId
9+
} from '../reducers/project-state';
710
import {setProjectTitle} from '../reducers/project-title';
811

912
const messages = defineMessages({
@@ -27,6 +30,12 @@ const TitledHOC = function (WrappedComponent) {
2730
if (this.props.projectTitle !== prevProps.projectTitle) {
2831
this.handleReceivedProjectTitle(this.props.projectTitle);
2932
}
33+
// if project is a new default project, and has loaded,
34+
if (this.props.isShowingWithoutId && prevProps.isAnyCreatingNewState) {
35+
// reset title to default
36+
const defaultProjectTitle = this.handleReceivedProjectTitle();
37+
this.props.onUpdateProjectTitle(defaultProjectTitle);
38+
}
3039
// if the projectTitle hasn't changed, but the reduxProjectTitle
3140
// HAS changed, we need to report that change to the projectTitle's owner
3241
if (this.props.reduxProjectTitle !== prevProps.reduxProjectTitle &&
@@ -40,11 +49,13 @@ const TitledHOC = function (WrappedComponent) {
4049
newTitle = this.props.intl.formatMessage(messages.defaultProjectTitle);
4150
}
4251
this.props.onChangedProjectTitle(newTitle);
52+
return newTitle;
4353
}
4454
render () {
4555
const {
4656
/* eslint-disable no-unused-vars */
4757
intl,
58+
isAnyCreatingNewState,
4859
isShowingWithoutId,
4960
onChangedProjectTitle,
5061
// for children, we replace onUpdateProjectTitle with our own
@@ -66,6 +77,7 @@ const TitledHOC = function (WrappedComponent) {
6677

6778
TitledComponent.propTypes = {
6879
intl: intlShape,
80+
isAnyCreatingNewState: PropTypes.bool,
6981
isShowingWithoutId: PropTypes.bool,
7082
onChangedProjectTitle: PropTypes.func,
7183
onUpdateProjectTitle: PropTypes.func,
@@ -80,6 +92,7 @@ const TitledHOC = function (WrappedComponent) {
8092
const mapStateToProps = state => {
8193
const loadingState = state.scratchGui.projectState.loadingState;
8294
return {
95+
isAnyCreatingNewState: getIsAnyCreatingNewState(loadingState),
8396
isShowingWithoutId: getIsShowingWithoutId(loadingState),
8497
reduxProjectTitle: state.scratchGui.projectTitle
8598
};

test/helpers/selenium-helper.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class SeleniumHelper {
2828
'loadUri',
2929
'rightClickText'
3030
]);
31+
32+
this.Key = webdriver.Key; // map Key constants, for sending special keys
3133
}
3234

3335
elementIsVisible (element, timeoutMessage = 'elementIsVisible timed out') {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import path from 'path';
2+
import SeleniumHelper from '../helpers/selenium-helper';
3+
4+
const {
5+
clickText,
6+
clickXpath,
7+
findByXpath,
8+
getDriver,
9+
Key,
10+
loadUri
11+
} = new SeleniumHelper();
12+
13+
const uri = path.resolve(__dirname, '../../build/index.html');
14+
15+
let driver;
16+
17+
describe('Project state', () => {
18+
beforeAll(() => {
19+
driver = getDriver();
20+
});
21+
22+
afterAll(async () => {
23+
await driver.quit();
24+
});
25+
26+
test('File->New resets project title', async () => {
27+
const defaultProjectTitle = 'Scratch Project';
28+
await loadUri(uri);
29+
const inputEl = await findByXpath(`//input[@value="${defaultProjectTitle}"]`);
30+
for (let i = 0; i < defaultProjectTitle.length; i++) {
31+
inputEl.sendKeys(Key.BACK_SPACE);
32+
}
33+
inputEl.sendKeys('Changed title of project');
34+
await clickText('Costumes'); // just to blur the input
35+
// verify that project title has changed
36+
await clickXpath('//input[@value="Changed title of project"]');
37+
await clickXpath(
38+
'//div[contains(@class, "menu-bar_menu-bar-item") and ' +
39+
'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
40+
);
41+
await clickXpath('//li[span[text()="New"]]');
42+
// project title should be default again
43+
await clickXpath(`//input[@value="${defaultProjectTitle}"]`);
44+
});
45+
});

0 commit comments

Comments
 (0)