Skip to content

Commit 4f7c61f

Browse files
test: test workspace ring styles (#667)
Covers each of the different selectors we use to style the workspace rings. Fixes #645
1 parent d9d35f9 commit 4f7c61f

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {Key} from 'webdriverio';
8+
import {
9+
focusOnBlock,
10+
keyDown,
11+
keyRight,
12+
PAUSE_TIME,
13+
sendKeyAndWait,
14+
tabNavigateToWorkspace,
15+
testFileLocations,
16+
testSetup,
17+
} from './test_setup.js';
18+
import * as chai from 'chai';
19+
20+
suite('Styling test', function () {
21+
// Setting timeout to unlimited as these tests take longer time to run
22+
this.timeout(0);
23+
24+
// Clear the workspace and load start blocks
25+
setup(async function () {
26+
this.browser = await testSetup(testFileLocations.BASE);
27+
await this.browser.pause(PAUSE_TIME);
28+
});
29+
30+
async function strokeColorEquals(
31+
browser: WebdriverIO.Browser,
32+
selector: string,
33+
color: string,
34+
): Promise<boolean> {
35+
const stroke = (await browser.$(selector).getCSSProperty('stroke')).value;
36+
chai.assert.include(['none', color], stroke);
37+
return stroke === color;
38+
}
39+
40+
async function workspaceHasActiveTreeStyle(
41+
browser: WebdriverIO.Browser,
42+
): Promise<boolean> {
43+
return strokeColorEquals(
44+
browser,
45+
'.blocklyWorkspaceFocusRing',
46+
'rgb(96,165,250)',
47+
);
48+
}
49+
50+
async function workspaceHasActiveNodeStyle(
51+
browser: WebdriverIO.Browser,
52+
): Promise<boolean> {
53+
return strokeColorEquals(
54+
browser,
55+
'.blocklyWorkspaceSelectionRing',
56+
'rgb(255,242,0)',
57+
);
58+
}
59+
60+
test('Workspace has no ring styles when not focused', async function () {
61+
chai.assert.isFalse(await workspaceHasActiveTreeStyle(this.browser));
62+
chai.assert.isFalse(await workspaceHasActiveNodeStyle(this.browser));
63+
});
64+
65+
test('Workspace has only active tree style when block selected', async function () {
66+
await tabNavigateToWorkspace(this.browser);
67+
chai.assert.isFalse(await workspaceHasActiveTreeStyle(this.browser));
68+
// Trigger keyboard mode.
69+
await keyDown(this.browser);
70+
71+
chai.assert.isTrue(await workspaceHasActiveTreeStyle(this.browser));
72+
chai.assert.isFalse(await workspaceHasActiveNodeStyle(this.browser));
73+
});
74+
75+
test('Workspace has active tree and active node style when workspace selected', async function () {
76+
await tabNavigateToWorkspace(this.browser);
77+
await sendKeyAndWait(this.browser, 'w');
78+
79+
chai.assert.isTrue(await workspaceHasActiveTreeStyle(this.browser));
80+
chai.assert.isTrue(await workspaceHasActiveNodeStyle(this.browser));
81+
});
82+
83+
test('Workspace has only active tree style when move is in progress', async function () {
84+
await tabNavigateToWorkspace(this.browser);
85+
await focusOnBlock(this.browser, 'set_background_color_1');
86+
// Moves block to drag layer which requires different selectors.
87+
await sendKeyAndWait(this.browser, 'm');
88+
89+
chai.assert.isTrue(await workspaceHasActiveTreeStyle(this.browser));
90+
chai.assert.isFalse(await workspaceHasActiveNodeStyle(this.browser));
91+
});
92+
93+
test('Workspace has only active tree style when widget has focus', async function () {
94+
await tabNavigateToWorkspace(this.browser);
95+
await focusOnBlock(this.browser, 'create_canvas_1');
96+
// Move to field.
97+
await keyRight(this.browser);
98+
// Enter moves focus to the widget div.
99+
await sendKeyAndWait(this.browser, Key.Enter);
100+
101+
chai.assert.isTrue(await workspaceHasActiveTreeStyle(this.browser));
102+
chai.assert.isFalse(await workspaceHasActiveNodeStyle(this.browser));
103+
});
104+
105+
test('Workspace has only active tree style when dropdown has focus', async function () {
106+
await tabNavigateToWorkspace(this.browser);
107+
await focusOnBlock(this.browser, 'set_background_color_1');
108+
// Move to color block.
109+
await keyRight(this.browser);
110+
// Enter moves focus to the dropdown div.
111+
await sendKeyAndWait(this.browser, Key.Enter);
112+
113+
chai.assert.isTrue(await workspaceHasActiveTreeStyle(this.browser));
114+
chai.assert.isFalse(await workspaceHasActiveNodeStyle(this.browser));
115+
});
116+
});

0 commit comments

Comments
 (0)