77import * as chai from 'chai' ;
88import { Key } from 'webdriverio' ;
99import {
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} ) ;
0 commit comments