import { by , browser } from 'protractor' ; import { Component } from '../component' ; import { isPresentAndDisplayed , waitForStaleness } from '../../utilities/utils' ; const moment = require ( 'moment' ) ; import { BrowserActions } from '@alfresco/adf-testing' ; export class DateTimePicker extends Component { calendar = this . byCss ( '.mat-datetimepicker-popup' , browser ) ; headerDate = this . byCss ( '.mat-datetimepicker-calendar-header-date' ) ; headerYear = this . byCss ( '.mat-datetimepicker-calendar-header-year' ) ; dayPicker = this . byCss ( 'mat-datetimepicker-month-view' ) ; rootElemLocator = by . css ( '.mat-datetimepicker-popup' ) ; constructor ( ancestor ? ) { super ( '.mat-datetimepicker-popup' , ancestor ) ; } async waitForDateTimePickerToClose ( ) { return waitForStaleness ( this . calendar ) ; } async isCalendarOpen ( ) { const element = browser . element ( this . rootElemLocator ) ; return isPresentAndDisplayed ( element ) ; } async setDefaultDay ( ) { const today = moment ( ) ; const tomorrow = today . add ( 1 , 'day' ) ; const dayOfTomorrow = tomorrow . date ( ) ; const date = await this . headerDate . getText ( ) ; const year = await this . headerYear . getText ( ) ; const firstActiveDay = '.mat-datetimepicker-calendar-body-active .mat-datetimepicker-calendar-body-cell-content' ; const elem = this . dayPicker . element ( by . cssContainingText ( firstActiveDay , `${ dayOfTomorrow }` ) ) ; await BrowserActions . click ( elem ) ; return `${ date } ${ year }` ; } }