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
1 change: 1 addition & 0 deletions packages/blockly/core/icons/mutator_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export class MutatorIcon extends Icon implements IHasBubble {
if (this.bubbleIsVisible() === visible) return;

await renderManagement.finishQueuedRenders();
if (this.sourceBlock.isDeadOrDying()) return;

if (visible) {
this.miniWorkspaceBubble = new MiniWorkspaceBubble(
Expand Down
1 change: 1 addition & 0 deletions packages/blockly/core/icons/warning_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class WarningIcon extends Icon implements IHasBubble {
if (this.bubbleIsVisible() === visible) return;

await renderManagement.finishQueuedRenders();
if (this.sourceBlock.isDeadOrDying()) return;

if (visible) {
this.textBubble = new TextBubble(
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 @@ -1954,6 +1954,18 @@ suite('Blocks', function () {
assert.equal(label, 'Bubble');
});
});

test('disposing the block while the bubble is opening does not open it', async function () {
this.block.setWarningText('Warning');
const icon = this.block.getIcon(Blockly.icons.WarningIcon.TYPE);
const opening = icon.setBubbleVisible(true);
this.block.dispose();
// Run the frame that setBubbleVisible waits for.
this.clock.runAll();
await opening;

assert.isFalse(icon.bubbleIsVisible());
});
});

suite('Warning icons and collapsing', function () {
Expand Down
3 changes: 0 additions & 3 deletions packages/blockly/tests/mocha/focus_manager_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ suite('FocusManager', function () {
}
this.allFocusableTrees = [];
this.allFocusableNodes = [];

// Reset the current active element.
document.body.focus();
});

assert.includesClass = function (classList, className) {
Expand Down
42 changes: 42 additions & 0 deletions packages/blockly/tests/mocha/mutator_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,46 @@ suite('Mutator', function () {
assert.equal(label, 'Bubble');
});
});

suite('Disposing the block', function () {
setup(function () {
this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS);
this.block = createRenderedBlock(this.workspace, 'controls_if');
this.icon = this.block.getIcon(Blockly.icons.MutatorIcon.TYPE);
});

teardown(function () {
sharedTestTeardown.call(this);
});

test('while the bubble is opening does not open it', async function () {
const opening = this.icon.setBubbleVisible(true);
this.block.dispose();
await opening;

assert.isFalse(this.icon.bubbleIsVisible());
assertEventNotFired(
this.eventsFireStub,
Blockly.Events.BubbleOpen,
{},
this.workspace.id,
this.block.id,
);
});

test('while the bubble is closing does not fire a close event', async function () {
await this.icon.setBubbleVisible(true);
const closing = this.icon.setBubbleVisible(false);
this.block.dispose();
await closing;

assertEventNotFired(
this.eventsFireStub,
Blockly.Events.BubbleOpen,
{isOpen: false},
this.workspace.id,
this.block.id,
);
});
});
});
8 changes: 8 additions & 0 deletions packages/blockly/tests/mocha/test_helpers/setup_teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ export function sharedTestTeardown(workspace = this.workspace) {
);
}

// Clear focus while the fake clock is still installed. While an element
// has focus, JSDom starts its animation frame interval on any DOM change,
// using whatever setInterval is current. If that happens after the
// restore below, later tests' animation frames end up on a real timer
// their fake clock cannot run, so their events arrive late.
document.activeElement?.blur?.();
this.clock.runAll();

// Restore all stubbed methods.
this.sharedSetupSandbox_.restore();
sinon.restore();
Expand Down
Loading