diff options
author | Artur Signell <artur@vaadin.com> | 2015-02-06 01:35:31 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-09-24 09:24:05 +0000 |
commit | da8b43ed411cdafe2ddefcb6078f49ab59c5958e (patch) | |
tree | 8952844fe1b9c728126998a274c93b673acd83f7 | |
parent | ca3c460cbd6edb801f7919d046a3323f5f8babf1 (diff) | |
download | vaadin-framework-da8b43ed411cdafe2ddefcb6078f49ab59c5958e.tar.gz vaadin-framework-da8b43ed411cdafe2ddefcb6078f49ab59c5958e.zip |
Correctly round tr width in Escalator (#18820)
* screenshot based tests for all themes for various features in Grid
Change-Id: Id44f319b517fdfa419b70d30a9f8d4bd5e82fa63
3 files changed, 261 insertions, 1 deletions
diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 761edf1f11..9b9616f474 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -1756,7 +1756,13 @@ public class Escalator extends Widget implements RequiresResize, Element row = root.getFirstChildElement(); while (row != null) { - row.getStyle().setWidth(rowWidth, Unit.PX); + // IF there is a rounding error when summing the columns, we + // need to round the tr width up to ensure that columns fit and + // do not wrap + // E.g.122.95+123.25+103.75+209.25+83.52+88.57+263.45+131.21+126.85+113.13=1365.9299999999998 + // For this we must set 1365.93 or the last column will wrap + row.getStyle().setWidth(WidgetUtil.roundSizeUp(rowWidth), + Unit.PX); row = row.getNextSiblingElement(); } } diff --git a/uitest/src/com/vaadin/tests/components/grid/GridThemeUI.java b/uitest/src/com/vaadin/tests/components/grid/GridThemeUI.java new file mode 100644 index 0000000000..09685d5b4c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridThemeUI.java @@ -0,0 +1,141 @@ +/* + * 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.grid; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import com.vaadin.annotations.Theme; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.data.validator.IntegerRangeValidator; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.NativeSelect; + +@Theme("valo") +public class GridThemeUI extends AbstractTestUIWithLog { + + private Grid grid; + + protected static String[] columns = new String[] { "firstName", "lastName", + "gender", "birthDate", "age", "alive", "address.streetAddress", + "address.postalCode", "address.city", "address.country" }; + + protected BeanItemContainer<ComplexPerson> container = ComplexPerson + .createContainer(100);; + { + container.addNestedContainerBean("address"); + } + protected ComboBox formType; + + private Component active = null; + + @Override + protected void setup(VaadinRequest request) { + setLocale(new Locale("en", "US")); + + final NativeSelect pageSelect = new NativeSelect("Page"); + pageSelect.setImmediate(true); + pageSelect.setId("page"); + addComponent(pageSelect); + + pageSelect.addItem(new Editor()); + pageSelect.addItem(new HeaderFooter()); + + pageSelect.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + if (active != null) { + removeComponent(active); + } + active = (Component) pageSelect.getValue(); + addComponent(active); + } + }); + pageSelect.setNullSelectionAllowed(false); + pageSelect.setValue(pageSelect.getItemIds().iterator().next()); + + } + + public class Editor extends Grid { + @Override + public String toString() { + return "Editor"; + }; + + public Editor() { + setContainerDataSource(container); + setColumnOrder((Object[]) columns); + removeColumn("salary"); + setEditorEnabled(true); + getColumn("lastName").setEditable(false); + setSizeFull(); + getColumn("age").getEditorField().addValidator( + new IntegerRangeValidator("Must be between 0 and 100", 0, + 100)); + } + } + + public class HeaderFooter extends Grid { + @Override + public String toString() { + return getClass().getSimpleName(); + }; + + public HeaderFooter() { + setContainerDataSource(container); + setColumnOrder((Object[]) columns); + HeaderRow row = addHeaderRowAt(0); + row.join("firstName", "lastName").setHtml("<b>Name</b>"); + Button b = new Button("The address, yo"); + b.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + HeaderRow row = addHeaderRowAt(0); + List<Object> pids = new ArrayList<Object>(); + for (Column c : getColumns()) { + pids.add(c.getPropertyId()); + } + row.join(pids.toArray()).setText("The big header"); + } + }); + b.setSizeFull(); + row.join("address.streetAddress", "address.postalCode", + "address.city", "address.country").setComponent(b); + getColumn("age").setWidth(25); + removeColumn("salary"); + setEditorEnabled(true); + setSizeFull(); + getColumn("age").getEditorField().addValidator( + new IntegerRangeValidator("Must be between 0 and 100", 0, + 100)); + + addFooterRowAt(0); + } + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridThemeUITest.java b/uitest/src/com/vaadin/tests/components/grid/GridThemeUITest.java new file mode 100644 index 0000000000..140e8a90d8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridThemeUITest.java @@ -0,0 +1,113 @@ +/* + * 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.grid; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserThemeTest; + +@TestCategory("grid") +public class GridThemeUITest extends MultiBrowserThemeTest { + + private GridElement grid; + + @Test + public void grid() throws Exception { + openTestURL(); + selectPage("Editor"); + compareScreen("basic"); + } + + @Test + public void headerAndFooter() throws Exception { + openTestURL(); + selectPage("HeaderFooter"); + compareScreen("basic"); + grid.getHeaderCell(0, 6).$(ButtonElement.class).first().click(); + compareScreen("additional-header"); + grid.getHeaderCell(2, 1).click(); + compareScreen("sorted-last-name"); + grid.getHeaderCell(2, 4).click(); + compareScreen("sorted-age"); + } + + @Test + public void editor() throws Exception { + openTestURL(); + selectPage("Editor"); + GridCellElement ritaBirthdate = grid.getCell(2, 3); + // Open editor row + openEditor(ritaBirthdate); + + compareScreen("initial"); + + GridEditorElement editor = grid.getEditor(); + + DateFieldElement dateField = editor.$(DateFieldElement.class).first(); + WebElement input = dateField.findElement(By.xpath("input")); + input.sendKeys("Invalid", Keys.TAB); + editor.save(); + compareScreen("one-invalid"); + + TextFieldElement age = editor.$(TextFieldElement.class).caption("Age") + .first(); + age.sendKeys("abc", Keys.TAB); + if (age.getValue().equals("21")) { + // Yes IE8, really type into the field + age.sendKeys("abc", Keys.TAB); + } + editor.save(); + + compareScreen("two-invalid"); + } + + private void openEditor(GridCellElement targetCell) { + new Actions(getDriver()).doubleClick(targetCell).perform(); + try { + if (grid.getEditor().isDisplayed()) { + return; + } + } catch (Exception e) { + + } + + // Try again if IE happen to fail.. + new Actions(getDriver()).doubleClick(targetCell).perform(); + } + + /** + * @since + * @param string + */ + private void selectPage(String string) { + $(NativeSelectElement.class).id("page").selectByText(string); + grid = $(GridElement.class).first(); + + } + +} |