Test to verify that the column width is not changed when toggling its visibility. Change-Id: I48c62b72bf7e66740ec516d43bc9b5995c1fefb4tags/7.6.0.beta2
@@ -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); | |||
} | |||
} |
@@ -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; | |||
} | |||
} |
@@ -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); | |||
} | |||
} |