summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Anisimov <denis@vaadin.com>2014-03-15 15:49:40 +0200
committerVaadin Code Review <review@vaadin.com>2014-04-08 07:45:08 +0000
commite3a07d6cb576e10dc79b68aff347ddab5cafe558 (patch)
tree78aafc601b31aa467796616f8010b55968ac857b
parentf32e3535c6ef73bca33f274e9906f57aa178d22a (diff)
downloadvaadin-framework-e3a07d6cb576e10dc79b68aff347ddab5cafe558.tar.gz
vaadin-framework-e3a07d6cb576e10dc79b68aff347ddab5cafe558.zip
Support for middle left/right positions in Notification (#12931).
Change-Id: Iac00191ace5d55f8b054f8b66d1802a788d368c2
-rw-r--r--client/src/com/vaadin/client/ui/VNotification.java9
-rw-r--r--uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPosition.java76
-rw-r--r--uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPositionTest.java98
3 files changed, 183 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VNotification.java b/client/src/com/vaadin/client/ui/VNotification.java
index 02411e20e3..3aa3fa847d 100644
--- a/client/src/com/vaadin/client/ui/VNotification.java
+++ b/client/src/com/vaadin/client/ui/VNotification.java
@@ -303,6 +303,15 @@ public class VNotification extends VOverlay {
DOM.setStyleAttribute(el, "top", "0px");
DOM.setStyleAttribute(el, "right", "0px");
break;
+ case MIDDLE_LEFT:
+ center();
+ DOM.setStyleAttribute(el, "left", "0px");
+ break;
+ case MIDDLE_RIGHT:
+ center();
+ DOM.setStyleAttribute(el, "left", "");
+ DOM.setStyleAttribute(el, "right", "0px");
+ break;
case BOTTOM_RIGHT:
DOM.setStyleAttribute(el, "position", "absolute");
DOM.setStyleAttribute(el, "bottom", "0px");
diff --git a/uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPosition.java b/uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPosition.java
new file mode 100644
index 0000000000..4050e4505e
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPosition.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2000-2013 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.notification;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.Position;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Notification;
+
+/**
+ * Test UI class for Notification with middle left and middle right positions.
+ *
+ * @since 7.2
+ * @author Vaadin Ltd
+ */
+public class MiddleNotificationPosition extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Button left = new Button("Show Notification in middle left");
+ left.addStyleName("show-middle-left");
+ left.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Notification notification = new Notification("Notification");
+ notification.setDelayMsec(10000);
+ notification.setPosition(Position.MIDDLE_LEFT);
+ notification.show(getUI().getPage());
+ }
+ });
+ addComponent(left);
+
+ Button right = new Button("Show Notification in middle right");
+ right.addStyleName("show-middle-right");
+ right.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Notification notification = new Notification("Notification");
+ notification.setDelayMsec(10000);
+ notification.setPosition(Position.MIDDLE_RIGHT);
+ notification.show(getUI().getPage());
+ }
+ });
+ addComponent(right);
+
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Position.MIDDLE_LEFT and Position.MIDDLE_RIGHT should work for Notification";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 12931;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPositionTest.java b/uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPositionTest.java
new file mode 100644
index 0000000000..9f31719a10
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/notification/MiddleNotificationPositionTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2000-2013 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.notification;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.Point;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Unit test class for Notification with middle left and middle right positions.
+ *
+ * @since 7.2
+ * @author Vaadin Ltd
+ */
+public class MiddleNotificationPositionTest extends MultiBrowserTest {
+
+ @Test
+ public void testMiddleLeft() {
+ openTestURL();
+
+ WebElement webElement = driver.findElement(By
+ .className("show-middle-left"));
+ webElement.click();
+
+ WebElement notification = driver.findElement(By
+ .className("v-Notification"));
+
+ Assert.assertNotNull(notification);
+ String left = notification.getCssValue("left");
+ Assert.assertEquals(
+ "Left position of notification element should be 0px", "0px",
+ left);
+ Point location = notification.getLocation();
+ Assert.assertEquals("X coordinate of notifiation element should be 0",
+ 0, location.getX());
+
+ WebElement body = driver.findElement(By.tagName("body"));
+ int height = body.getSize().height;
+
+ Assert.assertTrue("Y coordinate of notification element is too small",
+ height / 2 - notification.getSize().height / 2 - 1 <= location
+ .getY());
+ Assert.assertTrue("Y coordinate of notification element is too big",
+ height / 2 + 1 >= location.getY());
+ }
+
+ @Test
+ public void testMiddleRight() {
+ openTestURL();
+
+ WebElement webElement = driver.findElement(By
+ .className("show-middle-right"));
+ webElement.click();
+
+ WebElement notification = driver.findElement(By
+ .className("v-Notification"));
+
+ Assert.assertNotNull(notification);
+ String right = notification.getCssValue("right");
+ Assert.assertEquals(
+ "Right position of notification element should be 0px", "0px",
+ right);
+
+ WebElement body = driver.findElement(By.tagName("body"));
+ int height = body.getSize().height;
+ int width = body.getSize().width;
+
+ Point location = notification.getLocation();
+ Assert.assertTrue(
+ "Notification right border should be in the rightmost position",
+ width - 1 <= location.getX()
+ + notification.getSize().getWidth());
+
+ Assert.assertTrue("Y coordinate of notification element is too small",
+ height / 2 - notification.getSize().height / 2 - 1 <= location
+ .getY());
+ Assert.assertTrue("Y coordinate of notification element is too big",
+ height / 2 + 1 >= location.getY());
+ }
+
+}