aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeTest.java
blob: ebf0aed6b1c96488454d46a1143c26f918c865dd (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
package com.vaadin.tests.components.treegrid;

import static org.junit.Assert.assertEquals;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.TreeGridElement;
import com.vaadin.tests.performance.TreeGridMemory;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class TreeGridHugeTreeTest extends SingleBrowserTest {

    private TreeGridElement grid;

    @Test
    public void toggle_expand_when_row_out_of_cache() {
        openTestURL();

        grid = $(TreeGridElement.class).first();
        ButtonElement expandSecondRowButton = $(ButtonElement.class).get(0);
        ButtonElement collapseSecondRowButton = $(ButtonElement.class).get(1);

        grid.expandWithClick(2);
        grid.expandWithClick(3);
        grid.scrollToRow(300);
        grid.waitForVaadin();

        expandSecondRowButton.click();

        grid.scrollToRow(0);
        assertCellTexts(0, 0, new String[] { "Granddad 0", "Granddad 1",
                "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2", "Dad 2/0" });

        grid.scrollToRow(300);
        grid.waitForVaadin();
        collapseSecondRowButton.click();
        grid.scrollToRow(0);
        grid.waitForVaadin();
        assertCellTexts(0, 0, new String[] { "Granddad 0", "Granddad 1",
                "Granddad 2", "Dad 2/0" });

        grid.scrollToRow(300);
        grid.waitForVaadin();
        expandSecondRowButton.click();
        collapseSecondRowButton.click();
        grid.scrollToRow(0);
        grid.waitForVaadin();
        assertCellTexts(0, 0, new String[] { "Granddad 0", "Granddad 1",
                "Granddad 2", "Dad 2/0" });
    }

    @Test
    public void collapsed_rows_invalidated_correctly() {
        openTestURL();
        grid = $(TreeGridElement.class).first();
        grid.expandWithClick(2);
        grid.expandWithClick(3);
        grid.expandWithClick(0);
        grid.collapseWithClick(0);
        grid.expandWithClick(0);
        grid.expandWithClick(1);
        assertCellTexts(0, 0,
                new String[] { "Granddad 0", "Dad 0/0", "Son 0/0/0" });
    }

    @Test
    public void collapsed_subtrees_outside_of_cache_stay_expanded() {
        getDriver().get(StringUtils.strip(getBaseURL(), "/")
                + TreeGridMemory.PATH + "?items=200&initiallyExpanded");
        grid = $(TreeGridElement.class).first();

        String[] cellTexts = new String[100];
        for (int i = 0; i < 100; i++) {
            cellTexts[i] = grid.getRow(i).getCell(0).getText();
        }
        grid.scrollToRow(0);

        grid.collapseWithClick(1);
        grid.expandWithClick(1);

        assertCellTexts(0, 0, cellTexts);
    }

    private void assertCellTexts(int startRowIndex, int cellIndex,
            String[] cellTexts) {
        int index = startRowIndex;
        for (String cellText : cellTexts) {
            assertEquals(cellText,
                    grid.getRow(index).getCell(cellIndex).getText());
            index++;
        }
    }
}