diff options
author | Ilya Ermakov <ilya403403@gmail.com> | 2014-12-05 13:14:32 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-11-04 11:27:32 +0000 |
commit | 2b8cd659685c48fd6284ba3566009b2285132751 (patch) | |
tree | d26ce0e1ac6ab3fff89436d967795b3c0c68fe7f /uitest | |
parent | ffb28784b7e9b612a63edd997c4ecbcc3797cc73 (diff) | |
download | vaadin-framework-2b8cd659685c48fd6284ba3566009b2285132751.tar.gz vaadin-framework-2b8cd659685c48fd6284ba3566009b2285132751.zip |
Test for table column hiding and sizes (#12303)
Test to verify that the column width is not changed when toggling
its visibility.
Change-Id: I48c62b72bf7e66740ec516d43bc9b5995c1fefb4
Diffstat (limited to 'uitest')
3 files changed, 151 insertions, 7 deletions
diff --git a/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityTest.java b/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityTest.java index 4c44dcfed8..57ebfb7040 100644 --- a/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityTest.java +++ b/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityTest.java @@ -18,13 +18,15 @@ package com.vaadin.tests.components.table; import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; +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). + * (#6245, #12303). * * @author Vaadin Ltd */ @@ -34,8 +36,10 @@ public class TableToggleColumnVisibilityTest extends MultiBrowserTest { public void testColumnWidthRestoredAfterTogglingVisibility() { openTestURL(); - WebElement toggleVisibilityButton = findElement(By.id("visib-toggler")); - WebElement changeOrderButton = findElement(By.id("order-toggler")); + ButtonElement toggleVisibilityButton = $(ButtonElement.class).id( + "visib-toggler"); + ButtonElement changeOrderButton = $(ButtonElement.class).id( + "order-toggler"); checkHeaderAttributes(1); @@ -58,8 +62,8 @@ public class TableToggleColumnVisibilityTest extends MultiBrowserTest { * Checks column header with number columnNumber. */ private void checkHeaderAttributes(int columnNumber) { - WebElement headerCell = findElements( - By.className("v-table-header-cell")).get(columnNumber); + TableHeaderElement headerCell = $(TableElement.class).first() + .getHeaderCell(columnNumber); Assert.assertTrue("Column header text should be custom", headerCell .getText().equalsIgnoreCase("Hello World")); @@ -73,5 +77,4 @@ public class TableToggleColumnVisibilityTest extends MultiBrowserTest { By.className("v-table-caption-container-align-right")) .size() > 0); } - }
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityWidth.java b/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityWidth.java new file mode 100644 index 0000000000..442f00f346 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityWidth.java @@ -0,0 +1,83 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.table; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; + +/** + * Test that column width is restored after restoring column visibility + */ +@SuppressWarnings("serial") +public class TableToggleColumnVisibilityWidth extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + + final Table table = new Table(); + + table.addContainerProperty("Name", String.class, ""); + table.addContainerProperty("Last Name", String.class, ""); + + table.setColumnWidth("Name", 100); + table.setColumnWidth("Last Name", 200); + table.setHeight("200px"); + + table.addItem(new Object[] { "Adam", "Morrison" }, new Integer(1)); + table.addItem(new Object[] { "Eva", "Roberts" }, new Integer(2)); + table.addItem(new Object[] { "Rob", "Spears" }, new Integer(3)); + table.addItem(new Object[] { "Bob", "Michigan" }, new Integer(4)); + table.setVisibleColumns(new Object[] { "Name", "Last Name" }); + + final Button infoToggler = new Button("visibility"); + infoToggler.setId("toggler"); + infoToggler.addClickListener(new ClickListener() { + private boolean detailed = true; + + @Override + public void buttonClick(ClickEvent event) { + if (detailed) { + table.setVisibleColumns(new Object[] { "Name" }); + } else { + table.setVisibleColumns(new Object[] { "Name", "Last Name" }); + } + detailed = !detailed; + } + }); + + layout.addComponent(table); + layout.addComponent(infoToggler); + + addComponent(layout); + } + + @Override + protected String getTestDescription() { + return "Toggling visibility of table columns should not change the width of fixed sized columns"; + } + + @Override + protected Integer getTicketNumber() { + return 12303; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityWidthTest.java b/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityWidthTest.java new file mode 100644 index 0000000000..c89678d846 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableToggleColumnVisibilityWidthTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.table; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests that column keeps its width after it is made invisible and visible + * again (#12303). + * + * @author Vaadin Ltd + */ +public class TableToggleColumnVisibilityWidthTest extends MultiBrowserTest { + + @Test + public void testColumnWidthRestoredAfterTogglingVisibility() { + openTestURL(); + + int secondColumnWidthInitial = findElements( + By.className("v-table-header-cell")).get(1).getSize() + .getWidth(); + ButtonElement toggleButton = $(ButtonElement.class).id("toggler"); + + toggleButton.click(); + Assert.assertEquals("One column should be visible", + findElements(By.className("v-table-header-cell")).size(), 1); + + toggleButton.click(); + Assert.assertEquals("Two columns should be visible", + findElements(By.className("v-table-header-cell")).size(), 2); + int secondColumnWidthRestored = findElements( + By.className("v-table-header-cell")).get(1).getSize() + .getWidth(); + Assert.assertEquals( + "Column width should be the same as it was before hiding", + secondColumnWidthInitial, secondColumnWidthRestored); + + } + +} |