@@ -24,6 +24,7 @@ describe('Sidebar tests', () => {
2424 } ;
2525
2626 beforeEach ( ( ) => {
27+ console . warn = jest . fn ( ) ;
2728 const popover = getPopover ( ) ;
2829 expect ( popover ) . toBeNull ( ) ;
2930 } ) ;
@@ -271,7 +272,7 @@ describe('Sidebar tests', () => {
271272 await act ( async ( ) => {
272273 await fireEvent . contextMenu ( childNode ) ;
273274 } ) ;
274- const menuItems = getContextMenuItems ( ) ;
275+ const menuItems = getContextMenuItems ( `tree-ctxmenu- ${ childName } ` ) ;
275276 await act ( async ( ) => {
276277 await userEvent . click ( menuItems [ 0 ] . querySelector ( 'a' ) ) ;
277278 } ) ;
@@ -368,13 +369,15 @@ describe('Sidebar tests', () => {
368369 await act ( async ( ) => {
369370 fireEvent . contextMenu ( childNode ) ;
370371 } ) ;
371- const menuItems = getContextMenuItems ( ) ;
372+ const menuItems = getContextMenuItems ( `tree-ctxmenu-/users` ) ;
372373 // Delete path
373374 act ( ( ) => {
374375 userEvent . click ( menuItems [ 0 ] . querySelector ( 'a' ) ) ;
375376 } ) ;
376377
377- const editItem = getNodeFromSidebar ( NodeTypes . Path ) . querySelector ( 'input' ) ;
378+ const editItem = screen
379+ . getByLabelText ( NodeTypes . Path )
380+ . querySelector ( 'input' ) ;
378381 expect ( editItem ) . toHaveValue ( `/users` ) ;
379382 await act ( async ( ) => {
380383 await userEvent . type ( editItem , `/abc{Enter}` ) ;
@@ -444,7 +447,7 @@ describe('Sidebar tests', () => {
444447 await act ( async ( ) => {
445448 await fireEvent . contextMenu ( childNode ) ;
446449 } ) ;
447- const menuItems = getContextMenuItems ( ) ;
450+ const menuItems = getContextMenuItems ( `tree-ctxmenu-/users` ) ;
448451 // Delete operation
449452 act ( ( ) => {
450453 userEvent . click ( menuItems [ 2 ] . querySelector ( 'a' ) ) ;
@@ -496,21 +499,6 @@ function getChildNodeType(parentNodeType) {
496499 }
497500}
498501
499- async function addChildNode ( nodeType , name ) {
500- const parentNode = await getNodeFromSidebar ( nodeType ) ;
501- const addNewBtnLabel = getAddButtonLabel ( nodeType ) ;
502- await clickAddNewItem ( parentNode , addNewBtnLabel ) ;
503-
504- const editableItem = await screen . getAllByRole ( / e d i t i t e m / ) ;
505- expect ( editableItem ) . toHaveLength ( 1 ) ;
506- const editableInput = getEditableInput ( editableItem [ 0 ] ) ;
507- await act ( async ( ) => {
508- // Enter the new item name and press enter
509- await userEvent . type ( editableInput , `${ name } {Enter}` ) ;
510- } ) ;
511- return getNodeFromSidebar ( getChildNodeType ( nodeType ) ) ;
512- }
513-
514502async function clickAddNewItem ( menuItem , addBtnLabel ) {
515503 await act ( async ( ) => {
516504 await fireEvent . contextMenu ( menuItem ) ;
@@ -529,8 +517,8 @@ function getNodeFromSidebar(nodeType) {
529517 return screen . getByLabelText ( nodeType ) ;
530518}
531519
532- function getContextMenuItems ( ) {
533- const popover = getPopover ( ) ;
520+ function getContextMenuItems ( name ) {
521+ const popover = getPopover ( name ) ;
534522 return within ( popover ) . queryAllByRole ( 'listitem' ) ;
535523}
536524
@@ -541,7 +529,10 @@ function getEditableInput(containerElem, shouldRaiseException = false) {
541529 : within ( containerElem ) . queryByRole ( / t e x t b o x / ) ;
542530}
543531
544- function getPopover ( ) {
532+ function getPopover ( name ) {
533+ if ( name ) {
534+ return document . querySelector ( `ul[data-testid="${ name } "]` ) ;
535+ }
545536 return document . querySelector (
546537 `.${ PopoverClasses . POPOVER2 } .${ Classes . MINIMAL } ` ,
547538 ) ;
0 commit comments