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 ,
@@ -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} ) ;
0 commit comments