Skip to content
Merged
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
11 changes: 8 additions & 3 deletions plugins/workspace-search/test/workspace_search_test.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ suite('WorkspaceSearch', function () {
this.jsdomCleanup = require('jsdom-global')(
'<!DOCTYPE html><div id="blocklyDiv"></div>',
);
this.clock = sinon.useFakeTimers();
this.workspace = Blockly.inject('blocklyDiv');
this.workspaceSearch = new WorkspaceSearch(this.workspace);
// See https://github.com/RaspberryPiFoundation/blockly-samples/issues/2528 for context.
global.SVGElement = window.SVGElement;
});

teardown(function () {
this.workspaceSearch.dispose();
this.workspace.dispose();
this.clock.runAll();
this.clock.restore();
this.jsdomCleanup();
});

Expand Down Expand Up @@ -459,7 +464,7 @@ suite('WorkspaceSearch', function () {
this.workspaceSearch.init();
// Check starting position
this.focusManager = Blockly.FocusManager.getFocusManager();
this.focusManager.focusTree(this.workspace);
this.focusManager.focusNode(this.alphaBlock);
const originalBlock = /** @type {Blockly.BlockSvg} */ (
this.focusManager.getFocusedNode()
);
Expand All @@ -483,11 +488,11 @@ suite('WorkspaceSearch', function () {
assertFocusedNodeType('beta_block');
});

test('close with no match restores focus', function () {
test('close with no match restores focus to workspace', function () {
this.workspaceSearch.searchAndHighlight('nothingMatchesThis', false);
this.workspaceSearch.close();

assertFocusedNodeType('alpha_block');
assert.equal(Blockly.getFocusManager().getFocusedNode(), this.workspace);
});

test('close with match followed by non-match still focuses last found block', function () {
Expand Down
Loading