@@ -20,7 +20,7 @@ suite('Keyboard Shortcut Items', function () {
2020 setup ( function ( ) {
2121 sharedTestSetup . call ( this ) ;
2222 const toolbox = document . getElementById ( 'toolbox-test' ) ;
23- this . workspace = Blockly . inject ( 'blocklyDiv' , { toolbox} ) ;
23+ this . workspace = Blockly . inject ( 'blocklyDiv' , { toolbox, renderer : 'zelos' } ) ;
2424 this . injectionDiv = this . workspace . getInjectionDiv ( ) ;
2525 Blockly . ContextMenuRegistry . registry . reset ( ) ;
2626 Blockly . ContextMenuItems . registerDefaultOptions ( ) ;
@@ -628,22 +628,6 @@ suite('Keyboard Shortcut Items', function () {
628628 } ) ;
629629
630630 suite ( 'Focus Toolbox (T)' , function ( ) {
631- setup ( function ( ) {
632- Blockly . defineBlocksWithJsonArray ( [
633- {
634- 'type' : 'basic_block' ,
635- 'message0' : '%1' ,
636- 'args0' : [
637- {
638- 'type' : 'field_input' ,
639- 'name' : 'TEXT' ,
640- 'text' : 'default' ,
641- } ,
642- ] ,
643- } ,
644- ] ) ;
645- } ) ;
646-
647631 test ( 'Does not change focus when toolbox item is already focused' , function ( ) {
648632 const item = this . workspace . getToolbox ( ) . getToolboxItems ( ) [ 1 ] ;
649633 Blockly . getFocusManager ( ) . focusNode ( item ) ;
@@ -1028,4 +1012,216 @@ suite('Keyboard Shortcut Items', function () {
10281012 ) ;
10291013 } ) ;
10301014 } ) ;
1015+
1016+ suite ( 'Perform Action (Enter)' , function ( ) {
1017+ test ( 'Shows a toast with navigation hints on the workspace' , function ( ) {
1018+ const toastSpy = sinon . spy ( Blockly . Toast , 'show' ) ;
1019+
1020+ Blockly . getFocusManager ( ) . focusNode ( this . workspace ) ;
1021+
1022+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1023+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1024+
1025+ sinon . assert . calledWith ( toastSpy , this . workspace , {
1026+ id : 'workspaceNavigationHint' ,
1027+ message : Blockly . Msg [ 'KEYBOARD_NAV_WORKSPACE_NAVIGATION_HINT' ] ,
1028+ } ) ;
1029+
1030+ toastSpy . restore ( ) ;
1031+ } ) ;
1032+
1033+ test ( 'Inserts blocks from the flyout in move mode' , function ( ) {
1034+ this . workspace . getToolbox ( ) . selectItemByPosition ( 0 ) ;
1035+ const block = this . workspace
1036+ . getNavigator ( )
1037+ . getFirstChild ( this . workspace . getFlyout ( ) . getWorkspace ( ) ) ;
1038+ assert . instanceOf ( block , Blockly . BlockSvg ) ;
1039+ Blockly . getFocusManager ( ) . focusNode ( block ) ;
1040+
1041+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1042+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1043+
1044+ const movingBlock = Blockly . getFocusManager ( ) . getFocusedNode ( ) ;
1045+ assert . notEqual ( block , movingBlock ) ;
1046+ assert . instanceOf ( movingBlock , Blockly . BlockSvg ) ;
1047+ assert . isTrue ( movingBlock . isDragging ( ) ) ;
1048+ assert . isFalse ( movingBlock . workspace . isFlyout ) ;
1049+
1050+ Blockly . KeyboardMover . mover . abortMove ( ) ;
1051+ } ) ;
1052+
1053+ test ( 'Shows a toast with navigation hints for navigable blocks' , function ( ) {
1054+ const toastSpy = sinon . spy ( Blockly . Toast , 'show' ) ;
1055+
1056+ const block = this . workspace . newBlock ( 'controls_if' ) ;
1057+ block . initSvg ( ) ;
1058+ block . render ( ) ;
1059+ Blockly . getFocusManager ( ) . focusNode ( block ) ;
1060+
1061+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1062+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1063+
1064+ sinon . assert . calledWith ( toastSpy , this . workspace , {
1065+ id : 'blockNavigationHint' ,
1066+ message : Blockly . Msg [ 'KEYBOARD_NAV_BLOCK_NAVIGATION_HINT' ] ,
1067+ } ) ;
1068+ toastSpy . restore ( ) ;
1069+ } ) ;
1070+
1071+ test ( 'Shows a toast with instructions to view help for non-navigable blocks' , function ( ) {
1072+ const toastSpy = sinon . spy ( Blockly . Toast , 'show' ) ;
1073+
1074+ const block = this . workspace . newBlock ( 'test_align_dummy_right' ) ;
1075+ block . initSvg ( ) ;
1076+ block . render ( ) ;
1077+ Blockly . getFocusManager ( ) . focusNode ( block ) ;
1078+
1079+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1080+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1081+
1082+ sinon . assert . calledWith ( toastSpy , this . workspace , {
1083+ id : 'helpHint' ,
1084+ message : Blockly . Msg [ 'HELP_PROMPT' ] . replace ( '%1' , '' ) ,
1085+ } ) ;
1086+ toastSpy . restore ( ) ;
1087+ } ) ;
1088+
1089+ test ( 'Focuses field editor for blocks with full-block fields' , function ( ) {
1090+ const block = this . workspace . newBlock ( 'math_number' ) ;
1091+ block . initSvg ( ) ;
1092+ block . render ( ) ;
1093+ Blockly . getFocusManager ( ) . focusNode ( block ) ;
1094+
1095+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1096+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1097+
1098+ const field = block . getField ( 'NUM' ) ;
1099+ assert . isTrue ( Blockly . WidgetDiv . isVisible ( ) ) ;
1100+ assert . isTrue ( field . isBeingEdited_ ) ;
1101+ } ) ;
1102+
1103+ test ( 'Focuses field editor for fields' , function ( ) {
1104+ const block = this . workspace . newBlock ( 'logic_compare' ) ;
1105+ block . initSvg ( ) ;
1106+ block . render ( ) ;
1107+ const field = block . getField ( 'OP' ) ;
1108+ Blockly . getFocusManager ( ) . focusNode ( field ) ;
1109+
1110+ assert . isFalse ( Blockly . DropDownDiv . isVisible ( ) ) ;
1111+
1112+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1113+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1114+
1115+ assert . isTrue ( Blockly . DropDownDiv . isVisible ( ) ) ;
1116+ } ) ;
1117+
1118+ test ( 'Expands and focuses workspace comment editors' , function ( ) {
1119+ const comment = this . workspace . newComment ( ) ;
1120+ comment . setCollapsed ( true ) ;
1121+ Blockly . getFocusManager ( ) . focusNode ( comment ) ;
1122+
1123+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1124+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1125+
1126+ assert . strictEqual (
1127+ Blockly . getFocusManager ( ) . getFocusedNode ( ) ,
1128+ comment . getEditorFocusableNode ( ) ,
1129+ ) ;
1130+ assert . isFalse ( comment . view . isCollapsed ( ) ) ;
1131+ } ) ;
1132+
1133+ test ( 'Focuses mutator workspace for mutator bubble' , async function ( ) {
1134+ const block = this . workspace . newBlock ( 'controls_if' ) ;
1135+ block . initSvg ( ) ;
1136+ block . render ( ) ;
1137+ const icon = block . getIcon ( Blockly . icons . MutatorIcon . TYPE ) ;
1138+ await icon . setBubbleVisible ( true ) ;
1139+ Blockly . getFocusManager ( ) . focusNode ( icon . getBubble ( ) ) ;
1140+
1141+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1142+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1143+
1144+ assert . strictEqual (
1145+ Blockly . getFocusManager ( ) . getFocusedTree ( ) ,
1146+ icon . getWorkspace ( ) ,
1147+ ) ;
1148+ } ) ;
1149+
1150+ test ( 'Focuses comment editor for block comment bubble' , async function ( ) {
1151+ const block = this . workspace . newBlock ( 'controls_if' ) ;
1152+ block . initSvg ( ) ;
1153+ block . render ( ) ;
1154+ block . setCommentText ( 'Hello' ) ;
1155+ const icon = block . getIcon ( Blockly . icons . CommentIcon . TYPE ) ;
1156+ await icon . setBubbleVisible ( true ) ;
1157+ Blockly . getFocusManager ( ) . focusNode ( icon . getBubble ( ) ) ;
1158+
1159+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1160+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1161+
1162+ assert . strictEqual (
1163+ Blockly . getFocusManager ( ) . getFocusedNode ( ) ,
1164+ icon . getBubble ( ) . getEditor ( ) ,
1165+ ) ;
1166+ } ) ;
1167+
1168+ test ( 'Focuses bubble for icons' , async function ( ) {
1169+ const block = this . workspace . newBlock ( 'controls_if' ) ;
1170+ block . initSvg ( ) ;
1171+ block . render ( ) ;
1172+
1173+ block . setCommentText ( 'Hello world' ) ;
1174+ block . setWarningText ( 'Danger!' ) ;
1175+
1176+ const iconTypes = [
1177+ Blockly . icons . CommentIcon . TYPE ,
1178+ Blockly . icons . WarningIcon . TYPE ,
1179+ Blockly . icons . MutatorIcon . TYPE ,
1180+ ] ;
1181+
1182+ for ( const iconType of iconTypes ) {
1183+ const icon = block . getIcon ( iconType ) ;
1184+ Blockly . getFocusManager ( ) . focusNode ( icon ) ;
1185+
1186+ const bubbleShown = new Promise ( ( resolve ) => {
1187+ this . workspace . addChangeListener ( ( event ) => {
1188+ if ( event . type === Blockly . Events . BUBBLE_OPEN ) {
1189+ resolve ( ) ;
1190+ }
1191+ } ) ;
1192+ } ) ;
1193+
1194+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1195+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1196+
1197+ this . clock . tick ( 100 ) ;
1198+
1199+ await bubbleShown ;
1200+ assert . strictEqual (
1201+ Blockly . getFocusManager ( ) . getFocusedNode ( ) ,
1202+ icon . getBubble ( ) ,
1203+ ) ;
1204+ }
1205+ } ) ;
1206+
1207+ test ( 'Triggers flyout button actions' , function ( ) {
1208+ const toolbox = this . workspace . getToolbox ( ) ;
1209+ toolbox . selectItemByPosition ( 3 ) ;
1210+ const button = this . workspace . getFlyout ( ) . getContents ( ) [ 0 ] . getElement ( ) ;
1211+ assert . instanceOf ( button , Blockly . FlyoutButton ) ;
1212+ Blockly . getFocusManager ( ) . focusNode ( button ) ;
1213+
1214+ const oldCallback = this . workspace . getButtonCallback ( 'CREATE_VARIABLE' ) ;
1215+ let called = false ;
1216+ this . workspace . registerButtonCallback ( 'CREATE_VARIABLE' , ( ) => {
1217+ called = true ;
1218+ } ) ;
1219+
1220+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . ENTER ) ;
1221+ this . workspace . getInjectionDiv ( ) . dispatchEvent ( event ) ;
1222+
1223+ assert . isTrue ( called ) ;
1224+ this . workspace . registerButtonCallback ( 'CREATE_VARIABLE' , oldCallback ) ;
1225+ } ) ;
1226+ } ) ;
10311227} ) ;
0 commit comments