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
5 changes: 4 additions & 1 deletion src/actions/enter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ export class EnterAction {
Events.setGroup(true);
}

const stationaryNode = FocusableTreeTraverser.findFocusedNode(workspace);
// If the workspace has never had focus default the stationary node.
const stationaryNode =
FocusableTreeTraverser.findFocusedNode(workspace) ??
workspace.getRestoredFocusableNode(null);
const newBlock = this.createNewBlock(workspace);
if (!newBlock) return;
const insertStartPoint = stationaryNode
Expand Down
21 changes: 21 additions & 0 deletions test/webdriverio/test/insert_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
testFileLocations,
testSetup,
keyRight,
keyUp,
tabNavigateToToolbox,
} from './test_setup.js';

suite('Insert test', function () {
Expand Down Expand Up @@ -45,4 +47,23 @@ suite('Insert test', function () {
await getFocusedBlockType(this.browser),
);
});

test('Insert without having focused the workspace', async function () {
await tabNavigateToToolbox(this.browser);

// Insert 'if' block
await keyRight(this.browser);
// Choose.
await this.browser.keys(Key.Enter);
// Confirm position.
await this.browser.keys(Key.Enter);

// Assert inserted inside first block p5_setup not at top-level.
chai.assert.equal('controls_if', await getFocusedBlockType(this.browser));
await keyUp(this.browser);
chai.assert.equal(
'p5_background_color',
await getFocusedBlockType(this.browser),
);
});
});
13 changes: 13 additions & 0 deletions test/webdriverio/test/test_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,19 @@ export async function tabNavigateToWorkspace(
tabNavigateForward(browser); // Tab to the workspace itself.
}

/**
* Uses tabs to navigate to the toolbox on the test page (i.e. by going
* through top-level tab stops). Assumes initial load tab position.
*
* @param browser The active WebdriverIO Browser object.
*/
export async function tabNavigateToToolbox(browser: WebdriverIO.Browser) {
// Initial pre-injection focusable div element.
await tabNavigateForward(browser);
// Toolbox.
await tabNavigateForward(browser);
}

/**
* Navigates forward to the test page's next tab stop.
*
Expand Down