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

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.WebElement;

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

/**
 * Test for a Table with a customised BeanItemContainer.
 *
 * @author Vaadin Ltd
 */
public class TableWithContainerRequiringEqualsForItemIdTest
        extends MultiBrowserTest {

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

        TableElement table = $(TableElement.class).first();
        List<WebElement> rows = table.findElement(By.className("v-table-body"))
                .findElements(By.tagName("tr"));
        assertEquals("unexpect amount of rows", 46, rows.size());

        // click the button on the first visible row
        clickButton(table, 0, 3, "1. Button Button999 clicked");

        // click the button on the last visible row
        clickButton(table, 14, 3, "2. Button Button985 clicked");

        clickTableHeaderToSort(table);

        // check the first cell of the new first visible row
        checkFirstCell(table, "0");

        // click the button on the first visible row
        clickButton(table, 0, 3, "3. Button Button0 clicked");

        // sort by the first column (descending)
        clickTableHeaderToSort(table);

        // check the first cell of the new first visible row
        checkFirstCell(table, "999");

        // click the button on the first visible row
        clickButton(table, 0, 3, "4. Button Button999 clicked");
    }

    private void checkFirstCell(TableElement table, String expected) {
        assertEquals("unexpected contents", expected,
                table.getCell(0, 0).getText());
    }

    private void clickTableHeaderToSort(TableElement table) {
        table.findElement(By.className("v-table-header"))
                .findElement(By.tagName("tr"))
                .findElement(By.className("v-table-caption-container")).click();
    }

    private void clickButton(TableElement table, int row, int column,
            String expectedLog) {
        table.getCell(row, column).findElement(By.className("v-button"))
                .click();

        // check the new log row
        assertEquals("unexpected log row", expectedLog,
                findElement(By.id("Log_row_0")).getText());
    }

}