summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-01-10 10:30:57 +0200
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-01-15 11:43:19 +0200
commit9e54760b68b7682566a41827b3e2ef235da895ab (patch)
treec8fc60189e8e0781587a67d7ccd77982b8f5e0fd /uitest
parent531320c5051b7f72c9d96c7826b5cd4f9dcaae67 (diff)
downloadvaadin-framework-9e54760b68b7682566a41827b3e2ef235da895ab.tar.gz
vaadin-framework-9e54760b68b7682566a41827b3e2ef235da895ab.zip
Backport fix for removing Notifications on close (#10504)
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java18
-rw-r--r--uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseEventTest.java46
2 files changed, 60 insertions, 4 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java b/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java
index 6cd99cb53d..6a70679e04 100644
--- a/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java
+++ b/uitest/src/main/java/com/vaadin/tests/elements/notification/NotificationGetTypeAndDescription.java
@@ -1,14 +1,21 @@
package com.vaadin.tests.elements.notification;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.annotations.PreserveOnRefresh;
+import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
-public class NotificationGetTypeAndDescription extends AbstractTestUI {
+@Widgetset("com.vaadin.DefaultWidgetSet")
+@PreserveOnRefresh
+public class NotificationGetTypeAndDescription extends AbstractTestUIWithLog {
private static final Type[] types = { Type.WARNING_MESSAGE,
Type.ERROR_MESSAGE, Type.HUMANIZED_MESSAGE,
@@ -55,8 +62,11 @@ public class NotificationGetTypeAndDescription extends AbstractTestUI {
@Override
public void buttonClick(ClickEvent event) {
- Notification.show(captions[index], descriptions[index],
- types[index]);
+ Notification n = Notification.show(captions[index],
+ descriptions[index], types[index]);
+ n.addCloseListener(e -> {
+ log("Notification (" + descriptions[index] + ") closed");
+ });
}
}
diff --git a/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseEventTest.java b/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseEventTest.java
new file mode 100644
index 0000000000..3c462aa6d4
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/elements/notification/NotificationCloseEventTest.java
@@ -0,0 +1,46 @@
+package com.vaadin.tests.elements.notification;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.NotificationElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class NotificationCloseEventTest extends SingleBrowserTest {
+
+ @Override
+ protected Class<?> getUIClass() {
+ return NotificationGetTypeAndDescription.class;
+ }
+
+ @Test
+ public void testCloseByUser() {
+ openTestURL();
+ ButtonElement error = $(ButtonElement.class).caption("error").first();
+ error.click();
+ $(NotificationElement.class).get(0).close();
+ Assert.assertEquals("1. Notification (error) closed", getLogRow(0));
+ }
+
+ @Test
+ public void notificationsStayAwayAfterRefresh() {
+ openTestURL();
+ Assert.assertFalse(isElementPresent(NotificationElement.class));
+ ButtonElement warning = $(ButtonElement.class).caption("warning")
+ .first();
+ warning.click();
+ Assert.assertTrue("Notification should open",
+ isElementPresent(NotificationElement.class));
+ openTestURL();
+ Assert.assertTrue("Notification should still be present.",
+ isElementPresent(NotificationElement.class));
+ $(NotificationElement.class).first().close();
+ Assert.assertEquals("1. Notification (warning) closed", getLogRow(0));
+ Assert.assertFalse("No notification should be present",
+ isElementPresent(NotificationElement.class));
+ openTestURL();
+ Assert.assertFalse("Reloading should not open notifications",
+ isElementPresent(NotificationElement.class));
+ }
+}