Skip to content

Commit 05ad7d3

Browse files
chore: test asserting broken scroll behaviour
1 parent 9130145 commit 05ad7d3

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as Blockly from 'blockly';
8+
import * as chai from 'chai';
9+
import {Key} from 'webdriverio';
10+
import {
11+
keyDown,
12+
keyRight,
13+
PAUSE_TIME,
14+
tabNavigateToWorkspace,
15+
testFileLocations,
16+
testSetup,
17+
} from './test_setup.js';
18+
19+
suite('Scrolling into view', function () {
20+
// Setting timeout to unlimited as these tests take longer time to run
21+
this.timeout(0);
22+
23+
// Clear the workspace and load start blocks
24+
setup(async function () {
25+
this.browser = await testSetup(testFileLocations.BASE);
26+
// Predictable small window size for scrolling.
27+
this.browser.setWindowSize(800, 600);
28+
await this.browser.pause(PAUSE_TIME);
29+
});
30+
31+
test('Insert scrolls new block into view', async function () {
32+
await tabNavigateToWorkspace(this.browser);
33+
34+
// Separate the two top-level blocks by moving p5_draw_1 further down.
35+
await keyDown(this.browser, 3);
36+
await this.browser.keys('m');
37+
await this.browser.keys([Key.Alt, ...new Array(25).fill(Key.ArrowDown)]);
38+
await this.browser.keys(Key.Enter);
39+
// Scroll back up, leaving cursor on the draw block out of the viewport.
40+
await this.browser.execute(() => {
41+
const workspace = Blockly.getMainWorkspace() as Blockly.WorkspaceSvg;
42+
workspace.scrollBoundsIntoView(
43+
(
44+
workspace.getTopBlocks(true)[0] as Blockly.BlockSvg
45+
).getBoundingRectangleWithoutChildren(),
46+
);
47+
});
48+
49+
// Insert and confirm the test block which should be scrolled into view.
50+
await this.browser.keys('t');
51+
await keyRight(this.browser);
52+
await this.browser.keys(Key.Enter);
53+
await this.browser.keys(Key.Enter);
54+
55+
// Asset new block has been scrolled into the viewport.
56+
const inViewport = await this.browser.execute(() => {
57+
const workspace = Blockly.getMainWorkspace() as Blockly.WorkspaceSvg;
58+
const block = workspace.getBlocksByType(
59+
'controls_if',
60+
)[0] as Blockly.BlockSvg;
61+
const blockBounds = block.getBoundingRectangleWithoutChildren();
62+
const rawViewport = workspace.getMetricsManager().getViewMetrics(true);
63+
const viewport = new Blockly.utils.Rect(
64+
rawViewport.top,
65+
rawViewport.top + rawViewport.height,
66+
rawViewport.left,
67+
rawViewport.left + rawViewport.width,
68+
);
69+
return viewport.contains(blockBounds.left, blockBounds.top);
70+
});
71+
// FIXME: actually scrolls the wrong bounds into view
72+
chai.assert.isFalse(inViewport);
73+
});
74+
});

0 commit comments

Comments
 (0)