aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorScrollSyncTest.java
blob: 9c0c7360ee1e69e640bce60993ee1346c618a05a (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
package com.vaadin.tests.components.grid;

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

import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.number.IsCloseTo.closeTo;

public class GridEditorScrollSyncTest extends MultiBrowserTest {
    private GridElement grid;

    @Test
    public void testScrollAndEdit() {
        openTestURL();
        grid = $(GridElement.class).first();
        ((TestBenchElement) grid
                .findElement(By.className("v-grid-scroller-horizontal")))
                        .scrollLeft(300);
        openEditor();
        GridElement.GridCellElement rowCell = grid.getCell(1, 6);
        TestBenchElement editorField = grid.getEditor().getField(6);
        assertPosition(rowCell.getLocation().getX(),
                editorField.getWrappedElement().getLocation().getX());
    }

    private GridElement openEditor() {
        grid.getCell(0, 6).doubleClick();
        Assert.assertTrue("Grid editor should be displayed.",
                grid.getEditor().isDisplayed());
        return grid;
    }

    private void assertPosition(double expected, double actual) {
        // 1px leeway for calculations
        assertThat("Unexpected position.", expected, closeTo(actual, 1d));
    }
}