@Test @UseWithField(field = "todayControlMode", valuesFrom = FROM_ENUM, value = "") public void testTodayControlMode() { calendarAttributes.set(CalendarAttributes.todayControlMode, todayControlMode.value); switch (todayControlMode) { case HIDDEN: assertNotVisible(popupCalendar.openPopup().getFooterControls().getTodayButtonElement()); break; case NULL: case SELECT: // set date to tomorrow popupCalendar.setDateTime(todayMidday.plusDays(1)); // set date with calendar's 'Today' button, // this will scroll and select todays day MetamerPage.waitRequest(popupCalendar.openPopup().getFooterControls(), WaitRequestType.NONE) .todayDate(); CalendarDay selectedDay = popupCalendar.openPopup().getDayPicker().getSelectedDay(); assertNotNull(selectedDay); assertTrue(selectedDay.is(DayType.todayDay)); break; case SCROLL: popupCalendar.setDateTime(todayMidday.plusMonths(1)); // set date with calendar's 'Today' button, // this will only scroll to today but will not select it MetamerPage.waitRequest(popupCalendar.openPopup().getFooterControls(), WaitRequestType.NONE) .todayDate(); // no selected day should be in calendar assertNull(popupCalendar.openPopup().getDayPicker().getSelectedDay()); // but view of day picker should will change to current month assertEquals( popupCalendar.openPopup().getHeaderControls().getYearAndMonth().getMonthOfYear(), todayMidday.getMonthOfYear()); break; } }
@Test @UseWithField(field = "boundaryDatesMode", valuesFrom = FROM_ENUM, value = "") @Templates("plain") public void testBoundaryDatesMode() { calendarAttributes.set(CalendarAttributes.boundaryDatesMode, boundaryDatesMode.value); DayPicker dayPicker = popupCalendar.openPopup().getDayPicker(); MetamerPage.waitRequest(popupCalendar, WaitRequestType.XHR).setDateTime(firstOfNovember2012); PopupFooterControls footerControls = popupCalendar.openPopup().getFooterControls(); HeaderControls headerControls = popupCalendar.openPopup().getHeaderControls(); DateTime yearAndMonth; String firstOfNovember2012String = firstOfNovember2012.toString(dateTimeFormatter); switch (boundaryDatesMode) { case INACTIVE: case NULL: try { MetamerPage.waitRequest(dayPicker.getBoundaryDays().get(0), WaitRequestType.NONE) .select(); fail("Item should not be selected."); } catch (TimeoutException ex) { // ok } // apply and check, that the date has not changed footerControls = popupCalendar.openPopup().getFooterControls(); MetamerPage.waitRequest(footerControls, WaitRequestType.NONE).applyDate(); assertEquals(popupCalendar.getInput().getStringValue(), firstOfNovember2012String); break; case SCROLL: // scroll to 28th of October 2012 try { MetamerPage.waitRequest(dayPicker.getBoundaryDays().get(0), WaitRequestType.NONE) .select(); fail("Item should not be selected."); } catch (TimeoutException ex) { // ok } yearAndMonth = headerControls.getYearAndMonth(); assertEquals(yearAndMonth.getYear(), 2012); assertEquals(yearAndMonth.getMonthOfYear(), 10); // apply and check, that the date has not changed footerControls = popupCalendar.openPopup().getFooterControls(); MetamerPage.waitRequest(footerControls, WaitRequestType.NONE).applyDate(); assertEquals(popupCalendar.getInput().getStringValue(), firstOfNovember2012String); break; case SELECT: // select 28th of October 2012 CalendarDay day = dayPicker.getBoundaryDays().get(0); MetamerPage.waitRequest(day.getDayElement(), WaitRequestType.NONE).click(); yearAndMonth = headerControls.getYearAndMonth(); assertEquals(yearAndMonth.getYear(), 2012); assertEquals(yearAndMonth.getMonthOfYear(), 10); MetamerPage.waitRequest(footerControls, WaitRequestType.XHR).applyDate(); DateTime parsedDateTime = dateTimeFormatter.parseDateTime(popupCalendar.getInput().getStringValue()); assertEquals(parsedDateTime.getYear(), 2012); assertEquals(parsedDateTime.getMonthOfYear(), 10); assertEquals(parsedDateTime.getDayOfMonth(), 28); break; } }
@Test public void testDayDisableFunction() { calendarAttributes.set(CalendarAttributes.dayDisableFunction, "disableTuesdays"); int tuesdayDay = 3; // switch to next month to refresh classes popupCalendar.openPopup().getHeaderControls().nextMonth(); DayPicker dayPicker = popupCalendar.openPopup().getDayPicker(); List<CalendarDay> tuesdays = filterOutBoundaryDays(Lists.newArrayList(dayPicker.getSpecificDays(tuesdayDay))); for (CalendarDay tuesday : tuesdays) { assertFalse(tuesday.is(DayType.selectableDay), "All tuesdays should not be enabled."); } calendarAttributes.set(CalendarAttributes.dayDisableFunction, "null"); dayPicker = popupCalendar.openPopup().getDayPicker(); tuesdays = filterOutBoundaryDays(Lists.newArrayList(dayPicker.getSpecificDays(tuesdayDay))); for (CalendarDay tuesday : tuesdays) { assertTrue(tuesday.is(DayType.selectableDay), "All tuesdays should be enabled."); } }
@Test @Templates(value = "plain") public void testDayClassFunction() { int tuesdayDay = 3; calendarAttributes.set(CalendarAttributes.dayClassFunction, "yellowTuesdays"); // switch to next month to refresh classes popupCalendar.openPopup().getHeaderControls().nextMonth(); DayPicker dayPicker = popupCalendar.openPopup().getDayPicker(); List<CalendarDay> tuesdays = filterOutBoundaryDays(Lists.newArrayList(dayPicker.getSpecificDays(tuesdayDay))); for (CalendarDay tuesday : tuesdays) { assertTrue(tuesday.containsStyleClass("yellowDay"), "All tuesdays should be yellow."); } calendarAttributes.set(CalendarAttributes.dayClassFunction, "null"); dayPicker = popupCalendar.openPopup().getDayPicker(); tuesdays = filterOutBoundaryDays(Lists.newArrayList(dayPicker.getSpecificDays(tuesdayDay))); for (CalendarDay tuesday : tuesdays) { assertFalse(tuesday.containsStyleClass("yellowDay"), "All tuesdays should not be yellow."); } }