aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/data/DataProviderRefreshTest.java
blob: 03e566a7414dcbd715dcd6148cf1569b34f61441 (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
package com.vaadin.tests.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import static org.hamcrest.CoreMatchers.*;

import org.junit.Test;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class DataProviderRefreshTest extends SingleBrowserTest {

    @Test
    public void select_and_replace() {
        openTestURL();
        GridElement grid = $(GridElement.class).first();
        assertFalse("Row should not be initially selected",
                grid.getRow(0).isSelected());
        // Select item before replace
        $(ButtonElement.class).caption("Select old").first().click();
        assertTrue("Row should be selected", grid.getRow(0).isSelected());
        assertThat(getLogRow(0), containsString("{ Foo, 10 }"));

        $(ButtonElement.class).caption("Replace item").first().click();
        assertTrue("Row should still be selected after item replace",
                grid.getRow(0).isSelected());
        assertEquals("Grid content was not updated.", "{ Bar, 10 }",
                grid.getCell(0, 0).getText());
        assertThat(getLogRow(0), containsString("{ Bar, 10 }"));

        // Deselect row
        grid.getCell(0, 0).click();
        assertFalse("Row should be deselected after click",
                grid.getRow(0).isSelected());

        assertEquals("Second row was affected", "{ Baz, 11 }",
                grid.getCell(1, 0).getText());
    }

    @Test
    public void replace_and_select() {
        openTestURL();
        GridElement grid = $(GridElement.class).first();
        assertFalse("Row should not be initially selected",
                grid.getRow(0).isSelected());

        // Replace item before select
        $(ButtonElement.class).caption("Replace item").first().click();
        assertFalse("Row should not be selected after item replace",
                grid.getRow(0).isSelected());
        assertEquals("Grid content was not updated.", "{ Bar, 10 }",
                grid.getCell(0, 0).getText());

        $(ButtonElement.class).caption("Select old").first().click();
        assertTrue("Row should be selected", grid.getRow(0).isSelected());
        assertEquals("Grid content should not update.", "{ Bar, 10 }",
                grid.getCell(0, 0).getText());

        // Deselect row
        grid.getCell(0, 0).click();
        assertFalse("Row should be deselected after click",
                grid.getRow(0).isSelected());

        assertEquals("Second row was affected", "{ Baz, 11 }",
                grid.getCell(1, 0).getText());
    }
}