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 ,
@@ -19,6 +22,70 @@ import {
1922 contextMenuItems ,
2023} from './test_setup.js' ;
2124
25+ const isDarwin = process . platform === 'darwin' ;
26+
27+ const blockActionsViaKeyboard = [
28+ { 'text' : 'Duplicate D' } ,
29+ { 'text' : 'Add Comment' } ,
30+ { 'text' : 'External Inputs' } ,
31+ { 'text' : 'Collapse Block' } ,
32+ { 'text' : 'Disable Block' } ,
33+ { 'text' : 'Delete 2 Blocks Delete' } ,
34+ { 'text' : 'Move Block M' } ,
35+ { 'text' : 'Edit Block contents Right' } ,
36+ { 'text' : isDarwin ? 'Cut ⌘ X' : 'Cut Ctrl + X' } ,
37+ { 'text' : isDarwin ? 'Copy ⌘ C' : 'Copy Ctrl + C' } ,
38+ { 'disabled' : true , 'text' : isDarwin ? 'Paste ⌘ V' : 'Paste Ctrl + V' } ,
39+ ] ;
40+
41+ const blockActionsViaMouse = [
42+ { 'text' : 'Duplicate D' } ,
43+ { 'text' : 'Add Comment' } ,
44+ { 'text' : 'External Inputs' } ,
45+ { 'text' : 'Collapse Block' } ,
46+ { 'text' : 'Disable Block' } ,
47+ { 'text' : 'Delete 2 Blocks Delete' } ,
48+ { 'text' : isDarwin ? 'Cut ⌘ X' : 'Cut Ctrl + X' } ,
49+ { 'text' : isDarwin ? 'Copy ⌘ C' : 'Copy Ctrl + C' } ,
50+ { 'disabled' : true , 'text' : isDarwin ? 'Paste ⌘ V' : 'Paste Ctrl + V' } ,
51+ ] ;
52+
53+ const shadowBlockActionsViaKeyboard = [
54+ { 'text' : 'Add Comment' } ,
55+ { 'text' : 'Collapse Block' } ,
56+ { 'text' : 'Disable Block' } ,
57+ { 'text' : 'Help' } ,
58+ { 'text' : 'Move Block M' } ,
59+ { 'text' : 'Edit Block contents Right' } ,
60+ { 'disabled' : true , 'text' : isDarwin ? 'Cut ⌘ X' : 'Cut Ctrl + X' } ,
61+ { 'text' : isDarwin ? 'Copy ⌘ C' : 'Copy Ctrl + C' } ,
62+ { 'disabled' : true , 'text' : isDarwin ? 'Paste ⌘ V' : 'Paste Ctrl + V' } ,
63+ ] ;
64+
65+ const toolboxBlockActionsViaKeyboard = [
66+ { 'text' : 'Help' } ,
67+ { 'disabled' : true , 'text' : 'Move Block M' } ,
68+ { 'disabled' : true , 'text' : isDarwin ? 'Cut ⌘ X' : 'Cut Ctrl + X' } ,
69+ { 'text' : isDarwin ? 'Copy ⌘ C' : 'Copy Ctrl + C' } ,
70+ ] ;
71+
72+ const flyoutBlockActionsViaMouse = [
73+ { 'text' : 'Help' } ,
74+ { 'disabled' : true , 'text' : isDarwin ? 'Cut ⌘ X' : 'Cut Ctrl + X' } ,
75+ { 'text' : isDarwin ? 'Copy ⌘ C' : 'Copy Ctrl + C' } ,
76+ ] ;
77+
78+ const workspaceActionsViaKeyboard = [
79+ { 'disabled' : true , 'text' : 'Undo' } ,
80+ { 'disabled' : true , 'text' : 'Redo' } ,
81+ { 'text' : 'Clean up Blocks' } ,
82+ { 'text' : 'Collapse Blocks' } ,
83+ { 'disabled' : true , 'text' : 'Expand Blocks' } ,
84+ { 'text' : 'Delete 14 Blocks' } ,
85+ { 'text' : 'Add Comment' } ,
86+ { 'disabled' : true , 'text' : isDarwin ? 'Paste ⌘ V' : 'Paste Ctrl + V' } ,
87+ ] ;
88+
2289suite ( 'Menus test' , function ( ) {
2390 // Disable timeouts when non-zero PAUSE_TIME is used to watch tests run.
2491 if ( PAUSE_TIME ) this . timeout ( 0 ) ;
@@ -30,72 +97,72 @@ suite('Menus test', function () {
3097 // seconds. Allow 30s just in case.
3198 this . timeout ( 30000 ) ;
3299
33- this . browser = await testSetup ( testFileLocations . BASE ) ;
100+ this . browser = await testSetup ( testFileLocations . MORE_BLOCKS ) ;
34101 await this . browser . pause ( PAUSE_TIME ) ;
35102 } ) ;
36103
37- test ( 'Menu on block' , async function ( ) {
104+ test ( 'Menu action via keyboard on block opens menu ' , async function ( ) {
38105 // Navigate to draw_circle_1.
39106 await focusOnBlock ( this . browser , 'draw_circle_1' ) ;
40107 await this . browser . pause ( PAUSE_TIME ) ;
41108 await sendKeyAndWait ( this . browser , [ Key . Ctrl , Key . Return ] ) ;
42109
43110 chai . assert . deepEqual (
44- process . platform === 'darwin'
45- ? [
46- { 'text' : 'Duplicate D' } ,
47- { 'text' : 'Add Comment' } ,
48- { 'text' : 'External Inputs' } ,
49- { 'text' : 'Collapse Block' } ,
50- { 'text' : 'Disable Block' } ,
51- { 'text' : 'Delete 2 Blocks Delete' } ,
52- { 'text' : 'Move Block M' } ,
53- { 'text' : 'Edit Block contents Right' } ,
54- { 'text' : 'Cut ⌘ X' } ,
55- { 'text' : 'Copy ⌘ C' } ,
56- { 'disabled' : true , 'text' : 'Paste ⌘ V' } ,
57- ]
58- : [
59- { 'text' : 'Duplicate D' } ,
60- { 'text' : 'Add Comment' } ,
61- { 'text' : 'External Inputs' } ,
62- { 'text' : 'Collapse Block' } ,
63- { 'text' : 'Disable Block' } ,
64- { 'text' : 'Delete 2 Blocks Delete' } ,
65- { 'text' : 'Move Block M' } ,
66- { 'text' : 'Edit Block contents Right' } ,
67- { 'text' : 'Cut Ctrl + X' } ,
68- { 'text' : 'Copy Ctrl + C' } ,
69- { 'disabled' : true , 'text' : 'Paste Ctrl + V' } ,
70- ] ,
71111 await contextMenuItems ( this . browser ) ,
112+ blockActionsViaKeyboard ,
72113 ) ;
73114 } ) ;
74115
75- test ( 'Menu on block in the toolbox' , async function ( ) {
76- // Navigate to draw_circle_1.
77- await focusOnBlock ( this . browser , 'draw_circle_1' ) ;
116+ test ( 'Block menu via mouse displays expected items' , async function ( ) {
117+ await tabNavigateToWorkspace ( this . browser ) ;
118+ await clickBlock ( this . browser , 'draw_circle_1' , { button : 'right' } ) ;
119+
120+ chai . assert . deepEqual (
121+ await contextMenuItems ( this . browser ) ,
122+ blockActionsViaMouse ,
123+ ) ;
124+ } ) ;
125+
126+ test ( 'Shadow block menu via keyboard displays expected items' , async function ( ) {
127+ await tabNavigateToWorkspace ( this . browser ) ;
128+ await focusOnBlock ( this . browser , 'text_print_1' ) ;
129+ await this . browser . keys ( Key . ArrowRight ) ;
130+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
131+ await this . browser . pause ( PAUSE_TIME ) ;
132+
133+ chai . assert . deepEqual (
134+ await contextMenuItems ( this . browser ) ,
135+ shadowBlockActionsViaKeyboard ,
136+ ) ;
137+ } ) ;
138+
139+ test ( 'Menu action on block in the toolbox' , async function ( ) {
140+ await tabNavigateToWorkspace ( this . browser ) ;
78141 // Navigate to a toolbox category
79142 await moveToToolboxCategory ( this . browser , 'Functions' ) ;
80143 // Move to flyout.
81144 await keyRight ( this . browser ) ;
82145 await sendKeyAndWait ( this . browser , [ Key . Ctrl , Key . Return ] ) ;
83146
84147 chai . assert . deepEqual (
85- process . platform === 'darwin'
86- ? [
87- { 'text' : 'Help' } ,
88- { 'disabled' : true , 'text' : 'Move Block M' } ,
89- { 'disabled' : true , 'text' : 'Cut ⌘ X' } ,
90- { 'text' : 'Copy ⌘ C' } ,
91- ]
92- : [
93- { 'text' : 'Help' } ,
94- { 'disabled' : true , 'text' : 'Move Block M' } ,
95- { 'disabled' : true , 'text' : 'Cut Ctrl + X' } ,
96- { 'text' : 'Copy Ctrl + C' } ,
97- ] ,
98148 await contextMenuItems ( this . browser ) ,
149+ toolboxBlockActionsViaKeyboard ,
150+ ) ;
151+ } ) ;
152+
153+ test ( 'Flyout block menu via mouse displays expected items' , async function ( ) {
154+ await tabNavigateToWorkspace ( this . browser ) ;
155+ // Navigate to a toolbox category
156+ await moveToToolboxCategory ( this . browser , 'Math' ) ;
157+ // Move to flyout.
158+ await keyRight ( this . browser ) ;
159+ await this . browser . pause ( PAUSE_TIME ) ;
160+ await rightClickOnFlyoutBlockType ( this . browser , 'math_number' ) ;
161+ await this . browser . pause ( PAUSE_TIME ) ;
162+
163+ chai . assert . deepEqual (
164+ await contextMenuItems ( this . browser ) ,
165+ flyoutBlockActionsViaMouse ,
99166 ) ;
100167 } ) ;
101168
@@ -106,28 +173,8 @@ suite('Menus test', function () {
106173 await sendKeyAndWait ( this . browser , [ Key . Ctrl , Key . Return ] ) ;
107174
108175 chai . assert . deepEqual (
109- process . platform === 'darwin'
110- ? [
111- { 'disabled' : true , 'text' : 'Undo' } ,
112- { 'disabled' : true , 'text' : 'Redo' } ,
113- { 'text' : 'Clean up Blocks' } ,
114- { 'text' : 'Collapse Blocks' } ,
115- { 'disabled' : true , 'text' : 'Expand Blocks' } ,
116- { 'text' : 'Delete 4 Blocks' } ,
117- { 'text' : 'Add Comment' } ,
118- { 'disabled' : true , 'text' : 'Paste ⌘ V' } ,
119- ]
120- : [
121- { 'disabled' : true , 'text' : 'Undo' } ,
122- { 'disabled' : true , 'text' : 'Redo' } ,
123- { 'text' : 'Clean up Blocks' } ,
124- { 'text' : 'Collapse Blocks' } ,
125- { 'disabled' : true , 'text' : 'Expand Blocks' } ,
126- { 'text' : 'Delete 4 Blocks' } ,
127- { 'text' : 'Add Comment' } ,
128- { 'disabled' : true , 'text' : 'Paste Ctrl + V' } ,
129- ] ,
130176 await contextMenuItems ( this . browser ) ,
177+ workspaceActionsViaKeyboard ,
131178 ) ;
132179 } ) ;
133180
@@ -143,4 +190,32 @@ suite('Menus test', function () {
143190 'The menu should not be openable during a move' ,
144191 ) ;
145192 } ) ;
193+
194+ test ( 'Escape key dismisses menu' , async function ( ) {
195+ await tabNavigateToWorkspace ( this . browser ) ;
196+ await focusOnBlock ( this . browser , 'draw_circle_1' ) ;
197+ await this . browser . pause ( PAUSE_TIME ) ;
198+ await this . browser . keys ( [ Key . Ctrl , Key . Return ] ) ;
199+ await this . browser . pause ( PAUSE_TIME ) ;
200+ await this . browser . keys ( Key . Escape ) ;
201+ await this . browser . pause ( PAUSE_TIME ) ;
202+
203+ chai . assert . isTrue (
204+ await contextMenuExists ( this . browser , 'Duplicate' , /* reverse= */ true ) ,
205+ 'The menu should be closed' ,
206+ ) ;
207+ } ) ;
208+
209+ test ( 'Clicking workspace dismisses menu' , async function ( ) {
210+ await tabNavigateToWorkspace ( this . browser ) ;
211+ await clickBlock ( this . browser , 'draw_circle_1' , { button : 'right' } ) ;
212+ await this . browser . pause ( PAUSE_TIME ) ;
213+ await focusWorkspace ( this . browser ) ;
214+ await this . browser . pause ( PAUSE_TIME ) ;
215+
216+ chai . assert . isTrue (
217+ await contextMenuExists ( this . browser , 'Duplicate' , /* reverse= */ true ) ,
218+ 'The menu should be closed' ,
219+ ) ;
220+ } ) ;
146221} ) ;
0 commit comments