Merge pull request #3866 from benjiwheeler/dont-prompt

only prompt user to save if project has changed and won’t autosave
This commit is contained in:
Benjamin Wheeler authored and GitHub committed 2018-12-14 16:45:20 -05:00
commit ffa2e87824
2 files changed
+51 -6

No files matched your search

+14 -4
View File
@@ -157,10 +157,18 @@ class MenuBar extends React.Component {
]);
}
handleClickNew () {
// if canSave===true and canCreateNew===true, it's safe to replace current project,
// since we will auto-save first. Else, confirm first.
const readyToReplaceProject = (this.props.canSave && this.props.canCreateNew) ||
confirm(this.props.intl.formatMessage(messages.confirmNav)); // eslint-disable-line no-alert
let readyToReplaceProject = true;
// if the project is dirty, and user owns the project, we will autosave.
// but if they are not logged in and can't save, user should consider
// downloading or logging in first.
// Note that if user is logged in and editing someone else's project,
// they'll lose their work.
if (this.props.projectChanged && !this.props.canCreateNew) {
readyToReplaceProject = confirm( // eslint-disable-line no-alert
this.props.intl.formatMessage(messages.confirmNav)
);
}
this.props.onRequestCloseFile();
if (readyToReplaceProject) {
this.props.onClickNew(this.props.canSave && this.props.canCreateNew);
}
@@ -734,6 +742,7 @@ MenuBar.propTypes = {
onShare: PropTypes.func,
onToggleLoginOpen: PropTypes.func,
onUpdateProjectTitle: PropTypes.func,
projectChanged: PropTypes.bool,
projectTitle: PropTypes.string,
renderLogin: PropTypes.func,
sessionExists: PropTypes.bool,
@@ -757,6 +766,7 @@ const mapStateToProps = state => {
isShowingProject: getIsShowingProject(loadingState),
languageMenuOpen: languageMenuOpen(state),
loginMenuOpen: loginMenuOpen(state),
projectChanged: state.scratchGui.projectChanged,
projectTitle: state.scratchGui.projectTitle,
sessionExists: state.session && typeof state.session.session !== 'undefined',
username: user ? user.username : null
+37 -2
View File
@@ -115,9 +115,9 @@ describe('Loading scratch gui', () => {
test('Creating new project resets active tab to Code tab', async () => {
await loadUri(uri);
await clickText('View 2.0 Project');
const el = await findByXpath("//input[@placeholder='scratch.mit.edu/projects/123456789']");
const inputElement = await findByXpath("//input[@placeholder='scratch.mit.edu/projects/123456789']");
const projectId = '96708228';
await el.sendKeys(`scratch.mit.edu/projects/${projectId}`);
await inputElement.sendKeys(`scratch.mit.edu/projects/${projectId}`);
await clickXpath('//button[@title="View Project"]');
await new Promise(resolve => setTimeout(resolve, 2000));
await findByXpath('//*[span[text()="Costumes"]]');
@@ -127,6 +127,41 @@ describe('Loading scratch gui', () => {
'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
);
await clickXpath('//li[span[text()="New"]]');
await findByXpath('//*[div[@class="scratchCategoryMenu"]]');
await clickText('Operators', scope.blocksTab);
});
test('Not logged in->made no changes to project->create new project should not show alert', async () => {
await loadUri(uri);
await clickText('View 2.0 Project');
const inputElement = await findByXpath("//input[@placeholder='scratch.mit.edu/projects/123456789']");
const projectId = '96708228';
await inputElement.sendKeys(`scratch.mit.edu/projects/${projectId}`);
await clickXpath('//button[@title="View Project"]');
await new Promise(resolve => setTimeout(resolve, 2000));
await clickXpath(
'//div[contains(@class, "menu-bar_menu-bar-item") and ' +
'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
);
await clickXpath('//li[span[text()="New"]]');
await findByXpath('//*[div[@class="scratchCategoryMenu"]]');
await clickText('Operators', scope.blocksTab);
});
test('Not logged in->made a change to project->create new project should show alert', async () => {
await loadUri(uri);
await clickText('View 2.0 Project');
const inputElement = await findByXpath("//input[@placeholder='scratch.mit.edu/projects/123456789']");
const projectId = '96708228';
await inputElement.sendKeys(`scratch.mit.edu/projects/${projectId}`);
await clickXpath('//button[@title="View Project"]');
await new Promise(resolve => setTimeout(resolve, 2000));
await clickText('move');
await clickXpath(
'//div[contains(@class, "menu-bar_menu-bar-item") and ' +
'contains(@class, "menu-bar_hoverable")][span[text()="File"]]'
);
await clickXpath('//li[span[text()="New"]]');
driver.switchTo()
.alert()
.accept();