66
77import * as chai from 'chai' ;
88import * as Blockly from 'blockly' ;
9+ import * as webdriverio from 'webdriverio' ;
910import {
1011 testSetup ,
1112 testFileLocations ,
@@ -18,6 +19,7 @@ import {
1819 keyRight ,
1920 getCurrentFocusNodeId ,
2021 getCurrentFocusedBlockId ,
22+ tabNavigateToToolbox ,
2123} from './test_setup.js' ;
2224
2325suite ( 'Toolbox and flyout test' , function ( ) {
@@ -244,6 +246,77 @@ suite('Toolbox and flyout test', function () {
244246 chai . assert . strictEqual ( focusedId , elemId ) ;
245247 chai . assert . isTrue ( flyoutIsOpen ) ;
246248 } ) ;
249+
250+ suite ( 'Flyout buttons' , function ( ) {
251+ setup ( async function ( ) {
252+ // New toolbox definition
253+ const toolbox = {
254+ 'kind' : 'categoryToolbox' ,
255+ 'contents' : [
256+ {
257+ 'kind' : 'category' ,
258+ 'name' : 'test category' ,
259+ 'contents' : [
260+ {
261+ 'kind' : 'button' ,
262+ 'text' : 'A button' ,
263+ // Note lowercase
264+ 'callbackkey' : 'buttonCallback' ,
265+ } ,
266+ {
267+ 'kind' : 'button' ,
268+ 'text' : 'Second button' ,
269+ // Note camelCase
270+ 'callbackKey' : 'buttonCallback' ,
271+ } ,
272+ ] ,
273+ } ,
274+ ] ,
275+ } ;
276+
277+ // Replace toolbox contents & register button callback
278+ await this . browser . execute ( ( toolboxDef ) => {
279+ const ws = Blockly . getMainWorkspace ( ) as Blockly . WorkspaceSvg ;
280+ ws . updateToolbox ( toolboxDef ) ;
281+ ws . registerButtonCallback ( 'buttonCallback' , ( ) => {
282+ alert ( 'Button pressed' ) ;
283+ } ) ;
284+ } , toolbox ) ;
285+ } ) ;
286+ teardown ( async function ( ) {
287+ try {
288+ await this . browser . acceptAlert ( ) ;
289+ } catch {
290+ // Don't do anything if the alert isn't present, the test already failed elsewhere.
291+ }
292+ } ) ;
293+ test ( 'callbackkey is activated with enter' , async function ( ) {
294+ await tabNavigateToToolbox ( this . browser ) ;
295+ await this . browser . pause ( PAUSE_TIME ) ;
296+
297+ // First thing in the toolbox is the first button
298+ // Press Enter to activate it.
299+ await keyRight ( this . browser ) ;
300+ await sendKeyAndWait ( this . browser , webdriverio . Key . Enter ) ;
301+
302+ // This errors if there is no alert present
303+ await this . browser . getAlertText ( ) ;
304+ } ) ;
305+
306+ test ( 'callbackKey is activated with enter' , async function ( ) {
307+ await tabNavigateToToolbox ( this . browser ) ;
308+ await this . browser . pause ( PAUSE_TIME ) ;
309+
310+ // Navigate to second button.
311+ // Press Enter to activate it.
312+ await keyRight ( this . browser ) ;
313+ await keyDown ( this . browser ) ;
314+ await sendKeyAndWait ( this . browser , webdriverio . Key . Enter ) ;
315+
316+ // This errors if there is no alert present
317+ await this . browser . getAlertText ( ) ;
318+ } ) ;
319+ } ) ;
247320} ) ;
248321
249322/**
0 commit comments