Skip to content
Snippets Groups Projects
Unverified Commit db1d5bd2 authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #3473 from paulkaplan/switch-to-code-after-sprite

Make sure to switch back to code when adding new sprites
parents 837f99d9 25249f9f
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,9 @@ class SpriteLibrary extends React.PureComponent { ...@@ -39,7 +39,9 @@ class SpriteLibrary extends React.PureComponent {
clearInterval(this.intervalId); clearInterval(this.intervalId);
} }
handleItemSelect (item) { handleItemSelect (item) {
this.props.vm.addSprite(JSON.stringify(item.json)); this.props.vm.addSprite(JSON.stringify(item.json)).then(() => {
this.props.onActivateBlocksTab();
});
analytics.event({ analytics.event({
category: 'library', category: 'library',
action: 'Select Sprite', action: 'Select Sprite',
...@@ -95,6 +97,7 @@ class SpriteLibrary extends React.PureComponent { ...@@ -95,6 +97,7 @@ class SpriteLibrary extends React.PureComponent {
SpriteLibrary.propTypes = { SpriteLibrary.propTypes = {
intl: intlShape.isRequired, intl: intlShape.isRequired,
onActivateBlocksTab: PropTypes.func.isRequired,
onRequestClose: PropTypes.func, onRequestClose: PropTypes.func,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
closeSpriteLibrary closeSpriteLibrary
} from '../reducers/modals'; } from '../reducers/modals';
import {activateTab, COSTUMES_TAB_INDEX} from '../reducers/editor-tab'; import {activateTab, COSTUMES_TAB_INDEX, BLOCKS_TAB_INDEX} from '../reducers/editor-tab';
import {setReceivedBlocks} from '../reducers/hovered-target'; import {setReceivedBlocks} from '../reducers/hovered-target';
import {setRestore} from '../reducers/restore-deletion'; import {setRestore} from '../reducers/restore-deletion';
import DragConstants from '../lib/drag-constants'; import DragConstants from '../lib/drag-constants';
...@@ -23,6 +23,7 @@ class TargetPane extends React.Component { ...@@ -23,6 +23,7 @@ class TargetPane extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleActivateBlocksTab',
'handleBlockDragEnd', 'handleBlockDragEnd',
'handleChangeSpriteRotationStyle', 'handleChangeSpriteRotationStyle',
'handleChangeSpriteDirection', 'handleChangeSpriteDirection',
...@@ -72,7 +73,9 @@ class TargetPane extends React.Component { ...@@ -72,7 +73,9 @@ class TargetPane extends React.Component {
this.props.vm.postSpriteInfo({y}); this.props.vm.postSpriteInfo({y});
} }
handleDeleteSprite (id) { handleDeleteSprite (id) {
const restoreFun = this.props.vm.deleteSprite(id); const restoreSprite = this.props.vm.deleteSprite(id);
const restoreFun = () => restoreSprite().then(this.handleActivateBlocksTab);
this.props.dispatchUpdateRestore({ this.props.dispatchUpdateRestore({
restoreFun: restoreFun, restoreFun: restoreFun,
deletedItem: 'Sprite' deletedItem: 'Sprite'
...@@ -109,7 +112,8 @@ class TargetPane extends React.Component { ...@@ -109,7 +112,8 @@ class TargetPane extends React.Component {
} }
handleSurpriseSpriteClick () { handleSurpriseSpriteClick () {
const item = spriteLibraryContent[Math.floor(Math.random() * spriteLibraryContent.length)]; const item = spriteLibraryContent[Math.floor(Math.random() * spriteLibraryContent.length)];
this.props.vm.addSprite(JSON.stringify(item.json)); this.props.vm.addSprite(JSON.stringify(item.json))
.then(this.handleActivateBlocksTab);
} }
handlePaintSpriteClick () { handlePaintSpriteClick () {
const formatMessage = this.props.intl.formatMessage; const formatMessage = this.props.intl.formatMessage;
...@@ -124,8 +128,12 @@ class TargetPane extends React.Component { ...@@ -124,8 +128,12 @@ class TargetPane extends React.Component {
}); });
}); });
} }
handleActivateBlocksTab () {
this.props.onActivateTab(BLOCKS_TAB_INDEX);
}
handleNewSprite (spriteJSONString) { handleNewSprite (spriteJSONString) {
this.props.vm.addSprite(spriteJSONString); this.props.vm.addSprite(spriteJSONString)
.then(this.handleActivateBlocksTab);
} }
handleFileUploadClick () { handleFileUploadClick () {
this.fileInput.click(); this.fileInput.click();
......
...@@ -33,6 +33,7 @@ describe('Working with sprites', () => { ...@@ -33,6 +33,7 @@ describe('Working with sprites', () => {
await clickXpath('//button[@aria-label="Choose a Sprite"]'); await clickXpath('//button[@aria-label="Choose a Sprite"]');
await clickText('Apple', scope.modal); // Closes modal await clickText('Apple', scope.modal); // Closes modal
await rightClickText('Apple', scope.spriteTile); // Make sure it is there await rightClickText('Apple', scope.spriteTile); // Make sure it is there
await findByText('Motion'); // Make sure we are back to the code tab
const logs = await getLogs(); const logs = await getLogs();
await expect(logs).toEqual([]); await expect(logs).toEqual([]);
}); });
...@@ -49,6 +50,19 @@ describe('Working with sprites', () => { ...@@ -49,6 +50,19 @@ describe('Working with sprites', () => {
await expect(logs).toEqual([]); await expect(logs).toEqual([]);
}); });
test('Adding a sprite by paint button', async () => {
await loadUri(uri);
await clickXpath('//button[@title="Try It"]');
const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
await driver.actions().mouseMove(el)
.perform();
await driver.sleep(500); // Wait for thermometer menu to come up
await clickXpath('//button[@aria-label="Paint"]');
await findByText('Convert to Bitmap'); // Make sure we are on the paint editor
const logs = await getLogs();
await expect(logs).toEqual([]);
});
test('Deleting only sprite does not crash', async () => { test('Deleting only sprite does not crash', async () => {
await loadUri(uri); await loadUri(uri);
await clickXpath('//button[@title="Try It"]'); await clickXpath('//button[@title="Try It"]');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment