aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/gridlayout/GridLayoutRequiredIndicatorLocationTest.java
blob: 273ed1e0821f66e4719cf860b06e421e0cf4eb5b (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
85
86
87
88
89
90
91
92
package com.vaadin.tests.components.gridlayout;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.GridLayoutElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class GridLayoutRequiredIndicatorLocationTest extends MultiBrowserTest {

    private WebElement gridLayoutSlot;

    @Override
    public void setup() throws Exception {
        super.setup();
        openTestURL();
        gridLayoutSlot = $(GridLayoutElement.class).first()
                .findElement(By.className("v-gridlayout-slot"));
    }

    @Test
    public void testRequiredIndicatorLocationLeftFixedField() {
        assertIndicatorPosition(getSlot(1));
    }

    @Test
    public void testRequiredIndicatorLocationLeftRelativeField() {
        assertIndicatorPosition(getSlot(3));
    }

    @Test
    public void testRequiredIndicatorLocationLeft100PercentField() {
        assertIndicatorPosition(getSlot(5));
    }

    @Test
    public void testRequiredIndicatorLocationCenterFixedField() {
        assertIndicatorPosition(getSlot(7));
    }

    @Test
    public void testRequiredIndicatorLocationCenterRelativeField() {
        assertIndicatorPosition(getSlot(9));
    }

    @Test
    public void testRequiredIndicatorLocationCenter100PercentField() {
        assertIndicatorPosition(getSlot(11));
    }

    @Test
    public void testRequiredIndicatorLocationRightFixedField() {
        assertIndicatorPosition(getSlot(13));
    }

    @Test
    public void testRequiredIndicatorLocationRightRelativeField() {
        assertIndicatorPosition(getSlot(15));
    }

    @Test
    public void testRequiredIndicatorLocationRight100PercentField() {
        assertIndicatorPosition(getSlot(17));
    }

    private void assertIndicatorPosition(WebElement slot) {
        WebElement field = slot.findElement(By.tagName("input"));
        WebElement caption = slot.findElement(By.className("v-caption"));

        int desiredIndicatorPosition = field.getLocation().getX()
                + field.getSize().getWidth();
        int actualIndicatorPosition = caption.getLocation().getX();

        assertEquals("Required indicator has wrong position",
                desiredIndicatorPosition, actualIndicatorPosition, 1d);
    }

    @Test
    public void testScreenshotMatches() throws IOException {
        compareScreen("indicators");
    }

    private WebElement getSlot(int index) {
        return gridLayoutSlot.findElements(By.className("v-gridlayout-slot"))
                .get(index);
    }
}