import { Form } from '../../../e2elib/lib/src/pageobjects/form.component'; 
 | 
import { ListRow } from '../../../e2elib/lib/src/pageobjects/list/listrow.component'; 
 | 
import { DialogBookmark } from '../../dialogs/dialog.bookmark'; 
 | 
import { Button } from '../../../e2elib/lib/src/pageobjects/button/button.component'; 
 | 
import { ListBase } from '../../../libappbase/listbase'; 
 | 
import { ListSOP } from '../../../libappsop/listsop'; 
 | 
import { DialogDummy } from '../../dialogs/dialog.dummy'; 
 | 
import { ButtonSOP } from '../../../libappsop/buttonsop'; 
 | 
import { DataHierarchy, DataHierarchyProvider } from '../../../libappsop/datahierarchy'; 
 | 
import { PanelPeriod } from './panel.period'; 
 | 
  
 | 
export class FormNavigationPanel extends Form { 
 | 
  public static readonly btnAddBookmark = 'Bookmark current selection'; 
 | 
  
 | 
  // Buttons 
 | 
  public btnBookmark = new ButtonSOP('ButtonNavBookmark'); 
 | 
  public btnEntity = new ButtonSOP('ButtonNavEntity'); 
 | 
  public btnProduct = new ButtonSOP('ButtonNavProduct'); 
 | 
  public btnSalesSegment = new ButtonSOP('ButtonNavSalesSegment'); 
 | 
  public btnHome = new ButtonSOP('ButtonNavHome'); 
 | 
  public btnPeriod = new ButtonSOP('ButtonNavPeriod'); 
 | 
  public btnAddBookmark = new ButtonSOP('ButtonNavAddBookmark'); 
 | 
  
 | 
  // Lists 
 | 
  public listBookmark = new ListBookmark(); 
 | 
  public listEntity = new ListEntity(); 
 | 
  public listProduct = new ListProduct(); 
 | 
  public listSalesSegment = new ListSalesSegment(); 
 | 
  
 | 
  // Panels 
 | 
  public pnlPeriod = new PanelPeriod(); 
 | 
  
 | 
  public constructor() { 
 | 
    super('FormNavigationPanel'); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open navigation form and filter by stocking point 
 | 
   * 
 | 
   * @param name Display name of the stocking point 
 | 
   * @param parentNames Display name of all parent stocking points 
 | 
   * @returns Boolean to indicate if the entity is checked 
 | 
   */ 
 | 
  public async filterByEntity(name: string, parentNames?: string[]): Promise<boolean> { 
 | 
    await this.openNavigationPanel(); 
 | 
    await this.toggleEntityList(); 
 | 
    const row = await this.listEntity.getEntityRowByName(name, parentNames); 
 | 
    await row.checkboxClick(); 
 | 
    return row.isChecked(); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open navigation form and filter by product 
 | 
   * 
 | 
   * @param name Name of the product 
 | 
   * @param parentNames Name of all parent rows 
 | 
   * @returns Boolean to indicate if the product is checked 
 | 
   */ 
 | 
  public async filterByProduct(name: ListProductColumn, parentNames: ListProductColumn[]): Promise<void> { 
 | 
    await this.openNavigationPanel(); 
 | 
    await this.toggleProductList(); 
 | 
    const row = await this.listProduct.getRow(name, parentNames); 
 | 
    await row.checkboxClick(); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open navigation panel if it is collapse / minimize 
 | 
   * And wait until navigation panel is opened and stable 
 | 
   */ 
 | 
  public async openNavigationPanel(): Promise<void> { 
 | 
    // Check if navigation panel form is close 
 | 
    if (await this.isOpen(false)) { 
 | 
      await this.restore(); 
 | 
    } 
 | 
    await this.waitUntilPresent(); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * To reset data selection in navigation panel and hide all navigation lists 
 | 
   */ 
 | 
  public async reset(): Promise<void> { 
 | 
    await this.resetNaviToRoot(); 
 | 
  
 | 
    // Hide all the lists 
 | 
    await this.toggleBookmarkList(false); 
 | 
    await this.toggleEntityList(false); 
 | 
    await this.toggleProductList(false); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Reset navigation panel filter if there is any 
 | 
   */ 
 | 
  public async resetNaviToRoot(): Promise<void> { 
 | 
    await this.btnHome.click(); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open or hide Bookmark list in navigation panel 
 | 
   * 
 | 
   * @param toOpen Boolean indicating whether to open/hide Bookmark list in navigation panel, default is true 
 | 
   */ 
 | 
  public async toggleBookmarkList(toOpen: boolean = true): Promise<void> { 
 | 
    return this.toggleList(this.listBookmark, this.btnBookmark, toOpen); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open or hide Entity list in navigation panel 
 | 
   * 
 | 
   * @param toOpen Boolean indicating whether to open/hide Entity list in navigation panel, default is true 
 | 
   */ 
 | 
  
 | 
  public async toggleEntityList(toOpen: boolean = true): Promise<void> { 
 | 
    return this.toggleList(this.listEntity, this.btnEntity, toOpen); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open or hide Product list in navigation panel 
 | 
   * 
 | 
   * @param toOpen Boolean indicating whether to open/hide Product list in navigation panel, default is true 
 | 
   */ 
 | 
  public async toggleProductList(toOpen: boolean = true): Promise<void> { 
 | 
    return this.toggleList(this.listProduct, this.btnProduct, toOpen); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open or hide SalesSegment list in navigation panel 
 | 
   * 
 | 
   * @param toOpen Boolean indicating whether to open/hide Product list in navigation panel, default is true 
 | 
   */ 
 | 
  public async toggleSalesSegmentList(toOpen: boolean = true): Promise<void> { 
 | 
    return this.toggleList(this.listSalesSegment, this.btnSalesSegment, toOpen); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open or hide the Period panel in Navigation panel. 
 | 
   * 
 | 
   * @param toOpen Boolean indicating whether to open/hide Period panel. Default is true 
 | 
   */ 
 | 
  public async togglePeriod(toOpen: boolean = true): Promise<void> { 
 | 
    if ((await this.pnlPeriod.isVisible()) !== toOpen) { 
 | 
      await this.btnPeriod.click(); 
 | 
      await this.pnlPeriod.waitUntilPresent(); 
 | 
    } 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Show or hide a list in navigation panel. 
 | 
   * 
 | 
   * @param list List to be shown/hidden in navigation panel 
 | 
   * @param button Button that show/hide the given list in navigation panel 
 | 
   * @param toShow Indicates to show/hide the given list in navigation panel 
 | 
   */ 
 | 
  private async toggleList(list: ListBase, button: Button, toShow: boolean = true): Promise<void> { 
 | 
    if (toShow !== (await list.isVisible())) { 
 | 
      await button.click(); 
 | 
      await list.waitUntilPresent(); 
 | 
    } 
 | 
  } 
 | 
} 
 | 
  
 | 
export class ListBookmark extends ListSOP<DialogBookmark, ListBookmarkColumn> { 
 | 
  public static title = 'Bookmarks'; 
 | 
  
 | 
  public constructor() { 
 | 
    super('ListBookmark', new DialogBookmark()); 
 | 
  
 | 
    // Set primary key column name(s), to display in error message when assert fails 
 | 
    this.rowPrimaryColumnNames = { Name: '' }; 
 | 
  } 
 | 
} 
 | 
  
 | 
export class ListEntity extends ListSOP<DialogDummy, ListEntityColumn> { 
 | 
  public static title = 'Stocking points and units'; 
 | 
  
 | 
  public constructor() { 
 | 
    super('ListEntity', new DialogDummy()); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Get entity row by pass-in entity DisplayName and parent entity DisplayName(s) 
 | 
   * 
 | 
   * @param name target entity DisplayName 
 | 
   * @param parentNames all parent row entity DisplayName of target entity 
 | 
   * @returns row of entity 
 | 
   */ 
 | 
  public async getEntityRowByName(name: string, parentNames?: string[]): Promise<ListRow> { 
 | 
    return this.getRowByCellValue(ListEntityColumnName.DisplayName, name, parentNames); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Toggle Entity Row's checkbox on/off 
 | 
   * 
 | 
   * @param expectedState true = ON / false = OFF 
 | 
   * @param displayName target entity display name 
 | 
   * @param parentNames target entity parent(s) display name 
 | 
   * @returns Entity Row of pass-in displayName 
 | 
   */ 
 | 
  public async toggleEntityRowCheckbox(expectedState: boolean, displayName: string, parentNames?: string[]): Promise<ListRow> { 
 | 
    const row = await this.getEntityRowByName(displayName, parentNames); 
 | 
    const currentState = await row.isChecked(); 
 | 
    if (currentState !== expectedState) { 
 | 
      await row.checkboxClick(); 
 | 
    } 
 | 
    return row; 
 | 
  } 
 | 
  
 | 
  // Overrides ListSOP 
 | 
  public getHierarchy(hierarchyProvider: DataHierarchyProvider, name: DataHierarchy): [ListEntityColumn, ListEntityColumn[] | undefined] { 
 | 
    const [targetRowName, parentRowNames] = hierarchyProvider.getHierarchy(name); 
 | 
  
 | 
    const thisProduct: ListEntityColumn = { DisplayName: targetRowName.Name }; 
 | 
    // Only if ondraw image defined 
 | 
    if (targetRowName.OndrawImageName) { 
 | 
      thisProduct.OndrawImageName = targetRowName.OndrawImageName; 
 | 
    } 
 | 
  
 | 
    const parents: ListEntityColumn[] = []; 
 | 
    for (const p of parentRowNames) { 
 | 
      const parentObj: ListEntityColumn = { DisplayName: p.Name }; 
 | 
      // Only if ondraw image defined 
 | 
      if (p.OndrawImageName) { 
 | 
        parentObj.OndrawImageName = p.OndrawImageName; 
 | 
      } 
 | 
  
 | 
      parents.push(parentObj); 
 | 
    } 
 | 
  
 | 
    return [thisProduct, parents.length > 0 ? parents : undefined]; 
 | 
  } 
 | 
} 
 | 
  
 | 
export class ListProduct extends ListSOP<DialogDummy, ListProductColumn> { 
 | 
  public static title = 'Products'; 
 | 
  
 | 
  public constructor() { 
 | 
    super('ListProduct', new DialogDummy()); 
 | 
  } 
 | 
  
 | 
  // Overrides ListSOP 
 | 
  public getHierarchy(hierarchyProvider: DataHierarchyProvider, name: DataHierarchy): [ListProductColumn, ListProductColumn[] | undefined] { 
 | 
    const [targetRowName, parentRowNames] = hierarchyProvider.getHierarchy(name); 
 | 
  
 | 
    const thisProduct: ListProductColumn = { Name: targetRowName.Name }; 
 | 
    const parents: ListProductColumn[] = []; 
 | 
    for (const p of parentRowNames) { 
 | 
      parents.push({ Name: p.Name }); 
 | 
    } 
 | 
  
 | 
    return [thisProduct, parents.length > 0 ? parents : undefined]; 
 | 
  } 
 | 
} 
 | 
  
 | 
export class ListSalesSegment extends ListSOP<DialogDummy, ListSalesSegmentColumn> { 
 | 
  public static title = 'Sales segmants'; 
 | 
  
 | 
  public constructor() { 
 | 
    super('ListSalesSegment', new DialogDummy()); // Just read-only list, no context menu to create/edit/delete thus use dummy dialog 
 | 
  } 
 | 
  
 | 
  // Overrides ListSOP 
 | 
  public getHierarchy(hierarchyProvider: DataHierarchyProvider, name: DataHierarchy): [ListSalesSegmentColumn, ListSalesSegmentColumn[] | undefined] { 
 | 
    const [targetRowName, parentRowNames] = hierarchyProvider.getHierarchy(name); 
 | 
  
 | 
    const thisSalesSegment: ListSalesSegmentColumn = { Name: targetRowName.Name }; 
 | 
    const parents: ListSalesSegmentColumn[] = []; 
 | 
    for (const p of parentRowNames) { 
 | 
      parents.push({ Name: p.Name }); 
 | 
    } 
 | 
  
 | 
    return [thisSalesSegment, parents.length > 0 ? parents : undefined]; 
 | 
  } 
 | 
} 
 | 
  
 | 
export interface ListBookmarkColumn { 
 | 
  Name?: string; 
 | 
} 
 | 
  
 | 
const listBookmarkContextMenuItem = { 
 | 
  CreateFolder: { ContextMenu: 'listContextMenu445', Name: 'MenuCreateFolder', Label: 'Create folder' }, 
 | 
}; 
 | 
  
 | 
export { listBookmarkContextMenuItem as ListBookmarkContextMenuItem }; 
 | 
  
 | 
// List Entity columns (suffix New to be removed in future once the old enum ListEntityColumn removed after we extend from ListSOP) 
 | 
export interface ListEntityColumn { 
 | 
  OndrawImageName?: string; 
 | 
  DisplayName: string; 
 | 
} 
 | 
  
 | 
// List Entity columns 
 | 
export enum ListEntityColumnName { 
 | 
  DisplayName = 'DisplayName', 
 | 
} 
 | 
  
 | 
// List Product columns 
 | 
export interface ListProductColumn { 
 | 
  Name?: string; 
 | 
} 
 | 
  
 | 
export interface ListSalesSegmentColumn { 
 | 
  Name?: string; 
 | 
} 
 | 
  
 | 
// Step description to re-use in spec file to prevent scriptor re-write each time 
 | 
const stepNavigationPanel = { 
 | 
  checkProducts: (products: string[]): string => `In left Navigation panel, check product(s) ${products.join(', ')}.`, 
 | 
  checkSalesSegments: (salesSegments: string[]): string => `In left Navigation panel, check sales segment(s) ${salesSegments.join(', ')}.`, 
 | 
  checkStockingPoints: (stockingPoints: string[]): string => `In left Navigation panel, check stocking point(s) ${stockingPoints.join(', ')}.`, 
 | 
  checkUnits: (units: string[]): string => `In left Navigation panel, check unit(s) ${units.join(', ')}.`, 
 | 
  clickHomeResetToRoot: (): string => 'In left Navigation panel, click Home button to reset to Root.', 
 | 
  openNavigationPanel: (): string => 'Open left docked Navigation panel form.', 
 | 
  showEntitiesList: (): string => 'In left Navigation panel, show Stocking points and Units list by clicking Stocking points and Units button.', 
 | 
  showPeriodPanel: (): string => 'In left Navigation panel, show Period Panel by clicking Period button.', 
 | 
  showProductsList: (): string => 'In left Navigation panel, show Products list by clicking Products button.', 
 | 
  showSalesSegmentsList: (): string => 'In left Navigation panel, show Sales Segments list by clicking Sales Segments button.', 
 | 
  showBookmarkList: (): string => 'In left Navigation panel, show Bookmarks list by clicking Bookmarks button.', 
 | 
  unCheckProducts: (products: string[]): string => `In left Navigation panel, uncheck product(s) ${products.join(', ')}.`, 
 | 
  unCheckStockingPoints: (stockingpoints: string[]): string => `In left Navigation panel, uncheck stocking point(s) ${stockingpoints.join(', ')}.`, 
 | 
  unCheckSalesSegments: (salesSegments: string[]): string => `In left Navigation panel, uncheck sales segment(s) ${salesSegments.join(', ')}.`, 
 | 
  uncheckUnits: (units: string[]): string => `In left Navigation panel, uncheck unit(s) ${units.join(', ')}.`, 
 | 
}; 
 | 
  
 | 
export { stepNavigationPanel as StepNavigationPanel }; 
 |