@@ -12,7 +12,7 @@ import {
1212} from './test_helpers/setup_teardown.js' ;
1313import { createKeyDownEvent } from './test_helpers/user_input.js' ;
1414
15- suite ( 'Key Down ' , function ( ) {
15+ suite ( 'Keyboard Shortcut Items ' , function ( ) {
1616 setup ( function ( ) {
1717 sharedTestSetup . call ( this ) ;
1818 this . workspace = Blockly . inject ( 'blocklyDiv' , { } ) ;
@@ -35,6 +35,18 @@ suite('Key Down', function () {
3535 return block ;
3636 }
3737
38+ /**
39+ * Creates a block and sets its nextConnection as the focused node.
40+ * @param {Blockly.Workspace } workspace The workspace to create a new block on.
41+ */
42+ function setSelectedConnection ( workspace ) {
43+ defineStackBlock ( ) ;
44+ const block = workspace . newBlock ( 'stack_block' ) ;
45+ sinon
46+ . stub ( Blockly . getFocusManager ( ) , 'getFocusedNode' )
47+ . returns ( block . nextConnection ) ;
48+ }
49+
3850 /**
3951 * Creates a test for not running keyDown events when the workspace is in read only mode.
4052 * @param {Object } keyEvent Mocked key down event. Use createKeyDownEvent.
@@ -73,9 +85,14 @@ suite('Key Down', function () {
7385 this . injectionDiv . dispatchEvent ( this . event ) ;
7486 sinon . assert . notCalled ( this . hideChaffSpy ) ;
7587 } ) ;
88+ test ( 'Called when connection is focused' , function ( ) {
89+ setSelectedConnection ( this . workspace ) ;
90+ this . injectionDiv . dispatchEvent ( this . event ) ;
91+ sinon . assert . calledOnce ( this . hideChaffSpy ) ;
92+ } ) ;
7693 } ) ;
7794
78- suite ( 'Delete Block ' , function ( ) {
95+ suite ( 'Delete' , function ( ) {
7996 setup ( function ( ) {
8097 this . hideChaffSpy = sinon . spy (
8198 Blockly . WorkspaceSvg . prototype ,
@@ -89,6 +106,7 @@ suite('Key Down', function () {
89106 [ 'Backspace' , createKeyDownEvent ( Blockly . utils . KeyCodes . BACKSPACE ) ] ,
90107 ] ;
91108 // Delete a block.
109+ // Note that chaff is hidden when a block is deleted.
92110 suite ( 'Simple' , function ( ) {
93111 testCases . forEach ( function ( testCase ) {
94112 const testCaseName = testCase [ 0 ] ;
@@ -108,6 +126,16 @@ suite('Key Down', function () {
108126 runReadOnlyTest ( keyEvent , testCaseName ) ;
109127 } ) ;
110128 } ) ;
129+ // Do not delete anything if a connection is focused.
130+ test ( 'Not called when connection is focused' , function ( ) {
131+ // Restore the stub behavior called during setup
132+ Blockly . getFocusManager ( ) . getFocusedNode . restore ( ) ;
133+
134+ setSelectedConnection ( this . workspace ) ;
135+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . DELETE ) ;
136+ this . injectionDiv . dispatchEvent ( event ) ;
137+ sinon . assert . notCalled ( this . hideChaffSpy ) ;
138+ } ) ;
111139 } ) ;
112140
113141 suite ( 'Copy' , function ( ) {
@@ -194,6 +222,18 @@ suite('Key Down', function () {
194222 } ) ;
195223 } ) ;
196224 } ) ;
225+ test ( 'Not called when connection is focused' , function ( ) {
226+ // Restore the stub behavior called during setup
227+ Blockly . getFocusManager ( ) . getFocusedNode . restore ( ) ;
228+
229+ setSelectedConnection ( this . workspace ) ;
230+ const event = createKeyDownEvent ( Blockly . utils . KeyCodes . C , [
231+ Blockly . utils . KeyCodes . CTRL ,
232+ ] ) ;
233+ this . injectionDiv . dispatchEvent ( event ) ;
234+ sinon . assert . notCalled ( this . copySpy ) ;
235+ sinon . assert . notCalled ( this . hideChaffSpy ) ;
236+ } ) ;
197237 } ) ;
198238
199239 suite ( 'Undo' , function ( ) {
0 commit comments