Skip to content

Commit

Permalink
Use correct target on addBlock. Fixes #1089 (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb authored Sep 18, 2020
1 parent c740fe0 commit 1b18f31
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7614,7 +7614,9 @@ ScriptsMorph.prototype.moveBlock = function (block, target, hand) {
};

ScriptsMorph.prototype.addBlock = function (block) {
SnapActions.addBlock(block, this.scriptTarget(), block.position());
const target = this.parentThatIsA(BlockEditorMorph) ||
this.scriptTarget();
SnapActions.addBlock(block, target, block.position());
block.destroy();
};

Expand Down
34 changes: 34 additions & 0 deletions test/blocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,40 @@ describe('blocks', function() {
);
});

it('should add new block to block editor', async () => {
const {BlockEditorMorph} = driver.globals();
const sprite = driver.ide().currentSprite;
const spec = 'sprite block %s';
const definition = new CustomBlockDefinition(spec, sprite);

// Get the sprite
definition.category = 'motion';
await SnapActions.addCustomBlock(definition, sprite);

// Edit the custom block
driver.selectCategory('custom');
const customBlock = driver.palette().contents.children
.find(item => item instanceof CustomCommandBlockMorph);
driver.rightClick(customBlock);
let editBtn = driver.dialog().children.find(item => item.action === 'edit');
driver.click(editBtn);

const editor = driver.dialog();
const scripts = editor.body.contents;

driver.selectCategory('motion');
const positionBlock = driver.palette().contents.children
.find(item => item.selector === 'xPosition');

driver.dragAndDrop(positionBlock, scripts.center());
await driver.actionsSettled();
const block = Object.values(SnapActions._blocks)[0];
assert(
block.parentThatIsA(BlockEditorMorph),
'Expected position block to be in block editor'
);
});

it('should be able to change type from dialog', async () => {
var sprite = driver.ide().currentSprite,
spec = 'sprite block %s',
Expand Down

0 comments on commit 1b18f31

Please sign in to comment.