From 3e04bdfb0b406301231483cd5d064b7c4bfd6a9b Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Thu, 28 Aug 2025 12:14:16 +0100 Subject: [PATCH 1/3] fix(tests): Suppress tsc unintentional comparison error When PAUSE_TIME is set to a value other than 0 the comparison in sendKeyAndWait generates a TS unintentionl comparison error. --- test/webdriverio/test/test_setup.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/webdriverio/test/test_setup.ts b/test/webdriverio/test/test_setup.ts index 783270ad..d4141ff1 100644 --- a/test/webdriverio/test/test_setup.ts +++ b/test/webdriverio/test/test_setup.ts @@ -558,6 +558,7 @@ export async function sendKeyAndWait( keys: string | string[], times = 1, ) { + // @ts-ignore: Unintentional comparison error if (PAUSE_TIME === 0) { // Send all keys in one call if no pauses needed. keys = Array(times).fill(keys).flat(); From c375c3524f83a425d18fe55f4e0c61988a2fef6c Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Thu, 28 Aug 2025 12:29:29 +0100 Subject: [PATCH 2/3] refactor(tests): Simplify moveTest Simplify moveTest (and the tests that use it) by assuming that the move always finishes in the same location it started in. We will leave testing various move end scenarios (e.g. healing) for a separate suite of move-finishing tests, akin to existing move start tests. --- test/webdriverio/test/move_test.ts | 87 ++++++++++-------------------- 1 file changed, 28 insertions(+), 59 deletions(-) diff --git a/test/webdriverio/test/move_test.ts b/test/webdriverio/test/move_test.ts index 94db43ae..49d7db51 100644 --- a/test/webdriverio/test/move_test.ts +++ b/test/webdriverio/test/move_test.ts @@ -194,45 +194,30 @@ suite('Statement move tests', function () { {id: 'controls_if', index: 6, ownIndex: 0}, // "Else" statement input. {id: 'controls_if', index: 1, ownIndex: 0}, // Next. {id: 'p5_draw', index: 0, ownIndex: 0}, // Statement input. - {id: 'p5_canvas', index: 1, ownIndex: 0}, // Next; starting location again. ]; - const EXPECTED_SIMPLE_REVERSED = EXPECTED_SIMPLE.slice().reverse(); + /** + * Expected connection candidates when moving BLOCK_SIMPLE after + * pressing left or up arrow n times. + */ + const EXPECTED_SIMPLE_REVERSED = EXPECTED_SIMPLE.slice(0, 1).concat( + EXPECTED_SIMPLE.slice(1).reverse(), + ); test( 'Constrained move of simple stack block right', - moveTest(BLOCK_SIMPLE, Key.ArrowRight, EXPECTED_SIMPLE, { - parentId: 'complex_mover', - parentIndex: 3, - nextId: null, - valueId: null, - }), + moveTest(BLOCK_SIMPLE, Key.ArrowRight, EXPECTED_SIMPLE), ); test( 'Constrained move of simple stack block left', - moveTest(BLOCK_SIMPLE, Key.ArrowLeft, EXPECTED_SIMPLE_REVERSED, { - parentId: 'p5_draw', - parentIndex: 0, - nextId: null, - valueId: null, - }), + moveTest(BLOCK_SIMPLE, Key.ArrowLeft, EXPECTED_SIMPLE_REVERSED), ); test( 'Constrained move of simple stack block down', - moveTest(BLOCK_SIMPLE, Key.ArrowDown, EXPECTED_SIMPLE, { - parentId: 'complex_mover', - parentIndex: 3, - nextId: null, - valueId: null, - }), + moveTest(BLOCK_SIMPLE, Key.ArrowDown, EXPECTED_SIMPLE), ); test( 'Constrained move of simple stack block up', - moveTest(BLOCK_SIMPLE, Key.ArrowUp, EXPECTED_SIMPLE_REVERSED, { - parentId: 'p5_draw', - parentIndex: 0, - nextId: null, - valueId: null, - }), + moveTest(BLOCK_SIMPLE, Key.ArrowUp, EXPECTED_SIMPLE_REVERSED), ); /** ID of a statement block with multiple statement inputs. */ @@ -261,45 +246,30 @@ suite('Statement move tests', function () { {id: 'controls_if', index: 1, ownIndex: 0}, // Next. {id: 'p5_draw', index: 0, ownIndex: 0}, // Statement input. {id: 'p5_canvas', index: 1, ownIndex: 0}, // Next; starting location again. - {id: 'simple_mover', index: 1, ownIndex: 0}, // Next; starting location. ]; - const EXPECTED_COMPLEX_REVERSED = EXPECTED_COMPLEX.slice().reverse(); + /** + * Expected connection candidates when moving BLOCK_COMPLEX after + * pressing left or up arrow n times. + */ + const EXPECTED_COMPLEX_REVERSED = EXPECTED_COMPLEX.slice(0, 1).concat( + EXPECTED_COMPLEX.slice(1).reverse(), + ); test( 'Constrained move of complex stack block right', - moveTest(BLOCK_COMPLEX, Key.ArrowRight, EXPECTED_COMPLEX, { - parentId: null, - parentIndex: null, - nextId: null, // TODO(#702): Should be 'text_print', - valueId: null, - }), + moveTest(BLOCK_COMPLEX, Key.ArrowRight, EXPECTED_COMPLEX), ); test( 'Constrained move of complex stack block left', - moveTest(BLOCK_COMPLEX, Key.ArrowLeft, EXPECTED_COMPLEX_REVERSED, { - parentId: 'p5_canvas', - parentIndex: 1, - nextId: 'simple_mover', - valueId: null, - }), + moveTest(BLOCK_COMPLEX, Key.ArrowLeft, EXPECTED_COMPLEX_REVERSED), ); test( 'Constrained move of complex stack block down', - moveTest(BLOCK_COMPLEX, Key.ArrowDown, EXPECTED_COMPLEX, { - parentId: null, - parentIndex: null, - nextId: null, // TODO(#702): Should be 'text_print', - valueId: null, - }), + moveTest(BLOCK_COMPLEX, Key.ArrowDown, EXPECTED_COMPLEX), ); test( 'Constrained move of complex stack block up', - moveTest(BLOCK_COMPLEX, Key.ArrowUp, EXPECTED_COMPLEX_REVERSED, { - parentId: 'p5_canvas', - parentIndex: 1, - nextId: 'simple_mover', - valueId: null, - }), + moveTest(BLOCK_COMPLEX, Key.ArrowUp, EXPECTED_COMPLEX_REVERSED), ); // When a top-level block with no previous, next or output @@ -362,26 +332,25 @@ suite('Statement move tests', function () { * Create a mocha test function moving a specified block in a * particular direction, checking that it has the the expected * connection candidate after each step, and that once the move - * finishes it is connected as expected. + * finishes that the moving block is reconnected to its initial + * location. * * @param mover Block ID of the block to be moved. * @param key Key to send to move one step. * @param candidates Array of expected connection candidates. - * @param finalInfo Expected final connections when move finished, - * as returne d by getFocusedNeighbourInfo. * @returns function to pass as second argument to mocha's test function. */ function moveTest( mover: string, key: string | string[], candidates: Array<{id: string; index: number}>, - finalInfo: Awaited>, ) { return async function (this: Mocha.Context) { // Navigate to block to be moved and intiate move. await focusOnBlock(this.browser, mover); + const initialInfo = await getFocusedNeighbourInfo(this.browser); await sendKeyAndWait(this.browser, 'm'); - // Move to right multiple times, checking connection candidates. + // Press specified key multiple times, checking connection candidates. for (let i = 0; i < candidates.length; i++) { const candidate = await getConnectionCandidate(this.browser); chai.assert.deepEqual(candidate, candidates[i]); @@ -390,8 +359,8 @@ function moveTest( // Finish move and check final location of moved block. await sendKeyAndWait(this.browser, Key.Enter); - const info = await getFocusedNeighbourInfo(this.browser); - chai.assert.deepEqual(info, finalInfo); + const finalInfo = await getFocusedNeighbourInfo(this.browser); + chai.assert.deepEqual(initialInfo, finalInfo); }; } From 62de3b6a1ddfbc9ef0f3685098978c1a0acf749c Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Fri, 29 Aug 2025 12:02:09 +0100 Subject: [PATCH 3/3] fix(tests): eslint-disable to ignore @ts-igonre --- test/webdriverio/test/test_setup.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/webdriverio/test/test_setup.ts b/test/webdriverio/test/test_setup.ts index d4141ff1..016b3bfd 100644 --- a/test/webdriverio/test/test_setup.ts +++ b/test/webdriverio/test/test_setup.ts @@ -558,6 +558,7 @@ export async function sendKeyAndWait( keys: string | string[], times = 1, ) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore: Unintentional comparison error if (PAUSE_TIME === 0) { // Send all keys in one call if no pauses needed.