import { $ , $$ , browser , ElementFinder } from 'protractor' ; export class HierarchyBarPage { hierarchyBar = $ ( 'ux-hierarchy-bar' ) ; nodes = $$ ( '.hierarchy-bar-node' ) ; selectedLabel = $ ( '#selected' ) ; selectButton = $ ( '#set-selected-btn' ) ; showLeftAddonBtn = $ ( '#show-left-addon-btn' ) ; showRightAddonBtn = $ ( '#show-right-addon-btn' ) ; showTrailingAddonBtn = $ ( '#show-trailing-addon-btn' ) ; standardMode = $ ( '#standard-mode' ) ; collapsedMode = $ ( '#collapsed-mode' ) ; dropdownMode = $ ( '#dropdown-mode' ) ; readOnlyBtn = $ ( '#readonly-btn' ) ; async getPage ( ) { await browser . get ( '#/hierarchy-bar' ) ; } async getSelectedNodeTitle ( ) { return await this . selectedLabel . getText ( ) ; } async getNodeCount ( ) { return await this . nodes . count ( ) ; } async getNode ( index ) { return await this . nodes . get ( index ) ; } async clickNode ( index ) { const node = await this . getNode ( index ) ; const content = await node . $ ( '.hierarchy-bar-node-content' ) ; await content . click ( ) ; } async nodeHasChildren ( index ) { const node = await this . getNode ( index ) ; const arrow = await node . $$ ( '.hierarchy-bar-node-arrow' ) ; return arrow . length === 1 ; } async nodeHasChildrenDropdown ( index ) { const node = await this . getNode ( index ) ; const arrow = await node . $$ ( '.hierarchy-bar-node-arrow-icon-dropdown' ) ; return arrow . length === 1 ; } async showNodePopover ( index ) { const node = await this . getNode ( index ) ; const arrow = await node . $ ( '.hierarchy-bar-node-arrow' ) ; await arrow . click ( ) ; } async selectPopoverNode ( index , childIndex ) { const children = await this . getNodeChildren ( index ) ; const child = children [ childIndex ] ; await child . click ( ) ; } async selectPopoverNodeDropdown ( index , childIndex ) { const children = await this . getNodeChildrenDropdown ( index ) ; const child = children [ childIndex ] ; await child . click ( ) ; } async selectPopoverNodeCollapsed ( childIndex ) { const children = await this . getOverflowNodesCollapsed ( ) ; const child = children [ childIndex ] ; await child . click ( ) ; } async getNodeChildren ( index ) { if ( await this . nodeHasChildren ( index ) === false ) { return [ ] ; } await this . showNodePopover ( index ) ; return await $$ ( 'ux-hierarchy-bar-popover-item' ) ; } async getNodeChildrenDropdown ( index ) { if ( await this . nodeHasChildrenDropdown ( index ) === false ) { return [ ] ; } await this . clickNode ( index ) ; return await $$ ( 'ux-hierarchy-bar-popover-item' ) ; } async getNodeChildrenTitles ( index ) { const children = await this . getNodeChildren ( index ) ; const titles = [ ] ; for ( let child of children ) { const title = await child . $ ( '.hierarchy-bar-node-title' ) ; titles . push ( await title . getText ( ) ) ; } return titles ; } async getOverflowNodesCollapsed ( ) { const content = await $ ( '.hierarchy-bar-overflow' ) ; await content . click ( ) ; return await $$ ( 'ux-hierarchy-bar-popover-item' ) ; } async getOverflowNodes ( ) { const indicator = await $ ( '.hierarchy-bar-overflow-indicator' ) ; await indicator . click ( ) ; return await $$ ( 'ux-hierarchy-bar-popover-item' ) ; } async getOverflowNodeTitles ( ) { const children = await this . getOverflowNodes ( ) ; const titles = [ ] ; for ( let child of children ) { const title = await child . $ ( '.hierarchy-bar-node-title' ) ; titles . push ( await title . getText ( ) ) ; } return titles ; } async getAddons ( ) { return await this . hierarchyBar . $$ ( '.button-secondary' ) ; } }