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

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

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

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.testbench.elements.TableHeaderElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
 * Tests that column keeps its header, icon, alignment after toggling visibility
 * (#6245, #12303).
 *
 * @author Vaadin Ltd
 */
public class TableToggleColumnVisibilityTest extends MultiBrowserTest {

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

        ButtonElement toggleVisibilityButton = $(ButtonElement.class)
                .id("visib-toggler");
        ButtonElement changeOrderButton = $(ButtonElement.class)
                .id("order-toggler");

        checkHeaderAttributes(1);

        toggleVisibilityButton.click(); // hide column #1
        assertEquals("One column should be visible",
                findElements(By.className("v-table-header-cell")).size(), 1);

        toggleVisibilityButton.click(); // restore column #1
        assertEquals("Two columns should be visible",
                findElements(By.className("v-table-header-cell")).size(), 2);
        checkHeaderAttributes(1);

        // change column order, column #1 now becomes column #0
        changeOrderButton.click();
        checkHeaderAttributes(0);
    }

    /*
     * Checks column header with number columnNumber.
     */
    private void checkHeaderAttributes(int columnNumber) {
        TableHeaderElement headerCell = $(TableElement.class).first()
                .getHeaderCell(columnNumber);

        assertTrue("Column header text should be custom",
                headerCell.getText().equalsIgnoreCase("Hello World"));

        assertFalse("Column should have an icon",
                headerCell.findElements(By.className("v-icon")).isEmpty());

        assertFalse("Column should have alignment to the right", headerCell
                .findElements(
                        By.className("v-table-caption-container-align-right"))
                .isEmpty());
    }
}