import { $ , $$ , browser , ElementFinder } from 'protractor' ; export class DateTimePickerPage { header = $ ( '.header-title' ) ; weekdayColumns = $$ ( 'th.weekday' ) ; dates = $$ ( '.date-button' ) ; calendarItems = $$ ( '.calendar-item' ) ; previewDates = $$ ( '.date-button.preview' ) ; selectedDate = $ ( '.date-button.active' ) ; todayBtn = $ ( '.now-button' ) ; currentDate = $ ( '#current-date' ) ; nextDate = $ ( '.header-navigation-next-icon' ) ; changeWeekStartBtn = $ ( '#change-start-of-week' ) ; setMinAndMaxBtn = $ ( '#set-limits' ) ; headerButtons = $$ ( '.header-navigation' ) ; previousHeaderBtn = this . headerButtons . get ( 0 ) ; nextHeaderBtn = this . headerButtons . get ( 1 ) ; async getPage ( ) { await browser . get ( '#/date-time-picker' ) ; } async getCurrentDate ( ) { return await this . currentDate . getAttribute ( 'innerText' ) ; } async getWeekdayOrder ( ) { return await this . weekdayColumns . map < string > ( element => element . getText ( ) ) ; } async getPositionOfSelectedDate ( ) { const dates = await this . dates . map < string > ( element => element . getText ( ) ) ; const selected = await this . selectedDate . getText ( ) ; return dates . indexOf ( selected ) ; } async setMinAndMax ( ) { return this . setMinAndMaxBtn . click ( ) ; } async getDisabled ( element ) { return await element . getAttribute ( 'disabled' ) === 'true' ; } async getDate ( day , isPreview = false ) { for ( const date of await this . dates ) { const text = await date . getAttribute ( 'innerText' ) ; const classes = await date . getAttribute ( 'class' ) ; if ( ! isPreview && classes . indexOf ( 'preview' ) === - 1 && day === text ) { return date ; } if ( isPreview && classes . indexOf ( 'preview' ) !== - 1 && day === text ) { return date ; } } } async getCalendarItem ( item ) { for ( const date of await this . calendarItems ) { const text = await date . getAttribute ( 'innerText' ) ; if ( item === text ) { return date ; } } } async attemptClick ( item ) { try { await item . click ( ) ; return true ; } catch { return false ; } } }