summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests
diff options
context:
space:
mode:
authorAnthony Guerreiro <anthony@vaadin.com>2014-06-23 14:13:37 +0300
committerVaadin Code Review <review@vaadin.com>2014-06-25 09:38:35 +0000
commitf846f8d699ad6f599d91f7f86aa419be9b22b5a8 (patch)
treea1fc72df9712eaf24291b9d5bb2ea10212093d48 /uitest/src/com/vaadin/tests
parent5103cbf48b0d8eb615622d4d6439fc0d3f0bfaea (diff)
downloadvaadin-framework-f846f8d699ad6f599d91f7f86aa419be9b22b5a8.tar.gz
vaadin-framework-f846f8d699ad6f599d91f7f86aa419be9b22b5a8.zip
Fix wrong width on event resize in Vaadin Calendar (#13961)
Change-Id: I68775af42c1c6086d347bea81e54bbe3cf7e5a22
Diffstat (limited to 'uitest/src/com/vaadin/tests')
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEvents.java103
-rw-r--r--uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java153
2 files changed, 256 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEvents.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEvents.java
new file mode 100644
index 0000000000..2025ce2ea7
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEvents.java
@@ -0,0 +1,103 @@
+/*
+ * 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.tests.components.calendar;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Calendar;
+import com.vaadin.ui.components.calendar.event.BasicEvent;
+import com.vaadin.ui.components.calendar.event.CalendarEvent;
+import com.vaadin.ui.components.calendar.event.CalendarEventProvider;
+
+/**
+ *
+ * @author Vaadin Ltd
+ */
+public class CalendarResizeOverlappingEvents extends AbstractTestUI {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
+ * VaadinRequest)
+ */
+ @Override
+ protected void setup(VaadinRequest request) {
+ Calendar calendar = new Calendar(new CalendarEventProvider() {
+
+ @Override
+ public List<CalendarEvent> getEvents(Date startDate, Date endDate) {
+ DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ DateFormat dayFormat = new SimpleDateFormat("yyyy-MM-dd");
+ List<CalendarEvent> events = new ArrayList<CalendarEvent>();
+ try {
+ java.util.Calendar today = java.util.Calendar.getInstance();
+
+ String todayString = dayFormat.format(today.getTime());
+
+ Date date1 = format.parse(todayString + " 09:00:00");
+ Date date2 = format.parse(todayString + " 11:00:00");
+ Date date3 = format.parse(todayString + " 12:00:00");
+ Date date4 = format.parse(todayString + " 14:00:00");
+ Date date5 = format.parse(todayString + " 15:00:00");
+ Date date6 = format.parse(todayString + " 17:00:00");
+
+ CalendarEvent event1 = new BasicEvent("First", "", date1,
+ date2);
+ CalendarEvent event2 = new BasicEvent("Second", "", date3,
+ date4);
+ CalendarEvent event3 = new BasicEvent("Third", "", date5,
+ date6);
+
+ events.add(event1);
+ events.add(event2);
+ events.add(event3);
+ } catch (ParseException e) {
+ }
+ return events;
+ }
+ });
+ calendar.setSizeFull();
+ setContent(calendar);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
+ */
+ @Override
+ protected String getTestDescription() {
+ return "Verify the widths of the events are correctly recalculated when these are resized and overlapped";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
+ */
+ @Override
+ protected Integer getTicketNumber() {
+ return 13961;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java
new file mode 100644
index 0000000000..f664149cce
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarResizeOverlappingEventsTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.tests.components.calendar;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ *
+ * @author Vaadin Ltd
+ */
+public class CalendarResizeOverlappingEventsTest extends MultiBrowserTest {
+
+ private int noOverlapWidth;
+ private int oneOverlapWidth;
+ private int twoOverlapsWidth;
+
+ private WebElement firstEvent;
+ private WebElement secondEvent;
+ private WebElement thirdEvent;
+
+ private WebElement firstEventBottomResize;
+ private WebElement secondEventBottomResize;
+ private WebElement thirdEventBottomResize;
+
+ @Test
+ public void testCalendarResizeOverlappingEvents()
+ throws InterruptedException, IOException {
+
+ openTestURL();
+ initParams();
+ doTest();
+ }
+
+ private void doTest() {
+ assertWidths(noOverlapWidth, noOverlapWidth, noOverlapWidth);
+
+ dragAndDrop(firstEventBottomResize, 240);
+ assertWidths(oneOverlapWidth, oneOverlapWidth, oneOverlapWidth);
+
+ dragAndDrop(secondEventBottomResize, 240);
+ assertWidths(twoOverlapsWidth, twoOverlapsWidth, twoOverlapsWidth);
+
+ dragAndDrop(secondEventBottomResize, -240);
+ dragAndDrop(firstEventBottomResize, -240);
+ assertWidths(noOverlapWidth, noOverlapWidth, noOverlapWidth);
+
+ }
+
+ private void assertWidths(int firstEventExpectedWidth,
+ int secondEventExpectedWidth, int thirdEventExpectedWidth) {
+ int widthTolerance = 5;
+ String errorMessage = "Wrong event width after resizing, expected [%d] (+/-%d), obtained [%d]";
+
+ int actualWidth = firstEvent.getSize().getWidth();
+ int expectedWidth = firstEventExpectedWidth;
+ Assert.assertTrue(String.format(errorMessage, expectedWidth,
+ widthTolerance, actualWidth),
+ isAproximateWidth(actualWidth, expectedWidth, widthTolerance));
+
+ actualWidth = secondEvent.getSize().getWidth();
+ expectedWidth = secondEventExpectedWidth;
+ Assert.assertTrue(String.format(errorMessage, expectedWidth,
+ widthTolerance, actualWidth),
+ isAproximateWidth(actualWidth, expectedWidth, widthTolerance));
+
+ actualWidth = thirdEvent.getSize().getWidth();
+ expectedWidth = thirdEventExpectedWidth;
+ Assert.assertTrue(String.format(errorMessage, expectedWidth,
+ widthTolerance, actualWidth),
+ isAproximateWidth(actualWidth, expectedWidth, widthTolerance));
+ }
+
+ private boolean isAproximateWidth(int actualWidth, int expectedWidth,
+ int tolerance) {
+ return Math.abs(expectedWidth - actualWidth) <= tolerance;
+ }
+
+ private void dragAndDrop(WebElement element, int yOffset) {
+ /*
+ * Selenium doesn't properly drag and drop items in IE8. It tries to
+ * start dragging an element from a position above the element itself.
+ */
+ if (BrowserUtil.isIE8(getDesiredCapabilities())) {
+ Actions action = new Actions(getDriver());
+ action.moveToElement(element);
+ action.moveByOffset(0, 1);
+ action.clickAndHold();
+ action.moveByOffset(0, yOffset);
+ action.release();
+ action.build().perform();
+ } else {
+ Actions action = new Actions(getDriver());
+ action.dragAndDropBy(element, 0, yOffset);
+ action.build().perform();
+ }
+ }
+
+ private void initParams() {
+ WebElement dateSlot = getDriver().findElement(
+ By.className("v-datecellslot"));
+ int dateSlotWidth = dateSlot.getSize().getWidth();
+ noOverlapWidth = dateSlotWidth;
+ oneOverlapWidth = dateSlotWidth / 2;
+ twoOverlapsWidth = dateSlotWidth / 3;
+
+ Comparator<WebElement> startTimeComparator = new Comparator<WebElement>() {
+ @Override
+ public int compare(WebElement e1, WebElement e2) {
+ int e1Top = e1.getLocation().getY();
+ int e2Top = e2.getLocation().getY();
+ return e1Top - e2Top;
+ }
+ };
+
+ List<WebElement> eventElements = getDriver().findElements(
+ By.className("v-calendar-event-content"));
+ Collections.sort(eventElements, startTimeComparator);
+ firstEvent = eventElements.get(0);
+ secondEvent = eventElements.get(1);
+ thirdEvent = eventElements.get(2);
+
+ List<WebElement> resizeBottomElements = getDriver().findElements(
+ By.className("v-calendar-event-resizebottom"));
+ Collections.sort(resizeBottomElements, startTimeComparator);
+ firstEventBottomResize = resizeBottomElements.get(0);
+ secondEventBottomResize = resizeBottomElements.get(1);
+ thirdEventBottomResize = resizeBottomElements.get(2);
+ }
+}