@@ -12,6 +12,7 @@ import {
1212 sharedTestSetup ,
1313 sharedTestTeardown ,
1414} from './test_helpers/setup_teardown.js' ;
15+ import { getProperSimpleJson } from './test_helpers/toolbox_definitions.js' ;
1516import { dispatchPointerEvent } from './test_helpers/user_input.js' ;
1617
1718suite ( 'Gesture' , function ( ) {
@@ -54,8 +55,12 @@ suite('Gesture', function () {
5455 setup ( function ( ) {
5556 sharedTestSetup . call ( this ) ;
5657 defineBasicBlockWithField ( ) ;
57- const toolbox = document . getElementById ( 'gesture-test-toolbox' ) ;
58- this . workspace = Blockly . inject ( 'blocklyDiv' , { toolbox : toolbox } ) ;
58+ const toolbox = getProperSimpleJson ( ) ;
59+ toolbox . contents . unshift ( {
60+ 'kind' : 'block' ,
61+ 'type' : 'test_field_block' ,
62+ } ) ;
63+ this . workspace = Blockly . inject ( 'blocklyDiv' , { toolbox} ) ;
5964 } ) ;
6065
6166 teardown ( function ( ) {
@@ -94,4 +99,35 @@ suite('Gesture', function () {
9499 const block = getTopFlyoutBlock ( flyout ) ;
95100 testGestureIsFieldClick ( block , true , this . eventsFireStub ) ;
96101 } ) ;
102+
103+ test ( 'Clicking on shadow block does not select it' , function ( ) {
104+ const flyout = this . workspace . getFlyout ( true ) ;
105+ flyout . createBlock (
106+ flyout . getWorkspace ( ) . getBlocksByType ( 'logic_compare' ) [ 0 ] ,
107+ ) ;
108+ const block = this . workspace . getBlocksByType ( 'logic_compare' ) [ 0 ] ;
109+ const shadowBlock = block . getInput ( 'A' ) . connection . targetBlock ( ) ;
110+
111+ this . eventsFireStub . resetHistory ( ) ;
112+ const eventTarget = shadowBlock . getSvgRoot ( ) ;
113+ dispatchPointerEvent ( eventTarget , 'pointerdown' ) ;
114+ dispatchPointerEvent ( eventTarget , 'pointerup' ) ;
115+ dispatchPointerEvent ( eventTarget , 'click' ) ;
116+
117+ // The shadow block should not be selected, even though it was clicked.
118+ assertEventNotFired (
119+ this . eventsFireStub ,
120+ Blockly . Events . Selected ,
121+ { newElementId : shadowBlock . id , type : EventType . SELECTED } ,
122+ this . workspace . id ,
123+ ) ;
124+
125+ // Its parent block should be selected, however.
126+ assertEventFired (
127+ this . eventsFireStub ,
128+ Blockly . Events . Selected ,
129+ { newElementId : block . id , type : EventType . SELECTED } ,
130+ this . workspace . id ,
131+ ) ;
132+ } ) ;
97133} ) ;
0 commit comments