summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2016-12-14 13:50:06 +0200
committerIlia Motornyi <elmot@vaadin.com>2016-12-14 13:50:06 +0200
commitfc011f6a8a08064f48fd5f4280f1d4d3647ab7f1 (patch)
tree3cb8e0f9022aa752b55e9f83f209388e1557b0ba /uitest
parent692bbef040a61388d8ba028a9701a760b64baa43 (diff)
downloadvaadin-framework-fc011f6a8a08064f48fd5f4280f1d4d3647ab7f1.tar.gz
vaadin-framework-fc011f6a8a08064f48fd5f4280f1d4d3647ab7f1.zip
Provide configuration for events order in month and week views
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSort.java223
-rw-r--r--uitest/src/test/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSortTest.java183
2 files changed, 406 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSort.java b/uitest/src/main/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSort.java
new file mode 100644
index 0000000000..4236aad2c9
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSort.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.v7.tests.components.calendar;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.v7.shared.ui.calendar.CalendarState.EventSortOrder;
+import com.vaadin.v7.ui.Calendar;
+import com.vaadin.v7.ui.components.calendar.event.BasicEvent;
+import com.vaadin.v7.ui.components.calendar.event.CalendarEvent;
+import com.vaadin.v7.ui.components.calendar.event.CalendarEventProvider;
+
+/**
+ *
+ * Test UI for event sorting in calendar month and week views.
+ *
+ * @author Vaadin Ltd
+ */
+public class CalendarEventsSort extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ getContent().setSizeFull();
+ final Calendar calendar = new Calendar("Test calendar");
+
+ toMonthView(calendar);
+ calendar.setEventSortOrder(EventSortOrder.UNSORTED);
+
+ calendar.setEventProvider(createEventProvider());
+ addComponent(calendar);
+
+ createSortByDateButton(calendar);
+ createSortByDurationButton(calendar);
+ createSortByProviderButton(calendar);
+ createViewSwitchButton(calendar);
+ }
+
+ private void createViewSwitchButton(final Calendar calendar) {
+ Button toWeek = new Button("Switch to week view", new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Button button = event.getButton();
+ Boolean month = (Boolean) button.getData();
+ button.setData(!month);
+ if (month) {
+ button.setCaption("Switch to month view");
+ toWeekView(calendar);
+ } else {
+ button.setCaption("Switch to week view");
+ toMonthView(calendar);
+ }
+ }
+
+ });
+ toWeek.addStyleName("view");
+ toWeek.setData(true);
+ addComponent(toWeek);
+ }
+
+ private Button createSortByProviderButton(final Calendar calendar) {
+ Button byProvider = new Button("Sort by provider", new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ calendar.setEventSortOrder(EventSortOrder.UNSORTED);
+ }
+ });
+ byProvider.addStyleName("by-provider");
+ addComponent(byProvider);
+ return byProvider;
+ }
+
+ private void createSortByDurationButton(final Calendar calendar) {
+ Button byDuration = new Button("Sort by duration DESC",
+ new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Button button = event.getButton();
+ EventSortOrder order = (EventSortOrder) button
+ .getData();
+ if (EventSortOrder.DURATION_DESC.equals(order)) {
+ order = EventSortOrder.DURATION_ASC;
+ button.setCaption("Sort by duration DESC");
+ addSortOrder(true, button);
+ } else {
+ order = EventSortOrder.DURATION_DESC;
+ button.setCaption("Sort by duration ASC");
+ addSortOrder(false, button);
+ }
+ button.setData(order);
+ calendar.setEventSortOrder(order);
+ }
+ });
+ byDuration.addStyleName("by-duration");
+ byDuration.setData(EventSortOrder.DURATION_ASC);
+ addComponent(byDuration);
+ }
+
+ private void createSortByDateButton(final Calendar calendar) {
+ Button byStartDate = new Button("Sort by start date DESC",
+ new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Button button = event.getButton();
+ EventSortOrder order = (EventSortOrder) button
+ .getData();
+ if (EventSortOrder.START_DATE_DESC.equals(order)) {
+ order = EventSortOrder.START_DATE_ASC;
+ button.setCaption("Sort by start date DESC");
+ addSortOrder(true, button);
+ } else {
+ order = EventSortOrder.START_DATE_DESC;
+ button.setCaption("Sort by start date ASC");
+ addSortOrder(false, button);
+ }
+ button.setData(order);
+ calendar.setEventSortOrder(order);
+ }
+ });
+ byStartDate.setData(EventSortOrder.START_DATE_ASC);
+ byStartDate.addStyleName("by-start-date");
+ addComponent(byStartDate);
+ }
+
+ private CalendarEventProvider createEventProvider() {
+ CalendarEventProvider provider = new CalendarEventProvider() {
+
+ @Override
+ public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
+ java.util.Calendar cal = java.util.Calendar.getInstance();
+ cal.set(java.util.Calendar.HOUR_OF_DAY, 5);
+ cal.set(java.util.Calendar.MINUTE, 0);
+ cal.set(java.util.Calendar.SECOND, 0);
+ cal.set(java.util.Calendar.MILLISECOND, 0);
+
+ Date start = cal.getTime();
+ cal.add(java.util.Calendar.HOUR_OF_DAY, 2);
+ Date end = cal.getTime();
+
+ CalendarEvent event1 = new BasicEvent("first", "descr1", start,
+ end);
+
+ cal.set(java.util.Calendar.HOUR_OF_DAY, 2);
+ start = cal.getTime();
+ cal.add(java.util.Calendar.HOUR_OF_DAY, 4);
+ end = cal.getTime();
+
+ CalendarEvent event2 = new BasicEvent("second", "descr2", start,
+ end);
+
+ cal.set(java.util.Calendar.HOUR_OF_DAY, 1);
+ start = cal.getTime();
+ cal.add(java.util.Calendar.HOUR_OF_DAY, 2);
+ end = cal.getTime();
+
+ CalendarEvent event3 = new BasicEvent("third", "descr2", start,
+ end);
+
+ return Arrays.asList(event1, event2, event3);
+ }
+
+ };
+ return provider;
+ }
+
+ private void addSortOrder(boolean ascending, Button button) {
+ if (ascending) {
+ button.addStyleName("asc");
+ button.removeStyleName("desc");
+ } else {
+ button.removeStyleName("asc");
+ button.addStyleName("desc");
+ }
+ }
+
+ private void toMonthView(final Calendar calendar) {
+ final java.util.Calendar cal = java.util.Calendar.getInstance();
+
+ cal.add(java.util.Calendar.DAY_OF_YEAR, -2);
+ calendar.setStartDate(cal.getTime());
+ cal.add(java.util.Calendar.DAY_OF_YEAR, 14);
+ calendar.setEndDate(cal.getTime());
+ }
+
+ private void toWeekView(final Calendar calendar) {
+ java.util.Calendar cal = java.util.Calendar.getInstance();
+ cal.add(java.util.Calendar.DAY_OF_YEAR, 2);
+ calendar.setEndDate(cal.getTime());
+ }
+
+ @Override
+ public String getDescription() {
+ return "Make event sorting strategy customizable.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14849;
+ }
+} \ No newline at end of file
diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSortTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSortTest.java
new file mode 100644
index 0000000000..27cf549a4f
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/v7/tests/components/calendar/CalendarEventsSortTest.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.v7.tests.components.calendar;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Check how event sorting works in calendar month and week views.
+ *
+ * @author Vaadin Ltd
+ */
+public class CalendarEventsSortTest extends MultiBrowserTest {
+
+ @Test
+ public void testByDuration() {
+ openTestURL();
+
+ checkSortByDuration(true);
+ }
+
+ @Test
+ public void testByStartDate() {
+ openTestURL();
+
+ checkSortByStartDate(true);
+ }
+
+ @Test
+ public void testByProvider() {
+ openTestURL();
+
+ List<WebElement> events = findElements(
+ By.className("v-calendar-event-month"));
+ checkProviderOrder(events);
+ }
+
+ @Test
+ public void testWeekByDuration() {
+ openTestURL();
+
+ findElement(By.className("view")).click();
+
+ checkSortByDuration(false);
+ }
+
+ @Test
+ public void testWeekByStartDate() {
+ openTestURL();
+
+ findElement(By.className("view")).click();
+
+ checkSortByStartDate(false);
+ }
+
+ @Test
+ public void testWeekByProvider() {
+ openTestURL();
+
+ findElement(By.className("view")).click();
+
+ List<WebElement> events = findElements(
+ By.className("v-calendar-event-caption"));
+ checkProviderOrder(events);
+ }
+
+ private void checkSortByStartDate(boolean month) {
+ sort("by-start-date", false);
+
+ String style = month ? "v-calendar-event-month"
+ : "v-calendar-event-caption";
+ List<WebElement> events = findElements(By.className(style));
+ checkStartDateOrderDesc(events);
+
+ sort("by-start-date", true);
+
+ events = findElements(By.className(style));
+ checkStartDateOrderAsc(events);
+ }
+
+ private void sort(String style, boolean ascending) {
+ findElement(By.className(style)).click();
+
+ if (!isElementPresent(
+ By.cssSelector('.' + style + (ascending ? ".asc" : ".desc")))) {
+ findElement(By.className(style)).click();
+ }
+ }
+
+ private void checkSortByDuration(boolean month) {
+ sort("by-duration", false);
+
+ String style = month ? "v-calendar-event-month"
+ : "v-calendar-event-caption";
+
+ List<WebElement> events = findElements(By.className(style));
+ checkDurationOrderDesc(events);
+
+ sort("by-duration", true);
+ events = findElements(By.className(style));
+ checkDurationOrderAsc(events);
+ }
+
+ private void checkDurationOrderDesc(List<WebElement> events) {
+ Assert.assertTrue(
+ "'Second' event should be the first when sorted by duration",
+ events.get(0).getText().endsWith("second"));
+ Assert.assertTrue(
+ "'Third' event should be the second when sorted by duration",
+ events.get(1).getText().endsWith("third"));
+ Assert.assertTrue(
+ "'First' event should be the third when sorted by duration",
+ events.get(2).getText().endsWith("first"));
+ }
+
+ private void checkDurationOrderAsc(List<WebElement> events) {
+ Assert.assertTrue(
+ "'First' event should be the first when sorted by duration",
+ events.get(0).getText().endsWith("first"));
+ Assert.assertTrue(
+ "'Third' event should be the second when sorted by duration",
+ events.get(1).getText().endsWith("third"));
+ Assert.assertTrue(
+ "'Second' event should be the third when sorted by duration",
+ events.get(2).getText().endsWith("second"));
+ }
+
+ private void checkStartDateOrderDesc(List<WebElement> events) {
+ Assert.assertTrue(
+ "'Third' event should be the first when sorted by start date",
+ events.get(0).getText().endsWith("third"));
+ Assert.assertTrue(
+ "'Second' event should be the second when sorted by start date",
+ events.get(1).getText().endsWith("second"));
+ Assert.assertTrue(
+ "'First' event should be the third when sorted by start date",
+ events.get(2).getText().endsWith("first"));
+ }
+
+ private void checkStartDateOrderAsc(List<WebElement> events) {
+ Assert.assertTrue(
+ "'First' event should be the first when sorted by start date",
+ events.get(0).getText().endsWith("first"));
+ Assert.assertTrue(
+ "'Second' event should be the second when sorted by start date",
+ events.get(1).getText().endsWith("second"));
+ Assert.assertTrue(
+ "'Third' event should be the third when sorted by start date",
+ events.get(2).getText().endsWith("third"));
+ }
+
+ private void checkProviderOrder(List<WebElement> events) {
+ Assert.assertTrue(
+ "'First' event should be the first when sorted by provider",
+ events.get(0).getText().endsWith("first"));
+ Assert.assertTrue(
+ "'Second' event should be the second when sorted by provider",
+ events.get(1).getText().endsWith("second"));
+ Assert.assertTrue(
+ "'Third' event should be the third when sorted by provider",
+ events.get(2).getText().endsWith("third"));
+ }
+
+}