aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/table/TableDropIndicatorValoTest.java
blob: 267d211c9ffb7d05eeb822a5b4ab812f7cf725f3 (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
package com.vaadin.tests.components.table;

import java.util.List;

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

import com.vaadin.testbench.Parameters;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Tests that clicking on active fields doesn't change Table selection, nor does
 * dragging rows.
 *
 * @author Vaadin Ltd
 */

public class TableDropIndicatorValoTest extends MultiBrowserTest {

    @Override
    public void setup() throws Exception {

        super.setup();
        openTestURL();
    }

    @Test
    public void indicator() throws Exception {

        dragRowWithoutDropping(1);
        Parameters.setScreenshotComparisonTolerance(0.1);
        compareScreen("indicator");
    }

    private List<WebElement> getCellContents(WebElement row) {

        return row.findElements(By.className("v-table-cell-content"));
    }

    private List<WebElement> getRows() {

        return getTable().findElement(By.className("v-table-body"))
                .findElements(By.tagName("tr"));
    }

    private TableElement getTable() {

        return $(TableElement.class).first();
    }

    private void dragRowWithoutDropping(int from) {

        List<WebElement> rows = getRows();
        WebElement row = rows.get(from);
        List<WebElement> cellContents = getCellContents(row);

        int rowHeight = row.getSize().getHeight();
        int halfRowHeight = (int) (rowHeight + 0.5) / 2; // rounded off
        int oneAndAHalfRow = rowHeight + halfRowHeight;

        new Actions(getDriver()).moveToElement(cellContents.get(1))
                .clickAndHold().moveByOffset(0, oneAndAHalfRow).perform();
    }
}