aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/table/ItemClickEventsTest.java
blob: 0861e662dc31005287005990429ac92744e679cd (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.vaadin.tests.components.table;

import org.junit.Before;
import org.junit.Test;

import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.CheckBoxElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class ItemClickEventsTest extends MultiBrowserTest {

    @Before
    public void init() {
        openTestURL("restartApplication");
    }

    private void clickElement(TestBenchElement e) {
        assertNotNull(e);
        e.click();
    }

    private void doubleClickElement(TestBenchElement e) {
        assertNotNull(e);
        e.doubleClick();
    }

    private void assertLog(String compare) {
        LabelElement logRow = $(LabelElement.class).id("Log_row_0");
        assertNotNull(logRow);
        assertTrue(logRow.getText().contains(compare));
    }

    private void assertSelected(TestBenchElement e) {
        assertNotNull(e);
        assertTrue(hasCssClass(e, "v-selected"));
    }

    @Test
    public void testSingleSelectNull() throws Exception {

        // Activate table null selection mode
        clickElement($(CheckBoxElement.class).caption("nullsel").get(1));

        // Get at the table element
        TableElement table = $(TableElement.class).id("table");

        // Select the first item
        clickElement(table.getRow(0));
        assertLog("left click on table/Item 0");
        sleep(100);

        // Do it again
        clickElement(table.getRow(0));
        assertLog("left click on table/Item 0");

        // Select the sixth item
        clickElement(table.getRow(5));
        assertLog("left click on table/Item 5");

        // Double click the sixth item
        doubleClickElement(table.getRow(5));
        assertLog("doubleClick on table/Item 5");
    }

    @Test
    public void testSingleSelectNotNull() throws Exception {
        // Get reference to table
        TableElement table = $(TableElement.class).id("table");

        // Select first item in list
        clickElement(table.getRow(0));
        assertSelected(table.getRow(0));

        // Check that the log contains "clicked item 0"
        assertLog("left click on table/Item 0");

        // Click on second item in list
        clickElement(table.getRow(1));

        // Make sure it got selected
        assertSelected(table.getRow(1));

        // Check log output
        assertLog("left click on table/Item 1");
        sleep(500);

        // Click row 1 again
        clickElement(table.getRow(1));
        assertLog("left click on table/Item 1");

        // Test double click
        doubleClickElement(table.getRow(1));
        // kludge: testbench seems to send an extra click; that doesn't affect
        // our test too much, though, and can be ignored.
        assertLog("doubleClick on table/Item 1");

        // Double click first item
        doubleClickElement(table.getRow(0));
        assertLog("doubleClick on table/Item 0");

        // Make sure it got selected again
        assertSelected(table.getRow(0));
    }

    @Test
    public void testSingleSelectNotSelectable() throws Exception {

        // Remove the 'selectable' mode from Table
        $(CheckBoxElement.class).caption("selectable").get(1).click();

        // Get table element
        TableElement table = $(TableElement.class).id("table");

        // Click some items and check that clicks go through
        clickElement(table.getCell(0, 0));
        assertLog("left click on table/Item 0");

        clickElement(table.getCell(5, 0));
        assertLog("left click on table/Item 5");

        clickElement(table.getCell(2, 0));
        assertLog("left click on table/Item 2");

        clickElement(table.getCell(8, 0));
        assertLog("left click on table/Item 8");

        clickElement(table.getCell(1, 0));
        assertLog("left click on table/Item 1");

        clickElement(table.getCell(0, 0));
        assertLog("left click on table/Item 0");

    }

    @Test
    public void testNonImmediateSingleSelectable() throws Exception {

        // Disable table immediate mode
        clickElement($(CheckBoxElement.class).caption("immediate").get(1));

        // Get table element
        TableElement table = $(TableElement.class).id("table");

        // Click items and verify that click event went through
        clickElement(table.getCell(1, 0));
        assertLog("left click on table/Item 1");

        clickElement(table.getCell(8, 0));
        assertLog("left click on table/Item 8");

        clickElement(table.getCell(1, 0));
        assertLog("left click on table/Item 1");

        clickElement(table.getCell(0, 0));
        assertLog("left click on table/Item 0");

        clickElement(table.getCell(6, 0));
        assertLog("left click on table/Item 6");

    }

}