Skip to content

Commit 754193e

Browse files
committed
fix: Fix tests for auto tab management.
Also, rename some helpers and improve test safety.
1 parent 9809ff2 commit 754193e

File tree

7 files changed

+57
-61
lines changed

7 files changed

+57
-61
lines changed

test/webdriverio/test/actions_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
contextMenuExists,
1111
moveToToolboxCategory,
1212
PAUSE_TIME,
13-
setCurrentCursorNodeById,
13+
focusOnBlock,
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
@@ -29,7 +29,7 @@ suite('Menus test', function () {
2929
test('Menu action opens menu', async function () {
3030
// Navigate to draw_circle_1.
3131
await tabNavigateToWorkspace(this.browser);
32-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
32+
await focusOnBlock(this.browser, 'draw_circle_1');
3333
await this.browser.pause(PAUSE_TIME);
3434
await this.browser.keys([Key.Ctrl, Key.Return]);
3535
await this.browser.pause(PAUSE_TIME);
@@ -42,7 +42,7 @@ suite('Menus test', function () {
4242
test('Menu action returns true in the toolbox', async function () {
4343
// Navigate to draw_circle_1.
4444
await tabNavigateToWorkspace(this.browser);
45-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
45+
await focusOnBlock(this.browser, 'draw_circle_1');
4646
// Navigate to a toolbox category
4747
await moveToToolboxCategory(this.browser, 'Functions');
4848
// Move to flyout.
@@ -59,7 +59,7 @@ suite('Menus test', function () {
5959
test('Menu action returns false during drag', async function () {
6060
// Navigate to draw_circle_1.
6161
await tabNavigateToWorkspace(this.browser);
62-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
62+
await focusOnBlock(this.browser, 'draw_circle_1');
6363
// Start moving the block
6464
await this.browser.keys('m');
6565
await this.browser.keys([Key.Ctrl, Key.Return]);

test/webdriverio/test/basic_test.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as chai from 'chai';
88
import * as Blockly from 'blockly';
99
import {
1010
isDragging,
11-
setCurrentCursorNodeById,
12-
setCurrentCursorNodeByIdAndFieldName,
11+
focusOnBlock,
12+
focusOnBlockField,
1313
getCurrentFocusNodeId,
1414
getCurrentFocusedBlockId,
1515
getFocusedFieldName,
@@ -53,7 +53,7 @@ suite('Keyboard navigation on Blocks', function () {
5353
test('Down from statement block selects next block across stacks', async function () {
5454
await tabNavigateToWorkspace(this.browser);
5555
await this.browser.pause(PAUSE_TIME);
56-
await setCurrentCursorNodeById(this.browser, 'p5_canvas_1');
56+
await focusOnBlock(this.browser, 'p5_canvas_1');
5757
await this.browser.pause(PAUSE_TIME);
5858
await this.browser.keys(Key.ArrowDown);
5959
await this.browser.pause(PAUSE_TIME);
@@ -66,7 +66,7 @@ suite('Keyboard navigation on Blocks', function () {
6666
test('Up from statement block selects previous block', async function () {
6767
await tabNavigateToWorkspace(this.browser);
6868
await this.browser.pause(PAUSE_TIME);
69-
await setCurrentCursorNodeById(this.browser, 'simple_circle_1');
69+
await focusOnBlock(this.browser, 'simple_circle_1');
7070
await this.browser.pause(PAUSE_TIME);
7171
await this.browser.keys(Key.ArrowUp);
7272
await this.browser.pause(PAUSE_TIME);
@@ -79,7 +79,7 @@ suite('Keyboard navigation on Blocks', function () {
7979
test('Down from parent block selects first child block', async function () {
8080
await tabNavigateToWorkspace(this.browser);
8181
await this.browser.pause(PAUSE_TIME);
82-
await setCurrentCursorNodeById(this.browser, 'p5_setup_1');
82+
await focusOnBlock(this.browser, 'p5_setup_1');
8383
await this.browser.pause(PAUSE_TIME);
8484
await this.browser.keys(Key.ArrowDown);
8585
await this.browser.pause(PAUSE_TIME);
@@ -91,7 +91,7 @@ suite('Keyboard navigation on Blocks', function () {
9191
test('Up from child block selects parent block', async function () {
9292
await tabNavigateToWorkspace(this.browser);
9393
await this.browser.pause(PAUSE_TIME);
94-
await setCurrentCursorNodeById(this.browser, 'p5_canvas_1');
94+
await focusOnBlock(this.browser, 'p5_canvas_1');
9595
await this.browser.pause(PAUSE_TIME);
9696
await this.browser.keys(Key.ArrowUp);
9797
await this.browser.pause(PAUSE_TIME);
@@ -103,7 +103,7 @@ suite('Keyboard navigation on Blocks', function () {
103103
test('Right from block selects first field', async function () {
104104
await tabNavigateToWorkspace(this.browser);
105105
await this.browser.pause(PAUSE_TIME);
106-
await setCurrentCursorNodeById(this.browser, 'p5_canvas_1');
106+
await focusOnBlock(this.browser, 'p5_canvas_1');
107107
await this.browser.pause(PAUSE_TIME);
108108
await this.browser.keys(Key.ArrowRight);
109109
await this.browser.pause(PAUSE_TIME);
@@ -118,7 +118,7 @@ suite('Keyboard navigation on Blocks', function () {
118118
test('Right from block selects first inline input', async function () {
119119
await tabNavigateToWorkspace(this.browser);
120120
await this.browser.pause(PAUSE_TIME);
121-
await setCurrentCursorNodeById(this.browser, 'simple_circle_1');
121+
await focusOnBlock(this.browser, 'simple_circle_1');
122122
await this.browser.pause(PAUSE_TIME);
123123
await this.browser.keys(Key.ArrowRight);
124124
await this.browser.pause(PAUSE_TIME);
@@ -132,7 +132,7 @@ suite('Keyboard navigation on Blocks', function () {
132132
test('Up from inline input selects statement block', async function () {
133133
await tabNavigateToWorkspace(this.browser);
134134
await this.browser.pause(PAUSE_TIME);
135-
await setCurrentCursorNodeById(this.browser, 'math_number_2');
135+
await focusOnBlock(this.browser, 'math_number_2');
136136
await this.browser.pause(PAUSE_TIME);
137137
await this.browser.keys(Key.ArrowUp);
138138
await this.browser.pause(PAUSE_TIME);
@@ -146,7 +146,7 @@ suite('Keyboard navigation on Blocks', function () {
146146
test('Left from first inline input selects block', async function () {
147147
await tabNavigateToWorkspace(this.browser);
148148
await this.browser.pause(PAUSE_TIME);
149-
await setCurrentCursorNodeById(this.browser, 'math_number_2');
149+
await focusOnBlock(this.browser, 'math_number_2');
150150
await this.browser.pause(PAUSE_TIME);
151151
await this.browser.keys(Key.ArrowLeft);
152152
await this.browser.pause(PAUSE_TIME);
@@ -160,7 +160,7 @@ suite('Keyboard navigation on Blocks', function () {
160160
test('Right from first inline input selects second inline input', async function () {
161161
await tabNavigateToWorkspace(this.browser);
162162
await this.browser.pause(PAUSE_TIME);
163-
await setCurrentCursorNodeById(this.browser, 'math_number_2');
163+
await focusOnBlock(this.browser, 'math_number_2');
164164
await this.browser.pause(PAUSE_TIME);
165165
await this.browser.keys(Key.ArrowRight);
166166
await this.browser.pause(PAUSE_TIME);
@@ -174,7 +174,7 @@ suite('Keyboard navigation on Blocks', function () {
174174
test('Left from second inline input selects first inline input', async function () {
175175
await tabNavigateToWorkspace(this.browser);
176176
await this.browser.pause(PAUSE_TIME);
177-
await setCurrentCursorNodeById(this.browser, 'math_number_3');
177+
await focusOnBlock(this.browser, 'math_number_3');
178178
await this.browser.pause(PAUSE_TIME);
179179
await this.browser.keys(Key.ArrowLeft);
180180
await this.browser.pause(PAUSE_TIME);
@@ -188,7 +188,7 @@ suite('Keyboard navigation on Blocks', function () {
188188
test('Right from last inline input selects next block', async function () {
189189
await tabNavigateToWorkspace(this.browser);
190190
await this.browser.pause(PAUSE_TIME);
191-
await setCurrentCursorNodeById(this.browser, 'colour_picker_1');
191+
await focusOnBlock(this.browser, 'colour_picker_1');
192192
await this.browser.pause(PAUSE_TIME);
193193
await this.browser.keys(Key.ArrowRight);
194194
await this.browser.pause(PAUSE_TIME);
@@ -201,7 +201,7 @@ suite('Keyboard navigation on Blocks', function () {
201201
test('Down from inline input selects next block', async function () {
202202
await tabNavigateToWorkspace(this.browser);
203203
await this.browser.pause(PAUSE_TIME);
204-
await setCurrentCursorNodeById(this.browser, 'colour_picker_1');
204+
await focusOnBlock(this.browser, 'colour_picker_1');
205205
await this.browser.pause(PAUSE_TIME);
206206
await this.browser.keys(Key.ArrowDown);
207207
await this.browser.pause(PAUSE_TIME);
@@ -214,7 +214,7 @@ suite('Keyboard navigation on Blocks', function () {
214214
test("Down from inline input selects block's child block", async function () {
215215
await tabNavigateToWorkspace(this.browser);
216216
await this.browser.pause(PAUSE_TIME);
217-
await setCurrentCursorNodeById(this.browser, 'logic_boolean_1');
217+
await focusOnBlock(this.browser, 'logic_boolean_1');
218218
await this.browser.pause(PAUSE_TIME);
219219
await this.browser.keys(Key.ArrowDown);
220220
await this.browser.pause(PAUSE_TIME);
@@ -227,7 +227,7 @@ suite('Keyboard navigation on Blocks', function () {
227227
test('Right from text block selects shadow block then field', async function () {
228228
await tabNavigateToWorkspace(this.browser);
229229
await this.browser.pause(PAUSE_TIME);
230-
await setCurrentCursorNodeById(this.browser, 'text_print_1');
230+
await focusOnBlock(this.browser, 'text_print_1');
231231
await this.browser.pause(PAUSE_TIME);
232232
await this.browser.keys(Key.ArrowRight);
233233
await this.browser.pause(PAUSE_TIME);
@@ -252,7 +252,7 @@ suite('Keyboard navigation on Blocks', function () {
252252
test('Losing focus cancels move', async function () {
253253
await tabNavigateToWorkspace(this.browser);
254254
await this.browser.pause(PAUSE_TIME);
255-
await setCurrentCursorNodeById(this.browser, 'text_print_1');
255+
await focusOnBlock(this.browser, 'text_print_1');
256256
await this.browser.keys('m');
257257
await this.browser.pause(PAUSE_TIME);
258258

@@ -265,7 +265,6 @@ suite('Keyboard navigation on Blocks', function () {
265265
});
266266
});
267267

268-
// TODO(#499) These tests fail because focusing on a field doesn't update the cursor
269268
suite('Keyboard navigation on Fields', function () {
270269
// Setting timeout to unlimited as these tests take a longer time to run than most mocha test
271270
this.timeout(0);
@@ -278,7 +277,7 @@ suite('Keyboard navigation on Fields', function () {
278277
test('Up from first field selects block', async function () {
279278
await tabNavigateToWorkspace(this.browser);
280279
await this.browser.pause(PAUSE_TIME);
281-
await setCurrentCursorNodeByIdAndFieldName(
280+
await focusOnBlockField(
282281
this.browser,
283282
'p5_canvas_1',
284283
'WIDTH',
@@ -296,7 +295,7 @@ suite('Keyboard navigation on Fields', function () {
296295
test('Left from first field selects block', async function () {
297296
await tabNavigateToWorkspace(this.browser);
298297
await this.browser.pause(PAUSE_TIME);
299-
await setCurrentCursorNodeByIdAndFieldName(
298+
await focusOnBlockField(
300299
this.browser,
301300
'p5_canvas_1',
302301
'WIDTH',
@@ -314,7 +313,7 @@ suite('Keyboard navigation on Fields', function () {
314313
test('Right from first field selects second field', async function () {
315314
await tabNavigateToWorkspace(this.browser);
316315
await this.browser.pause(PAUSE_TIME);
317-
await setCurrentCursorNodeByIdAndFieldName(
316+
await focusOnBlockField(
318317
this.browser,
319318
'p5_canvas_1',
320319
'WIDTH',
@@ -333,7 +332,7 @@ suite('Keyboard navigation on Fields', function () {
333332
test('Left from second field selects first field', async function () {
334333
await tabNavigateToWorkspace(this.browser);
335334
await this.browser.pause(PAUSE_TIME);
336-
await setCurrentCursorNodeByIdAndFieldName(
335+
await focusOnBlockField(
337336
this.browser,
338337
'p5_canvas_1',
339338
'HEIGHT',
@@ -352,7 +351,7 @@ suite('Keyboard navigation on Fields', function () {
352351
test('Right from second field selects next block', async function () {
353352
await tabNavigateToWorkspace(this.browser);
354353
await this.browser.pause(PAUSE_TIME);
355-
await setCurrentCursorNodeByIdAndFieldName(
354+
await focusOnBlockField(
356355
this.browser,
357356
'p5_canvas_1',
358357
'HEIGHT',
@@ -369,7 +368,7 @@ suite('Keyboard navigation on Fields', function () {
369368
test('Down from field selects next block', async function () {
370369
await tabNavigateToWorkspace(this.browser);
371370
await this.browser.pause(PAUSE_TIME);
372-
await setCurrentCursorNodeByIdAndFieldName(
371+
await focusOnBlockField(
373372
this.browser,
374373
'p5_canvas_1',
375374
'WIDTH',
@@ -386,7 +385,7 @@ suite('Keyboard navigation on Fields', function () {
386385
test("Down from field selects block's child block", async function () {
387386
await tabNavigateToWorkspace(this.browser);
388387
await this.browser.pause(PAUSE_TIME);
389-
await setCurrentCursorNodeByIdAndFieldName(
388+
await focusOnBlockField(
390389
this.browser,
391390
'controls_repeat_1',
392391
'TIMES',

test/webdriverio/test/clipboard_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
getSelectedBlockId,
1515
ElementWithId,
1616
tabNavigateToWorkspace,
17-
setCurrentCursorNodeById,
17+
focusOnBlock,
1818
} from './test_setup.js';
1919
import {Key, KeyAction, PointerAction, WheelAction} from 'webdriverio';
2020

@@ -31,7 +31,7 @@ suite('Clipboard test', function () {
3131
test('Copy and paste while block selected', async function () {
3232
// Navigate to draw_circle_1.
3333
await tabNavigateToWorkspace(this.browser);
34-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
34+
await focusOnBlock(this.browser, 'draw_circle_1');
3535

3636
// Copy and paste
3737
await this.browser.keys([Key.Ctrl, 'c']);
@@ -52,7 +52,7 @@ suite('Clipboard test', function () {
5252
test('Cut and paste while block selected', async function () {
5353
// Navigate to draw_circle_1.
5454
await tabNavigateToWorkspace(this.browser);
55-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
55+
await focusOnBlock(this.browser, 'draw_circle_1');
5656
const block = await getBlockElementById(this.browser, 'draw_circle_1');
5757

5858
// Cut and paste

test/webdriverio/test/delete_test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import * as chai from 'chai';
88
import {
99
blockIsPresent,
10-
setCurrentCursorNodeById,
10+
focusOnBlock,
1111
getCurrentFocusedBlockId,
1212
getFocusedBlockType,
1313
moveToToolboxCategory,
@@ -30,7 +30,7 @@ suite('Deleting Blocks', function () {
3030
test('Deleting block selects parent block', async function () {
3131
await tabNavigateToWorkspace(this.browser);
3232
await this.browser.pause(PAUSE_TIME);
33-
await setCurrentCursorNodeById(this.browser, 'controls_if_2');
33+
await focusOnBlock(this.browser, 'controls_if_2');
3434
await this.browser.pause(PAUSE_TIME);
3535

3636
chai
@@ -52,7 +52,7 @@ suite('Deleting Blocks', function () {
5252
test('Cutting block selects parent block', async function () {
5353
await tabNavigateToWorkspace(this.browser);
5454
await this.browser.pause(PAUSE_TIME);
55-
await setCurrentCursorNodeById(this.browser, 'controls_if_2');
55+
await focusOnBlock(this.browser, 'controls_if_2');
5656
await this.browser.pause(PAUSE_TIME);
5757

5858
chai
@@ -74,7 +74,7 @@ suite('Deleting Blocks', function () {
7474
test('Deleting block also deletes children and inputs', async function () {
7575
await tabNavigateToWorkspace(this.browser);
7676
await this.browser.pause(PAUSE_TIME);
77-
await setCurrentCursorNodeById(this.browser, 'controls_if_2');
77+
await focusOnBlock(this.browser, 'controls_if_2');
7878
await this.browser.pause(PAUSE_TIME);
7979

8080
chai
@@ -96,7 +96,7 @@ suite('Deleting Blocks', function () {
9696
test('Cutting block also removes children and inputs', async function () {
9797
await tabNavigateToWorkspace(this.browser);
9898
await this.browser.pause(PAUSE_TIME);
99-
await setCurrentCursorNodeById(this.browser, 'controls_if_2');
99+
await focusOnBlock(this.browser, 'controls_if_2');
100100
await this.browser.pause(PAUSE_TIME);
101101

102102
chai
@@ -118,7 +118,7 @@ suite('Deleting Blocks', function () {
118118
test('Deleting inline input selects parent block', async function () {
119119
await tabNavigateToWorkspace(this.browser);
120120
await this.browser.pause(PAUSE_TIME);
121-
await setCurrentCursorNodeById(this.browser, 'logic_boolean_1');
121+
await focusOnBlock(this.browser, 'logic_boolean_1');
122122
await this.browser.pause(PAUSE_TIME);
123123

124124
chai
@@ -140,7 +140,7 @@ suite('Deleting Blocks', function () {
140140
test('Cutting inline input selects parent block', async function () {
141141
await tabNavigateToWorkspace(this.browser);
142142
await this.browser.pause(PAUSE_TIME);
143-
await setCurrentCursorNodeById(this.browser, 'logic_boolean_1');
143+
await focusOnBlock(this.browser, 'logic_boolean_1');
144144
await this.browser.pause(PAUSE_TIME);
145145

146146
chai

test/webdriverio/test/insert_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
getFocusedBlockType,
1111
moveToToolboxCategory,
1212
PAUSE_TIME,
13-
setCurrentCursorNodeById,
13+
focusOnBlock,
1414
tabNavigateToWorkspace,
1515
testFileLocations,
1616
testSetup,
@@ -29,7 +29,7 @@ suite('Insert test', function () {
2929
test('Insert C-shaped block with statement block selected', async function () {
3030
// Navigate to draw_circle_1.
3131
await tabNavigateToWorkspace(this.browser);
32-
await setCurrentCursorNodeById(this.browser, 'draw_circle_1');
32+
await focusOnBlock(this.browser, 'draw_circle_1');
3333

3434
await moveToToolboxCategory(this.browser, 'Functions');
3535
// Move to flyout.

test/webdriverio/test/move_test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as chai from 'chai';
99
import {Browser, Key} from 'webdriverio';
1010
import {
1111
PAUSE_TIME,
12-
setCurrentCursorNodeById,
12+
focusOnBlock,
1313
tabNavigateToWorkspace,
1414
testFileLocations,
1515
testSetup,
@@ -34,7 +34,7 @@ suite('Move tests', function () {
3434
for (let i = 1; i < 7; i++) {
3535
// Navigate to statement_<i>.
3636
await tabNavigateToWorkspace(this.browser);
37-
await setCurrentCursorNodeById(this.browser, `statement_${i}`);
37+
await focusOnBlock(this.browser, `statement_${i}`);
3838

3939
// Get information about parent connection of selected block,
4040
// and block connected to selected block's next connection.
@@ -94,7 +94,7 @@ suite('Move tests', function () {
9494
for (let i = 1; i < 7; i++) {
9595
// Navigate to statement_<i>.
9696
await tabNavigateToWorkspace(this.browser);
97-
await setCurrentCursorNodeById(this.browser, `value_${i}`);
97+
await focusOnBlock(this.browser, `value_${i}`);
9898

9999
// Get information about parent connection of selected block,
100100
// and block connected to selected block's value input.

0 commit comments

Comments
 (0)