From 9f9efe0058397992fda43e104c90b79039d41c0f Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Wed, 27 Sep 2017 12:44:01 +0200 Subject: Support addCloseListener for Notification (#10027) Converts Notification to an Extension and adds support for listening to the closing of notifications. Fixes #888 --- .../extensions/NotificationCloseListener.java | 47 +++++++++++++++++++++ .../extensions/NotificationCloseListenerTest.java | 49 ++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 uitest/src/main/java/com/vaadin/tests/extensions/NotificationCloseListener.java create mode 100644 uitest/src/test/java/com/vaadin/tests/extensions/NotificationCloseListenerTest.java (limited to 'uitest/src') diff --git a/uitest/src/main/java/com/vaadin/tests/extensions/NotificationCloseListener.java b/uitest/src/main/java/com/vaadin/tests/extensions/NotificationCloseListener.java new file mode 100644 index 0000000000..2528f935b2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/extensions/NotificationCloseListener.java @@ -0,0 +1,47 @@ +/* + * 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.extensions; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Notification; + +/** + * UI used to validate Notification closes works. + */ +public class NotificationCloseListener extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + CheckBox checkBox = new CheckBox(); + addComponent(checkBox); + + Notification notification = Notification.show("something"); + notification.addCloseListener(e -> checkBox.setValue(true)); + } + + @Override + protected String getTestDescription() { + return "Notification Close listener is called."; + } + + @Override + protected Integer getTicketNumber() { + return 10027; + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/extensions/NotificationCloseListenerTest.java b/uitest/src/test/java/com/vaadin/tests/extensions/NotificationCloseListenerTest.java new file mode 100644 index 0000000000..3b241a49d8 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/extensions/NotificationCloseListenerTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 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.extensions; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class NotificationCloseListenerTest extends MultiBrowserTest { + + @Test + public void closeListenerCalled() throws Exception { + openTestURL(); + + $(NotificationElement.class).first().close(); + + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + try { + return $(CheckBoxElement.class).first().isChecked(); + } + catch (Exception e) { + e.printStackTrace(); + return false; + } + } + }); + } +} -- cgit v1.2.3