@@ -8,9 +8,13 @@ import * as chai from 'chai';
88import { Key } from 'webdriverio' ;
99import {
1010 contextMenuExists ,
11+ getContextMenuItemNames ,
1112 moveToToolboxCategory ,
1213 PAUSE_TIME ,
1314 focusOnBlock ,
15+ focusWorkspace ,
16+ rightClickOnBlock ,
17+ rightClickOnFlyoutBlockType ,
1418 tabNavigateToWorkspace ,
1519 testFileLocations ,
1620 testSetup ,
@@ -27,6 +31,18 @@ suite('Menus test', function () {
2731 await this . browser . pause ( PAUSE_TIME ) ;
2832 } ) ;
2933
34+ test ( 'Menu keyboard shortcut on workspace does not open menu' , async function ( ) {
35+ await tabNavigateToWorkspace ( this . browser ) ;
36+ await this . browser . pause ( PAUSE_TIME ) ;
37+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
38+ await this . browser . pause ( PAUSE_TIME ) ;
39+
40+ chai . assert . isTrue (
41+ await contextMenuExists ( this . browser , 'Undo' , /* reverse= */ true ) ,
42+ 'The menu should not be openable on the workspace' ,
43+ ) ;
44+ } ) ;
45+
3046 test ( 'Menu action opens menu' , async function ( ) {
3147 // Navigate to draw_circle_1.
3248 await tabNavigateToWorkspace ( this . browser ) ;
@@ -41,9 +57,7 @@ suite('Menus test', function () {
4157 } ) ;
4258
4359 test ( 'Menu action returns true in the toolbox' , async function ( ) {
44- // Navigate to draw_circle_1.
4560 await tabNavigateToWorkspace ( this . browser ) ;
46- await focusOnBlock ( this . browser , 'draw_circle_1' ) ;
4761 // Navigate to a toolbox category
4862 await moveToToolboxCategory ( this . browser , 'Functions' ) ;
4963 // Move to flyout.
@@ -70,4 +84,133 @@ suite('Menus test', function () {
7084 'The menu should not be openable during a move' ,
7185 ) ;
7286 } ) ;
87+
88+ test ( 'Block menu via keyboard displays expected items' , async function ( ) {
89+ await tabNavigateToWorkspace ( this . browser ) ;
90+ await focusOnBlock ( this . browser , 'draw_circle_1' ) ;
91+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
92+ await this . browser . pause ( PAUSE_TIME ) ;
93+
94+ chai . assert . deepEqual (
95+ await getContextMenuItemNames ( this . browser ) ,
96+ [
97+ 'Duplicate' ,
98+ 'Add Comment' ,
99+ 'External Inputs' ,
100+ 'Collapse Block' ,
101+ 'Disable Block' ,
102+ 'Delete 2 Blocks' ,
103+ 'Move Block' ,
104+ 'Edit Block contents' ,
105+ 'Cut' ,
106+ 'Copy' ,
107+ 'Paste' ,
108+ ] ,
109+ 'A block context menu should display certain items' ,
110+ ) ;
111+ } ) ;
112+
113+ test ( 'Block menu via mouse displays expected items' , async function ( ) {
114+ await tabNavigateToWorkspace ( this . browser ) ;
115+ await rightClickOnBlock ( this . browser , 'draw_circle_1' ) ;
116+
117+ chai . assert . deepEqual (
118+ await getContextMenuItemNames ( this . browser ) ,
119+ [
120+ 'Duplicate' ,
121+ 'Add Comment' ,
122+ 'External Inputs' ,
123+ 'Collapse Block' ,
124+ 'Disable Block' ,
125+ 'Delete 2 Blocks' ,
126+ 'Cut' ,
127+ 'Copy' ,
128+ 'Paste' ,
129+ ] ,
130+ 'A block context menu should display certain items' ,
131+ ) ;
132+ } ) ;
133+
134+ test ( 'Shadow block menu via keyboard displays expected items' , async function ( ) {
135+ await tabNavigateToWorkspace ( this . browser ) ;
136+ await focusOnBlock ( this . browser , 'draw_circle_1_color' ) ;
137+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
138+ await this . browser . pause ( PAUSE_TIME ) ;
139+
140+ chai . assert . deepEqual (
141+ await getContextMenuItemNames ( this . browser ) ,
142+ [
143+ 'Add Comment' ,
144+ 'Collapse Block' ,
145+ 'Disable Block' ,
146+ 'Help' ,
147+ 'Move Block' ,
148+ 'Cut' ,
149+ 'Copy' ,
150+ 'Paste' ,
151+ ] ,
152+ 'A shadow block context menu should display certain items' ,
153+ ) ;
154+ } ) ;
155+
156+ test ( 'Flyout block menu via keyboard displays expected items' , async function ( ) {
157+ await tabNavigateToWorkspace ( this . browser ) ;
158+ // Navigate to a toolbox category
159+ await moveToToolboxCategory ( this . browser , 'Functions' ) ;
160+ // Move to flyout.
161+ await keyRight ( this . browser ) ;
162+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
163+ await this . browser . pause ( PAUSE_TIME ) ;
164+
165+ chai . assert . deepEqual (
166+ await getContextMenuItemNames ( this . browser ) ,
167+ [ 'Help' , 'Move Block' , 'Cut' , 'Copy' , 'Paste' ] ,
168+ 'A flyout block context menu should display certain items' ,
169+ ) ;
170+ } ) ;
171+
172+ test ( 'Flyout block menu via mouse displays expected items' , async function ( ) {
173+ await tabNavigateToWorkspace ( this . browser ) ;
174+ // Navigate to a toolbox category
175+ await moveToToolboxCategory ( this . browser , 'Math' ) ;
176+ // Move to flyout.
177+ await keyRight ( this . browser ) ;
178+ await this . browser . pause ( PAUSE_TIME ) ;
179+ await rightClickOnFlyoutBlockType ( this . browser , 'math_number' ) ;
180+ await this . browser . pause ( PAUSE_TIME ) ;
181+
182+ chai . assert . deepEqual (
183+ await getContextMenuItemNames ( this . browser ) ,
184+ [ 'Help' , 'Cut' , 'Copy' , 'Paste' ] ,
185+ 'A flyout block context menu should display certain items' ,
186+ ) ;
187+ } ) ;
188+
189+ test ( 'Escape key dismisses menu' , async function ( ) {
190+ await tabNavigateToWorkspace ( this . browser ) ;
191+ await focusOnBlock ( this . browser , 'draw_circle_1' ) ;
192+ await this . browser . pause ( PAUSE_TIME ) ;
193+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
194+ await this . browser . pause ( PAUSE_TIME ) ;
195+ await this . browser . keys ( Key . Escape ) ;
196+ await this . browser . pause ( PAUSE_TIME ) ;
197+
198+ chai . assert . isTrue (
199+ await contextMenuExists ( this . browser , 'Duplicate' , /* reverse= */ true ) ,
200+ 'The menu should be closed' ,
201+ ) ;
202+ } ) ;
203+
204+ test ( 'Clicking workspace dismisses menu' , async function ( ) {
205+ await tabNavigateToWorkspace ( this . browser ) ;
206+ await rightClickOnBlock ( this . browser , 'draw_circle_1' ) ;
207+ await this . browser . pause ( PAUSE_TIME ) ;
208+ await focusWorkspace ( this . browser ) ;
209+ await this . browser . pause ( PAUSE_TIME ) ;
210+
211+ chai . assert . isTrue (
212+ await contextMenuExists ( this . browser , 'Duplicate' , /* reverse= */ true ) ,
213+ 'The menu should be closed' ,
214+ ) ;
215+ } ) ;
73216} ) ;
0 commit comments