import { Form } from '../../e2elib/lib/src/pageobjects/form.component'; 
 | 
import { ListBase } from '../../libappbase/listbase'; 
 | 
import { DialogStockingCost } from '../dialogs/dialog.stockingcost'; 
 | 
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component'; 
 | 
import { AppMP } from '../appmp'; 
 | 
import { CheckboxBase } from '../../libappbase/checkboxbase'; 
 | 
import { LogMessage } from '../../libappbase/logmessage'; 
 | 
import { ActionTriggerType } from '../../libappbase/utils'; 
 | 
import { QContextMenu } from '../../e2elib/lib/api/pageobjects/qcontextmenu.component'; 
 | 
import { ContextMenuSOP } from '../../libappsop/contextmenusop'; 
 | 
  
 | 
export class FormStockingCost extends Form { 
 | 
  public lstStockingCost = new ListStockingCost(); 
 | 
  public cbFilterByAccount = new CheckboxBase('cbFilterByAccounts'); 
 | 
  
 | 
  public constructor() { 
 | 
    super('FormStockingCosts'); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open StockingPoint Dialog via "Copy" button in abp 
 | 
   */ 
 | 
  public async openCopyStockingCostDialog(): Promise<DialogStockingCost> { 
 | 
    await AppMP.getInstance().abpData.btnCopy.click(); 
 | 
    await this.lstStockingCost.dlgStockingCost.waitUntilPresent(); 
 | 
    return this.lstStockingCost.dlgStockingCost; 
 | 
  } 
 | 
} 
 | 
  
 | 
export class ListStockingCost extends ListBase { 
 | 
  private readonly _cmMenu = new QContextMenu('lsContextMenuAccCosts'); 
 | 
  public dlgStockingCost = new DialogStockingCost(); 
 | 
  
 | 
  public constructor() { 
 | 
    super('lsAccountCosts'); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * To open stocking cost dialog via context menu or action bar page to "Create" or "Edit" (if pass-in stockingCostRow) 
 | 
   * 
 | 
   * @param via Open the dialog via button or context menu. 
 | 
   * @param stockingCostRow [Optional] Target stocking cost row to be edited. 
 | 
   * @returns stocking cost dialog 
 | 
   */ 
 | 
  public async openStockingCostDialog(via: ActionTriggerType, stockingCostRow?: ListRow, isCopy: boolean = false): Promise<DialogStockingCost> { 
 | 
    switch (via) { 
 | 
      case ActionTriggerType.Button: 
 | 
        await this.focus(); 
 | 
        if (stockingCostRow) { 
 | 
          await stockingCostRow.leftClick(); 
 | 
          if (isCopy) { 
 | 
            await AppMP.getInstance().abpData.btnCopy.click(); 
 | 
          } else { 
 | 
            await AppMP.getInstance().abpData.btnEdit.click(); 
 | 
          } 
 | 
        } else { 
 | 
          await AppMP.getInstance().abpData.btnCreate.click(); 
 | 
        } 
 | 
        break; 
 | 
      case ActionTriggerType.ContextMenu: 
 | 
        if (stockingCostRow) { 
 | 
          if (isCopy) { 
 | 
            await stockingCostRow.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Copy); 
 | 
          } else { 
 | 
            await stockingCostRow.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Edit); 
 | 
          } 
 | 
        } else { 
 | 
          await this.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Create); 
 | 
        } 
 | 
        break; 
 | 
      default: 
 | 
        break; 
 | 
    } 
 | 
    await this.dlgStockingCost.waitForScreenUpdate(); 
 | 
    return this.dlgStockingCost; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open Edit Stocking Cost Dialog 
 | 
   * 
 | 
   * @returns stocking cost dialog 
 | 
   */ 
 | 
  public async openEditStockingCostDialog(): Promise<DialogStockingCost> { 
 | 
    await this.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Edit); 
 | 
    await this.dlgStockingCost.waitForScreenUpdate(); 
 | 
    return this.dlgStockingCost; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Check stocking cost is existed by value from the list 
 | 
   * 
 | 
   * @param stockingPoint Stocking Point column value 
 | 
   * @param account Account column value 
 | 
   * @param costDriver Cost driver column value 
 | 
   * @param cost Cost column value 
 | 
   * @param uom UoM column value 
 | 
   * @param start Start column value 
 | 
   * @param end End column value 
 | 
   * @returns boolean to indicate whether a the row is existed in the list 
 | 
   */ 
 | 
  public async isStockingCostExisted(stockingPoint: string, account: string, costDriver: string, cost: string, uom: string, start: string, end: string): Promise<boolean> { 
 | 
    const result = await this.getRowByValue([ 
 | 
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint }, 
 | 
      { columnID: ListStockingCostColumn.Account, value: account }, 
 | 
      { columnID: ListStockingCostColumn.CostDriver, value: costDriver }, 
 | 
      { columnID: ListStockingCostColumn.Cost, value: cost }, 
 | 
      { columnID: ListStockingCostColumn.UoM, value: uom }, 
 | 
      { columnID: ListStockingCostColumn.Start, value: start }, 
 | 
      { columnID: ListStockingCostColumn.End, value: end }, 
 | 
    ]).catch(() => { 
 | 
      // do nothing as error is thrown due to no row is found 
 | 
    }); 
 | 
    return result !== undefined; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Returns tooltip of the menu item 
 | 
   * 
 | 
   * @param menuItemPath MenuItem name 
 | 
   * @returns tooltip text of the menu item 
 | 
   */ 
 | 
  public async getMenuItemTooltip(menuItemPath: string): Promise<string> { 
 | 
    await this._cmMenu.waitForScreenUpdate(); 
 | 
    const tooltip = await this._cmMenu.getToolTip(menuItemPath); 
 | 
    await this._cmMenu.dismiss(); 
 | 
    return tooltip; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Check if the context menu item is disabled 
 | 
   * 
 | 
   * @param menuitem Name of target menu item 
 | 
   * @returns An array of combination of boolean and string, where boolean indicate whether the menuItem is clickable and string inidcate the disabled tooltip 
 | 
   */ 
 | 
  public async verifyIsMenuItemClickable(menuitem: string): Promise<[boolean, string]> { 
 | 
    const [isMenuItemClickable, menuItemDisabledTooltip] = await ContextMenuSOP.verifyIsMenuItemClickable(this._cmMenu, menuitem); 
 | 
    await this._cmMenu.dismiss(); 
 | 
    return [isMenuItemClickable, menuItemDisabledTooltip]; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Get stocking cost by value from the list 
 | 
   * 
 | 
   * @param stockingPoint Stocking Point column value 
 | 
   * @param cost Cost column value 
 | 
   */ 
 | 
  public async getStockingCost(stockingPoint: string, cost: string): Promise<ListRow> { 
 | 
    return this.getRowByValue([ 
 | 
      { columnID: ListStockingCostColumn.StockingPoint, value: stockingPoint }, 
 | 
      { columnID: ListStockingCostColumn.Cost, value: cost }, 
 | 
    ]); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Get all stocking costs with the account name 
 | 
   * 
 | 
   * @param accountName Account column value 
 | 
   * @returns An array of ListRow that match the account name 
 | 
   */ 
 | 
  public async getStockingCostsByAccount(accountName: string): Promise<ListRow[]> { 
 | 
    const allRows = await this.getAllRows(); 
 | 
    const resultRows: ListRow[] = []; 
 | 
    for (const row of allRows) { 
 | 
      if ((await this.getCellValueFromRow(ListStockingCostColumn.Account, row)) === accountName) { 
 | 
        resultRows.push(row); 
 | 
      } 
 | 
    } 
 | 
    return resultRows; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Delete stocking cost 
 | 
   * 
 | 
   * @param row Stocking Cost row 
 | 
   */ 
 | 
  public async deleteStockingCost(row: ListRow): Promise<void> { 
 | 
    return row.rightClick(undefined, this._cmMenu, ListStockingCostContextMenuItem.Delete); 
 | 
  } 
 | 
  
 | 
  public async openStockingCostDialogViaAbp(): Promise<DialogStockingCost> { 
 | 
    const appMP = AppMP.getInstance(); 
 | 
    const abpData = appMP.abpData; 
 | 
  
 | 
    await this.leftClickOnWhiteSpace(); 
 | 
    await abpData.btnCreate.click(); 
 | 
    await this.dlgStockingCost.waitUntilPresent(); 
 | 
    expect(await this.dlgStockingCost.isVisible()).toBe(true, LogMessage.dialog_notVisible('Stocking Cost')); 
 | 
  
 | 
    return this.dlgStockingCost; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Click on "Edit" button on "Data" action bar page and wait for Stocking Cost dialog to appear 
 | 
   * 
 | 
   * @returns Stocking Cost dialog 
 | 
   */ 
 | 
  public async startEditViaButton(): Promise<DialogStockingCost> { 
 | 
    await AppMP.getInstance().abpData.btnEdit.click(); 
 | 
    await this.dlgStockingCost.waitForScreenUpdate(); 
 | 
    return this.dlgStockingCost; 
 | 
  } 
 | 
} 
 | 
  
 | 
export enum ListStockingCostColumn { 
 | 
  StockingPoint = 'Stocking Point', 
 | 
  Account = 'Account', 
 | 
  CostDriver = 'Cost driver', 
 | 
  Cost = 'Cost', 
 | 
  UoM = 'UoM', 
 | 
  Start = 'Start', 
 | 
  End = 'End', 
 | 
} 
 | 
  
 | 
export enum ListStockingCostContextMenuItem { 
 | 
  Create = 'MenuCreate', 
 | 
  Edit = 'MenuEdit', 
 | 
  Copy = 'MenuCopy', 
 | 
  Delete = 'MenuDelete', 
 | 
} 
 |