import { imageCompare } from '../common/image-compare' ; import { DateTimePickerPage } from './date-time-picker.po.spec' ; describe ( 'Date Time Picker Tests' , ( ) => { let page ; beforeEach ( async ( ) => { page = new DateTimePickerPage ( ) ; await page . getPage ( ) ; } ) ; it ( 'should have correct initial states' , async ( ) => { expect ( ( await page . header . getText ( ) ) . toLocaleLowerCase ( ) ) . toBe ( 'january 2019' ) ; expect ( await page . selectedDate . getText ( ) ) . toBe ( '3' ) ; expect ( await page . dates . count ( ) ) . toBe ( 35 ) ; expect ( await page . previewDates . count ( ) ) . toBe ( 4 ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' ] ) ; expect ( await page . getCurrentDate ( ) ) . toBe ( 'January 3, 2019, 12:00:00 PM' ) ; expect ( await page . getDisabled ( page . previousHeaderBtn ) ) . toBe ( false ) ; expect ( await page . getDisabled ( page . nextHeaderBtn ) ) . toBe ( false ) ; expect ( await page . getDisabled ( page . todayBtn ) ) . toBe ( false ) ; expect ( await imageCompare ( 'date-picker-initial' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should select a valid date on click' , async ( ) => { const date = await page . getDate ( '8' ) ; await date . click ( ) ; const classes = await date . getAttribute ( 'class' ) ; expect ( classes . indexOf ( 'active' ) ) . toBeGreaterThan ( - 1 ) ; expect ( await page . getCurrentDate ( ) ) . toBe ( 'January 8, 2019, 12:00:00 PM' ) ; expect ( await imageCompare ( 'date-picker-select' ) ) . toEqual ( 0 ) ; } ) ; it ( 'should allow changing the startOfWeek' , async ( ) => { expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 4 ) ; await page . changeWeekStartBtn . click ( ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' , 'Sun' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 3 ) ; await page . changeWeekStartBtn . click ( ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' , 'Sun' , 'Mon' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 2 ) ; await page . changeWeekStartBtn . click ( ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Wed' , 'Thu' , 'Fri' , 'Sat' , 'Sun' , 'Mon' , 'Tue' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 8 ) ; await page . changeWeekStartBtn . click ( ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Thu' , 'Fri' , 'Sat' , 'Sun' , 'Mon' , 'Tue' , 'Wed' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 7 ) ; await page . changeWeekStartBtn . click ( ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Fri' , 'Sat' , 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 6 ) ; await page . changeWeekStartBtn . click ( ) ; expect ( await page . getWeekdayOrder ( ) ) . toEqual ( [ 'Sat' , 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' ] ) ; expect ( await page . getPositionOfSelectedDate ( ) ) . toBe ( 5 ) ; } ) ; it ( 'should allow minimum and maximum dates to be set' , async ( ) => { await page . setMinAndMax ( ) ; expect ( await page . getDisabled ( await page . getDate ( '30' , true ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '31' , true ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '1' , false ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '29' , false ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '30' , false ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '31' , false ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '1' , true ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getDate ( '2' , true ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( page . previousHeaderBtn ) ) . toBe ( true ) ; expect ( await page . getDisabled ( page . nextHeaderBtn ) ) . toBe ( true ) ; expect ( await page . getDisabled ( page . todayBtn ) ) . toBe ( true ) ; const date = await page . getDate ( '1' ) ; await date . click ( ) ; const classes = await date . getAttribute ( 'class' ) ; expect ( classes . indexOf ( 'active' ) ) . toBe ( - 1 ) ; expect ( await page . getCurrentDate ( ) ) . toBe ( 'January 3, 2019, 12:00:00 PM' ) ; await page . header . click ( ) ; expect ( await page . getDisabled ( page . previousHeaderBtn ) ) . toBe ( true ) ; expect ( await page . getDisabled ( page . nextHeaderBtn ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Jan' ) ) ) . toBe ( false ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Feb' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Mar' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Apr' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'May' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Jun' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Jul' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Aug' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Sep' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Oct' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Nov' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( 'Dec' ) ) ) . toBe ( true ) ; await page . header . click ( ) ; expect ( await page . getDisabled ( page . previousHeaderBtn ) ) . toBe ( true ) ; expect ( await page . getDisabled ( page . nextHeaderBtn ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2010' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2011' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2012' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2013' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2014' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2015' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2016' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2017' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2018' ) ) ) . toBe ( true ) ; expect ( await page . getDisabled ( await page . getCalendarItem ( '2019' ) ) ) . toBe ( false ) ; } ) ; it ( 'should correctly set the date when the current day value does not exist in the selected month' , async ( ) => { let date = await page . getDate ( '31' ) ; await date . click ( ) ; date = await page . getDate ( '1' , true ) ; if ( await page . attemptClick ( date ) ) { expect ( await page . getCurrentDate ( ) ) . toBe ( 'February 1, 2019, 12:00:00 PM' ) ; } else { expect ( await page . getCurrentDate ( ) ) . toBe ( 'January 31, 2019, 12:00:00 PM' ) ; } } ) ; it ( 'should correctly set the date when select an adjacent month' , async ( ) => { const date = await page . getDate ( '31' ) ; await date . click ( ) ; await page . nextDate . click ( ) ; const activeDate = await page . getDate ( '31' , true ) ; const classes = await activeDate . getAttribute ( 'class' ) ; expect ( classes . indexOf ( 'active' ) ) . toBeGreaterThan ( - 1 ) ; expect ( await page . getCurrentDate ( ) ) . toBe ( 'January 31, 2019, 12:00:00 PM' ) ; expect ( await imageCompare ( 'date-picker-adjacent-month-selection' ) ) . toBe ( 0 ) ; } ) ; } ) ;