import { ChainablePromiseElement } from 'webdriverio' ; import utils from '../libs/utils' ; type Targets = 'environments' | 'routes' ; class ContextMenu { private targetSelectors = { environments : '.environments-menu' , routes : '.routes-menu' } ; public async openContextMenu ( targetMenu , menuItemIndex ? ) { await this . getMenuEntry ( targetMenu , menuItemIndex ) . click ( { button : 'right' } ) ; await $ ( '.context-menu' ) . waitForExist ( ) ; } public async closeContextMenu ( ) { await $ ( 'body' ) . click ( { x : 0 , y : 0 } ) ; } public async click ( targetMenu , menuItemIndex ? , contextMenuItemIndex ? ) { await this . openContextMenu ( targetMenu , menuItemIndex ) ; await $ ( `.context-menu .context-menu-item:nth-child(${ contextMenuItemIndex })` ) . click ( ) ; } public async assertEntryDisabled ( targetMenu , menuItemIndex , contextMenuItemIndex , reverse = false ) { await this . openContextMenu ( targetMenu , menuItemIndex ) ; await utils . assertHasClass ( $ ( `.context-menu .context-menu-item:nth-child(${ contextMenuItemIndex })` ) , 'disabled' , reverse ) ; } public async clickAndConfirm ( targetMenu , menuItemIndex ? , contextMenuItemIndex ? ) { await this . openContextMenu ( targetMenu , menuItemIndex ) ; await $ ( `.context-menu .context-menu-item:nth-child(${ contextMenuItemIndex })` ) . click ( ) ; await $ ( `.context-menu .context-menu-item:nth-child(${ contextMenuItemIndex })` ) . click ( ) ; } private getMenuEntry ( targetMenu , menuItemIndex ? ) { const itemSelector = menuItemIndex === undefined ? ' .nav-link.active' : `:nth-child(${ menuItemIndex })` ; return $ ( `${ this . targetSelectors [ targetMenu ] } .menu-list .nav-item${ itemSelector }` ) ; } } export default new ContextMenu ( ) ;