Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 28 additions & 59 deletions test/webdriverio/test/move_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ReturnType<typeof getFocusedNeighbourInfo>>,
) {
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]);
Expand All @@ -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);
};
}

Expand Down
1 change: 1 addition & 0 deletions test/webdriverio/test/test_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
keys: string | string[],
times = 1,
) {
// @ts-ignore: Unintentional comparison error

Check failure on line 561 in test/webdriverio/test/test_setup.ts

View workflow job for this annotation

GitHub Actions / Eslint check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
if (PAUSE_TIME === 0) {
// Send all keys in one call if no pauses needed.
keys = Array(times).fill(keys).flat();
Expand Down
Loading