diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2015-01-30 17:46:07 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-02-19 14:36:52 +0200 |
commit | c4f36c2a35b9bc2db7b1da15d91edab6d6d68a9e (patch) | |
tree | 1950bdeae335f241fbda7ab9251030a5faed861f /uitest | |
parent | ba163b261c4791c6648d6c31841ec892a0246e8b (diff) | |
download | vaadin-framework-c4f36c2a35b9bc2db7b1da15d91edab6d6d68a9e.tar.gz vaadin-framework-c4f36c2a35b9bc2db7b1da15d91edab6d6d68a9e.zip |
Enable navigation on a readonly Calendar. (#16523)
- Month view: navigate to week and day views
- Week view: navigate to day view and to next and prev weeks
- Day view: navigate to next and prev days
- Month view: hidden events can be expanded to view.
Change-Id: I19c64ae64c55b8e07be7f73be64e18e700f849b5
Diffstat (limited to 'uitest')
4 files changed, 320 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java new file mode 100644 index 0000000000..8b8122dcf9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarDisabledTest.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.components.calendar; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.newelements.CalendarElement; + +public class CalendarDisabledTest extends MultiBrowserTest { + + @Override + protected Class<?> getUIClass() { + return CalendarReadOnly.class; + } + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL("restartApplication&disabled"); + } + + private CalendarElement getCalendar() { + return $(CalendarElement.class).first(); + } + + @Test + public void weekViewCannotBeOpenedFromMonthView() { + tryOpenWeekView(); + assertCalendarInMonthView(); + } + + @Test + public void dayViewCannotBeOpenedFromMonthView() { + tryOpenDayView(); + assertCalendarInMonthView(); + } + + private void tryOpenDayView() { + getCalendar().getDayNumbers().get(0).click(); + } + + private void tryOpenWeekView() { + getCalendar().getWeekNumbers().get(0).click(); + } + + private void assertCalendarInMonthView() { + assertTrue("Calendar wasn't in month view.", getCalendar() + .hasMonthView()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java new file mode 100644 index 0000000000..8e82555e87 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnly.java @@ -0,0 +1,71 @@ +package com.vaadin.tests.components.calendar; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Calendar; +import com.vaadin.ui.components.calendar.CalendarComponentEvents; +import com.vaadin.ui.components.calendar.event.BasicEvent; +import com.vaadin.ui.themes.ValoTheme; + +@Theme(ValoTheme.THEME_NAME) +public class CalendarReadOnly extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Calendar calendar = new Calendar(); + + if (request.getParameter("readonly") != null) { + calendar.setReadOnly(true); + } + + if (request.getParameter("disabled") != null) { + calendar.setEnabled(false); + } + + calendar.setFirstVisibleHourOfDay(8); + calendar.setLastVisibleHourOfDay(16); + + calendar.setTimeFormat(Calendar.TimeFormat.Format24H); + calendar.setHandler((CalendarComponentEvents.EventResizeHandler) null); + + calendar.setSizeFull(); + + try { + calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-09-01")); + calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd") + .parse("2013-09-30")); + + BasicEvent event = new BasicEvent("EVENT NAME 1", + "EVENT TOOLTIP 1", + new SimpleDateFormat("yyyy-MM-dd HH:mm") + .parse("2013-09-05 15:30"), new SimpleDateFormat( + "yyyy-MM-dd HH:mm").parse("2013-09-05 22:20")); + event.setStyleName("color1"); + + calendar.addEvent(event); + calendar.addEvent(event); + calendar.addEvent(event); + calendar.addEvent(event); + + } catch (ParseException e) { + + } + + addComponent(calendar); + } + + @Override + protected Integer getTicketNumber() { + return 16523; + } + + @Override + protected String getTestDescription() { + return "When set to readonly, you should still be able to navigate through the calendar."; + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java new file mode 100644 index 0000000000..142353f314 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarReadOnlyTest.java @@ -0,0 +1,149 @@ +package com.vaadin.tests.components.calendar; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.newelements.CalendarElement; + +public class CalendarReadOnlyTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL("restartApplication&readonly"); + } + + @Test + public void weekViewCanBeOpenedFromMonthView() { + openWeekView(); + + assertTrue("Calendar wasn't in week view.", getCalendar().hasWeekView()); + } + + @Test + public void dayViewCanBeOpenedFromMonthView() { + openDayView(); + + assertTrue("Calendar wasn't in day view.", getCalendar().hasDayView()); + } + + @Test + public void dayViewCanBeOpenedFromWeekView() { + openWeekView(); + + getCalendar().getDayHeaders().get(0).click(); + + assertTrue("Calendar wasn't in day view.", getCalendar().hasDayView()); + } + + @Test + public void weekViewCanBeBrowsedForwards() { + openWeekView(); + + String firstDayOfCurrentWeek = getVisibleFirstDay(); + getCalendar().next(); + + String firstDayOfNextWeek = getVisibleFirstDay(); + + assertThat("Week didn't change.", firstDayOfCurrentWeek, + is(not(firstDayOfNextWeek))); + } + + @Test + public void weekViewCanBeBrowsedBackwards() { + openWeekView(); + + String firstDayOfCurrentWeek = getVisibleFirstDay(); + getCalendar().back(); + + String firstDayOfPreviousWeek = getVisibleFirstDay(); + + assertThat("Week didn't change.", firstDayOfCurrentWeek, + is(not(firstDayOfPreviousWeek))); + } + + @Test + public void dayViewCanBeBrowsedForwards() { + openDayView(); + + String currentDay = getVisibleFirstDay(); + getCalendar().next(); + + String nextDay = getVisibleFirstDay(); + + assertThat("Day didn't change.", currentDay, is(not(nextDay))); + } + + @Test + public void dayViewCanBeBrowsedBackwards() { + openDayView(); + + String currentDay = getVisibleFirstDay(); + getCalendar().back(); + + String previousDay = getVisibleFirstDay(); + + assertThat("Day didn't change.", currentDay, is(not(previousDay))); + } + + @Test + public void hiddenEventsCanBeExpanded() { + WebElement dayWithEvents = getFirstDayWithEvents(); + + assertThat("Incorrect event count.", getVisibleEvents(dayWithEvents) + .size(), is(2)); + + toggleExpandEvents(dayWithEvents).click(); + assertThat("Incorrect event count.", getVisibleEvents(dayWithEvents) + .size(), is(4)); + + toggleExpandEvents(dayWithEvents).click(); + assertThat("Incorrect event count.", getVisibleEvents(dayWithEvents) + .size(), is(2)); + } + + private CalendarElement getCalendar() { + return $(CalendarElement.class).first(); + } + + private void openDayView() { + getCalendar().getDayNumbers().get(0).click(); + } + + private void openWeekView() { + getCalendar().getWeekNumbers().get(0).click(); + } + + private String getVisibleFirstDay() { + return getCalendar().getDayHeaders().get(0).getText(); + } + + private WebElement getFirstDayWithEvents() { + for (WebElement monthDay : getCalendar().getMonthDays()) { + if (getVisibleEvents(monthDay).size() > 0) { + return monthDay; + } + } + + return null; + } + + private WebElement toggleExpandEvents(WebElement dayWithEvents) { + return dayWithEvents.findElement(By + .className("v-calendar-bottom-spacer")); + } + + private List<WebElement> getVisibleEvents(WebElement dayWithEvents) { + return dayWithEvents.findElements(By.className("v-calendar-event")); + } +} diff --git a/uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java b/uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java new file mode 100644 index 0000000000..e5213b21b5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/newelements/CalendarElement.java @@ -0,0 +1,48 @@ +package com.vaadin.tests.tb3.newelements; + +import java.util.List; + +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ServerClass; + +@ServerClass("com.vaadin.ui.Calendar") +public class CalendarElement extends + com.vaadin.testbench.elements.CalendarElement { + public List<WebElement> getWeekNumbers() { + return findElements(By.className("v-calendar-week-number")); + } + + public boolean hasMonthView() { + return isElementPresent(By.className("v-calendar-week-numbers")); + } + + public boolean hasWeekView() { + return isElementPresent(By.className("v-calendar-header-week")); + } + + public List<WebElement> getDayNumbers() { + return findElements(By.className("v-calendar-day-number")); + } + + public List<WebElement> getMonthDays() { + return findElements(By.className("v-calendar-month-day")); + } + + public boolean hasDayView() { + return getDayHeaders().size() == 1; + } + + public List<WebElement> getDayHeaders() { + return findElements(By.className("v-calendar-header-day")); + } + + public void back() { + findElement(By.className("v-calendar-back")).click(); + } + + public void next() { + findElement(By.className("v-calendar-next")).click(); + } +} |