Skip to content

Commit 0cf5b1f

Browse files
authored
Merge pull request #3745 from paulkaplan/fix-highlight-deleted-sprite
Prevent crash after deleting sprite that had been highlighted
2 parents ae0e265 + 93587c7 commit 0cf5b1f

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/containers/target-highlight.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class TargetHighlight extends React.Component {
3232
vm
3333
} = this.props;
3434

35-
if (!(highlightedTargetId && vm && vm.renderer)) return null;
35+
if (!(highlightedTargetId && vm && vm.renderer &&
36+
vm.runtime.getTargetById(highlightedTargetId))) return null;
3637

3738
const target = vm.runtime.getTargetById(highlightedTargetId);
3839
const bounds = vm.renderer.getBounds(target.drawableID);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import path from 'path';
2+
import SeleniumHelper from '../helpers/selenium-helper';
3+
4+
const {
5+
clickText,
6+
clickXpath,
7+
rightClickText,
8+
getDriver,
9+
getLogs,
10+
loadUri,
11+
scope
12+
} = new SeleniumHelper();
13+
14+
const uri = path.resolve(__dirname, '../../build/index.html');
15+
16+
let driver;
17+
18+
describe('Loading scratch gui', () => {
19+
beforeAll(() => {
20+
driver = getDriver();
21+
});
22+
23+
afterAll(async () => {
24+
await driver.quit();
25+
});
26+
27+
test('Switching small/large stage after highlighting and deleting sprite', async () => {
28+
await loadUri(uri);
29+
await clickXpath('//button[@title="Try It"]');
30+
31+
// Highlight the sprite
32+
await clickText('Sprite1', scope.spriteTile);
33+
34+
// Delete it
35+
await rightClickText('Sprite1', scope.spriteTile);
36+
await clickText('delete', scope.spriteTile);
37+
38+
// Go to small stage mode
39+
await clickXpath('//img[@alt="Switch to small stage"]');
40+
41+
// Confirm app still working
42+
await clickXpath('//img[@alt="Switch to large stage"]');
43+
44+
const logs = await getLogs();
45+
await expect(logs).toEqual([]);
46+
});
47+
});

0 commit comments

Comments
 (0)