import { AdminActions , LoginPage , BrowsingPage , EXTENSIBILITY_CONFIGS , RepoClient , Utils } from '@alfresco/aca-testing-shared' ; describe ( 'Extensions - Context submenu' , ( ) => { const username = `user-${ Utils . random ( ) }` ; const file = `file-${ Utils . random ( ) }.txt` ; let fileId ; const folder = `folder-${ Utils . random ( ) }` ; let folderId ; const restrictedPermissionsItem = 'Share' ; const menuItem1 = { label : 'Test Menu1' , submenu : [ 'Test submenu1' , 'Test submenu2' , restrictedPermissionsItem ] } ; const menuItem2 = { label : 'Test Menu2' , submenu : [ restrictedPermissionsItem ] } ; const apis = { user : new RepoClient ( username , username ) } ; const loginPage = new LoginPage ( ) ; const page = new BrowsingPage ( ) ; const { dataTable } = page ; const contextMenu = dataTable . menu ; const adminApiActions = new AdminActions ( ) ; beforeAll ( async ( done ) => { await adminApiActions . createUser ( { username } ) ; fileId = ( await apis . user . nodes . createFile ( file ) ) . entry . id ; folderId = ( await apis . user . nodes . createFolder ( folder ) ) . entry . id ; await loginPage . load ( ) ; await Utils . setSessionStorageFromConfig ( EXTENSIBILITY_CONFIGS . CONTEXT_SUBMENUS ) ; await loginPage . loginWith ( username ) ; done ( ) ; } ) ; beforeEach ( async ( done ) => { await Utils . pressEscape ( ) ; await dataTable . clearSelection ( ) ; await page . clickPersonalFilesAndWait ( ) ; done ( ) ; } ) ; afterAll ( async ( done ) => { await apis . user . nodes . deleteNodeById ( fileId , true ) ; await apis . user . nodes . deleteNodeById ( folderId , true ) ; done ( ) ; } ) ; it ( '[C286717] Displays the submenu actions set from config' , async ( ) => { await dataTable . rightClickOnItem ( file ) ; expect ( await contextMenu . isMenuItemPresent ( menuItem1 . label ) ) . toBe ( true , `${ menuItem1 . label } is not displayed for ${ file }` ) ; expect ( await contextMenu . hasSubMenu ( menuItem1 . label ) ) . toBe ( true , 'Menu does not have submenu' ) ; await contextMenu . mouseOverMenuItem ( menuItem1 . label ) ; expect ( await contextMenu . getSubmenuItemsCount ( ) ) . toBe ( 3 , 'submenu has wrong number of items' ) ; expect ( await contextMenu . isSubMenuItemPresent ( menuItem1 . submenu [ 0 ] ) ) . toBe ( true , `${ menuItem1 . submenu [ 0 ] } is not displayed for ${ file }` ) ; expect ( await contextMenu . isSubMenuItemPresent ( menuItem1 . submenu [ 1 ] ) ) . toBe ( true , `${ menuItem1 . submenu [ 1 ] } is not displayed for ${ file }` ) ; expect ( await contextMenu . isSubMenuItemPresent ( menuItem1 . submenu [ 2 ] ) ) . toBe ( true , `${ restrictedPermissionsItem } is not displayed for ${ file }` ) ; } ) ; it ( '[C286718] Does not display submenu actions without permissions' , async ( ) => { await dataTable . rightClickOnItem ( folder ) ; expect ( await contextMenu . isMenuItemPresent ( menuItem1 . label ) ) . toBe ( true , `${ menuItem1 . label } is not displayed for ${ folder }` ) ; await contextMenu . mouseOverMenuItem ( menuItem1 . label ) ; expect ( await contextMenu . getSubmenuItemsCount ( ) ) . toBe ( 2 , 'submenu has wrong number of items' ) ; expect ( await contextMenu . isSubMenuItemPresent ( menuItem1 . submenu [ 0 ] ) ) . toBe ( true , `${ menuItem1 . submenu [ 0 ] } is not displayed for ${ file }` ) ; expect ( await contextMenu . isSubMenuItemPresent ( menuItem1 . submenu [ 1 ] ) ) . toBe ( true , `${ menuItem1 . submenu [ 1 ] } is not displayed for ${ file }` ) ; expect ( await contextMenu . isSubMenuItemPresent ( menuItem1 . submenu [ 2 ] ) ) . toBe ( false , `no permission submenu ${ restrictedPermissionsItem } is displayed` ) ; } ) ; it ( '[C287784] The parent item is not displayed if all its children have no permission to be displayed' , async ( ) => { await dataTable . rightClickOnItem ( folder ) ; expect ( await contextMenu . isMenuItemPresent ( menuItem2 . label ) ) . toBe ( false , `${ menuItem2 . label } menu is displayed for ${ folder }` ) ; } ) ; } ) ;