Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/blockly/core/rendered_connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,9 @@ export class RenderedConnection
}

private findHighlightSvg(): SVGPathElement | null {
// This cast is valid as TypeScript's definition is wrong. See:
// https://github.com/microsoft/TypeScript/issues/60996.
const root = this.getSourceBlock().getSvgRoot().getRootNode() as
ShadowRoot | HTMLDocument;
return root.getElementById(this.id) as SVGPathElement | null;
return this.getSourceBlock()
.getSvgRoot()
.querySelector<SVGPathElement>(`#${CSS.escape(this.id)}`);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/blockly/core/trashcan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ export class Trashcan
*/
dispose() {
this.workspace.getComponentManager().removeComponent('trashcan');
this.flyout?.dispose();
this.flyout = null;
if (this.svgGroup) {
dom.removeNode(this.svgGroup);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/blockly/tests/mocha/block_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2963,6 +2963,11 @@ suite('Blocks', function () {
block.render();
}
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

test('Bubbles are moved to drag layer along with their blocks', async function () {
this.blocks.A.setCommentText('a');
this.blocks.B.setCommentText('b');
Expand Down Expand Up @@ -3007,6 +3012,12 @@ suite('Blocks', function () {
firstBlock.moveBy(-500, -500);
});

teardown(function () {
if (this.workspace) {
workspaceTeardown.call(this, this.workspace);
}
});

test('Deleting the sole block on the workspace focuses the workspace', function () {
const block = this.workspace.getTopBlocks(false)[0];
Blockly.getFocusManager().focusNode(block);
Expand Down Expand Up @@ -3111,6 +3122,7 @@ suite('Blocks', function () {
this.workspace.getTopBlocks(false)[0],
);
this.workspace.dispose();
this.workspace = null;
this.clock.runAll();

// No assert, this just shouldn't throw.
Expand Down
25 changes: 21 additions & 4 deletions packages/blockly/tests/mocha/blocks/procedures_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1930,14 +1930,23 @@ suite('Procedures', function () {
const statementField = containerBlock.getField('STATEMENTS');
statementField.setValue(value);
defBlock.compose(containerBlock);
workspaceTeardown.call(this, mutatorWorkspace);
}
if (testSuite.defType === 'procedures_defreturn') {
test('Has Statements', function () {
setStatementValue(this.workspace, this.defBlock, true);
setStatementValue.apply(this, [
this.workspace,
this.defBlock,
true,
]);
assert.isTrue(this.defBlock.hasStatements_);
});
test('Has No Statements', function () {
setStatementValue(this.workspace, this.defBlock, false);
setStatementValue.apply(this, [
this.workspace,
this.defBlock,
false,
]);
assert.isFalse(this.defBlock.hasStatements_);
});
test('Saving Statements', function () {
Expand All @@ -1952,9 +1961,13 @@ suite('Procedures', function () {
blockXml,
this.workspace,
);
setStatementValue(this.workspace, defBlock, false);
setStatementValue.apply(this, [
this.workspace,
defBlock,
false,
]);
assert.isNull(defBlock.getInput('STACK'));
setStatementValue(this.workspace, defBlock, true);
setStatementValue.apply(this, [this.workspace, defBlock, true]);
assert.isNotNull(defBlock.getInput('STACK'));
const statementBlocks = defBlock.getChildren();
assert.equal(statementBlocks.length, 1);
Expand Down Expand Up @@ -2064,6 +2077,7 @@ suite('Procedures', function () {
.getTopBlocks()[0]
.getInput('STATEMENT_INPUT');
assert.isNotNull(statementInput);
workspaceTeardown.call(this, mutatorWorkspace);
});
test('Has Statements', function () {
this.defBlock.hasStatements_ = true;
Expand All @@ -2078,6 +2092,7 @@ suite('Procedures', function () {
.getField('STATEMENTS')
.getValueBoolean();
assert.isTrue(statementValue);
workspaceTeardown.call(this, mutatorWorkspace);
});
test('No Has Statements', function () {
this.defBlock.hasStatements_ = false;
Expand All @@ -2092,6 +2107,7 @@ suite('Procedures', function () {
.getField('STATEMENTS')
.getValueBoolean();
assert.isFalse(statementValue);
workspaceTeardown.call(this, mutatorWorkspace);
});
} else {
test('Has no Statement Input', function () {
Expand All @@ -2105,6 +2121,7 @@ suite('Procedures', function () {
.getTopBlocks()[0]
.getInput('STATEMENT_INPUT');
assert.isNull(statementInput);
workspaceTeardown.call(this, mutatorWorkspace);
});
}
});
Expand Down
25 changes: 9 additions & 16 deletions packages/blockly/tests/mocha/clipboard_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ suite('Clipboard', function () {
});

test('pasted blocks are bumped to not overlap in RTL', function () {
this.workspace.dispose();
this.workspace = Blockly.inject('blocklyDiv', {
const workspace = Blockly.inject('blocklyDiv', {
...DEFAULT_INJECT_OPTIONS,
rtl: true,
});
Expand All @@ -170,11 +169,11 @@ suite('Clipboard', function () {
'x': 38,
'y': 13,
},
this.workspace,
workspace,
);
const data = block.toCopyData();

const newBlock = Blockly.clipboard.paste(data, this.workspace);
const newBlock = Blockly.clipboard.paste(data, workspace);
const oldBlockXY = block.getRelativeToSurfaceXY();
assert.deepEqual(
newBlock.getRelativeToSurfaceXY(),
Expand All @@ -183,10 +182,7 @@ suite('Clipboard', function () {
oldBlockXY.y + Blockly.config.snapRadius * 2,
),
);

// Restore an LTR workspace.
this.workspace.dispose();
this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS);
workspace.dispose();
});

test('pasted blocks are bumped to be outside the connection snap radius', function () {
Expand Down Expand Up @@ -242,29 +238,26 @@ suite('Clipboard', function () {
});

test('pasted comments are bumped to not overlap in RTL', function () {
this.workspace.dispose();
this.workspace = Blockly.inject('blocklyDiv', {
const workspace = Blockly.inject('blocklyDiv', {
...DEFAULT_INJECT_OPTIONS,
rtl: true,
});
Blockly.Xml.domToWorkspace(
Blockly.utils.xml.textToDom(
'<xml><comment id="test" x=10 y=10/></xml>',
),
this.workspace,
workspace,
);
const comment = this.workspace.getTopComments(false)[0];
const comment = workspace.getTopComments(false)[0];
const data = comment.toCopyData();

const newComment = Blockly.clipboard.paste(data, this.workspace);
const newComment = Blockly.clipboard.paste(data, workspace);
const oldCommentXY = comment.getRelativeToSurfaceXY();
assert.deepEqual(
newComment.getRelativeToSurfaceXY(),
new Blockly.utils.Coordinate(oldCommentXY.x - 30, oldCommentXY.y + 30),
);
// Restore an LTR workspace.
this.workspace.dispose();
this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS);
workspace.dispose();
});
});
});
11 changes: 9 additions & 2 deletions packages/blockly/tests/mocha/connection_checker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DEFAULT_INJECT_OPTIONS,
sharedTestSetup,
sharedTestTeardown,
workspaceTeardown,
} from './test_helpers/setup_teardown.js';

suite('Connection checker', function () {
Expand Down Expand Up @@ -514,9 +515,16 @@ suite('Connection checker', function () {
});
});
suite('Dragging Checks', function () {
setup(function () {
this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS);
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

suite('Stacks', function () {
setup(function () {
this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS);
// Load in three blocks: A and B are connected (next/prev); B is unmovable.
Blockly.Xml.domToWorkspace(
Blockly.utils.xml
Expand Down Expand Up @@ -627,7 +635,6 @@ suite('Connection checker', function () {
});
suite('Rows', function () {
setup(function () {
this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS);
// Load 3 blocks: A and B are connected (input/output); B is unmovable.
Blockly.Xml.domToWorkspace(
Blockly.utils.xml
Expand Down
4 changes: 4 additions & 0 deletions packages/blockly/tests/mocha/connection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,10 @@ suite('Connection', function () {
};
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

suite('Disconnect from old parent', function () {
test('Value', function () {
const oldParent = this.workspace.newBlock('row_block');
Expand Down
2 changes: 2 additions & 0 deletions packages/blockly/tests/mocha/dropdowndiv_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DEFAULT_INJECT_OPTIONS,
sharedTestSetup,
sharedTestTeardown,
workspaceTeardown,
} from './test_helpers/setup_teardown.js';

suite('DropDownDiv', function () {
Expand Down Expand Up @@ -155,6 +156,7 @@ suite('DropDownDiv', function () {
});
teardown(function () {
this.boundsStub.restore();
workspaceTeardown.call(this, this.workspace);
});
test('Escape dismisses DropDownDiv', function () {
let hidden = false;
Expand Down
5 changes: 5 additions & 0 deletions packages/blockly/tests/mocha/field_checkbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ suite('Checkbox Fields', function () {

this.focusableElement = this.field.getClickTarget_();
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

test('Block has field type name in ARIA label', function () {
const blockLabel = this.block.getAriaLabel();
assert.include(blockLabel, 'checkbox');
Expand Down
5 changes: 5 additions & 0 deletions packages/blockly/tests/mocha/field_dropdown_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ suite('Dropdown Fields', function () {
renderer: 'geras',
});
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

suite('Simple Dropdown', function () {
setup(function () {
this.block = this.workspace.newBlock('logic_boolean');
Expand Down
6 changes: 6 additions & 0 deletions packages/blockly/tests/mocha/field_image_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DEFAULT_INJECT_OPTIONS,
sharedTestSetup,
sharedTestTeardown,
workspaceTeardown,
} from './test_helpers/setup_teardown.js';

suite('Image Fields', function () {
Expand Down Expand Up @@ -364,6 +365,11 @@ suite('Image Fields', function () {
renderer: 'geras',
});
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

suite('Image without click handler', function () {
setup(function () {
this.block = this.workspace.newBlock('text');
Expand Down
2 changes: 2 additions & 0 deletions packages/blockly/tests/mocha/field_label_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
DEFAULT_INJECT_OPTIONS,
sharedTestSetup,
sharedTestTeardown,
workspaceTeardown,
} from './test_helpers/setup_teardown.js';

suite('Label Fields', function () {
Expand Down Expand Up @@ -239,6 +240,7 @@ suite('Label Fields', function () {
const focusableElement = field.getFocusableElement();
const ariaHidden = focusableElement.getAttribute('aria-hidden');
assert.equal(ariaHidden, 'true');
workspaceTeardown.call(this, workspace);
});
});
});
5 changes: 5 additions & 0 deletions packages/blockly/tests/mocha/field_number_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ suite('Number Fields', function () {

this.focusableElement = this.field.getClickTarget_();
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

test('Field has field type name in ARIA label', function () {
const fieldLabel = this.focusableElement.getAttribute('aria-label');
assert.include(fieldLabel, 'number:');
Expand Down
5 changes: 5 additions & 0 deletions packages/blockly/tests/mocha/field_textinput_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,11 @@ suite('Text Input Fields', function () {

this.focusableElement = this.field.getClickTarget_();
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

test('Field has field type name in ARIA label', function () {
const fieldLabel = this.focusableElement.getAttribute('aria-label');
assert.include(fieldLabel, 'text:');
Expand Down
5 changes: 5 additions & 0 deletions packages/blockly/tests/mocha/field_variable_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,11 @@ suite('Variable Fields', function () {

this.focusableElement = this.field.getFocusableElement();
});

teardown(function () {
workspaceTeardown.call(this, this.workspace);
});

test('Block has "Variable" qualifier in ARIA label', function () {
const blockLabel = this.block.getAriaLabel();
assert.include(blockLabel, 'Variable');
Expand Down
Loading
Loading