Skip to content

Commit 8f193b5

Browse files
committed
chore: Added context menu item tests.
1 parent d9d35f9 commit 8f193b5

File tree

3 files changed

+139
-6
lines changed

3 files changed

+139
-6
lines changed

test/webdriverio/test/actions_test.ts

Lines changed: 123 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import * as chai from 'chai';
88
import {Key} from 'webdriverio';
99
import {
10+
clickBlock,
1011
contextMenuExists,
1112
moveToToolboxCategory,
1213
PAUSE_TIME,
1314
focusOnBlock,
15+
focusWorkspace,
16+
rightClickOnFlyoutBlockType,
1417
tabNavigateToWorkspace,
1518
testFileLocations,
1619
testSetup,
@@ -28,7 +31,7 @@ suite('Menus test', function () {
2831
await this.browser.pause(PAUSE_TIME);
2932
});
3033

31-
test('Menu on block', async function () {
34+
test('Menu action via keyboard on block opens menu', async function () {
3235
// Navigate to draw_circle_1.
3336
await tabNavigateToWorkspace(this.browser);
3437
await focusOnBlock(this.browser, 'draw_circle_1');
@@ -37,6 +40,7 @@ suite('Menus test', function () {
3740
await this.browser.pause(PAUSE_TIME);
3841

3942
chai.assert.deepEqual(
43+
await contextMenuItems(this.browser),
4044
process.platform === 'darwin'
4145
? [
4246
{'text': 'Duplicate D'},
@@ -64,14 +68,75 @@ suite('Menus test', function () {
6468
{'text': 'Copy Ctrl + C'},
6569
{'disabled': true, 'text': 'Paste Ctrl + V'},
6670
],
71+
);
72+
});
73+
74+
test('Block menu via mouse displays expected items', async function () {
75+
await tabNavigateToWorkspace(this.browser);
76+
await clickBlock(this.browser, 'draw_circle_1', {button: 'right'});
77+
78+
chai.assert.deepEqual(
6779
await contextMenuItems(this.browser),
80+
process.platform === 'darwin'
81+
? [
82+
{'text': 'Duplicate D'},
83+
{'text': 'Add Comment'},
84+
{'text': 'External Inputs'},
85+
{'text': 'Collapse Block'},
86+
{'text': 'Disable Block'},
87+
{'text': 'Delete 2 Blocks Delete'},
88+
{'text': 'Cut ⌘ X'},
89+
{'text': 'Copy ⌘ C'},
90+
{'disabled': true, 'text': 'Paste ⌘ V'},
91+
]
92+
: [
93+
{'text': 'Duplicate D'},
94+
{'text': 'Add Comment'},
95+
{'text': 'External Inputs'},
96+
{'text': 'Collapse Block'},
97+
{'text': 'Disable Block'},
98+
{'text': 'Delete 2 Blocks Delete'},
99+
{'text': 'Cut Ctrl + X'},
100+
{'text': 'Copy Ctrl + C'},
101+
{'disabled': true, 'text': 'Paste Ctrl + V'},
102+
],
68103
);
69104
});
70105

71-
test('Menu on block in the toolbox', async function () {
72-
// Navigate to draw_circle_1.
106+
test('Shadow block menu via keyboard displays expected items', async function () {
107+
await tabNavigateToWorkspace(this.browser);
108+
await focusOnBlock(this.browser, 'draw_circle_1_color');
109+
await this.browser.keys([Key.Ctrl, Key.Return]);
110+
await this.browser.pause(PAUSE_TIME);
111+
112+
chai.assert.deepEqual(
113+
await contextMenuItems(this.browser),
114+
process.platform === 'darwin'
115+
? [
116+
{'text': 'Add Comment'},
117+
{'text': 'Collapse Block'},
118+
{'text': 'Disable Block'},
119+
{'text': 'Help'},
120+
{'text': 'Move Block M'},
121+
{'disabled': true, 'text': 'Cut ⌘ X'},
122+
{'text': 'Copy ⌘ C'},
123+
{'disabled': true, 'text': 'Paste ⌘ V'},
124+
]
125+
: [
126+
{'text': 'Add Comment'},
127+
{'text': 'Collapse Block'},
128+
{'text': 'Disable Block'},
129+
{'text': 'Help'},
130+
{'text': 'Move Block M'},
131+
{'disabled': true, 'text': 'Cut Ctrl + X'},
132+
{'text': 'Copy Ctrl + C'},
133+
{'disabled': true, 'text': 'Paste Ctrl + V'},
134+
],
135+
);
136+
});
137+
138+
test('Menu action on block in the toolbox', async function () {
73139
await tabNavigateToWorkspace(this.browser);
74-
await focusOnBlock(this.browser, 'draw_circle_1');
75140
// Navigate to a toolbox category
76141
await moveToToolboxCategory(this.browser, 'Functions');
77142
// Move to flyout.
@@ -97,6 +162,32 @@ suite('Menus test', function () {
97162
);
98163
});
99164

165+
test('Flyout block menu via mouse displays expected items', async function () {
166+
await tabNavigateToWorkspace(this.browser);
167+
// Navigate to a toolbox category
168+
await moveToToolboxCategory(this.browser, 'Math');
169+
// Move to flyout.
170+
await keyRight(this.browser);
171+
await this.browser.pause(PAUSE_TIME);
172+
await rightClickOnFlyoutBlockType(this.browser, 'math_number');
173+
await this.browser.pause(PAUSE_TIME);
174+
175+
chai.assert.deepEqual(
176+
process.platform === 'darwin'
177+
? [
178+
{'text': 'Help'},
179+
{'disabled': true, 'text': 'Cut ⌘ X'},
180+
{'text': 'Copy ⌘ C'},
181+
]
182+
: [
183+
{'text': 'Help'},
184+
{'disabled': true, 'text': 'Cut Ctrl + X'},
185+
{'text': 'Copy Ctrl + C'},
186+
],
187+
await contextMenuItems(this.browser),
188+
);
189+
});
190+
100191
test('Menu on workspace', async function () {
101192
// Navigate to draw_circle_1.
102193
await tabNavigateToWorkspace(this.browser);
@@ -143,4 +234,32 @@ suite('Menus test', function () {
143234
'The menu should not be openable during a move',
144235
);
145236
});
237+
238+
test('Escape key dismisses menu', async function () {
239+
await tabNavigateToWorkspace(this.browser);
240+
await focusOnBlock(this.browser, 'draw_circle_1');
241+
await this.browser.pause(PAUSE_TIME);
242+
await this.browser.keys([Key.Ctrl, Key.Return]);
243+
await this.browser.pause(PAUSE_TIME);
244+
await this.browser.keys(Key.Escape);
245+
await this.browser.pause(PAUSE_TIME);
246+
247+
chai.assert.isTrue(
248+
await contextMenuExists(this.browser, 'Duplicate', /* reverse= */ true),
249+
'The menu should be closed',
250+
);
251+
});
252+
253+
test('Clicking workspace dismisses menu', async function () {
254+
await tabNavigateToWorkspace(this.browser);
255+
await clickBlock(this.browser, 'draw_circle_1', {button: 'right'});
256+
await this.browser.pause(PAUSE_TIME);
257+
await focusWorkspace(this.browser);
258+
await this.browser.pause(PAUSE_TIME);
259+
260+
chai.assert.isTrue(
261+
await contextMenuExists(this.browser, 'Duplicate', /* reverse= */ true),
262+
'The menu should be closed',
263+
);
264+
});
146265
});

test/webdriverio/test/keyboard_mode_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ suite(
126126

127127
await this.browser.pause(PAUSE_TIME);
128128
// Right click a block
129-
clickBlock(this.browser, 'controls_if_1', {button: 'right'});
129+
await clickBlock(this.browser, 'controls_if_1', {button: 'right'});
130130
await this.browser.pause(PAUSE_TIME);
131131

132132
chai.assert.isFalse(await isKeyboardNavigating(this.browser));

test/webdriverio/test/test_setup.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ export async function isDragging(
552552
}
553553

554554
/**
555-
* Returns the result of the specificied action precondition.
555+
* Returns the result of the specified action precondition.
556556
*
557557
* @param browser The active WebdriverIO Browser object.
558558
* @param action The action to check the precondition for.
@@ -689,3 +689,17 @@ export async function clickBlock(
689689
document.getElementById(elemId)?.removeAttribute('id');
690690
}, findableId);
691691
}
692+
693+
/**
694+
* Right-clicks on a block with the provided type in the flyout.
695+
*
696+
* @param browser The active WebdriverIO Browser object.
697+
* @param blockType The name of the type block to right click on.
698+
*/
699+
export async function rightClickOnFlyoutBlockType(
700+
browser: WebdriverIO.Browser,
701+
blockType: string,
702+
) {
703+
const elem = await browser.$(`.blocklyFlyout .${blockType}`);
704+
await elem.click({button: 'right'});
705+
}

0 commit comments

Comments
 (0)