From: Heikki Ohinmaa Date: Tue, 19 Aug 2014 10:26:20 +0000 (+0300) Subject: CalendarNotifications test rewrite X-Git-Tag: 7.4.0.beta1~295 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c5c1fe1d0290fcda05e1db4f4fac4a13fb42ca1f;p=vaadin-framework.git CalendarNotifications test rewrite Change-Id: I78f8b0c6a762541f62a3881ce8abb52837d1cad9 --- diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.html b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.html deleted file mode 100644 index 15bf29a0fd..0000000000 --- a/uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - -New Test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
New Test
open/run/com.vaadin.tests.components.calendar.NotificationTestUI?restartApplication
mouseClickvaadin=runcomvaadintestscomponentscalendarNotificationTestUI::/VGridLayout[0]/VCalendar[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]83,11
mouseMovevaadin=runcomvaadintestscomponentscalendarNotificationTestUI::/VGridLayout[0]/VCalendar[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[1]/domChild[1]/domChild[3]/domChild[0]/domChild[3]10,10
closeNotification//div[@id='runcomvaadintestscomponentscalendarNotificationTestUI-1842310749-overlays']/div0,0
screenCaptureno-notification
- - diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.java new file mode 100644 index 0000000000..9b9a64624a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.java @@ -0,0 +1,116 @@ +/* + * 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.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Calendar; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Notification; +import com.vaadin.ui.components.calendar.CalendarComponentEvents.DateClickEvent; +import com.vaadin.ui.components.calendar.CalendarComponentEvents.DateClickHandler; +import com.vaadin.ui.components.calendar.event.BasicEvent; +import com.vaadin.ui.components.calendar.event.CalendarEvent; +import com.vaadin.ui.components.calendar.event.CalendarEventProvider; + +public class CalendarNotifications extends AbstractTestUIWithLog { + + private DummyEventProvider provider; + + private static class DummyEventProvider implements CalendarEventProvider { + + private int index; + private List events = new ArrayList(); + + public void addEvent(Date date) { + BasicEvent e = new BasicEvent(); + e.setAllDay(true); + e.setStart(date); + e.setEnd(date); + e.setCaption("Some event " + ++index); + events.add(e); + } + + @Override + public List getEvents(Date startDate, Date endDate) { + return events; + } + + } + + @Override + protected void setup(VaadinRequest request) { + GridLayout content = new GridLayout(1, 2); + content.setSizeFull(); + content.setRowExpandRatio(1, 1.0f); + addComponent(content); + final Button btn = new Button("Show working notification", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Notification + .show("This will disappear when you move your mouse!"); + } + }); + content.addComponent(btn); + + provider = new DummyEventProvider(); + final Calendar cal = new Calendar(provider); + cal.setLocale(Locale.US); + cal.setSizeFull(); + cal.setHandler(new DateClickHandler() { + @Override + public void dateClick(DateClickEvent event) { + provider.addEvent(event.getDate()); + log("Opening a notification"); + Notification + .show("This should disappear when the mouse is moved."); + + // this requestRepaint call interferes with the notification + cal.markAsDirty(); + } + }); + content.addComponent(cal); + + java.util.Calendar javaCal = java.util.Calendar.getInstance(); + javaCal.set(java.util.Calendar.YEAR, 2000); + javaCal.set(java.util.Calendar.MONTH, 0); + javaCal.set(java.util.Calendar.DAY_OF_MONTH, 1); + Date start = javaCal.getTime(); + javaCal.set(java.util.Calendar.DAY_OF_MONTH, 31); + Date end = javaCal.getTime(); + + cal.setStartDate(start); + cal.setEndDate(end); + } + + @Override + protected String getTestDescription() { + return "Notifications should be opened and then closed after the user has moved the mouse."; + } + + @Override + protected Integer getTicketNumber() { + return 6769; + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTest.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTest.java new file mode 100644 index 0000000000..2431b2f4d0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTest.java @@ -0,0 +1,82 @@ +/* + * 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.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests opening and closing of calendar notifications. + * + * @since + * @author Vaadin Ltd + */ +public class CalendarNotificationsTest extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return NotificationTestUI.class; + } + + @Override + protected DesiredCapabilities getDesiredCapabilities() { + DesiredCapabilities desiredCapabilities = new DesiredCapabilities( + super.getDesiredCapabilities()); + desiredCapabilities.setCapability("enablePersistentHover", false); + desiredCapabilities.setCapability("requireWindowFocus", true); + + return desiredCapabilities; + } + + @Override + public List getBrowsersToTest() { + // TODO: IE testing is pending on #14312. For now, IE testing is handled + // with a logger. + return getBrowsersExcludingIE(); + } + + @Test + public void notificationTest() throws Exception { + openTestURL(); + + WebElement day = findElements(By.className("v-calendar-day-number")) + .get(2); + // IE8 requires you to click on the text part to fire the event + new Actions(getDriver()).moveToElement(day, 83, 11).click().perform(); + + Assert.assertTrue("There should be a notification", + $(NotificationElement.class).exists()); + + // move the mouse around a bit + new Actions(getDriver()).moveByOffset(5, 5).moveByOffset(100, 100) + .perform(); + + // wait until the notification has animated out + sleep(1000); + + Assert.assertFalse("There should be no notification on the page", + $(NotificationElement.class).exists()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTestIE.java b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTestIE.java new file mode 100644 index 0000000000..7ab6f01113 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTestIE.java @@ -0,0 +1,91 @@ +/* + * 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.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests opening and closing of calendar notifications. + * + * @since + * @author Vaadin Ltd + */ +public class CalendarNotificationsTestIE extends MultiBrowserTest { + + @Override + protected Class getUIClass() { + return CalendarNotifications.class; + } + + @Override + protected DesiredCapabilities getDesiredCapabilities() { + DesiredCapabilities desiredCapabilities = new DesiredCapabilities( + super.getDesiredCapabilities()); + desiredCapabilities.setCapability("enablePersistentHover", false); + desiredCapabilities.setCapability("requireWindowFocus", true); + + return desiredCapabilities; + } + + @Override + public List getBrowsersToTest() { + List browsers = super.getBrowsersToTest(); + browsers.remove(Browser.CHROME.getDesiredCapabilities()); + browsers.remove(Browser.FIREFOX.getDesiredCapabilities()); + browsers.remove(Browser.OPERA.getDesiredCapabilities()); + browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + browsers.remove(Browser.SAFARI.getDesiredCapabilities()); + return browsers; + } + + @Test + public void notificationTest() throws Exception { + openTestURL(); + + WebElement day = findElements(By.className("v-calendar-day-number")) + .get(2); + // IE8 requires you to click on the text part to fire the event + new Actions(getDriver()).moveToElement(day, 83, 11).click().perform(); + + // check that a notification was opened, this is done with a log instead + // of a screenshot or element presence check due to problems with IE + // webdriver + String text = findElement(By.id("Log")).findElement( + By.className("v-label")).getText(); + Assert.assertTrue("Notification should've opened", + "1. Opening a notification".equals(text)); + + // move the mouse around a bit + new Actions(getDriver()).moveByOffset(5, 5).moveByOffset(100, 100) + .perform(); + + // wait until the notification has animated out + sleep(1000); + + Assert.assertFalse("There should be no notification on the page", + $(NotificationElement.class).exists()); + } +}