55 */
66
77import * as chai from 'chai' ;
8+ import * as Blockly from 'blockly' ;
89import { Key } from 'webdriverio' ;
910import {
1011 getFocusedBlockType ,
@@ -16,6 +17,7 @@ import {
1617 testSetup ,
1718 sendKeyAndWait ,
1819 keyRight ,
20+ keyDown ,
1921 getCurrentFocusedBlockId ,
2022 blockIsPresent ,
2123 keyUp ,
@@ -103,4 +105,81 @@ suite('Insert test', function () {
103105 await getFocusedBlockType ( this . browser ) ,
104106 ) ;
105107 } ) ;
108+
109+ test ( 'Does not insert between immovable blocks' , async function ( ) {
110+ // Focus the create canvas block; we want to ensure that the newly
111+ // inserted block is not attached to its next connection, because doing
112+ // so would splice it into an immovable stack.
113+ await focusOnBlock ( this . browser , 'create_canvas_1' ) ;
114+ await this . browser . execute ( ( ) => {
115+ Blockly . getMainWorkspace ( )
116+ . getAllBlocks ( )
117+ . forEach ( ( b ) => b . setMovable ( false ) ) ;
118+ } ) ;
119+ await tabNavigateToToolbox ( this . browser ) ;
120+
121+ // Insert 'if' block
122+ await keyRight ( this . browser ) ;
123+ // Choose.
124+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
125+ // Confirm position.
126+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
127+
128+ // Assert inserted inside first block p5_setup not at top-level.
129+ chai . assert . equal ( 'controls_if' , await getFocusedBlockType ( this . browser ) ) ;
130+ await keyUp ( this . browser ) ;
131+ chai . assert . equal (
132+ 'p5_background_color' ,
133+ await getFocusedBlockType ( this . browser ) ,
134+ ) ;
135+ } ) ;
136+ } ) ;
137+
138+ suite ( 'Insert test with more blocks' , function ( ) {
139+ // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run.
140+ if ( PAUSE_TIME ) this . timeout ( 0 ) ;
141+
142+ // Clear the workspace and load start blocks.
143+ setup ( async function ( ) {
144+ this . browser = await testSetup (
145+ testFileLocations . MORE_BLOCKS ,
146+ this . timeout ( ) ,
147+ ) ;
148+ await this . browser . pause ( PAUSE_TIME ) ;
149+ } ) ;
150+
151+ test ( 'Does not bump immovable input blocks on insert' , async function ( ) {
152+ // Focus the print block with a connected input block. Ordinarily, inserting
153+ // an input block would connect it to this block and bump its child, but
154+ // if all blocks are immovable the connected input block should not move
155+ // and the newly inserted block should be added as a top-level block on the
156+ // workspace.
157+ await focusOnBlock ( this . browser , 'text_print_2' ) ;
158+ await this . browser . execute ( ( ) => {
159+ Blockly . getMainWorkspace ( )
160+ . getAllBlocks ( )
161+ . forEach ( ( b ) => b . setMovable ( false ) ) ;
162+ } ) ;
163+ await tabNavigateToToolbox ( this . browser ) ;
164+
165+ // Insert number block
166+ await keyDown ( this . browser , 2 ) ;
167+ await keyRight ( this . browser ) ;
168+ // Choose.
169+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
170+ // Confirm position.
171+ await sendKeyAndWait ( this . browser , Key . Enter ) ;
172+
173+ // Assert inserted at the top-level due to immovable block occupying the
174+ // selected block's input.
175+ chai . assert . equal ( 'math_number' , await getFocusedBlockType ( this . browser ) ) ;
176+ const focusedBlockIsParentless = await this . browser . execute ( ( ) => {
177+ const focusedNode = Blockly . getFocusManager ( ) . getFocusedNode ( ) ;
178+ return (
179+ focusedNode instanceof Blockly . BlockSvg &&
180+ focusedNode . getParent ( ) === null
181+ ) ;
182+ } ) ;
183+ chai . assert . isTrue ( focusedBlockIsParentless ) ;
184+ } ) ;
106185} ) ;
0 commit comments