Skip to content

Commit b12ea50

Browse files
committed
Make sure to switch back to code when adding new sprites
1 parent d1024cd commit b12ea50

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/containers/sprite-library.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class SpriteLibrary extends React.PureComponent {
3939
clearInterval(this.intervalId);
4040
}
4141
handleItemSelect (item) {
42-
this.props.vm.addSprite(JSON.stringify(item.json));
42+
this.props.vm.addSprite(JSON.stringify(item.json)).then(() => {
43+
this.props.onActivateBlocksTab();
44+
});
4345
analytics.event({
4446
category: 'library',
4547
action: 'Select Sprite',
@@ -95,6 +97,7 @@ class SpriteLibrary extends React.PureComponent {
9597

9698
SpriteLibrary.propTypes = {
9799
intl: intlShape.isRequired,
100+
onActivateBlocksTab: PropTypes.func.isRequired,
98101
onRequestClose: PropTypes.func,
99102
vm: PropTypes.instanceOf(VM).isRequired
100103
};

src/containers/target-pane.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
closeSpriteLibrary
1010
} from '../reducers/modals';
1111

12-
import {activateTab, COSTUMES_TAB_INDEX} from '../reducers/editor-tab';
12+
import {activateTab, COSTUMES_TAB_INDEX, BLOCKS_TAB_INDEX} from '../reducers/editor-tab';
1313
import {setReceivedBlocks} from '../reducers/hovered-target';
1414
import {setRestore} from '../reducers/restore-deletion';
1515
import DragConstants from '../lib/drag-constants';
@@ -23,6 +23,7 @@ class TargetPane extends React.Component {
2323
constructor (props) {
2424
super(props);
2525
bindAll(this, [
26+
'handleActivateBlocksTab',
2627
'handleBlockDragEnd',
2728
'handleChangeSpriteRotationStyle',
2829
'handleChangeSpriteDirection',
@@ -109,7 +110,8 @@ class TargetPane extends React.Component {
109110
}
110111
handleSurpriseSpriteClick () {
111112
const item = spriteLibraryContent[Math.floor(Math.random() * spriteLibraryContent.length)];
112-
this.props.vm.addSprite(JSON.stringify(item.json));
113+
this.props.vm.addSprite(JSON.stringify(item.json))
114+
.then(this.handleActivateBlocksTab);
113115
}
114116
handlePaintSpriteClick () {
115117
const formatMessage = this.props.intl.formatMessage;
@@ -124,8 +126,12 @@ class TargetPane extends React.Component {
124126
});
125127
});
126128
}
129+
handleActivateBlocksTab () {
130+
this.props.onActivateTab(BLOCKS_TAB_INDEX);
131+
}
127132
handleNewSprite (spriteJSONString) {
128-
this.props.vm.addSprite(spriteJSONString);
133+
this.props.vm.addSprite(spriteJSONString)
134+
.then(this.handleActivateBlocksTab);
129135
}
130136
handleFileUploadClick () {
131137
this.fileInput.click();

test/integration/sprites.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('Working with sprites', () => {
3333
await clickXpath('//button[@aria-label="Choose a Sprite"]');
3434
await clickText('Apple', scope.modal); // Closes modal
3535
await rightClickText('Apple', scope.spriteTile); // Make sure it is there
36+
await findByText('Motion'); // Make sure we are back to the code tab
3637
const logs = await getLogs();
3738
await expect(logs).toEqual([]);
3839
});
@@ -49,6 +50,19 @@ describe('Working with sprites', () => {
4950
await expect(logs).toEqual([]);
5051
});
5152

53+
test('Adding a sprite by paint button', async () => {
54+
await loadUri(uri);
55+
await clickXpath('//button[@title="Try It"]');
56+
const el = await findByXpath('//button[@aria-label="Choose a Sprite"]');
57+
await driver.actions().mouseMove(el)
58+
.perform();
59+
await driver.sleep(500); // Wait for thermometer menu to come up
60+
await clickXpath('//button[@aria-label="Paint"]');
61+
await findByText('Convert to Bitmap'); // Make sure we are on the paint editor
62+
const logs = await getLogs();
63+
await expect(logs).toEqual([]);
64+
});
65+
5266
test('Deleting only sprite does not crash', async () => {
5367
await loadUri(uri);
5468
await clickXpath('//button[@title="Try It"]');

0 commit comments

Comments
 (0)