@@ -310,3 +310,81 @@ test.describe('Doc Tree: Inheritance', () => {
310310 await expect ( docTree . getByText ( docParent ) ) . toBeVisible ( ) ;
311311 } ) ;
312312} ) ;
313+
314+ test . describe ( 'Doc tree keyboard interactions (subdocs)' , ( ) => {
315+ test . beforeEach ( async ( { page } ) => {
316+ await page . goto ( '/' ) ;
317+ } ) ;
318+ test ( 'navigates in the tree and actions with keyboard and toggles menu (options and create childDoc)' , async ( {
319+ page,
320+ browserName,
321+ } ) => {
322+ const [ rootDocTitle ] = await createDoc (
323+ page ,
324+ 'doc-tree-keyboard' ,
325+ browserName ,
326+ 1 ,
327+ ) ;
328+ await verifyDocName ( page , rootDocTitle ) ;
329+
330+ const { name : childTitle } = await createRootSubPage (
331+ page ,
332+ browserName ,
333+ 'subdoc-tree-actions' ,
334+ ) ;
335+
336+ await verifyDocName ( page , childTitle ) ;
337+
338+ const docTree = page . getByTestId ( 'doc-tree' ) ;
339+
340+ const actionsGroup = page . getByRole ( 'group' , {
341+ name : `Actions for ${ childTitle } ` ,
342+ } ) ;
343+ await expect ( actionsGroup ) . toBeVisible ( ) ;
344+
345+ const moreOptions = actionsGroup . getByRole ( 'button' , {
346+ name : `More options for ${ childTitle } ` ,
347+ } ) ;
348+ await expect ( moreOptions ) . toBeVisible ( ) ;
349+
350+ await moreOptions . focus ( ) ;
351+ await expect ( moreOptions ) . toBeFocused ( ) ;
352+
353+ await page . keyboard . press ( 'ArrowRight' ) ;
354+ const addChild = actionsGroup . getByTestId ( 'add-child-doc' ) ;
355+ await expect ( addChild ) . toBeFocused ( ) ;
356+
357+ await page . keyboard . press ( 'ArrowLeft' ) ;
358+ await expect ( moreOptions ) . toBeFocused ( ) ;
359+
360+ await page . keyboard . press ( 'Enter' ) ;
361+ await expect ( page . getByText ( 'Copy link' ) ) . toBeVisible ( ) ;
362+
363+ await page . keyboard . press ( 'Escape' ) ;
364+ await expect ( page . getByText ( 'Copy link' ) ) . toBeHidden ( ) ;
365+
366+ await page . keyboard . press ( 'ArrowRight' ) ;
367+ await expect ( addChild ) . toBeFocused ( ) ;
368+
369+ const responsePromise = page . waitForResponse (
370+ ( response ) =>
371+ response . url ( ) . includes ( '/documents/' ) &&
372+ response . url ( ) . includes ( '/children/' ) &&
373+ response . request ( ) . method ( ) === 'POST' ,
374+ ) ;
375+
376+ await page . keyboard . press ( 'Enter' ) ;
377+
378+ const response = await responsePromise ;
379+ expect ( response . ok ( ) ) . toBeTruthy ( ) ;
380+ const newChildDoc = ( await response . json ( ) ) as { id : string } ;
381+
382+ const childButton = page . getByTestId ( `doc-sub-page-item-${ newChildDoc . id } ` ) ;
383+ const childTreeItem = docTree
384+ . locator ( '.c__tree-view--row' )
385+ . filter ( { has : childButton } )
386+ . first ( ) ;
387+
388+ await childTreeItem . focus ( ) ;
389+ } ) ;
390+ } ) ;
0 commit comments