From 42064ade8f01440432792b27ecd16a98f29fb74d Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 6 Mar 2017 13:20:35 +0200 Subject: Fix exception when no columns are shown (#8733) * Fix exception when no columns are shown or all columns are frozen Fixes #8329 --- .../grid/GridInitiallyHiddenColumns.java | 8 +++- .../components/grid/InitialFrozenColumns.java | 48 +++++++++++++++++++ .../components/grid/InitialFrozenColumns.java | 41 ---------------- .../grid/GridInitiallyHiddenColumnsTest.java | 20 ++++++++ .../components/grid/InitialFrozenColumnsTest.java | 56 ++++++++++++++++++++++ .../components/grid/InitialFrozenColumnsTest.java | 42 ---------------- 6 files changed, 130 insertions(+), 85 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java (limited to 'uitest') diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java index 1c0a662abb..d040aa54f3 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java @@ -26,6 +26,7 @@ import com.vaadin.tests.data.bean.Person; import com.vaadin.tests.util.PortableRandom; import com.vaadin.tests.util.TestDataGenerator; import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; import com.vaadin.ui.renderers.NumberRenderer; public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { @@ -36,8 +37,11 @@ public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { grid.addColumn(Person::getFirstName).setHidden(true).setHidable(true) .setCaption("First Name"); - grid.addColumn(Person::getLastName).setHidable(true) - .setCaption("Last Name"); + Column col2 = grid.addColumn(Person::getLastName) + .setHidable(true).setCaption("Last Name"); + if (request.getParameter("allHidden") != null) { + col2.setHidden(true); + } grid.addColumn(Person::getAge, new NumberRenderer()).setHidden(true) .setHidable(true).setCaption("Age"); diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java b/uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java new file mode 100644 index 0000000000..ec49d24dc1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/InitialFrozenColumns.java @@ -0,0 +1,48 @@ +/* + * 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.tests.data.bean.Person; +import com.vaadin.tests.data.bean.Sex; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; + +public class InitialFrozenColumns extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(Person.class); + grid.setSelectionMode(SelectionMode.NONE); + grid.setColumns(); + grid.addColumn("firstName").setWidth(200); + grid.addColumn("lastName").setWidth(200); + grid.addColumn("email").setWidth(200); + + grid.setItems( + new Person("First", "last", "email", 242, Sex.UNKNOWN, null)); + + int frozen = 2; + if (request.getParameter("frozen") != null) { + frozen = Integer.parseInt(request.getParameter("frozen")); + } + grid.setFrozenColumnCount(frozen); + + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java deleted file mode 100644 index 07a41337f2..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java +++ /dev/null @@ -1,41 +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.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class InitialFrozenColumns extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.NONE); - - grid.addColumn("foo").setWidth(200); - grid.addColumn("bar").setWidth(200); - grid.addColumn("baz").setWidth(200); - - grid.addRow("a", "b", "c"); - - grid.setFrozenColumnCount(2); - - addComponent(grid); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java index 017ef14e2b..1a909e7a32 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java @@ -50,6 +50,26 @@ public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest { } + @Test + public void ensureCorrectlyRenderedAllInitiallyHidden() { + openTestURL("debug&allHidden"); + GridElement grid = $(GridElement.class).first(); + + getSidebarOpenButton(grid).click(); + getColumnHidingToggle(grid, "First Name").click(); + getColumnHidingToggle(grid, "Last Name").click(); + getColumnHidingToggle(grid, "Age").click(); + getSidebarOpenButton(grid).click(); + + Assert.assertEquals("Umberto", grid.getCell(0, 0).getText()); + Assert.assertEquals("Rowling", grid.getCell(0, 1).getText()); + Assert.assertEquals("40", grid.getCell(0, 2).getText()); + Assert.assertEquals("Alex", grid.getCell(1, 0).getText()); + Assert.assertEquals("Barks", grid.getCell(1, 1).getText()); + Assert.assertEquals("25", grid.getCell(1, 2).getText()); + + } + // TODO: as to the getX methods reuse ones from GridBasicFeaturesTest? protected WebElement getSidebarOpenButton(GridElement grid) { diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java new file mode 100644 index 0000000000..58abe75731 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/InitialFrozenColumnsTest.java @@ -0,0 +1,56 @@ +/* + * 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.logging.Level; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class InitialFrozenColumnsTest extends MultiBrowserTest { + @Test + public void testInitialFrozenColumns() { + setDebug(true); + openTestURL(); + + Assert.assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + + WebElement cell = $(GridElement.class).first().getCell(0, 0); + assertTrue(cell.getAttribute("class").contains("frozen")); + } + + @Test + public void testInitialAllColumnsFrozen() { + setDebug(true); + openTestURL("frozen=3"); + + Assert.assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + assertNoDebugMessage(Level.SEVERE); + WebElement cell = $(GridElement.class).first().getCell(0, 2); + assertTrue(cell.getAttribute("class").contains("frozen")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java deleted file mode 100644 index fec0087168..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java +++ /dev/null @@ -1,42 +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.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class InitialFrozenColumnsTest extends MultiBrowserTest { - @Test - public void testInitialFrozenColumns() { - setDebug(true); - openTestURL(); - - Assert.assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - - WebElement cell = $(GridElement.class).first().getCell(0, 0); - assertTrue(cell.getAttribute("class").contains("frozen")); - } -} -- cgit v1.2.3