diff --git a/src/containers/sprite-library.jsx b/src/containers/sprite-library.jsx index 15d75970c1b9123373d37e7c93d3a4aa20fe4c4c..72efa4fc94d4fac0efbefa7206c44692f47a1278 100644 --- a/src/containers/sprite-library.jsx +++ b/src/containers/sprite-library.jsx @@ -39,7 +39,9 @@ class SpriteLibrary extends React.PureComponent { clearInterval(this.intervalId); } handleItemSelect (item) { - this.props.vm.addSprite(JSON.stringify(item.json)); + this.props.vm.addSprite(JSON.stringify(item.json)).then(() => { + this.props.onActivateBlocksTab(); + }); analytics.event({ category: 'library', action: 'Select Sprite', @@ -95,6 +97,7 @@ class SpriteLibrary extends React.PureComponent { SpriteLibrary.propTypes = { intl: intlShape.isRequired, + onActivateBlocksTab: PropTypes.func.isRequired, onRequestClose: PropTypes.func, vm: PropTypes.instanceOf(VM).isRequired }; diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx index a2e5fdcc5f11eeb516375c2908da2214f75ffeb4..cd8d9d6358eacfe6acf93e6f523faf8a949963bb 100644 --- a/src/containers/target-pane.jsx +++ b/src/containers/target-pane.jsx @@ -9,7 +9,7 @@ import { closeSpriteLibrary } 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 {setRestore} from '../reducers/restore-deletion'; import DragConstants from '../lib/drag-constants'; @@ -23,6 +23,7 @@ class TargetPane extends React.Component { constructor (props) { super(props); bindAll(this, [ + 'handleActivateBlocksTab', 'handleBlockDragEnd', 'handleChangeSpriteRotationStyle', 'handleChangeSpriteDirection', @@ -109,7 +110,8 @@ class TargetPane extends React.Component { } handleSurpriseSpriteClick () { 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 () { const formatMessage = this.props.intl.formatMessage; @@ -124,8 +126,12 @@ class TargetPane extends React.Component { }); }); } + handleActivateBlocksTab () { + this.props.onActivateTab(BLOCKS_TAB_INDEX); + } handleNewSprite (spriteJSONString) { - this.props.vm.addSprite(spriteJSONString); + this.props.vm.addSprite(spriteJSONString) + .then(this.handleActivateBlocksTab); } handleFileUploadClick () { this.fileInput.click(); diff --git a/test/integration/sprites.test.js b/test/integration/sprites.test.js index 5b99efcb62e0496312d31f15e8746b260ad204a1..0aa957bfcfe3c5b07c14c0ac8cc0756240c924e7 100644 --- a/test/integration/sprites.test.js +++ b/test/integration/sprites.test.js @@ -33,6 +33,7 @@ describe('Working with sprites', () => { await clickXpath('//button[@aria-label="Choose a Sprite"]'); await clickText('Apple', scope.modal); // Closes modal 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(); await expect(logs).toEqual([]); }); @@ -49,6 +50,19 @@ describe('Working with sprites', () => { 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 () => { await loadUri(uri); await clickXpath('//button[@title="Try It"]');