fix: Detect if deleting shadow block affects selection highlight (#8533)

* fix: Detect if deleting shadow block affects selection highlight

* Use contains instead of descendsFrom for html consistency.

* Added tests.

* Removing and manually inlining new contains function.
This commit is contained in:
John Nesky
2024-08-26 12:22:37 -07:00
committed by GitHub
parent 9445adf8fe
commit 095f29e274
2 changed files with 54 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import * as common from '../../build/src/core/common.js';
import {ConnectionType} from '../../build/src/core/connection_type.js';
import {EventType} from '../../build/src/core/events/type.js';
import * as eventUtils from '../../build/src/core/events/utils.js';
@@ -444,6 +445,39 @@ suite('Blocks', function () {
});
});
});
suite('Disposing selected shadow block', function () {
setup(function () {
this.workspace = Blockly.inject('blocklyDiv');
this.parentBlock = this.workspace.newBlock('row_block');
this.parentBlock.initSvg();
this.parentBlock.render();
this.parentBlock.inputList[0].connection.setShadowState({
'type': 'row_block',
'id': 'shadow_child',
});
this.shadowChild =
this.parentBlock.inputList[0].connection.targetConnection.getSourceBlock();
});
teardown(function () {
workspaceTeardown.call(this, this.workspace);
});
test('Disposing selected shadow unhighlights parent', function () {
const parentBlock = this.parentBlock;
common.setSelected(this.shadowChild);
assert.isTrue(
parentBlock.pathObject.svgRoot.classList.contains('blocklySelected'),
'Expected parent to be highlighted after selecting shadow child',
);
this.shadowChild.dispose();
assert.isFalse(
parentBlock.pathObject.svgRoot.classList.contains('blocklySelected'),
'Expected parent to be unhighlighted after deleting shadow child',
);
});
});
});
suite('Remove Input', function () {