Skip to content

Commit d5e67fc

Browse files
committed
chore: Added context menu item tests.
1 parent 7991855 commit d5e67fc

File tree

2 files changed

+139
-5
lines changed

2 files changed

+139
-5
lines changed

test/webdriverio/test/actions_test.ts

Lines changed: 124 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,
@@ -34,13 +37,14 @@ suite('Menus test', function () {
3437
await this.browser.pause(PAUSE_TIME);
3538
});
3639

37-
test('Menu on block', async function () {
40+
test('Menu action via keyboard on block opens menu', async function () {
3841
// Navigate to draw_circle_1.
3942
await focusOnBlock(this.browser, 'draw_circle_1');
4043
await this.browser.pause(PAUSE_TIME);
4144
await sendKeyAndWait(this.browser, [Key.Ctrl, Key.Return]);
4245

4346
chai.assert.deepEqual(
47+
await contextMenuItems(this.browser),
4448
process.platform === 'darwin'
4549
? [
4650
{'text': 'Duplicate D'},
@@ -68,13 +72,75 @@ suite('Menus test', function () {
6872
{'text': 'Copy Ctrl + C'},
6973
{'disabled': true, 'text': 'Paste Ctrl + V'},
7074
],
75+
);
76+
});
77+
78+
test('Block menu via mouse displays expected items', async function () {
79+
await tabNavigateToWorkspace(this.browser);
80+
await clickBlock(this.browser, 'draw_circle_1', {button: 'right'});
81+
82+
chai.assert.deepEqual(
7183
await contextMenuItems(this.browser),
84+
process.platform === 'darwin'
85+
? [
86+
{'text': 'Duplicate D'},
87+
{'text': 'Add Comment'},
88+
{'text': 'External Inputs'},
89+
{'text': 'Collapse Block'},
90+
{'text': 'Disable Block'},
91+
{'text': 'Delete 2 Blocks Delete'},
92+
{'text': 'Cut ⌘ X'},
93+
{'text': 'Copy ⌘ C'},
94+
{'disabled': true, 'text': 'Paste ⌘ V'},
95+
]
96+
: [
97+
{'text': 'Duplicate D'},
98+
{'text': 'Add Comment'},
99+
{'text': 'External Inputs'},
100+
{'text': 'Collapse Block'},
101+
{'text': 'Disable Block'},
102+
{'text': 'Delete 2 Blocks Delete'},
103+
{'text': 'Cut Ctrl + X'},
104+
{'text': 'Copy Ctrl + C'},
105+
{'disabled': true, 'text': 'Paste Ctrl + V'},
106+
],
72107
);
73108
});
74109

75-
test('Menu on block in the toolbox', async function () {
76-
// Navigate to draw_circle_1.
77-
await focusOnBlock(this.browser, 'draw_circle_1');
110+
test('Shadow block menu via keyboard displays expected items', async function () {
111+
await tabNavigateToWorkspace(this.browser);
112+
await focusOnBlock(this.browser, 'draw_circle_1_color');
113+
await this.browser.keys([Key.Ctrl, Key.Return]);
114+
await this.browser.pause(PAUSE_TIME);
115+
116+
chai.assert.deepEqual(
117+
await contextMenuItems(this.browser),
118+
process.platform === 'darwin'
119+
? [
120+
{'text': 'Add Comment'},
121+
{'text': 'Collapse Block'},
122+
{'text': 'Disable Block'},
123+
{'text': 'Help'},
124+
{'text': 'Move Block M'},
125+
{'disabled': true, 'text': 'Cut ⌘ X'},
126+
{'text': 'Copy ⌘ C'},
127+
{'disabled': true, 'text': 'Paste ⌘ V'},
128+
]
129+
: [
130+
{'text': 'Add Comment'},
131+
{'text': 'Collapse Block'},
132+
{'text': 'Disable Block'},
133+
{'text': 'Help'},
134+
{'text': 'Move Block M'},
135+
{'disabled': true, 'text': 'Cut Ctrl + X'},
136+
{'text': 'Copy Ctrl + C'},
137+
{'disabled': true, 'text': 'Paste Ctrl + V'},
138+
],
139+
);
140+
});
141+
142+
test('Menu action on block in the toolbox', async function () {
143+
await tabNavigateToWorkspace(this.browser);
78144
// Navigate to a toolbox category
79145
await moveToToolboxCategory(this.browser, 'Functions');
80146
// Move to flyout.
@@ -99,6 +165,32 @@ suite('Menus test', function () {
99165
);
100166
});
101167

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

test/webdriverio/test/test_setup.ts

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

575575
/**
576-
* Returns the result of the specificied action precondition.
576+
* Returns the result of the specified action precondition.
577577
*
578578
* @param browser The active WebdriverIO Browser object.
579579
* @param action The action to check the precondition for.
@@ -710,3 +710,17 @@ export async function clickBlock(
710710
document.getElementById(elemId)?.removeAttribute('id');
711711
}, findableId);
712712
}
713+
714+
/**
715+
* Right-clicks on a block with the provided type in the flyout.
716+
*
717+
* @param browser The active WebdriverIO Browser object.
718+
* @param blockType The name of the type block to right click on.
719+
*/
720+
export async function rightClickOnFlyoutBlockType(
721+
browser: WebdriverIO.Browser,
722+
blockType: string,
723+
) {
724+
const elem = await browser.$(`.blocklyFlyout .${blockType}`);
725+
await elem.click({button: 'right'});
726+
}

0 commit comments

Comments
 (0)