@@ -194,45 +194,30 @@ suite('Statement move tests', function () {
194194 { id : 'controls_if' , index : 6 , ownIndex : 0 } , // "Else" statement input.
195195 { id : 'controls_if' , index : 1 , ownIndex : 0 } , // Next.
196196 { id : 'p5_draw' , index : 0 , ownIndex : 0 } , // Statement input.
197- { id : 'p5_canvas' , index : 1 , ownIndex : 0 } , // Next; starting location again.
198197 ] ;
199- const EXPECTED_SIMPLE_REVERSED = EXPECTED_SIMPLE . slice ( ) . reverse ( ) ;
198+ /**
199+ * Expected connection candidates when moving BLOCK_SIMPLE after
200+ * pressing left or up arrow n times.
201+ */
202+ const EXPECTED_SIMPLE_REVERSED = EXPECTED_SIMPLE . slice ( 0 , 1 ) . concat (
203+ EXPECTED_SIMPLE . slice ( 1 ) . reverse ( ) ,
204+ ) ;
200205
201206 test (
202207 'Constrained move of simple stack block right' ,
203- moveTest ( BLOCK_SIMPLE , Key . ArrowRight , EXPECTED_SIMPLE , {
204- parentId : 'complex_mover' ,
205- parentIndex : 3 ,
206- nextId : null ,
207- valueId : null ,
208- } ) ,
208+ moveTest ( BLOCK_SIMPLE , Key . ArrowRight , EXPECTED_SIMPLE ) ,
209209 ) ;
210210 test (
211211 'Constrained move of simple stack block left' ,
212- moveTest ( BLOCK_SIMPLE , Key . ArrowLeft , EXPECTED_SIMPLE_REVERSED , {
213- parentId : 'p5_draw' ,
214- parentIndex : 0 ,
215- nextId : null ,
216- valueId : null ,
217- } ) ,
212+ moveTest ( BLOCK_SIMPLE , Key . ArrowLeft , EXPECTED_SIMPLE_REVERSED ) ,
218213 ) ;
219214 test (
220215 'Constrained move of simple stack block down' ,
221- moveTest ( BLOCK_SIMPLE , Key . ArrowDown , EXPECTED_SIMPLE , {
222- parentId : 'complex_mover' ,
223- parentIndex : 3 ,
224- nextId : null ,
225- valueId : null ,
226- } ) ,
216+ moveTest ( BLOCK_SIMPLE , Key . ArrowDown , EXPECTED_SIMPLE ) ,
227217 ) ;
228218 test (
229219 'Constrained move of simple stack block up' ,
230- moveTest ( BLOCK_SIMPLE , Key . ArrowUp , EXPECTED_SIMPLE_REVERSED , {
231- parentId : 'p5_draw' ,
232- parentIndex : 0 ,
233- nextId : null ,
234- valueId : null ,
235- } ) ,
220+ moveTest ( BLOCK_SIMPLE , Key . ArrowUp , EXPECTED_SIMPLE_REVERSED ) ,
236221 ) ;
237222
238223 /** ID of a statement block with multiple statement inputs. */
@@ -261,45 +246,30 @@ suite('Statement move tests', function () {
261246 { id : 'controls_if' , index : 1 , ownIndex : 0 } , // Next.
262247 { id : 'p5_draw' , index : 0 , ownIndex : 0 } , // Statement input.
263248 { id : 'p5_canvas' , index : 1 , ownIndex : 0 } , // Next; starting location again.
264- { id : 'simple_mover' , index : 1 , ownIndex : 0 } , // Next; starting location.
265249 ] ;
266- const EXPECTED_COMPLEX_REVERSED = EXPECTED_COMPLEX . slice ( ) . reverse ( ) ;
250+ /**
251+ * Expected connection candidates when moving BLOCK_COMPLEX after
252+ * pressing left or up arrow n times.
253+ */
254+ const EXPECTED_COMPLEX_REVERSED = EXPECTED_COMPLEX . slice ( 0 , 1 ) . concat (
255+ EXPECTED_COMPLEX . slice ( 1 ) . reverse ( ) ,
256+ ) ;
267257
268258 test (
269259 'Constrained move of complex stack block right' ,
270- moveTest ( BLOCK_COMPLEX , Key . ArrowRight , EXPECTED_COMPLEX , {
271- parentId : null ,
272- parentIndex : null ,
273- nextId : null , // TODO(#702): Should be 'text_print',
274- valueId : null ,
275- } ) ,
260+ moveTest ( BLOCK_COMPLEX , Key . ArrowRight , EXPECTED_COMPLEX ) ,
276261 ) ;
277262 test (
278263 'Constrained move of complex stack block left' ,
279- moveTest ( BLOCK_COMPLEX , Key . ArrowLeft , EXPECTED_COMPLEX_REVERSED , {
280- parentId : 'p5_canvas' ,
281- parentIndex : 1 ,
282- nextId : 'simple_mover' ,
283- valueId : null ,
284- } ) ,
264+ moveTest ( BLOCK_COMPLEX , Key . ArrowLeft , EXPECTED_COMPLEX_REVERSED ) ,
285265 ) ;
286266 test (
287267 'Constrained move of complex stack block down' ,
288- moveTest ( BLOCK_COMPLEX , Key . ArrowDown , EXPECTED_COMPLEX , {
289- parentId : null ,
290- parentIndex : null ,
291- nextId : null , // TODO(#702): Should be 'text_print',
292- valueId : null ,
293- } ) ,
268+ moveTest ( BLOCK_COMPLEX , Key . ArrowDown , EXPECTED_COMPLEX ) ,
294269 ) ;
295270 test (
296271 'Constrained move of complex stack block up' ,
297- moveTest ( BLOCK_COMPLEX , Key . ArrowUp , EXPECTED_COMPLEX_REVERSED , {
298- parentId : 'p5_canvas' ,
299- parentIndex : 1 ,
300- nextId : 'simple_mover' ,
301- valueId : null ,
302- } ) ,
272+ moveTest ( BLOCK_COMPLEX , Key . ArrowUp , EXPECTED_COMPLEX_REVERSED ) ,
303273 ) ;
304274
305275 // When a top-level block with no previous, next or output
@@ -362,26 +332,25 @@ suite('Statement move tests', function () {
362332 * Create a mocha test function moving a specified block in a
363333 * particular direction, checking that it has the the expected
364334 * connection candidate after each step, and that once the move
365- * finishes it is connected as expected.
335+ * finishes that the moving block is reconnected to its initial
336+ * location.
366337 *
367338 * @param mover Block ID of the block to be moved.
368339 * @param key Key to send to move one step.
369340 * @param candidates Array of expected connection candidates.
370- * @param finalInfo Expected final connections when move finished,
371- * as returne d by getFocusedNeighbourInfo.
372341 * @returns function to pass as second argument to mocha's test function.
373342 */
374343function moveTest (
375344 mover : string ,
376345 key : string | string [ ] ,
377346 candidates : Array < { id : string ; index : number } > ,
378- finalInfo : Awaited < ReturnType < typeof getFocusedNeighbourInfo > > ,
379347) {
380348 return async function ( this : Mocha . Context ) {
381349 // Navigate to block to be moved and intiate move.
382350 await focusOnBlock ( this . browser , mover ) ;
351+ const initialInfo = await getFocusedNeighbourInfo ( this . browser ) ;
383352 await sendKeyAndWait ( this . browser , 'm' ) ;
384- // Move to right multiple times, checking connection candidates.
353+ // Press specified key multiple times, checking connection candidates.
385354 for ( let i = 0 ; i < candidates . length ; i ++ ) {
386355 const candidate = await getConnectionCandidate ( this . browser ) ;
387356 chai . assert . deepEqual ( candidate , candidates [ i ] ) ;
@@ -390,8 +359,8 @@ function moveTest(
390359
391360 // Finish move and check final location of moved block.
392361 await sendKeyAndWait ( this . browser , Key . Enter ) ;
393- const info = await getFocusedNeighbourInfo ( this . browser ) ;
394- chai . assert . deepEqual ( info , finalInfo ) ;
362+ const finalInfo = await getFocusedNeighbourInfo ( this . browser ) ;
363+ chai . assert . deepEqual ( initialInfo , finalInfo ) ;
395364 } ;
396365}
397366
0 commit comments