yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Not meant to extend QContextMenu, just to have utility methods here in case QContextMenu has bugs
 
import { QContextMenu } from '../e2elib/lib/api/pageobjects/qcontextmenu.component';
 
/**
 * Context menu item to click on. ContextMenu field to define the parent context menu technical name.
 */
export interface ContextMenuItemSOP {
  ContextMenu: string;
  Name: string;
  Label: string;
}
 
export class ContextMenuSOP {
  /**
   * If menu disabled but has NO tooltip, we cannot invoke QContextMenu.isMenuItemClickable() as it will return error tooltip not visible.
   * Caller decide if need verify tooltip so that we use the appropriate method to either check clickable only (without query tooltip) or
   * invoke the usual QContextMenu.isMenuItemClickable() which returns tuple [boolean clickable, string tooltip].
   *
   * @param contextMenu QContextMenu element to verify.
   * @param menuItemName Context menu item name.
   * @param needVerifyTooltip Caller decide if needs to verify tooltip. Pass false to skip tooltip check.
   * @param waitTime [Optional] Miliseconds of how long it should wait for menu to be clickable.
   * @returns An array of combination of boolean and string, where boolean indicates whether the menuItem is clickable and string indicating the disabled tooltip
   */
  public static async verifyIsMenuItemClickable(contextMenu: QContextMenu, menuItemName: string | string[], needVerifyTooltip: boolean = true): Promise<[boolean, string]> {
    let disabledTooltip = '';
    const isEnabled = await contextMenu.isMenuItemClickable(menuItemName);
 
    // Only query tooltip if caller wants to (else if menu disabled and has NO tooltip, an error tooltip not visible thrown)
    if (needVerifyTooltip && !isEnabled) {
      disabledTooltip = await contextMenu.getToolTip(menuItemName);
    }
 
    return [isEnabled, disabledTooltip];
  }
 
  public static getMenuPaths(menuName: string): string | string[] {
    const tokens = menuName.split('|');
 
    return tokens.length === 1 ? menuName : tokens;
  }
 }