aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditRowTest.java
blob: 924937c78b2f786a1c6fd586dce7a167625d8f8b (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.vaadin.tests.components.grid;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;

import org.junit.Test;

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridEditorElement;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Tests for ensuring that the furthest away visible rows don't get emptied when
 * editRow is called, and that the editor doesn't open beyond the lower border
 * of the Grid.
 *
 */
@TestCategory("grid")
public class GridEditRowTest extends MultiBrowserTest {

    private GridElement grid;
    private ButtonElement addButton;
    private ButtonElement editButton;

    @Override
    public void setup() throws Exception {
        super.setup();
        openTestURL();
        grid = $(GridElement.class).first();
        addButton = $(ButtonElement.class).caption("Add").first();
        editButton = $(ButtonElement.class).caption("Edit").first();
    }

    public void addRows(int count) {
        for (int i = 0; i < count; ++i) {
            addButton.click();
        }
    }

    public void editLastRow() {
        editButton.click();
    }

    private void assertRowContents(int rowIndex) {
        assertThat(grid.getCell(rowIndex, 0).getText(), is("name" + rowIndex));
    }

    private void assertEditorWithinGrid() {
        GridEditorElement editor = grid.getEditor();
        // allow 1px leeway
        assertThat(editor.getLocation().y + editor.getSize().height, not(
                greaterThan(grid.getLocation().y + grid.getSize().height + 1)));
    }

    @Test
    public void testEditWhenAllRowsVisible() {
        addRows(7);

        assertRowContents(0);

        editLastRow();

        assertRowContents(0);

        waitForElementVisible(By.className("v-grid-editor"));
        // wait for position corrections
        sleep(100);

        assertEditorWithinGrid();
    }

    @Test
    public void testEditWhenSomeRowsNotVisible() {
        addRows(11);

        assertRowContents(3);

        editLastRow();

        waitForElementVisible(By.className("v-grid-editor"));
        // wait for position corrections
        sleep(100);

        assertRowContents(3);
        assertEditorWithinGrid();
    }

    @Test
    public void testEditWhenSomeRowsOutsideOfCache() {
        addRows(100);

        assertRowContents(91);

        editLastRow();

        waitForElementVisible(By.className("v-grid-editor"));
        // wait for position corrections
        sleep(100);

        assertRowContents(91);
        assertEditorWithinGrid();
    }
}