Skip to content

Commit 86e0950

Browse files
authored
chore: Introduce tests for flyout & toolbox (#557)
Fixes part of google/blockly#8915 Fixes part of google/blockly#9020 This PR does a few things: - It introduces some new helpers to simplify arrow key inputs across all of the webdriver tests. - It introduces a new focusable div element that exists in the tab order before toolbox (so that back navigation can be tested). - It renames a few functions for clarity: `setCurrentCursorNodeById` -> `focusOnBlock` and `setCurrentCursorNodeByIdAndFieldName` -> `focusOnBlockField`. This is closer to what the functions are actually doing, and it moves away from cursor verbiage (which could become confusing in the future once the cursor is removed). - It introduces some robustness sanity checks for test utility functions. These should fail if an assumption isn't met rather than return null or undefined--failing fast is really useful in tests to avoid hiding legitimate failures. - It introduces a whole test suite for toolbox and flyout (though a lot more tests can be added). This specifically emphasizes regressions fixed by google/blockly#9079.
1 parent 18c3ad3 commit 86e0950

File tree

10 files changed

+462
-147
lines changed

10 files changed

+462
-147
lines changed

test/toolboxCategories.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
{
1818
type: 'controls_if',
1919
kind: 'block',
20+
id: 'if_block',
2021
},
2122
{
2223
type: 'logic_compare',
@@ -374,6 +375,7 @@ export default {
374375
fields: {
375376
TEXT: '',
376377
},
378+
id: 'text_block',
377379
},
378380
{
379381
type: 'text_join',
@@ -382,6 +384,7 @@ export default {
382384
{
383385
type: 'text_append',
384386
kind: 'block',
387+
id: 'append_text_block',
385388
fields: {
386389
name: 'item',
387390
},

test/webdriverio/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
<body>
6464
<div id="root">
65+
<div id="focusableDiv" tabindex="0">Simple div to focus.</div>
6566
<div id="blocklyDiv"></div>
6667
<div id="shortcuts"></div>
6768
</div>

test/webdriverio/test/actions_test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import {
1010
contextMenuExists,
1111
moveToToolboxCategory,
1212
PAUSE_TIME,
13-
setCurrentCursorNodeById,
13+
focusOnBlock,
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
17+
keyRight,
1718
} from './test_setup.js';
1819

1920
suite('Menus test', function () {
@@ -29,7 +30,7 @@ suite('Menus test', function () {
2930
test('Menu action opens menu', async function () {
3031
// Navigate to draw_circle_1.
3132
await tabNavigateToWorkspace(this.browser);
32-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
33+
await focusOnBlock(this.browser, 'draw_circle_1');
3334
await this.browser.pause(PAUSE_TIME);
3435
await this.browser.keys([Key.Ctrl, Key.Return]);
3536
await this.browser.pause(PAUSE_TIME);
@@ -42,11 +43,11 @@ suite('Menus test', function () {
4243
test('Menu action returns true in the toolbox', async function () {
4344
// Navigate to draw_circle_1.
4445
await tabNavigateToWorkspace(this.browser);
45-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
46+
await focusOnBlock(this.browser, 'draw_circle_1');
4647
// Navigate to a toolbox category
4748
await moveToToolboxCategory(this.browser, 'Functions');
4849
// Move to flyout.
49-
await this.browser.keys(Key.ArrowRight);
50+
await keyRight(this.browser);
5051
await this.browser.keys([Key.Ctrl, Key.Return]);
5152
await this.browser.pause(PAUSE_TIME);
5253

@@ -59,7 +60,7 @@ suite('Menus test', function () {
5960
test('Menu action returns false during drag', async function () {
6061
// Navigate to draw_circle_1.
6162
await tabNavigateToWorkspace(this.browser);
62-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
63+
await focusOnBlock(this.browser, 'draw_circle_1');
6364
// Start moving the block
6465
await this.browser.keys('m');
6566
await this.browser.keys([Key.Ctrl, Key.Return]);

0 commit comments

Comments
 (0)