Skip to content

Commit 7ba2c1e

Browse files
committed
Fix: Fix tests broken by changes to block positions
1 parent d3575fa commit 7ba2c1e

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-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: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
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,} from './test_setup.js';
15+
import {Key, ClickOptions,} from 'webdriverio';
1116

1217
suite('Keyboard navigation', function () {
1318
// Setting timeout to unlimited as these tests take a longer time to run than most mocha test
@@ -27,13 +32,11 @@ suite('Keyboard navigation', function () {
2732
});
2833

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

36-
for (let i = 0; i < 9; i++) {
39+
for (let i = 0; i < 8; i++) {
3740
await this.browser.keys(Key.ArrowDown);
3841
await this.browser.pause(PAUSE_TIME);
3942
}

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,11 @@ 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(block.getBoundingRectangleWithoutChildren());
206209
for (const input of block.inputList) {
207210
for (const field of input.fieldRow) {
208211
if (field instanceof Blockly.FieldLabel) {
@@ -214,9 +217,9 @@ export async function clickBlock(
214217
}
215218
}
216219
}
220+
// No label field found. Fall back to the block's SVG root.
221+
block.getSvgRoot().id = findableId;
217222
}
218-
// No label field found. Fall back to the block's SVG root.
219-
(block as Blockly.BlockSvg).getSvgRoot().id = findableId;
220223
},
221224
block.id,
222225
findableId,

0 commit comments

Comments
 (0)