From: Anna Miroshnik Date: Tue, 2 Dec 2014 15:13:41 +0000 (+0300) Subject: Add test for Table visible column order/count change (#9781) X-Git-Tag: 7.5.1~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f7ff3c31cbf89a9a5be0cf2ee5efe6ac01452c01;p=vaadin-framework.git Add test for Table visible column order/count change (#9781) Table should work correctly when changing both column properties (width etc) and the number/order of visible columns. This is nearly a duplicate of #17927 and its fix (commit 08dfe45d) fixes #9781 as well so only committing the test here. Change-Id: I9fc74dd0f4c8631ff97fae3e85ab97a940640273 --- diff --git a/uitest/src/com/vaadin/tests/components/table/ColumnWidthsAfterChangeTableColumnsCountOrOrder.java b/uitest/src/com/vaadin/tests/components/table/ColumnWidthsAfterChangeTableColumnsCountOrOrder.java new file mode 100644 index 0000000000..7e33de502c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/ColumnWidthsAfterChangeTableColumnsCountOrOrder.java @@ -0,0 +1,119 @@ +package com.vaadin.tests.components.table; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; + +public class ColumnWidthsAfterChangeTableColumnsCountOrOrder extends + AbstractTestUI { + + protected static final String BUTTON_CHANGE_ORDER_AND_WIDTH_ID = "buttonChangeOrderAndWidth"; + protected static final String BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH = "buttonChangeColumnCountAndWidth"; + protected static final int NEW_COLUMN_WIDTH = 17; + + @Override + protected void setup(VaadinRequest request) { + List beanList = new ArrayList(); + beanList.add(new TestBean(1, "name1", "descr1")); + beanList.add(new TestBean(2, "name2", "descr2")); + beanList.add(new TestBean(3, "name3", "descr3")); + beanList.add(new TestBean(4, "name4", "descr4")); + beanList.add(new TestBean(5, "name5", "descr5")); + + BeanItemContainer container = new BeanItemContainer( + TestBean.class, beanList); + + VerticalLayout layout = new VerticalLayout(); + + final Table table = new Table("Test Table"); + table.setContainerDataSource(container); + table.setVisibleColumns(new Object[] { "id", "name", "descr" }); + layout.addComponent(table); + + Button buttonChangeOrderAndWidth = new Button("Change order and width", + new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent clickEvent) { + table.setVisibleColumns(new Object[] { "name", "descr", + "id" }); + table.setColumnWidth("descr", NEW_COLUMN_WIDTH); + } + }); + buttonChangeOrderAndWidth.setId(BUTTON_CHANGE_ORDER_AND_WIDTH_ID); + + Button buttonChangeColumnCountAndWidth = new Button( + "Change columns count and width", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent clickEvent) { + table.setVisibleColumns(new Object[] { "name", "descr" }); + table.setColumnWidth("descr", NEW_COLUMN_WIDTH); + } + }); + buttonChangeColumnCountAndWidth + .setId(BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH); + + layout.addComponent(buttonChangeOrderAndWidth); + layout.addComponent(buttonChangeColumnCountAndWidth); + + addComponents(layout); + } + + public class TestBean { + private int id; + private String name; + private String descr; + + public TestBean(int id, String name, String descr) { + this.id = id; + this.name = name; + this.descr = descr; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescr() { + return descr; + } + + public void setDescr(String descr) { + this.descr = descr; + } + + @Override + public String toString() { + return "TestBean{" + "id=" + id + ", name='" + name + '\'' + + ", descr='" + descr + '\'' + '}'; + } + } + + @Override + protected String getTestDescription() { + return "Tests that properties of columns are changed correctly after changing column's order/count"; + } + + @Override + protected Integer getTicketNumber() { + return 9781; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/table/ColumnWidthsAfterChangeTableColumnsCountOrOrderTest.java b/uitest/src/com/vaadin/tests/components/table/ColumnWidthsAfterChangeTableColumnsCountOrOrderTest.java new file mode 100644 index 0000000000..970b832e0c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/ColumnWidthsAfterChangeTableColumnsCountOrOrderTest.java @@ -0,0 +1,72 @@ +/* + * 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 static com.vaadin.tests.components.table.ColumnWidthsAfterChangeTableColumnsCountOrOrder.BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH; +import static com.vaadin.tests.components.table.ColumnWidthsAfterChangeTableColumnsCountOrOrder.BUTTON_CHANGE_ORDER_AND_WIDTH_ID; +import static com.vaadin.tests.components.table.ColumnWidthsAfterChangeTableColumnsCountOrOrder.NEW_COLUMN_WIDTH; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class ColumnWidthsAfterChangeTableColumnsCountOrOrderTest extends + MultiBrowserTest { + + @Test + public void testColumnWidthAfterChangeTableColumnsOrder() { + openTestURL(); + + getButtonChangeOrderAndWidth().click(); + + waitForElementPresent(By.className("v-table")); + + assertEquals("The width of descr column should be " + NEW_COLUMN_WIDTH, + NEW_COLUMN_WIDTH, getDescriptionColumnWidth()); + } + + @Test + public void testColumnWidthAfterChangeTableColumnsCount() { + openTestURL(); + + getButtonChangeColumnCountAndWidth().click(); + + waitForElementPresent(By.className("v-table")); + + assertEquals("The width of descr column should be " + NEW_COLUMN_WIDTH, + NEW_COLUMN_WIDTH, getDescriptionColumnWidth()); + } + + private WebElement getButtonChangeOrderAndWidth() { + return vaadinElementById(BUTTON_CHANGE_ORDER_AND_WIDTH_ID); + } + + private WebElement getButtonChangeColumnCountAndWidth() { + return vaadinElementById(BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH); + } + + private int getDescriptionColumnWidth() { + return driver + .findElement( + By.xpath("//div[@class='v-table-cell-wrapper'" + + " and text() = 'descr1']")).getSize() + .getWidth(); + } + +}