]> source.dussan.org Git - vaadin-framework.git/commitdiff
CalendarNotifications test rewrite
authorHeikki Ohinmaa <heikki@vaadin.com>
Tue, 19 Aug 2014 10:26:20 +0000 (13:26 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 25 Aug 2014 12:11:49 +0000 (12:11 +0000)
Change-Id: I78f8b0c6a762541f62a3881ce8abb52837d1cad9

uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.html [deleted file]
uitest/src/com/vaadin/tests/components/calendar/CalendarNotifications.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/calendar/CalendarNotificationsTestIE.java [new file with mode: 0644]

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 (file)
index 15bf29a..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="http://localhost:8080/" />
-<title>New Test</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">New Test</td></tr>
-</thead><tbody>
-<tr>
-       <td>open</td>
-       <td>/run/com.vaadin.tests.components.calendar.NotificationTestUI?restartApplication</td>
-       <td></td>
-</tr>
-<tr>
-       <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentscalendarNotificationTestUI::/VGridLayout[0]/VCalendar[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]</td>
-       <td>83,11</td>
-</tr>
-<tr>
-       <td>mouseMove</td>
-       <td>vaadin=runcomvaadintestscomponentscalendarNotificationTestUI::/VGridLayout[0]/VCalendar[0]/domChild[0]/domChild[1]/domChild[1]/domChild[0]/domChild[1]/domChild[1]/domChild[3]/domChild[0]/domChild[3]</td>
-       <td>10,10</td>
-</tr>
-<tr>
-       <td>closeNotification</td>
-       <td>//div[@id='runcomvaadintestscomponentscalendarNotificationTestUI-1842310749-overlays']/div</td>
-       <td>0,0</td>
-</tr>
-<tr>
-       <td>screenCapture</td>
-       <td></td>
-       <td>no-notification</td>
-</tr>
-</tbody></table>
-</body>
-</html>
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 (file)
index 0000000..9b9a646
--- /dev/null
@@ -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<CalendarEvent> events = new ArrayList<CalendarEvent>();
+
+        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<CalendarEvent> 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 (file)
index 0000000..2431b2f
--- /dev/null
@@ -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<DesiredCapabilities> 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 (file)
index 0000000..7ab6f01
--- /dev/null
@@ -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<DesiredCapabilities> getBrowsersToTest() {
+        List<DesiredCapabilities> 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());
+    }
+}