Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/containers/sprite-library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
};
Expand Down
16 changes: 12 additions & 4 deletions src/containers/target-pane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,6 +23,7 @@ class TargetPane extends React.Component {
constructor (props) {
super(props);
bindAll(this, [
'handleActivateBlocksTab',
'handleBlockDragEnd',
'handleChangeSpriteRotationStyle',
'handleChangeSpriteDirection',
Expand Down Expand Up @@ -72,7 +73,9 @@ class TargetPane extends React.Component {
this.props.vm.postSpriteInfo({y});
}
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({
restoreFun: restoreFun,
deletedItem: 'Sprite'
Expand Down Expand Up @@ -109,7 +112,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;
Expand All @@ -124,8 +128,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();
Expand Down
14 changes: 14 additions & 0 deletions test/integration/sprites.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
Expand All @@ -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"]');
Expand Down