@@ -21,6 +21,8 @@ import {
2121 keyRight ,
2222 keyUp ,
2323 keyDown ,
24+ sendKeyAndWait ,
25+ isEphemeralFocusActive ,
2426} from './test_setup.js' ;
2527import { Key } from 'webdriverio' ;
2628
@@ -239,13 +241,11 @@ suite('Keyboard navigation on Blocks', function () {
239241 await tabNavigateToWorkspace ( this . browser ) ;
240242 await this . browser . pause ( PAUSE_TIME ) ;
241243 await focusOnBlock ( this . browser , 'text_print_1' ) ;
242- await this . browser . keys ( 'm' ) ;
243- await this . browser . pause ( PAUSE_TIME ) ;
244+ await sendKeyAndWait ( this . browser , 'm' ) ;
244245
245246 chai . assert . isTrue ( await isDragging ( this . browser ) ) ;
246247
247- await this . browser . keys ( Key . Tab ) ;
248- await this . browser . pause ( PAUSE_TIME ) ;
248+ await sendKeyAndWait ( this . browser , Key . Tab ) ;
249249
250250 chai . assert . isFalse ( await isDragging ( this . browser ) ) ;
251251 } ) ;
@@ -354,8 +354,7 @@ suite('Keyboard navigation on Fields', function () {
354354 // Open a field editor dropdown
355355 await focusOnBlockField ( this . browser , 'logic_boolean_1' , 'BOOL' ) ;
356356 await this . browser . pause ( PAUSE_TIME ) ;
357- await this . browser . keys ( Key . Enter ) ;
358- await this . browser . pause ( PAUSE_TIME ) ;
357+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
359358
360359 // Try to navigate to a different block
361360 await keyRight ( this . browser ) ;
@@ -368,13 +367,12 @@ suite('Keyboard navigation on Fields', function () {
368367 // Open colour picker
369368 await focusOnBlockField ( this . browser , 'colour_picker_1' , 'COLOUR' ) ;
370369 await this . browser . pause ( PAUSE_TIME ) ;
371- await this . browser . keys ( Key . Enter ) ;
372- await this . browser . pause ( PAUSE_TIME ) ;
370+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
373371
374372 // Move right to pick a new colour.
375373 await keyRight ( this . browser ) ;
376374 // Enter to choose.
377- await this . browser . keys ( Key . Enter ) ;
375+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
378376
379377 // Focus seems to take longer than a single pause to settle.
380378 await this . browser . waitUntil (
@@ -385,4 +383,36 @@ suite('Keyboard navigation on Fields', function () {
385383 { timeout : 1000 } ,
386384 ) ;
387385 } ) ;
386+
387+ test ( 'Exiting inline field editor should restore focus to field' , async function ( ) {
388+ // Select a block with an inline-editable field.
389+ await focusOnBlock ( this . browser , 'p5_canvas_1' ) ;
390+ // Select the field.
391+ await keyRight ( this . browser ) ;
392+ // Open the field's editor.
393+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
394+
395+ // Exit the editor.
396+ await sendKeyAndWait ( this . browser , Key . Escape ) ;
397+
398+ // The field should be focused without ephemeral focus.
399+ chai . assert . equal ( await getFocusedFieldName ( this . browser ) , 'WIDTH' ) ;
400+ chai . assert . isFalse ( await isEphemeralFocusActive ( this . browser ) ) ;
401+ } ) ;
402+
403+ test ( 'Exiting drop-down field editor should restore focus to field' , async function ( ) {
404+ // Select a block with a drop-down editable field.
405+ await focusOnBlock ( this . browser , 'logic_boolean_1' ) ;
406+ // Select the field.
407+ await keyRight ( this . browser ) ;
408+ // Open the field's editor.
409+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
410+
411+ // Exit the editor.
412+ await sendKeyAndWait ( this . browser , Key . Escape ) ;
413+
414+ // The field should be focused without ephemeral focus.
415+ chai . assert . equal ( await getFocusedFieldName ( this . browser ) , 'BOOL' ) ;
416+ chai . assert . isFalse ( await isEphemeralFocusActive ( this . browser ) ) ;
417+ } ) ;
388418} ) ;
0 commit comments