From fe0f401977a6f13ae8061db69b2d357e1626fd17 Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Mon, 11 Jan 2021 09:05:59 -0800 Subject: [PATCH] Fix collapsing bug and add tests (#4568) --- core/block_svg.js | 1 + tests/mocha/block_test.js | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/core/block_svg.js b/core/block_svg.js index 46fdfb44e..ed9b58fee 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -662,6 +662,7 @@ Blockly.BlockSvg.prototype.updateCollapsed_ = function() { } if (!collapsed) { + this.updateDisabled(); this.removeInput(collapsedInputName); return; } diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 5943b7cef..34c56ddeb 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -1577,6 +1577,64 @@ suite('Blocks', function() { assertCollapsed(blockA, 'X'); }); }); + suite('Disabled Blocks', function() { + test('Children of Collapsed Blocks Should Enable Properly', function() { + var blockA = createRenderedBlock(this.workspace,'statement_block'); + var blockB = createRenderedBlock(this.workspace,'stack_block'); + blockA.getInput('STATEMENT').connection + .connect(blockB.previousConnection); + // Disable the block and collapse it. + blockA.setEnabled(false); + blockA.setCollapsed(true); + + // Enable the block before expanding it. + blockA.setEnabled(true); + blockA.setCollapsed(false); + + // The child blocks should be enabled. + chai.assert.isFalse(blockB.disabled); + chai.assert.isFalse(blockB.getSvgRoot().classList.contains('blocklyDisabled')); + }); + test('Children of Collapsed Block Should Not Update', function() { + var blockA = createRenderedBlock(this.workspace,'statement_block'); + var blockB = createRenderedBlock(this.workspace,'stack_block'); + blockA.getInput('STATEMENT').connection + .connect(blockB.previousConnection); + + // Disable the block and collapse it. + blockA.setEnabled(false); + blockA.setCollapsed(true); + + var blockUpdateDisabled = sinon.stub(blockB, 'updateDisabled'); + + // Enable the block before expanding it. + blockA.setEnabled(true); + + // For performance reasons updateDisabled should not be called + // on children of collapsed blocks. + sinon.assert.notCalled(blockUpdateDisabled); + }); + test('Disabled Children of Collapsed Blocks Should Stay Disabled', function() { + var blockA = createRenderedBlock(this.workspace,'statement_block'); + var blockB = createRenderedBlock(this.workspace,'stack_block'); + blockA.getInput('STATEMENT').connection + .connect(blockB.previousConnection); + + // Disable the child block. + blockB.setEnabled(false); + + // Collapse and disable the parent block. + blockA.setCollapsed(false); + blockA.setEnabled(false); + + // Enable the parent block. + blockA.setEnabled(true); + blockA.setCollapsed(true); + + // Child blocks should stay disabled if they have been set. + chai.assert.isTrue(blockB.disabled); + }); + }); }); suite('Style', function() { suite('Headless', function() {