aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/notification/MiddleNotificationPositionTest.java
blob: 5f866ef5e9c4be3bbe209e302219bede88ee3a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.vaadin.tests.components.notification;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

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"));

        assertNotNull(notification);
        String left = notification.getCssValue("left");
        assertEquals("Left position of notification element should be 0px",
                "0px", left);
        Point location = notification.getLocation();
        assertEquals("X coordinate of notifiation element should be 0", 0,
                location.getX());

        WebElement body = driver.findElement(By.tagName("body"));
        int height = body.getSize().height;

        assertTrue("Y coordinate of notification element is too small",
                height / 2 - notification.getSize().height / 2 - 1 <= location
                        .getY());
        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"));

        assertNotNull(notification);
        String right = notification.getCssValue("right");
        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();
        assertTrue(
                "Notification right border should be in the rightmost position",
                width - 1 <= location.getX()
                        + notification.getSize().getWidth());

        assertTrue("Y coordinate of notification element is too small",
                height / 2 - notification.getSize().height / 2 - 1 <= location
                        .getY());
        assertTrue("Y coordinate of notification element is too big",
                height / 2 + 1 >= location.getY());
    }

}