import { $ , browser , ElementFinder , Key } from 'protractor' ; export class VirtualForPage { table = $ ( 'tbody' ) ; spacer = this . table . $ ( '.ux-virtual-scroll-spacer' ) ; rows = this . table . $$ ( '.table-row' ) ; reorderBtn = $ ( '#reorder-button' ) ; async getPage ( ) { return await browser . get ( '#/virtual-for' ) ; } async getVisibleRowCount ( ) { return await this . rows . count ( ) ; } async getSpacerHeight ( ) { return await this . spacer . getCssValue ( 'height' ) ; } async getRow ( visibleIndex ) { return await this . rows . get ( visibleIndex ) ; } async getCell ( visibleRow , columnIdx ) { const row = await this . getRow ( visibleRow ) ; const column = await row . $$ ( 'td' ) . get ( columnIdx ) ; return await column . getAttribute ( 'textContent' ) ; } async focusRow ( visibleRow ) { const row = await this . getRow ( visibleRow ) ; await row . click ( ) ; } async moveFocusDown ( ) { await browser . actions ( ) . sendKeys ( Key . ARROW_DOWN ) . perform ( ) ; } async moveFocusUp ( ) { await browser . actions ( ) . sendKeys ( Key . ARROW_UP ) . perform ( ) ; } async moveFocusHome ( ) { await browser . actions ( ) . sendKeys ( Key . HOME ) . perform ( ) ; } async moveFocusEnd ( ) { await browser . actions ( ) . sendKeys ( Key . END ) . perform ( ) ; } async pageFocusDown ( ) { await browser . actions ( ) . sendKeys ( Key . PAGE_DOWN ) . perform ( ) ; } async pageFocusUp ( ) { await browser . actions ( ) . sendKeys ( Key . PAGE_UP ) . perform ( ) ; } async getRowFocused ( visibleRow ) { const row = await this . getRow ( visibleRow ) ; const classes = await row . getAttribute ( 'class' ) ; return classes . split ( ' ' ) . indexOf ( 'ux-focus-indicator-active' ) !== - 1 ; } async getFocusedRow ( ) { for ( let idx = 0 ; idx < await this . rows . count ( ) ; idx ++ ) { if ( await this . getRowFocused ( idx ) ) { return idx ; } } } async getValue ( visibleRow ) { return await this . getCell ( visibleRow , 0 ) ; } async getIndex ( visibleRow ) { return await this . getCell ( visibleRow , 1 ) ; } async getCount ( visibleRow ) { return await this . getCell ( visibleRow , 2 ) ; } async getFirst ( visibleRow ) { return await this . getCell ( visibleRow , 3 ) === 'true' ; } async getLast ( visibleRow ) { return await this . getCell ( visibleRow , 4 ) === 'true' ; } async getEven ( visibleRow ) { return await this . getCell ( visibleRow , 5 ) === 'true' ; } async getOdd ( visibleRow ) { return await this . getCell ( visibleRow , 6 ) === 'true' ; } async scrollToPosition ( position ) { await browser . executeScript ( `arguments[0].scrollTop = ${ position }` , this . table ) ; } }