From 451161461bf240e4fd25211ed997d96e565a211b Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 4 Jan 2017 09:56:18 +0200 Subject: Grid UI tests migration P3. (#8121) * Grid UI tests migration P2. Fixes vaadin/framework8-issues#588 * Grid UI tests migration P3. Fixes vaadin/framework8-issues#589 * Merge branch 'master' into 589-grid-tests-migration Conflicts: uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java * Update screenshot submodule reference. --- .../components/grid/GridCellFocusOnResetSize.java | 4 +- .../grid/GridClientDataChangeHandler.java | 4 +- .../vaadin/tests/components/grid/GridColspans.java | 108 ++++++++++++++ .../components/grid/GridColumnAutoExpand.java | 45 ++++++ .../tests/components/grid/GridColumnAutoWidth.java | 54 +++++++ .../components/grid/GridColumnAutoWidthClient.java | 33 +++++ .../grid/GridColumnWidthsWithoutData.java | 100 +++++++++++++ .../tests/components/grid/GridDataSourceReset.java | 60 ++++++++ .../tests/components/grid/GridDetailsDetach.java | 136 ++++++++++++++++++ .../components/grid/GridDetailsLayoutExpand.java | 113 +++++++++++++++ .../tests/components/grid/GridDetailsWidth.java | 77 ++++++++++ .../widgetset/client/TestWidgetConnector.java | 6 + .../grid/GridColumnAutoWidthClientWidget.java | 71 +++++++++ .../v7/grid/GridColumnAutoWidthClientWidget.java | 71 --------- .../v7/tests/components/grid/GridColspans.java | 102 ------------- .../components/grid/GridColumnAutoExpand.java | 46 ------ .../tests/components/grid/GridColumnAutoWidth.java | 63 -------- .../components/grid/GridColumnAutoWidthClient.java | 33 ----- .../v7/tests/components/grid/GridColumnExpand.java | 160 --------------------- .../grid/GridColumnWidthRecalculation.java | 92 ------------ .../grid/GridColumnWidthsWithoutData.java | 108 -------------- .../tests/components/grid/GridDataSourceReset.java | 65 --------- .../tests/components/grid/GridDetailsDetach.java | 150 ------------------- .../components/grid/GridDetailsLayoutExpand.java | 105 -------------- .../tests/components/grid/GridDetailsLocation.java | 7 + .../v7/tests/components/grid/GridDetailsWidth.java | 91 ------------ .../grid/AbstractGridColumnAutoWidthTest.java | 118 +++++++++++++++ .../tests/components/grid/GridColspansTest.java | 95 ++++++++++++ .../components/grid/GridColumnAutoExpandTest.java | 49 +++++++ .../grid/GridColumnAutoWidthClientTest.java | 27 ++++ .../grid/GridColumnAutoWidthServerTest.java | 27 ++++ .../grid/GridColumnWidthsWithoutDataTest.java | 139 ++++++++++++++++++ .../components/grid/GridDataSourceResetTest.java | 50 +++++++ .../components/grid/GridDetailsDetachTest.java | 97 +++++++++++++ .../grid/GridDetailsLayoutExpandTest.java | 74 ++++++++++ .../components/grid/GridDetailsWidthTest.java | 92 ++++++++++++ .../v7/tests/components/grid/GridColspansTest.java | 101 ------------- .../components/grid/GridColumnAutoExpandTest.java | 39 ----- .../grid/GridColumnAutoWidthClientTest.java | 27 ---- .../grid/GridColumnAutoWidthServerTest.java | 27 ---- .../grid/GridColumnWidthRecalculationTest.java | 82 ----------- .../grid/GridColumnWidthsWithoutDataTest.java | 139 ------------------ .../components/grid/GridDataSourceResetTest.java | 50 ------- .../components/grid/GridDetailsDetachTest.java | 97 ------------- .../grid/GridDetailsLayoutExpandTest.java | 74 ---------- .../components/grid/GridDetailsWidthTest.java | 92 ------------ 46 files changed, 1582 insertions(+), 1818 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridColspans.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoExpand.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidth.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClient.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutData.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridDataSourceReset.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsDetach.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsWidth.java create mode 100644 uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridColumnAutoWidthClientWidget.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridColumnAutoWidthClientWidget.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColspans.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpand.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidth.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClient.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnExpand.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculation.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutData.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDataSourceReset.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsDetach.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpand.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsWidth.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridColspansTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoExpandTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClientTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthServerTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutDataTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridDataSourceResetTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsDetachTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsWidthTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColspansTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpandTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClientTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthServerTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculationTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutDataTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDataSourceResetTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsDetachTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpandTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsWidthTest.java (limited to 'uitest') diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java index bfe3244554..9dcabebbf7 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java @@ -17,13 +17,13 @@ package com.vaadin.tests.components.grid; import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.widgetset.TestingWidgetSet; import com.vaadin.tests.widgetset.client.grid.GridCellFocusOnResetSizeWidget; import com.vaadin.tests.widgetset.server.TestWidgetComponent; @Widgetset(TestingWidgetSet.NAME) -public class GridCellFocusOnResetSize extends AbstractReindeerTestUI { +public class GridCellFocusOnResetSize extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java index 50f7e40837..a9f686b107 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java @@ -17,13 +17,13 @@ package com.vaadin.tests.components.grid; import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.widgetset.TestingWidgetSet; import com.vaadin.tests.widgetset.client.grid.GridDataChangeHandlerWidget; import com.vaadin.tests.widgetset.server.TestWidgetComponent; @Widgetset(TestingWidgetSet.NAME) -public class GridClientDataChangeHandler extends AbstractReindeerTestUI { +public class GridClientDataChangeHandler extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColspans.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColspans.java new file mode 100644 index 0000000000..ce29ca3d9e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColspans.java @@ -0,0 +1,108 @@ +/* + * Copyright 2000-2016 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.stream.Collectors; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.components.grid.FooterRow; +import com.vaadin.ui.components.grid.HeaderRow; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridColspans extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Person person = new Person(); + person.setFirstName("Rudolph"); + person.setLastName("Reindeer"); + person.setEmail("test@vaadin.com"); + person.setAge(34); + person.setSalary(3210); + + Grid grid = new Grid<>(); + grid.setWidth("600px"); + + Column firstNameColumn = grid + .addColumn(Person::getFirstName); + firstNameColumn.setId("firstName").setCaption("First name"); + Column lastNameColumn = grid + .addColumn(Person::getLastName); + lastNameColumn.setCaption("Last name"); + Column emailColumn = grid.addColumn(Person::getEmail); + Column ageColumn = grid.addColumn(Person::getAge, + new NumberRenderer()); + ageColumn.setCaption("Age"); + ageColumn.setId("ageColumn"); + Column salaryColumn = grid.addColumn(Person::getSalary, + new NumberRenderer()); + + grid.setItems(person); + + grid.setSelectionMode(SelectionMode.MULTI); + addComponent(grid); + + HeaderRow row = grid.prependHeaderRow(); + row.join(row.getCell(firstNameColumn), row.getCell(lastNameColumn)) + .setText("Full Name"); + row.join(row.getCell(emailColumn), row.getCell(ageColumn), + row.getCell(salaryColumn)).setText("Misc"); + grid.prependHeaderRow().join(grid.getColumns().stream() + .map(row::getCell).collect(Collectors.toSet())) + .setText("All the stuff"); + + FooterRow footerRow = grid.appendFooterRow(); + footerRow.join(footerRow.getCell(firstNameColumn), + footerRow.getCell(lastNameColumn)).setText("Full Name"); + footerRow.join(footerRow.getCell(emailColumn), + footerRow.getCell(ageColumn), footerRow.getCell(salaryColumn)) + .setText("Misc"); + grid.appendFooterRow().join(grid.getColumns().stream() + .map(footerRow::getCell).collect(Collectors.toSet())) + .setText("All the stuff"); + + addComponent(new Button("Show/Hide firstName", event -> { + Column column = grid.getColumn("firstName"); + if (column != null) { + grid.removeColumn(column); + } else { + grid.addColumn(Person::getFirstName).setId("firstName"); + } + })); + + addComponent(new Button("Change column order", event -> { + grid.setColumnOrder(grid.getColumn("ageColumn"), + grid.getColumn("firstName")); + })); + } + + @Override + protected String getTestDescription() { + return "Grid header and footer colspans"; + } + + @Override + protected Integer getTicketNumber() { + return 13334; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoExpand.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoExpand.java new file mode 100644 index 0000000000..3daa978af3 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoExpand.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2016 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 com.vaadin.data.ValueProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.VerticalLayout; + +public class GridColumnAutoExpand extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout layout = new VerticalLayout(); + layout.setSizeFull(); + layout.setMargin(true); + addComponent(layout); + + Grid grid = new Grid<>(); + grid.setCaption("Broken Grid with Caption"); + grid.setWidth("100%"); + grid.setHeight("100px"); + + grid.addColumn(ValueProvider.identity()).setCaption("Col1") + .setWidth(100); + grid.addColumn(ValueProvider.identity()).setCaption("Col2") + .setMinimumWidth(100).setExpandRatio(1); + + layout.addComponent(grid); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidth.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidth.java new file mode 100644 index 0000000000..1434aea7cd --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidth.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2016 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 com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.renderers.HtmlRenderer; + +public class GridColumnAutoWidth extends AbstractReindeerTestUI { + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(); + grid.addColumn(item -> "equal width", new HtmlRenderer()) + .setId("equal width"); + grid.addColumn(item -> "a very long cell content", + new HtmlRenderer()).setId("short"); + grid.addColumn(item -> "short", new HtmlRenderer()) + .setId("a very long header content"); + + grid.addColumn(item -> "fixed width narrow", + new HtmlRenderer()).setId("fixed width narrow").setWidth(50); + grid.addColumn(item -> "fixed width wide", + new HtmlRenderer()).setId("fixed width wide").setWidth(200); + + for (Column column : grid.getColumns()) { + column.setExpandRatio(0); + grid.getHeaderRow(0).getCell(column) + .setHtml("" + column.getId() + ""); + } + + grid.setItems(new Object()); + + grid.setSelectionMode(SelectionMode.NONE); + grid.setWidth("750px"); + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClient.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClient.java new file mode 100644 index 0000000000..b26f56b55b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClient.java @@ -0,0 +1,33 @@ +/* + * Copyright 2000-2016 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 com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.grid.GridColumnAutoWidthClientWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class GridColumnAutoWidthClient extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent( + new TestWidgetComponent(GridColumnAutoWidthClientWidget.class)); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutData.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutData.java new file mode 100644 index 0000000000..c184cd71d1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutData.java @@ -0,0 +1,100 @@ +/* + * Copyright 2000-2016 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.EnumSet; +import java.util.List; + +import com.vaadin.data.provider.DataProvider; +import com.vaadin.server.SerializablePredicate; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.VerticalLayout; + +public class GridColumnWidthsWithoutData extends AbstractTestUI { + + private SelectionMode selectionMode = SelectionMode.NONE; + private List items; + private DataProvider> provider; + private Grid grid = createGrid(true); + + @Override + protected void setup(VaadinRequest request) { + addComponent(grid); + + NativeSelect selectionModeSelector = new NativeSelect<>( + "Selection mode", EnumSet.allOf(SelectionMode.class)); + selectionModeSelector.setValue(selectionMode); + selectionModeSelector.addValueChangeListener(event -> { + selectionMode = selectionModeSelector.getValue(); + grid.setSelectionMode(selectionMode); + }); + + addComponent(selectionModeSelector); + + addComponent(new Button("Recreate without data", + event -> replaceGrid(createGrid(false)))); + + addComponent(new Button("Recreate with data", + event -> replaceGrid(createGrid(true)))); + + addComponent(new Button("Add data", event -> addDataToGrid())); + + addComponent(new Button("Remove data", event -> { + items.clear(); + provider.refreshAll(); + })); + + } + + private void replaceGrid(Grid newGrid) { + ((VerticalLayout) grid.getParent()).replaceComponent(grid, newGrid); + grid = newGrid; + } + + private Grid createGrid(boolean withData) { + Grid grid = new Grid<>(); + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getLastName); + grid.setWidth("300px"); + grid.setSelectionMode(selectionMode); + + items = new ArrayList<>(); + provider = DataProvider.create(items); + grid.setDataProvider(provider); + + if (withData) { + addDataToGrid(); + } + + return grid; + } + + private void addDataToGrid() { + Person person = new Person(); + person.setFirstName("Some"); + person.setLastName("Data with more data in one col"); + items.add(person); + provider.refreshAll(); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataSourceReset.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataSourceReset.java new file mode 100644 index 0000000000..b04e004f53 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataSourceReset.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2016 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.Random; + +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; + +public class GridDataSourceReset extends AbstractTestUI { + + private List persons; + private Grid grid; + + @Override + protected void setup(VaadinRequest request) { + persons = createPersons(10, new Random(1)); + + grid = new Grid<>(); + ListDataProvider provider = DataProvider.create(persons); + grid.setDataProvider(provider); + grid.getSelectionModel().select(persons.get(0)); + addComponent(new Button("Remove first", event -> { + persons.remove(0); + + provider.refreshAll(); + grid.getSelectionModel().select(persons.get(0)); + })); + + addComponent(grid); + } + + public static List createPersons(int count, Random r) { + List c = new ArrayList<>(); + for (int i = 0; i < count; ++i) { + c.add(ComplexPerson.create(r)); + } + return c; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsDetach.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsDetach.java new file mode 100644 index 0000000000..b34d0cd4b1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsDetach.java @@ -0,0 +1,136 @@ +/* + * Copyright 2000-2016 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 com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridDetailsDetach extends AbstractTestUI { + + private Grid currentGrid; + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setSpacing(false); + layout.setMargin(false); + layout.setSizeFull(); + + Button button = new Button("Test"); + layout.addComponent(button); + layout.setExpandRatio(button, 0f); + + currentGrid = generateGrid(); + final VerticalLayout gridContainer = new VerticalLayout(); + gridContainer.setSpacing(false); + gridContainer.setMargin(false); + gridContainer.addComponent(currentGrid); + + button.addClickListener(event -> gridContainer + .replaceComponent(currentGrid, new Label("Foo"))); + + layout.addComponent(new Button("Reattach Grid", event -> { + gridContainer.removeAllComponents(); + gridContainer.addComponent(currentGrid); + })); + + layout.addComponent(gridContainer); + layout.setExpandRatio(gridContainer, 1f); + + addComponent(layout); + } + + private Grid generateGrid() { + List items = new ArrayList<>(); + for (int i = 0; i < 1000; i++) { + items.add(new GridExampleBean("Bean " + i, i * i, i / 10d)); + } + + final Grid grid = new Grid<>(); + grid.setItems(items); + grid.addColumn(GridExampleBean::getName); + grid.addColumn(GridExampleBean::getAmount, new NumberRenderer()); + grid.addColumn(GridExampleBean::getCount, new NumberRenderer()); + grid.setSizeFull(); + grid.setSelectionMode(SelectionMode.NONE); + + grid.setDetailsGenerator(item -> { + VerticalLayout layout = new VerticalLayout( + new Label("Extra data for " + item.getName())); + layout.setMargin(true); + return layout; + }); + + grid.addItemClickListener(event -> { + GridExampleBean item = event.getItem(); + grid.setDetailsVisible(item, !grid.isDetailsVisible(item)); + }); + return grid; + } + + public class GridExampleBean { + + private String name; + + private int count; + + private double amount; + + public GridExampleBean() { + } + + public GridExampleBean(String name, int count, double amount) { + this.name = name; + this.count = count; + this.amount = amount; + } + + public String getName() { + return name; + } + + public int getCount() { + return count; + } + + public double getAmount() { + return amount; + } + + public void setName(String name) { + this.name = name; + } + + public void setCount(int count) { + this.count = count; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java new file mode 100644 index 0000000000..ab8d3d84f7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java @@ -0,0 +1,113 @@ +/* + * Copyright 2000-2016 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 com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Grid; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.renderers.NumberRenderer; + +/** + * Tests the layouting of Grid's details row when it contains a HorizontalLayout + * with expand ratios. + * + * @author Vaadin Ltd + */ +@SuppressWarnings("serial") +public class GridDetailsLayoutExpand extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid<>(); + grid.setSizeFull(); + + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getAge, new NumberRenderer()); + + List persons = new ArrayList<>(); + Person person = new Person(); + person.setFirstName("Nicolaus Copernicus"); + person.setAge(1543); + persons.add(person); + + person = new Person(); + person.setFirstName("Galileo Galilei"); + person.setAge(1564); + persons.add(person); + + person = new Person(); + person.setFirstName("Johannes Kepler"); + person.setAge(1571); + persons.add(person); + + grid.setItems(persons); + addComponent(grid); + + grid.setDetailsGenerator(item -> { + final HorizontalLayout detailsLayout = new HorizontalLayout(); + detailsLayout.setSizeFull(); + detailsLayout.setHeightUndefined(); + + // Label 1 first element of the detailsLayout, taking 200 pixels + final Label lbl1 = new Label("test1"); + lbl1.setWidth("200px"); + detailsLayout.addComponent(lbl1); + + // layout2 second element of the detailsLayout, taking the rest + // of the available space + final HorizontalLayout layout2 = new HorizontalLayout(); + layout2.setSizeFull(); + layout2.setHeightUndefined(); + detailsLayout.addComponent(layout2); + detailsLayout.setExpandRatio(layout2, 1); + + // 2 Labels added to the layout2 + final Label lbl2 = new Label("test2"); + lbl2.setWidth("100%"); + lbl2.setId("lbl2"); + layout2.addComponent(lbl2); + + final Label lbl3 = new Label("test3"); + lbl3.setWidth("100%"); + lbl3.setId("lbl3"); + layout2.addComponent(lbl3); + + return detailsLayout; + }); + + grid.addItemClickListener(event -> { + final Person itemId = event.getItem(); + grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); + }); + + } + + @Override + protected Integer getTicketNumber() { + return 18821; + } + + @Override + protected String getTestDescription() { + return "Details row must be the same after opening another details row"; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsWidth.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsWidth.java new file mode 100644 index 0000000000..678b4ad925 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsWidth.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2016 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.stream.IntStream; + +import com.vaadin.data.ValueProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.TextArea; +import com.vaadin.ui.VerticalLayout; + +public class GridDetailsWidth extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout layout = new VerticalLayout(); + layout.setMargin(true); + + final Grid grid = new Grid<>(); + + Column column = grid.addColumn(ValueProvider.identity()) + .setCaption("Hello"); + grid.setItems(IntStream.range(0, 3).mapToObj(i -> "Hello " + i)); + + column.setWidth(600); + grid.setWidth(400, Unit.PIXELS); + + grid.setDetailsGenerator(item -> { + HorizontalLayout myLayout = new HorizontalLayout(); + TextArea textArea1 = new TextArea(); + TextArea textArea2 = new TextArea(); + textArea1.setSizeFull(); + textArea2.setSizeFull(); + myLayout.addComponent(textArea1); + myLayout.addComponent(textArea2); + myLayout.setWidth(100, Unit.PERCENTAGE); + myLayout.setHeight(null); + myLayout.setMargin(true); + return myLayout; + }); + + grid.addItemClickListener(event -> grid.setDetailsVisible( + event.getItem(), !grid.isDetailsVisible(event.getItem()))); + + layout.addComponent(grid); + + addComponent(layout); + } + + @Override + protected Integer getTicketNumber() { + return 18223; + } + + @Override + protected String getTestDescription() { + return "Tests that Escalator will not set explicit widths to the TD element in a details row."; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/TestWidgetConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/TestWidgetConnector.java index 7b10fba579..8498218e88 100644 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/TestWidgetConnector.java +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/TestWidgetConnector.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.Map; import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Style.Position; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.SimplePanel; @@ -35,6 +36,11 @@ import com.vaadin.tests.widgetset.server.TestWidgetComponent; public class TestWidgetConnector extends AbstractComponentConnector { public static class SubPartAwareSimplePanel extends SimplePanel implements SubPartAware { + + public SubPartAwareSimplePanel() { + getElement().getStyle().setPosition(Position.ABSOLUTE); + } + @Override public Element getSubPartElement(String subPart) { Widget target = getWidget(); diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridColumnAutoWidthClientWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridColumnAutoWidthClientWidget.java new file mode 100644 index 0000000000..df2041744a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridColumnAutoWidthClientWidget.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2016 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.widgetset.client.grid; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.vaadin.client.renderers.HtmlRenderer; +import com.vaadin.client.widget.grid.datasources.ListDataSource; +import com.vaadin.client.widget.grid.selection.SelectionModel; +import com.vaadin.client.widgets.Grid; + +public class GridColumnAutoWidthClientWidget + extends PureGWTTestApplication>> { + + private Grid> grid; + + private class Col extends Grid.Column> { + public Col(String header) { + super(header, new HtmlRenderer()); + setExpandRatio(0); + } + + @Override + public String getValue(List row) { + int index = grid.getColumns().indexOf(this); + return "" + String.valueOf(row.get(index)) + ""; + } + } + + public GridColumnAutoWidthClientWidget() { + super(new Grid>()); + grid = getTestedWidget(); + grid.setSelectionModel(new SelectionModel.NoSelectionModel<>()); + grid.setWidth("750px"); + + addColumn("equal length"); + addColumn("short"); + addColumn("a very long header content"); + addColumn("fixed width narrow").setWidth(50); + addColumn("fixed width wide").setWidth(200); + + List> list = new ArrayList<>(); + list.add(Arrays.asList("equal length", "a very long cell content", + "short", "fixed width narrow", "fixed width wide")); + grid.setDataSource(new ListDataSource<>(list)); + + addNorth(grid, 400); + } + + private Col addColumn(String header) { + Col column = grid.addColumn(new Col(header)); + grid.getHeaderRow(0).getCell(column) + .setHtml("" + header + ""); + return column; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridColumnAutoWidthClientWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridColumnAutoWidthClientWidget.java deleted file mode 100644 index 139835b31a..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridColumnAutoWidthClientWidget.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2000-2016 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.widgetset.client.v7.grid; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.vaadin.v7.client.renderers.HtmlRenderer; -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.SelectionMode; - -public class GridColumnAutoWidthClientWidget - extends PureGWTTestApplication>> { - - private Grid> grid; - - private class Col extends Grid.Column> { - public Col(String header) { - super(header, new HtmlRenderer()); - setExpandRatio(0); - } - - @Override - public String getValue(List row) { - int index = grid.getColumns().indexOf(this); - return "" + String.valueOf(row.get(index)) + ""; - } - } - - public GridColumnAutoWidthClientWidget() { - super(new Grid>()); - grid = getTestedWidget(); - grid.setSelectionMode(SelectionMode.NONE); - grid.setWidth("750px"); - - List> list = new ArrayList<>(); - list.add(Arrays.asList("equal length", "a very long cell content", - "short", "fixed width narrow", "fixed width wide")); - grid.setDataSource(new ListDataSource<>(list)); - - addColumn("equal length"); - addColumn("short"); - addColumn("a very long header content"); - addColumn("fixed width narrow").setWidth(50); - addColumn("fixed width wide").setWidth(200); - - addNorth(grid, 400); - } - - private Col addColumn(String header) { - Col column = grid.addColumn(new Col(header)); - grid.getHeaderRow(0).getCell(column) - .setHtml("" + header + ""); - return column; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColspans.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColspans.java deleted file mode 100644 index dc0b84a6da..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColspans.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.v7.data.Container.Indexed; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.FooterRow; -import com.vaadin.v7.ui.Grid.HeaderRow; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.renderers.NumberRenderer; - -public class GridColspans extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - Indexed dataSource = new IndexedContainer(); - final Grid grid; - - dataSource.addContainerProperty("firstName", String.class, ""); - dataSource.addContainerProperty("lastName", String.class, ""); - dataSource.addContainerProperty("streetAddress", String.class, ""); - dataSource.addContainerProperty("zipCode", Integer.class, null); - dataSource.addContainerProperty("city", String.class, ""); - Item i = dataSource.addItem(0); - i.getItemProperty("firstName").setValue("Rudolph"); - i.getItemProperty("lastName").setValue("Reindeer"); - i.getItemProperty("streetAddress").setValue("Ruukinkatu 2-4"); - i.getItemProperty("zipCode").setValue(20540); - i.getItemProperty("city").setValue("Turku"); - grid = new Grid(dataSource); - grid.setWidth("600px"); - grid.getColumn("zipCode").setRenderer(new NumberRenderer()); - grid.setSelectionMode(SelectionMode.MULTI); - addComponent(grid); - - HeaderRow row = grid.prependHeaderRow(); - row.join("firstName", "lastName").setText("Full Name"); - row.join("streetAddress", "zipCode", "city").setText("Address"); - grid.prependHeaderRow() - .join(dataSource.getContainerPropertyIds().toArray()) - .setText("All the stuff"); - - FooterRow footerRow = grid.appendFooterRow(); - footerRow.join("firstName", "lastName").setText("Full Name"); - footerRow.join("streetAddress", "zipCode", "city").setText("Address"); - grid.appendFooterRow() - .join(dataSource.getContainerPropertyIds().toArray()) - .setText("All the stuff"); - - addComponent( - new Button("Show/Hide firstName", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - if (grid.getColumn("firstName") != null) { - grid.removeColumn("firstName"); - } else { - grid.addColumn("firstName"); - } - } - })); - - addComponent( - new Button("Change column order", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.setColumnOrder("zipCode", "firstName"); - } - })); - } - - @Override - protected String getTestDescription() { - return "Grid header and footer colspans"; - } - - @Override - protected Integer getTicketNumber() { - return 13334; - } - -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpand.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpand.java deleted file mode 100644 index 269f16eb1c..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpand.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; - -public class GridColumnAutoExpand extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - final VerticalLayout layout = new VerticalLayout(); - layout.setSizeFull(); - layout.setMargin(true); - addComponent(layout); - - Grid grid = new Grid("Broken Grid with Caption"); - grid.setWidth("100%"); - grid.setHeight("100px"); - - Column col1 = grid.addColumn("Col1"); - col1.setWidth(100); - - Column col2 = grid.addColumn("Col2"); - col2.setMinimumWidth(100); - col2.setExpandRatio(1); - - layout.addComponent(grid); - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidth.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidth.java deleted file mode 100644 index c03aa05b47..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidth.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.v7.data.Container; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.renderers.HtmlRenderer; - -public class GridColumnAutoWidth extends AbstractReindeerTestUI { - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(createContainer()); - grid.getColumn("fixed width narrow").setWidth(50); - grid.getColumn("fixed width wide").setWidth(200); - - for (Object propertyId : grid.getContainerDataSource() - .getContainerPropertyIds()) { - Column column = grid.getColumn(propertyId); - column.setExpandRatio(0); - column.setRenderer(new HtmlRenderer()); - grid.getHeaderRow(0).getCell(propertyId) - .setHtml("" + column.getHeaderCaption() + ""); - } - - grid.setSelectionMode(SelectionMode.NONE); - grid.setWidth("750px"); - addComponent(grid); - } - - private static Container.Indexed createContainer() { - IndexedContainer c = new IndexedContainer(); - c.addContainerProperty("equal width", String.class, - "equal width"); - c.addContainerProperty("short", String.class, - "a very long cell content"); - c.addContainerProperty("a very long header content", String.class, - "short"); - c.addContainerProperty("fixed width narrow", String.class, - "fixed width narrow"); - c.addContainerProperty("fixed width wide", String.class, - "fixed width wide"); - c.addItem(); - return c; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClient.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClient.java deleted file mode 100644 index 9991efc08f..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClient.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.v7.grid.GridColumnAutoWidthClientWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; - -@Widgetset(TestingWidgetSet.NAME) -public class GridColumnAutoWidthClient extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - addComponent( - new TestWidgetComponent(GridColumnAutoWidthClientWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnExpand.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnExpand.java deleted file mode 100644 index d3c71ed3e4..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnExpand.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.tests.util.PersonContainer; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.themes.Reindeer; - -@Theme(Reindeer.THEME_NAME) -public class GridColumnExpand extends AbstractReindeerTestUI { - private Grid grid; - private Label firstInfo = new Label(); - private Label secondInfo = new Label(); - private Column firstColumn; - private Column secondColumn; - - @Override - protected void setup(VaadinRequest request) { - grid = new Grid(PersonContainer.createWithTestData()); - grid.removeAllColumns(); - grid.addColumn("address.streetAddress"); - grid.addColumn("lastName"); - firstColumn = grid.getColumns().get(0); - secondColumn = grid.getColumns().get(1); - - updateInfoLabels(); - addComponent(grid); - addComponent(firstInfo); - addComponent(secondInfo); - addButtons(); - } - - private void addButtons() { - HorizontalLayout layout = new HorizontalLayout(); - layout.addComponent(createButtons(firstColumn)); - layout.addComponent(createButtons(secondColumn)); - layout.setExpandRatio(layout.getComponent(1), 1); - addComponent(layout); - } - - private Component createButtons(Column column) { - CssLayout layout = new CssLayout(); - layout.addComponent(new Label("Column 1")); - - CssLayout widthLayout = new CssLayout(); - layout.addComponent(widthLayout); - widthLayout.addComponent(new Label("Width")); - widthLayout.addComponent(createWidthButton(column, -1)); - widthLayout.addComponent(createWidthButton(column, 50)); - widthLayout.addComponent(createWidthButton(column, 200)); - - CssLayout minLayout = new CssLayout(); - layout.addComponent(minLayout); - minLayout.addComponent(new Label("Min width")); - minLayout.addComponent(createMinButton(column, -1)); - minLayout.addComponent(createMinButton(column, 50)); - minLayout.addComponent(createMinButton(column, 200)); - - CssLayout maxLayout = new CssLayout(); - maxLayout.addComponent(new Label("Max width")); - maxLayout.addComponent(createMaxButton(column, -1)); - maxLayout.addComponent(createMaxButton(column, 50)); - maxLayout.addComponent(createMaxButton(column, 200)); - layout.addComponent(maxLayout); - - CssLayout expandLayout = new CssLayout(); - expandLayout.addComponent(new Label("Expand ratio")); - expandLayout.addComponent(createExpandButton(column, -1)); - expandLayout.addComponent(createExpandButton(column, 0)); - expandLayout.addComponent(createExpandButton(column, 1)); - expandLayout.addComponent(createExpandButton(column, 2)); - layout.addComponent(expandLayout); - - return layout; - } - - private Component createWidthButton(final Column column, - final double width) { - return new Button("" + width, new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - if (width >= 0) { - column.setWidth(width); - } else { - column.setWidthUndefined(); - } - updateInfoLabels(); - } - }); - } - - private Component createMinButton(final Column column, final double width) { - return new Button("" + width, new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - column.setMinimumWidth(width); - updateInfoLabels(); - } - }); - } - - private Component createMaxButton(final Column column, final double width) { - return new Button("" + width, new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - column.setMaximumWidth(width); - updateInfoLabels(); - } - }); - } - - private Component createExpandButton(final Column column, final int ratio) { - return new Button("" + ratio, new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - column.setExpandRatio(ratio); - updateInfoLabels(); - } - }); - } - - private void updateInfoLabels() { - updateLabel(firstInfo, firstColumn); - updateLabel(secondInfo, secondColumn); - } - - private void updateLabel(Label label, Column column) { - int expandRatio = column.getExpandRatio(); - double minimumWidth = Math.round(column.getMinimumWidth() * 100) / 100; - double maximumWidth = Math.round(column.getMaximumWidth() * 100) / 100; - double width = Math.round(column.getWidth() * 100) / 100; - Object propertyId = column.getPropertyId(); - label.setValue(String.format( - "[%s] Expand ratio: %s - min: %s - max: %s - width: %s", - propertyId, expandRatio, minimumWidth, maximumWidth, width)); - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculation.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculation.java deleted file mode 100644 index 8045075b7c..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculation.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import java.util.ArrayList; - -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.v7.data.Container.Indexed; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.ui.Grid; - -public class GridColumnWidthRecalculation extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - - grid.addColumn("Column 1"); - grid.addColumn("Column 2"); - - grid.addRow("Narrow", - "Wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiide"); - addComponent(grid); - - Button b = new Button("Swap content", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - swapData(grid); - } - }); - addComponent(b); - - b = new Button("Swap content and recalculate columns", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - swapData(grid); - grid.recalculateColumnWidths(); - - } - }); - addComponent(b); - } - - @SuppressWarnings("unchecked") - protected void swapData(Grid grid) { - Indexed dataSource = grid.getContainerDataSource(); - Object itemId = dataSource.getItemIds().iterator().next(); - Item item = dataSource.getItem(itemId); - ArrayList pIds = new ArrayList<>(item.getItemPropertyIds()); - for (int i = 0; i < pIds.size() / 2; i++) { - int j = pIds.size() - 1 - i; - Object pid1 = pIds.get(i); - Object pid2 = pIds.get(j); - - Property property1 = item.getItemProperty(pid1); - Property property2 = item.getItemProperty(pid2); - Object tmp = property1.getValue(); - property1.setValue(property2.getValue()); - property2.setValue(tmp); - } - } - - @Override - protected String getTestDescription() { - return "There should be a way to ask Grid to recalculate column widths from server-side."; - } - - @Override - protected Integer getTicketNumber() { - return 16748; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutData.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutData.java deleted file mode 100644 index 011a1ec306..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutData.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import java.util.EnumSet; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.data.Property.ValueChangeListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.NativeSelect; - -public class GridColumnWidthsWithoutData extends AbstractReindeerTestUI { - - private SelectionMode selectionMode = SelectionMode.NONE; - private Grid grid = createGrid(true); - - @Override - protected void setup(VaadinRequest request) { - addComponent(grid); - - NativeSelect selectionModeSelector = new NativeSelect("Selection mode", - EnumSet.allOf(SelectionMode.class)); - selectionModeSelector.setValue(selectionMode); - selectionModeSelector.setNullSelectionAllowed(false); - selectionModeSelector.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - selectionMode = (SelectionMode) event.getProperty().getValue(); - grid.setSelectionMode(selectionMode); - } - }); - addComponent(selectionModeSelector); - - addComponent( - new Button("Recreate without data", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - replaceGrid(createGrid(false)); - } - })); - - addComponent( - new Button("Recreate with data", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - replaceGrid(createGrid(true)); - } - })); - - addComponent(new Button("Add data", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - addDataToGrid(grid); - } - })); - - addComponent(new Button("Remove data", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getContainerDataSource().removeAllItems(); - } - })); - - } - - private void replaceGrid(Grid newGrid) { - ((VerticalLayout) grid.getParent()).replaceComponent(grid, newGrid); - grid = newGrid; - } - - private Grid createGrid(boolean withData) { - Grid grid = new Grid(); - grid.addColumn("foo"); - grid.addColumn("bar"); - grid.setWidth("300px"); - grid.setSelectionMode(selectionMode); - - if (withData) { - addDataToGrid(grid); - } - - return grid; - } - - private void addDataToGrid(Grid grid) { - grid.addRow("Some", "Data with more data in one col"); - } - -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDataSourceReset.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDataSourceReset.java deleted file mode 100644 index f27f985015..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDataSourceReset.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -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.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; - -public class GridDataSourceReset extends AbstractReindeerTestUI { - - BeanItemContainer container; - List persons; - Grid grid; - - @Override - protected void setup(VaadinRequest request) { - persons = createPersons(10, new Random(1)); - container = new BeanItemContainer<>(ComplexPerson.class, persons); - - grid = new Grid(container); - grid.select(container.firstItemId()); - addComponent(new Button("Remove first", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - container.removeAllItems(); - persons.remove(0); - - container.addAll(persons); - grid.select(container.firstItemId()); - } - })); - addComponent(grid); - } - - public static List createPersons(int count, Random r) { - List c = new ArrayList<>(); - for (int i = 0; i < count; ++i) { - c.add(ComplexPerson.create(r)); - } - return c; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsDetach.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsDetach.java deleted file mode 100644 index d77f493de0..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsDetach.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Component; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.DetailsGenerator; -import com.vaadin.v7.ui.Grid.RowReference; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridDetailsDetach extends AbstractReindeerTestUI { - - private Grid currentGrid; - - @Override - protected void setup(VaadinRequest request) { - VerticalLayout layout = new VerticalLayout(); - layout.setSizeFull(); - - Button button = new Button("Test"); - layout.addComponent(button); - layout.setExpandRatio(button, 0f); - - currentGrid = generateGrid(); - final VerticalLayout gridContainer = new VerticalLayout(); - gridContainer.addComponent(currentGrid); - - button.addClickListener(new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - gridContainer.replaceComponent(currentGrid, new Label("Foo")); - } - }); - - layout.addComponent( - new Button("Reattach Grid", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - gridContainer.removeAllComponents(); - gridContainer.addComponent(currentGrid); - } - })); - - layout.addComponent(gridContainer); - layout.setExpandRatio(gridContainer, 1f); - - addComponent(layout); - } - - private Grid generateGrid() { - BeanItemContainer container = new BeanItemContainer<>( - GridExampleBean.class); - for (int i = 0; i < 1000; i++) { - container.addItem(new GridExampleBean("Bean " + i, i * i, i / 10d)); - } - - final Grid grid = new Grid(container); - grid.setColumnOrder("name", "amount", "count"); - grid.setSizeFull(); - grid.setSelectionMode(SelectionMode.NONE); - - grid.setDetailsGenerator(new DetailsGenerator() { - @Override - public Component getDetails(RowReference rowReference) { - final GridExampleBean bean = (GridExampleBean) rowReference - .getItemId(); - VerticalLayout layout = new VerticalLayout( - new Label("Extra data for " + bean.getName())); - layout.setMargin(true); - return layout; - } - }); - - grid.addItemClickListener(new ItemClickListener() { - @Override - public void itemClick(ItemClickEvent event) { - Object itemId = event.getItemId(); - grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); - } - }); - return grid; - } - - public class GridExampleBean { - - private String name; - - private int count; - - private double amount; - - public GridExampleBean() { - } - - public GridExampleBean(String name, int count, double amount) { - this.name = name; - this.count = count; - this.amount = amount; - } - - public String getName() { - return name; - } - - public int getCount() { - return count; - } - - public double getAmount() { - return amount; - } - - public void setName(String name) { - this.name = name; - } - - public void setCount(int count) { - this.count = count; - } - - public void setAmount(double amount) { - this.amount = amount; - } - - } - -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpand.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpand.java deleted file mode 100644 index 21dba5b4b2..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpand.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.DetailsGenerator; -import com.vaadin.v7.ui.Grid.RowReference; - -/** - * Tests the layouting of Grid's details row when it contains a HorizontalLayout - * with expand ratios. - * - * @author Vaadin Ltd - */ -@SuppressWarnings("serial") -public class GridDetailsLayoutExpand extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.setSizeFull(); - grid.addColumn("name", String.class); - grid.addColumn("born", Integer.class); - - grid.addRow("Nicolaus Copernicus", 1543); - grid.addRow("Galileo Galilei", 1564); - grid.addRow("Johannes Kepler", 1571); - - addComponent(grid); - - grid.setDetailsGenerator(new DetailsGenerator() { - @Override - public Component getDetails(final RowReference rowReference) { - final HorizontalLayout detailsLayout = new HorizontalLayout(); - detailsLayout.setSizeFull(); - detailsLayout.setHeightUndefined(); - - // Label 1 first element of the detailsLayout, taking 200 pixels - final Label lbl1 = new Label("test1"); - lbl1.setWidth("200px"); - detailsLayout.addComponent(lbl1); - - // layout2 second element of the detailsLayout, taking the rest - // of the available space - final HorizontalLayout layout2 = new HorizontalLayout(); - layout2.setSizeFull(); - layout2.setHeightUndefined(); - detailsLayout.addComponent(layout2); - detailsLayout.setExpandRatio(layout2, 1); - - // 2 Labels added to the layout2 - final Label lbl2 = new Label("test2"); - lbl2.setWidth("100%"); - lbl2.setId("lbl2"); - layout2.addComponent(lbl2); - - final Label lbl3 = new Label("test3"); - lbl3.setWidth("100%"); - lbl3.setId("lbl3"); - layout2.addComponent(lbl3); - - return detailsLayout; - } - }); - - grid.addItemClickListener(new ItemClickListener() { - @Override - public void itemClick(final ItemClickEvent event) { - final Object itemId = event.getItemId(); - grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); - } - }); - - } - - @Override - protected Integer getTicketNumber() { - return 18821; - } - - @Override - protected String getTestDescription() { - return "Details row must be the same after opening another details row"; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLocation.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLocation.java index 7a88da395b..bd451e978b 100644 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLocation.java +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLocation.java @@ -32,6 +32,13 @@ import com.vaadin.v7.ui.Grid.DetailsGenerator; import com.vaadin.v7.ui.Grid.RowReference; import com.vaadin.v7.ui.Grid.SelectionMode; +/** + * This test cannot be migrated to V8 since there is no Grid::scrollTo method. + * Will it be there in the future ? (may be this test should be just removed). + * + * @author Vaadin Ltd + * + */ public class GridDetailsLocation extends UI { private final DetailsGenerator detailsGenerator = new DetailsGenerator() { diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsWidth.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsWidth.java deleted file mode 100644 index 8194cee0b6..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsWidth.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.DetailsGenerator; -import com.vaadin.v7.ui.Grid.RowReference; -import com.vaadin.v7.ui.TextArea; - -public class GridDetailsWidth extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - final VerticalLayout layout = new VerticalLayout(); - layout.setMargin(true); - - final Grid grid = new Grid(); - - Column column = grid.addColumn("Hello", String.class); - for (int i = 0; i < 3; i++) { - grid.addRow("Hello " + i); - } - - column.setWidth(600); - grid.setWidth(400, Unit.PIXELS); - - grid.setDetailsGenerator(new DetailsGenerator() { - - @Override - public Component getDetails(RowReference rowReference) { - HorizontalLayout myLayout = new HorizontalLayout(); - TextArea textArea1 = new TextArea(); - TextArea textArea2 = new TextArea(); - textArea1.setSizeFull(); - textArea2.setSizeFull(); - myLayout.addComponent(textArea1); - myLayout.addComponent(textArea2); - myLayout.setWidth(100, Unit.PERCENTAGE); - myLayout.setHeight(null); - myLayout.setMargin(true); - return myLayout; - } - }); - - grid.addItemClickListener(new ItemClickListener() { - - @Override - public void itemClick(ItemClickEvent event) { - grid.setDetailsVisible(event.getItemId(), - !grid.isDetailsVisible(event.getItemId())); - - } - }); - - layout.addComponent(grid); - - addComponent(layout); - } - - @Override - protected Integer getTicketNumber() { - return 18223; - } - - @Override - protected String getTestDescription() { - return "Tests that Escalator will not set explicit widths to the TD element in a details row."; - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java new file mode 100644 index 0000000000..b5ff8a33b4 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2000-2016 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 static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.regex.Pattern; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@SuppressWarnings("boxing") +@TestCategory("grid") +public abstract class AbstractGridColumnAutoWidthTest extends MultiBrowserTest { + + public static final int TOTAL_MARGIN_PX = 21; + + @Before + public void before() { + openTestURL(); + } + + @Test + public void testNarrowHeaderWideBody() { + WebElement[] col = getColumn(1); + int headerWidth = col[0].getSize().getWidth(); + int bodyWidth = col[1].getSize().getWidth(); + int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; + + assertLessThan("header should've been narrower than body", headerWidth, + bodyWidth); + assertEquals("column should've been roughly as wide as the body", + bodyWidth, colWidth, 5); + } + + @Test + public void testWideHeaderNarrowBody() { + WebElement[] col = getColumn(2); + int headerWidth = col[0].getSize().getWidth(); + int bodyWidth = col[1].getSize().getWidth(); + int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; + + assertGreater("header should've been wider than body", headerWidth, + bodyWidth); + assertEquals("column should've been roughly as wide as the header", + headerWidth, colWidth, 5); + + } + + @Test + public void testTooNarrowColumn() { + if (BrowserUtil.isIE(getDesiredCapabilities())) { + // IE can't deal with overflow nicely. + return; + } + + WebElement[] col = getColumn(3); + int headerWidth = col[0].getSize().getWidth(); + int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; + + assertLessThan("column should've been narrower than content", colWidth, + headerWidth); + } + + @Test + public void testTooWideColumn() { + WebElement[] col = getColumn(4); + int headerWidth = col[0].getSize().getWidth(); + int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; + + assertGreater("column should've been wider than content", colWidth, + headerWidth); + } + + @Test + public void testColumnsRenderCorrectly() throws IOException { + WebElement loadingIndicator = findElement( + By.className("v-loading-indicator")); + Pattern pattern = Pattern.compile("display: *none;"); + waitUntil(driver -> { + return pattern.matcher(loadingIndicator.getAttribute("style")) + .find(); + }); + compareScreen("grid-v8-initialRender"); + } + + private WebElement[] getColumn(int i) { + WebElement[] col = new WebElement[3]; + col[0] = getDriver().findElement( + By.xpath("//thead//th[" + (i + 1) + "]/div[1]/span")); + col[1] = getDriver() + .findElement(By.xpath("//tbody//td[" + (i + 1) + "]//span")); + col[2] = getDriver() + .findElement(By.xpath("//tbody//td[" + (i + 1) + "]")); + return col; + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColspansTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColspansTest.java new file mode 100644 index 0000000000..bd1cf1a27b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColspansTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2000-2016 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridColspansTest extends MultiBrowserTest { + + @Before + public void setUp() { + setDebug(true); + } + + @Test + public void testColSpans() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + assertEquals("5", grid.getHeaderCell(0, 1).getAttribute("colspan")); + assertEquals("2", grid.getHeaderCell(1, 1).getAttribute("colspan")); + assertEquals("3", grid.getHeaderCell(1, 3).getAttribute("colspan")); + + assertEquals("5", grid.getFooterCell(1, 1).getAttribute("colspan")); + assertEquals("2", grid.getFooterCell(0, 1).getAttribute("colspan")); + assertEquals("3", grid.getFooterCell(0, 3).getAttribute("colspan")); + } + + @Test + public void testHideFirstColumnOfColspan() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + assertEquals("Failed initial condition.", "all the stuff", + grid.getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Failed initial condition.", "first name", + grid.getHeaderCell(2, 1).getText().toLowerCase()); + $(ButtonElement.class).caption("Show/Hide firstName").first().click(); + assertEquals("Header text changed on column hide.", "all the stuff", + grid.getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Failed initial condition.", "last name", + grid.getHeaderCell(2, 1).getText().toLowerCase()); + } + + @Test + public void testSplittingMergedHeaders() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + GridCellElement headerCell = grid.getHeaderCell(1, 1); + assertEquals("Failed initial condition.", "full name", + headerCell.getText().toLowerCase()); + assertEquals("Failed initial condition.", "first name", + grid.getHeaderCell(2, 1).getText().toLowerCase()); + $(ButtonElement.class).get(1).click(); + headerCell = grid.getHeaderCell(1, 1); + assertEquals("Joined Header text not changed on column reorder.", + "misc", headerCell.getText().toLowerCase()); + assertEquals("Unexpected colspan", "1", + headerCell.getAttribute("colspan")); + headerCell = grid.getHeaderCell(1, 2); + assertEquals("Header text not changed on column reorder", "full name", + headerCell.getText().toLowerCase()); + assertEquals("Unexpected colspan", "2", + headerCell.getAttribute("colspan")); + + assertFalse("Error indicator not present", + isElementPresent(By.className("v-errorindicator"))); + + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoExpandTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoExpandTest.java new file mode 100644 index 0000000000..be8f122c99 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoExpandTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 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 static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridColumnAutoExpandTest extends MultiBrowserTest { + + @Override + public List getBrowsersToTest() { + // The functionality doesn't work for PHJS_1. And the test fails. It + // works for PHJS_2. + return getBrowsersExcludingPhantomJS(); + } + + @Test + public void testSecondColumnHasExpanded() { + openTestURL(); + + GridCellElement headerCell = $(GridElement.class).first() + .getHeaderCell(0, 1); + + assertTrue("Column did not expand as expected", + headerCell.getSize().getWidth() > 400); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClientTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClientTest.java new file mode 100644 index 0000000000..8b1745d1ea --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClientTest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2016 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 com.vaadin.testbench.parallel.TestCategory; + +@TestCategory("grid") +public class GridColumnAutoWidthClientTest + extends AbstractGridColumnAutoWidthTest { + @Override + protected Class getUIClass() { + return GridColumnAutoWidthClient.class; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthServerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthServerTest.java new file mode 100644 index 0000000000..b41c626c0f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthServerTest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2016 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 com.vaadin.testbench.parallel.TestCategory; + +@TestCategory("grid") +public class GridColumnAutoWidthServerTest + extends AbstractGridColumnAutoWidthTest { + @Override + protected Class getUIClass() { + return GridColumnAutoWidth.class; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutDataTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutDataTest.java new file mode 100644 index 0000000000..6797353728 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutDataTest.java @@ -0,0 +1,139 @@ +/* + * Copyright 2000-2016 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.List; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridColumnWidthsWithoutDataTest extends SingleBrowserTest { + + @Test + public void testWidthsWhenAddingDataBack() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + int[] baseWidths = getColWidths(grid); + Assert.assertEquals("Sanity check", 2, baseWidths.length); + + Assert.assertTrue("Columns should not have equal width", + Math.abs(baseWidths[0] - baseWidths[1]) > 2); + + removeData(); + + assertSameWidths(baseWidths, getColWidths(grid)); + + addData(); + + assertSameWidths(baseWidths, getColWidths(grid)); + } + + @Test + public void testWidthsWhenInitiallyEmpty() { + setDebug(true); + openTestURL(); + $(ButtonElement.class).caption("Recreate without data").first().click(); + + GridElement grid = $(GridElement.class).first(); + + int[] baseWidths = getColWidths(grid); + Assert.assertEquals("Sanity check", 2, baseWidths.length); + + Assert.assertTrue("Columns should have roughly equal width", + Math.abs(baseWidths[0] - baseWidths[1]) < 10); + Assert.assertTrue("Columns should not have default widths", + baseWidths[0] > 140); + Assert.assertTrue("Columns should not have default widths", + baseWidths[1] > 140); + + addData(); + + assertSameWidths(baseWidths, getColWidths(grid)); + + Assert.assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + } + + @Test + public void testMultiSelectWidths() { + setDebug(true); + openTestURL(); + $(NativeSelectElement.class).caption("Selection mode").first() + .selectByText("MULTI"); + + GridElement grid = $(GridElement.class).first(); + + int sum = sumUsedWidths(grid); + + // 295 instead of 300 to avoid rounding issues + Assert.assertTrue("Only " + sum + " out of 300px was used", sum > 295); + + $(ButtonElement.class).caption("Recreate without data").first().click(); + + grid = $(GridElement.class).first(); + sum = sumUsedWidths(grid); + + // 295 instead of 300 to avoid rounding issues + Assert.assertTrue("Only " + sum + " out of 300px was used", sum > 295); + } + + private int sumUsedWidths(GridElement grid) { + int sum = 0; + for (int i : getColWidths(grid)) { + sum += i; + } + return sum; + } + + private static void assertSameWidths(int[] expected, int[] actual) { + Assert.assertEquals("Arrays have differing lengths", expected.length, + actual.length); + + for (int i = 0; i < expected.length; i++) { + if (Math.abs(expected[i] - actual[i]) > 1) { + Assert.fail("Differing sizes at index " + i + ". Expected " + + expected[i] + " but got " + actual[i]); + } + } + } + + private void removeData() { + $(ButtonElement.class).caption("Remove data").first().click(); + } + + private void addData() { + $(ButtonElement.class).caption("Add data").first().click(); + } + + private int[] getColWidths(GridElement grid) { + List headerCells = grid.getHeaderCells(0); + int[] widths = new int[headerCells.size()]; + for (int i = 0; i < widths.length; i++) { + widths[i] = headerCells.get(i).getSize().getWidth(); + } + return widths; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDataSourceResetTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDataSourceResetTest.java new file mode 100644 index 0000000000..4e3ce3e4c8 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDataSourceResetTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2016 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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridDataSourceResetTest extends SingleBrowserTest { + + @Test + public void testRemoveWithSelectUpdatesRowsCorrectly() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + assertTrue("First row was not selected", grid.getRow(0).isSelected()); + for (int i = 1; i < 10; ++i) { + assertFalse("Only first row should be selected", + grid.getRow(i).isSelected()); + } + + $(ButtonElement.class).first().click(); + + assertTrue("First row was not selected after remove", + grid.getRow(0).isSelected()); + for (int i = 1; i < 9; ++i) { + assertFalse("Only first row should be selected after remove", + grid.getRow(i).isSelected()); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsDetachTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsDetachTest.java new file mode 100644 index 0000000000..5ede362f29 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsDetachTest.java @@ -0,0 +1,97 @@ +/* + * Copyright 2000-2016 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.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridDetailsDetachTest extends MultiBrowserTest { + + @Test + public void testDetachGridWithDetailsOpen() { + setDebug(true); + openTestURL(); + + $(GridElement.class).first().getCell(3, 0).click(); + $(GridElement.class).first().getCell(5, 0).click(); + + assertNoErrorNotifications(); + + $(ButtonElement.class).first().click(); + + assertNoErrorNotifications(); + } + + @Test + public void testDetachAndReattachGridWithDetailsOpen() { + setDebug(true); + openTestURL(); + + $(GridElement.class).first().getCell(1, 0).click(); + $(GridElement.class).first().getCell(3, 0).click(); + + assertNoErrorNotifications(); + + $(ButtonElement.class).first().click(); + + assertNoErrorNotifications(); + + $(ButtonElement.class).get(1).click(); + + assertNoErrorNotifications(); + + List spacers = findElements(By.className("v-grid-spacer")); + Assert.assertEquals("Not enough spacers in DOM", 2, spacers.size()); + Assert.assertEquals("Spacer content not visible", + "Extra data for Bean 1", spacers.get(0).getText()); + Assert.assertEquals("Spacer content not visible", + "Extra data for Bean 3", spacers.get(1).getText()); + } + + @Test + public void testDetachAndImmediateReattach() { + setDebug(true); + openTestURL(); + + $(GridElement.class).first().getCell(1, 0).click(); + $(GridElement.class).first().getCell(3, 0).click(); + + assertNoErrorNotifications(); + + // Detach and Re-attach Grid + $(ButtonElement.class).get(1).click(); + + assertNoErrorNotifications(); + + List spacers = findElements(By.className("v-grid-spacer")); + Assert.assertEquals("Not enough spacers in DOM", 2, spacers.size()); + Assert.assertEquals("Spacer content not visible", + "Extra data for Bean 1", spacers.get(0).getText()); + Assert.assertEquals("Spacer content not visible", + "Extra data for Bean 3", spacers.get(1).getText()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java new file mode 100644 index 0000000000..c1f4ee7e5e --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2016 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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.number.IsCloseTo.closeTo; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests the layouting of Grid's details row when it contains a HorizontalLayout + * with expand ratios. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridDetailsLayoutExpandTest extends MultiBrowserTest { + + @Override + public List getBrowsersToTest() { + List browsersToTest = super.getBrowsersToTest(); + // for some reason PhantomJS doesn't find the label even if it detects + // the presence + browsersToTest.remove(Browser.PHANTOMJS.getDesiredCapabilities()); + return browsersToTest; + } + + @Test + public void testLabelWidths() { + openTestURL(); + waitForElementPresent(By.className("v-grid")); + + GridElement grid = $(GridElement.class).first(); + int gridWidth = grid.getSize().width; + + grid.getRow(2).click(); + waitForElementPresent(By.id("lbl2")); + + // space left over from first label should be divided equally + double expectedWidth = (double) (gridWidth - 200) / 2; + assertLabelWidth("lbl2", expectedWidth); + assertLabelWidth("lbl3", expectedWidth); + } + + private void assertLabelWidth(String id, double expectedWidth) { + // 1px leeway for calculations + assertThat("Unexpected label width.", + (double) $(LabelElement.class).id(id).getSize().width, + closeTo(expectedWidth, 1d)); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsWidthTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsWidthTest.java new file mode 100644 index 0000000000..7c4ebb536c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsWidthTest.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2016 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.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridDetailsWidthTest extends SingleBrowserTest { + + @Test + public void testSpacerTDsHaveNoWidth() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Open all details rows + grid.getCell(0, 0).click(); + checkSpacersHaveNoWidths(1); + + grid.getCell(1, 0).click(); + checkSpacersHaveNoWidths(2); + + grid.getCell(2, 0).click(); + checkSpacersHaveNoWidths(3); + + // Close all details rows + grid.getCell(2, 0).click(); + checkSpacersHaveNoWidths(2); + + grid.getCell(1, 0).click(); + checkSpacersHaveNoWidths(1); + + grid.getCell(0, 0).click(); + checkSpacersHaveNoWidths(0); + } + + private void checkSpacersHaveNoWidths(int expectedCount) { + List spacers = findElements(By.className("v-grid-spacer")); + Assert.assertEquals("Wrong amount of spacers visible.", expectedCount, + spacers.size()); + for (WebElement spacer : spacers) { + Assert.assertFalse("Spacer element had an unexpected width set.", + spacer.findElement(By.tagName("td")).getAttribute("style") + .contains("width")); + } + } + + @Test + public void testDetailsOnSort() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Open a details rows + grid.getCell(0, 0).click(); + + GridCellElement cell = grid.getHeaderCell(0, 0); + cell.click(); + cell.click(); + + cell = grid.getCell(2, 0); + WebElement spacer = findElement(By.className("v-grid-spacer")); + Assert.assertEquals("Grid was not sorted correctly", "Hello 0", + cell.getText()); + Assert.assertEquals("Details row was not in correct location", + cell.getLocation().getY() + cell.getSize().getHeight(), + spacer.getLocation().getY(), 2); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColspansTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColspansTest.java deleted file mode 100644 index b50c5a2e5e..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColspansTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridColspansTest extends MultiBrowserTest { - - @Before - public void setUp() { - setDebug(true); - } - - @Test - public void testHeaderColSpans() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - assertEquals("5", grid.getHeaderCell(0, 1).getAttribute("colspan")); - assertEquals("2", grid.getHeaderCell(1, 1).getAttribute("colspan")); - assertEquals("3", grid.getHeaderCell(1, 3).getAttribute("colspan")); - } - - @Test - public void testFooterColSpans() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - assertEquals("5", grid.getFooterCell(1, 1).getAttribute("colspan")); - assertEquals("2", grid.getFooterCell(0, 1).getAttribute("colspan")); - assertEquals("3", grid.getFooterCell(0, 3).getAttribute("colspan")); - } - - @Test - public void testHideFirstColumnOfColspan() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - assertEquals("Failed initial condition.", "all the stuff", - grid.getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Failed initial condition.", "first name", - grid.getHeaderCell(2, 1).getText().toLowerCase()); - $(ButtonElement.class).caption("Show/Hide firstName").first().click(); - assertEquals("Header text changed on column hide.", "all the stuff", - grid.getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Failed initial condition.", "last name", - grid.getHeaderCell(2, 1).getText().toLowerCase()); - } - - @Test - public void testSplittingMergedHeaders() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - GridCellElement headerCell = grid.getHeaderCell(1, 1); - assertEquals("Failed initial condition.", "full name", - headerCell.getText().toLowerCase()); - assertEquals("Failed initial condition.", "first name", - grid.getHeaderCell(2, 1).getText().toLowerCase()); - $(ButtonElement.class).get(1).click(); - headerCell = grid.getHeaderCell(1, 1); - assertEquals("Header text not changed on column reorder.", "address", - headerCell.getText().toLowerCase()); - assertEquals("Unexpected colspan", "1", - headerCell.getAttribute("colspan")); - headerCell = grid.getHeaderCell(1, 2); - assertEquals("Header text not changed on column reorder", "full name", - headerCell.getText().toLowerCase()); - assertEquals("Unexpected colspan", "2", - headerCell.getAttribute("colspan")); - - assertTrue("Error indicator not present", - isElementPresent(By.className("v-errorindicator"))); - - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpandTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpandTest.java deleted file mode 100644 index cd77084aef..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpandTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class GridColumnAutoExpandTest extends MultiBrowserTest { - - @Test - public void testSecondColumnHasExpanded() { - openTestURL(); - - GridCellElement headerCell = $(GridElement.class).first() - .getHeaderCell(0, 1); - - assertTrue("Column did not expand as expected", - headerCell.getSize().getWidth() > 400); - } - -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClientTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClientTest.java deleted file mode 100644 index a0567bbf37..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClientTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.testbench.parallel.TestCategory; - -@TestCategory("grid") -public class GridColumnAutoWidthClientTest - extends AbstractGridColumnAutoWidthTest { - @Override - protected Class getUIClass() { - return GridColumnAutoWidthClient.class; - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthServerTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthServerTest.java deleted file mode 100644 index 0a0f823c42..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthServerTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import com.vaadin.testbench.parallel.TestCategory; - -@TestCategory("grid") -public class GridColumnAutoWidthServerTest - extends AbstractGridColumnAutoWidthTest { - @Override - protected Class getUIClass() { - return GridColumnAutoWidth.class; - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculationTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculationTest.java deleted file mode 100644 index 6bad840705..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculationTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.Dimension; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; - -@TestCategory("grid") -public class GridColumnWidthRecalculationTest extends SingleBrowserTest { - - private GridElement grid; - - @Before - public void open() { - openTestURL(); - grid = $(GridElement.class).first(); - } - - @Test - public void columnWidthAfterSwap() { - int column0Width = getColumnWidth(0); - int column1Width = getColumnWidth(1); - Assert.assertTrue("Column 0 should be narrower than column 1 initially", - column0Width < column1Width); - - $(ButtonElement.class).caption("Swap content").first().click(); - - Assert.assertEquals( - "Column 0 width should not change when swapping contents only", - column0Width, getColumnWidth(0)); - Assert.assertEquals( - "Column 1 width should not change when swapping contents only", - column1Width, getColumnWidth(1)); - } - - @Test - public void columnWidthAfterSwapAndRecalculate() { - int column0Width = getColumnWidth(0); - int column1Width = getColumnWidth(1); - Assert.assertTrue("Column 0 should be narrower than column 1 initially", - column0Width < column1Width); - - $(ButtonElement.class).caption("Swap content and recalculate columns") - .first().click(); - - column0Width = getColumnWidth(0); - column1Width = getColumnWidth(1); - - Assert.assertTrue( - "Column 1 should be narrower than column 0 after resize", - column1Width < column0Width); - } - - private int getColumnWidth(int columnIndex) { - GridCellElement headerColumn = grid.getHeaderCells(0).get(columnIndex); - Dimension column1Size = headerColumn.getSize(); - int columnWidth = column1Size.getWidth(); - return columnWidth; - } - -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutDataTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutDataTest.java deleted file mode 100644 index 81f0a83ea2..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutDataTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NativeSelectElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; - -@TestCategory("grid") -public class GridColumnWidthsWithoutDataTest extends SingleBrowserTest { - - @Test - public void testWidthsWhenAddingDataBack() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - int[] baseWidths = getColWidths(grid); - Assert.assertEquals("Sanity check", 2, baseWidths.length); - - Assert.assertTrue("Columns should not have equal width", - Math.abs(baseWidths[0] - baseWidths[1]) > 2); - - removeData(); - - assertSameWidths(baseWidths, getColWidths(grid)); - - addData(); - - assertSameWidths(baseWidths, getColWidths(grid)); - } - - @Test - public void testWidthsWhenInitiallyEmpty() { - setDebug(true); - openTestURL(); - $(ButtonElement.class).caption("Recreate without data").first().click(); - - GridElement grid = $(GridElement.class).first(); - - int[] baseWidths = getColWidths(grid); - Assert.assertEquals("Sanity check", 2, baseWidths.length); - - Assert.assertTrue("Columns should have roughly equal width", - Math.abs(baseWidths[0] - baseWidths[1]) < 10); - Assert.assertTrue("Columns should not have default widths", - baseWidths[0] > 140); - Assert.assertTrue("Columns should not have default widths", - baseWidths[1] > 140); - - addData(); - - assertSameWidths(baseWidths, getColWidths(grid)); - - Assert.assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - } - - @Test - public void testMultiSelectWidths() { - setDebug(true); - openTestURL(); - $(NativeSelectElement.class).caption("Selection mode").first() - .selectByText("Multi"); - - GridElement grid = $(GridElement.class).first(); - - int sum = sumUsedWidths(grid); - - // 295 instead of 300 to avoid rounding issues - Assert.assertTrue("Only " + sum + " out of 300px was used", sum > 295); - - $(ButtonElement.class).caption("Recreate without data").first().click(); - - grid = $(GridElement.class).first(); - sum = sumUsedWidths(grid); - - // 295 instead of 300 to avoid rounding issues - Assert.assertTrue("Only " + sum + " out of 300px was used", sum > 295); - } - - private int sumUsedWidths(GridElement grid) { - int sum = 0; - for (int i : getColWidths(grid)) { - sum += i; - } - return sum; - } - - private static void assertSameWidths(int[] expected, int[] actual) { - Assert.assertEquals("Arrays have differing lengths", expected.length, - actual.length); - - for (int i = 0; i < expected.length; i++) { - if (Math.abs(expected[i] - actual[i]) > 1) { - Assert.fail("Differing sizes at index " + i + ". Expected " - + expected[i] + " but got " + actual[i]); - } - } - } - - private void removeData() { - $(ButtonElement.class).caption("Remove data").first().click(); - } - - private void addData() { - $(ButtonElement.class).caption("Add data").first().click(); - } - - private int[] getColWidths(GridElement grid) { - List headerCells = grid.getHeaderCells(0); - int[] widths = new int[headerCells.size()]; - for (int i = 0; i < widths.length; i++) { - widths[i] = headerCells.get(i).getSize().getWidth(); - } - return widths; - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDataSourceResetTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDataSourceResetTest.java deleted file mode 100644 index 3405d81827..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDataSourceResetTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.SingleBrowserTest; - -public class GridDataSourceResetTest extends SingleBrowserTest { - - @Test - public void testRemoveWithSelectUpdatesRowsCorrectly() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - assertTrue("First row was not selected", grid.getRow(0).isSelected()); - for (int i = 1; i < 10; ++i) { - assertFalse("Only first row should be selected", - grid.getRow(i).isSelected()); - } - - $(ButtonElement.class).first().click(); - - assertTrue("First row was not selected after remove", - grid.getRow(0).isSelected()); - for (int i = 1; i < 9; ++i) { - assertFalse("Only first row should be selected after remove", - grid.getRow(i).isSelected()); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsDetachTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsDetachTest.java deleted file mode 100644 index fe700a13a6..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsDetachTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridDetailsDetachTest extends MultiBrowserTest { - - @Test - public void testDetachGridWithDetailsOpen() { - setDebug(true); - openTestURL(); - - $(GridElement.class).first().getCell(3, 0).click(); - $(GridElement.class).first().getCell(5, 0).click(); - - assertNoErrorNotifications(); - - $(ButtonElement.class).first().click(); - - assertNoErrorNotifications(); - } - - @Test - public void testDetachAndReattachGridWithDetailsOpen() { - setDebug(true); - openTestURL(); - - $(GridElement.class).first().getCell(3, 0).click(); - $(GridElement.class).first().getCell(5, 0).click(); - - assertNoErrorNotifications(); - - $(ButtonElement.class).first().click(); - - assertNoErrorNotifications(); - - $(ButtonElement.class).get(1).click(); - - assertNoErrorNotifications(); - - List spacers = findElements(By.className("v-grid-spacer")); - Assert.assertEquals("Not enough spacers in DOM", 2, spacers.size()); - Assert.assertEquals("Spacer content not visible", - "Extra data for Bean 3", spacers.get(0).getText()); - Assert.assertEquals("Spacer content not visible", - "Extra data for Bean 5", spacers.get(1).getText()); - } - - @Test - public void testDetachAndImmediateReattach() { - setDebug(true); - openTestURL(); - - $(GridElement.class).first().getCell(3, 0).click(); - $(GridElement.class).first().getCell(5, 0).click(); - - assertNoErrorNotifications(); - - // Detach and Re-attach Grid - $(ButtonElement.class).get(1).click(); - - assertNoErrorNotifications(); - - List spacers = findElements(By.className("v-grid-spacer")); - Assert.assertEquals("Not enough spacers in DOM", 2, spacers.size()); - Assert.assertEquals("Spacer content not visible", - "Extra data for Bean 3", spacers.get(0).getText()); - Assert.assertEquals("Spacer content not visible", - "Extra data for Bean 5", spacers.get(1).getText()); - } - -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpandTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpandTest.java deleted file mode 100644 index 67daf06c3c..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpandTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.number.IsCloseTo.closeTo; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.parallel.Browser; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -/** - * Tests the layouting of Grid's details row when it contains a HorizontalLayout - * with expand ratios. - * - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridDetailsLayoutExpandTest extends MultiBrowserTest { - - @Override - public List getBrowsersToTest() { - List browsersToTest = super.getBrowsersToTest(); - // for some reason PhantomJS doesn't find the label even if it detects - // the presence - browsersToTest.remove(Browser.PHANTOMJS.getDesiredCapabilities()); - return browsersToTest; - } - - @Test - public void testLabelWidths() { - openTestURL(); - waitForElementPresent(By.className("v-grid")); - - GridElement grid = $(GridElement.class).first(); - int gridWidth = grid.getSize().width; - - grid.getRow(2).click(); - waitForElementPresent(By.id("lbl2")); - - // space left over from first label should be divided equally - double expectedWidth = (double) (gridWidth - 200) / 2; - assertLabelWidth("lbl2", expectedWidth); - assertLabelWidth("lbl3", expectedWidth); - } - - private void assertLabelWidth(String id, double expectedWidth) { - // 1px leeway for calculations - assertThat("Unexpected label width.", - (double) $(LabelElement.class).id(id).getSize().width, - closeTo(expectedWidth, 1d)); - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsWidthTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsWidthTest.java deleted file mode 100644 index 055f4470fd..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsWidthTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2000-2016 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.v7.tests.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; - -@TestCategory("grid") -public class GridDetailsWidthTest extends SingleBrowserTest { - - @Test - public void testSpacerTDsHaveNoWidth() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Open all details rows - grid.getCell(0, 0).click(); - checkSpacersHaveNoWidths(1); - - grid.getCell(1, 0).click(); - checkSpacersHaveNoWidths(2); - - grid.getCell(2, 0).click(); - checkSpacersHaveNoWidths(3); - - // Close all details rows - grid.getCell(2, 0).click(); - checkSpacersHaveNoWidths(2); - - grid.getCell(1, 0).click(); - checkSpacersHaveNoWidths(1); - - grid.getCell(0, 0).click(); - checkSpacersHaveNoWidths(0); - } - - private void checkSpacersHaveNoWidths(int expectedCount) { - List spacers = findElements(By.className("v-grid-spacer")); - Assert.assertEquals("Wrong amount of spacers visible.", expectedCount, - spacers.size()); - for (WebElement spacer : spacers) { - Assert.assertFalse("Spacer element had an unexpected width set.", - spacer.findElement(By.tagName("td")).getAttribute("style") - .contains("width")); - } - } - - @Test - public void testDetailsOnSort() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Open a details rows - grid.getCell(0, 0).click(); - - GridCellElement cell = grid.getHeaderCell(0, 0); - cell.click(); - cell.click(); - - cell = grid.getCell(2, 0); - WebElement spacer = findElement(By.className("v-grid-spacer")); - Assert.assertEquals("Grid was not sorted correctly", "Hello 0", - cell.getText()); - Assert.assertEquals("Details row was not in correct location", - cell.getLocation().getY() + cell.getSize().getHeight(), - spacer.getLocation().getY()); - - } - -} -- cgit v1.2.3