Skip to content

Commit 548bd11

Browse files
authored
Fix: Fix tests broken by changes to block positions (#470)
* Fix: Fix tests broken by changes to block positions * Formatting cleanup
1 parent 1448451 commit 548bd11

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

test/loadTestBlocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const simpleCircle = {
182182
'blocks': [
183183
{
184184
'type': 'p5_setup',
185-
'id': '5.{;T}3Qv}Awi:1M$:ut',
185+
'id': 'p5_setup_1',
186186
'x': 0,
187187
'y': 75,
188188
'deletable': false,

test/webdriverio/test/basic_test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66

77
import * as chai from 'chai';
88
import * as Blockly from 'blockly';
9-
import {testSetup, testFileLocations, PAUSE_TIME} from './test_setup.js';
10-
import {Key} from 'webdriverio';
9+
import {
10+
testSetup,
11+
testFileLocations,
12+
PAUSE_TIME,
13+
getBlockElementById,
14+
clickBlock,
15+
} from './test_setup.js';
16+
import {Key, ClickOptions} from 'webdriverio';
1117

1218
suite('Keyboard navigation', function () {
1319
// Setting timeout to unlimited as these tests take a longer time to run than most mocha test
@@ -27,13 +33,11 @@ suite('Keyboard navigation', function () {
2733
});
2834

2935
test('Selected block', async function () {
30-
const workspace = await this.browser.$(
31-
'#blocklyDiv > div > svg.blocklySvg > g',
32-
);
33-
await workspace.click();
36+
const block = await getBlockElementById(this.browser, 'p5_setup_1');
37+
await clickBlock(this.browser, block, {button: 0} as ClickOptions);
3438
await this.browser.pause(PAUSE_TIME);
3539

36-
for (let i = 0; i < 9; i++) {
40+
for (let i = 0; i < 8; i++) {
3741
await this.browser.keys(Key.ArrowDown);
3842
await this.browser.pause(PAUSE_TIME);
3943
}

test/webdriverio/test/clipboard_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ suite('Clipboard test', function () {
3535

3636
test('Copy and paste while block selected', async function () {
3737
const block = await getBlockElementById(this.browser, 'draw_circle_1');
38-
await clickBlock(this.browser, block, {button: 1} as ClickOptions);
38+
await clickBlock(this.browser, block, {button: 0} as ClickOptions);
3939

4040
// Copy and paste
4141
await this.browser.keys([Key.Ctrl, 'c']);
@@ -55,7 +55,7 @@ suite('Clipboard test', function () {
5555

5656
test('Cut and paste while block selected', async function () {
5757
const block = await getBlockElementById(this.browser, 'draw_circle_1');
58-
await clickBlock(this.browser, block, {button: 1} as ClickOptions);
58+
await clickBlock(this.browser, block, {button: 0} as ClickOptions);
5959

6060
// Cut and paste
6161
await this.browser.keys([Key.Ctrl, 'x']);

test/webdriverio/test/test_setup.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,13 @@ export async function clickBlock(
201201
// In the browser context, find the element that we want and give it a findable ID.
202202
await browser.execute(
203203
(blockId, newElemId) => {
204-
const block = Blockly.getMainWorkspace().getBlockById(blockId);
204+
const workspaceSvg = Blockly.getMainWorkspace() as Blockly.WorkspaceSvg;
205+
const block = workspaceSvg.getBlockById(blockId);
205206
if (block) {
207+
// Ensure the block we want to click is within the viewport.
208+
workspaceSvg.scrollBoundsIntoView(
209+
block.getBoundingRectangleWithoutChildren(),
210+
);
206211
for (const input of block.inputList) {
207212
for (const field of input.fieldRow) {
208213
if (field instanceof Blockly.FieldLabel) {
@@ -214,9 +219,9 @@ export async function clickBlock(
214219
}
215220
}
216221
}
222+
// No label field found. Fall back to the block's SVG root.
223+
block.getSvgRoot().id = findableId;
217224
}
218-
// No label field found. Fall back to the block's SVG root.
219-
(block as Blockly.BlockSvg).getSvgRoot().id = findableId;
220225
},
221226
block.id,
222227
findableId,

0 commit comments

Comments
 (0)