From: Leif Åstrand Date: Thu, 1 Sep 2016 08:40:05 +0000 (+0300) Subject: Move uitests for the legacy Grid to a separate v7 package X-Git-Tag: 8.0.0.alpha1~30 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2f83685c804355b315dfe0f2dad4cecf9ffeb53c;p=vaadin-framework.git Move uitests for the legacy Grid to a separate v7 package Change-Id: Iba9614f9809714b2d3ac564e737f03e8f89c6f82 --- diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/BeanRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/BeanRenderer.java deleted file mode 100644 index 0c26449208..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/BeanRenderer.java +++ /dev/null @@ -1,25 +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.components.grid; - -import com.vaadin.tests.widgetset.client.SimpleTestBean; -import com.vaadin.v7.ui.Grid.AbstractRenderer; - -public class BeanRenderer extends AbstractRenderer { - public BeanRenderer() { - super(SimpleTestBean.class, ""); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/CustomRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/CustomRenderer.java deleted file mode 100644 index ca8a895f92..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/CustomRenderer.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.tests.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.SimpleTestBean; -import com.vaadin.ui.Label; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -@Widgetset(TestingWidgetSet.NAME) -public class CustomRenderer extends AbstractTestUI { - - private static final Object INT_ARRAY_PROPERTY = "int array"; - private static final Object VOID_PROPERTY = "void"; - private static final Object BEAN_PROPERTY = "pojo"; - - static final Object ITEM_ID = "itemId1"; - static final String DEBUG_LABEL_ID = "debuglabel"; - static final String INIT_DEBUG_LABEL_CAPTION = "Debug label placeholder"; - - @Override - protected void setup(VaadinRequest request) { - IndexedContainer container = new IndexedContainer(); - container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class, - new int[] {}); - container.addContainerProperty(VOID_PROPERTY, Void.class, null); - container.addContainerProperty(BEAN_PROPERTY, SimpleTestBean.class, - null); - - Item item = container.addItem(ITEM_ID); - - @SuppressWarnings("unchecked") - Property propertyIntArray = item - .getItemProperty(INT_ARRAY_PROPERTY); - propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 }); - - @SuppressWarnings("unchecked") - Property propertyPojo = item - .getItemProperty(BEAN_PROPERTY); - SimpleTestBean bean = new SimpleTestBean(); - bean.setValue(42); - propertyPojo.setValue(bean); - - Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION); - debugLabel.setId(DEBUG_LABEL_ID); - - Grid grid = new Grid(container); - - grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer()); - grid.getColumn(VOID_PROPERTY) - .setRenderer(new RowAwareRenderer(debugLabel)); - grid.getColumn(BEAN_PROPERTY).setRenderer(new BeanRenderer()); - - grid.setSelectionMode(SelectionMode.NONE); - - addComponent(grid); - addComponent(debugLabel); - } - - @Override - protected String getTestDescription() { - return "Verifies that renderers operating on other data than " - + "just Strings also work "; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(13334); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInit.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInit.java deleted file mode 100644 index d94969e51e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInit.java +++ /dev/null @@ -1,62 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.data.Container.Indexed; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -public class GridAddAndRemoveDataOnInit extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid gridAdd = new Grid(); - gridAdd.setHeight("240px"); - gridAdd.setWidth("140px"); - addComponent(gridAdd); - Indexed dataSource = gridAdd.getContainerDataSource(); - dataSource.addContainerProperty("foo", Integer.class, 0); - for (int i = 0; i < 10; ++i) { - Object id = dataSource.addItem(); - dataSource.getItem(id).getItemProperty("foo").setValue(i); - } - dataSource = new IndexedContainer(); - dataSource.addContainerProperty("bar", Integer.class, 0); - for (int i = 0; i < 10; ++i) { - Object id = dataSource.addItem(); - dataSource.getItem(id).getItemProperty("bar").setValue(i); - } - Grid gridRemove = new Grid(dataSource); - gridRemove.setHeight("150px"); - gridRemove.setWidth("140px"); - addComponent(gridRemove); - for (int i = 0; i < 5; ++i) { - dataSource.removeItem(dataSource.getIdByIndex(i)); - } - } - - @Override - protected String getTestDescription() { - return "Foo"; - } - - @Override - protected Integer getTicketNumber() { - return 13334; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddRow.java deleted file mode 100644 index f1fbedfce6..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridAddRow.java +++ /dev/null @@ -1,49 +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.components.grid; - -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.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridAddRow extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.MULTI); - grid.addColumn("firstName"); - grid.addColumn("age", Integer.class); - - grid.addRow("Lorem", Integer.valueOf(1)); - grid.addRow("Ipsum", Integer.valueOf(2)); - - addComponent(grid); - - addComponent(new Button("Add new row", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.addRow("Dolor", Integer.valueOf(3)); - } - })); - - } - -} 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 deleted file mode 100644 index 9dcabebbf7..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java +++ /dev/null @@ -1,34 +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.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -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 AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - addComponent( - new TestWidgetComponent(GridCellFocusOnResetSizeWidget.class)); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridCheckBoxDisplay.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridCheckBoxDisplay.java deleted file mode 100644 index 650ecb2e78..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridCheckBoxDisplay.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.tests.components.grid; - -import java.io.Serializable; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; - -public class GridCheckBoxDisplay extends AbstractTestUI { - - private static final long serialVersionUID = -5575892909354637168L; - private BeanItemContainer todoContainer = new BeanItemContainer( - Todo.class); - - @Override - protected void setup(VaadinRequest request) { - todoContainer.addBean(new Todo("Done task", true)); - todoContainer.addBean(new Todo("Not done", false)); - - Grid grid = new Grid(todoContainer); - grid.setSizeFull(); - - grid.setColumnOrder("done", "task"); - grid.getColumn("done").setWidth(75); - grid.getColumn("task").setExpandRatio(1); - - grid.setSelectionMode(Grid.SelectionMode.SINGLE); - - grid.setEditorEnabled(true); - grid.setImmediate(true); - - getLayout().addComponent(grid); - getLayout().setExpandRatio(grid, 1); - - } - - @Override - protected Integer getTicketNumber() { - return 16976; - } - - @Override - public String getDescription() { - return "Verify that checkbox state is correct for all items in editor"; - } - - public class Todo implements Serializable { - private static final long serialVersionUID = -5961103142478316018L; - - private boolean done; - private String task = ""; - - public Todo(String task, boolean done) { - this.task = task; - this.done = done; - } - - public boolean isDone() { - return done; - } - - public void setDone(boolean done) { - this.done = done; - } - - public String getTask() { - return task; - } - - public void setTask(String task) { - this.task = task; - } - } - -} 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 deleted file mode 100644 index a9f686b107..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.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.tests.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -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 AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - addComponent( - new TestWidgetComponent(GridDataChangeHandlerWidget.class)); - } -} 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 deleted file mode 100644 index a09e994a4c..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -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.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 AbstractTestUI { - - @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/tests/components/grid/GridColumnAutoExpand.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoExpand.java deleted file mode 100644 index 62d578d2c4..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; - -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("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/tests/components/grid/GridColumnAutoWidth.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidth.java deleted file mode 100644 index cc05a76e8e..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -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 AbstractTestUI { - @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/tests/components/grid/GridColumnAutoWidthClient.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClient.java deleted file mode 100644 index 48960ee68f..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -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 AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - addComponent( - new TestWidgetComponent(GridColumnAutoWidthClientWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnExpand.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnExpand.java deleted file mode 100644 index 3512cdae59..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -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.ui.themes.Reindeer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; - -@Theme(Reindeer.THEME_NAME) -public class GridColumnExpand extends AbstractTestUI { - 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/tests/components/grid/GridColumnWidthRecalculation.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthRecalculation.java deleted file mode 100644 index 67790bd392..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthRecalculation.java +++ /dev/null @@ -1,95 +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.components.grid; - -import java.util.ArrayList; - -import com.vaadin.annotations.Theme; -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; - -@Theme("valo") -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/tests/components/grid/GridColumnWidthsWithoutData.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutData.java deleted file mode 100644 index f2b4adddde..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import java.util.EnumSet; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.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 AbstractTestUI { - - 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/tests/components/grid/GridCustomSelectionModel.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridCustomSelectionModel.java deleted file mode 100644 index aee8da4125..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridCustomSelectionModel.java +++ /dev/null @@ -1,37 +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.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.v7.ui.Grid.MultiSelectionModel; - -@Widgetset(TestingWidgetSet.NAME) -public class GridCustomSelectionModel extends AbstractTestUI { - - public static class MySelectionModel extends MultiSelectionModel { - } - - @Override - protected void setup(VaadinRequest request) { - PersonTestGrid grid = new PersonTestGrid(500); - grid.setSelectionModel(new MySelectionModel()); - addComponent(grid); - } - -} 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 deleted file mode 100644 index 4fa76c6d3d..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDataSourceReset.java +++ /dev/null @@ -1,66 +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.components.grid; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -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.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 AbstractTestUI { - - 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/tests/components/grid/GridDefaultSelectionMode.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDefaultSelectionMode.java deleted file mode 100644 index ef7c059440..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDefaultSelectionMode.java +++ /dev/null @@ -1,94 +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.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.ui.Button.ClickListener; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; - -public class GridDefaultSelectionMode extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Person person1 = new Person(); - person1.setFirstName("person"); - person1.setLastName("one"); - - Person person2 = new Person(); - person2.setFirstName("person"); - person2.setLastName("two"); - - ArrayList items = new ArrayList(); - items.add(person1); - items.add(person2); - - final BeanItemContainer container = new BeanItemContainer( - Person.class, items); - - final Grid grid = new Grid(); - grid.setContainerDataSource(container); - - VerticalLayout v = new VerticalLayout(); - - v.addComponent(new Button("Deselect on server", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.select(null); - } - })); - - v.addComponent(new Button("Select on server", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.select(person1); - } - })); - v.addComponent(grid); - - addComponent(v); - } - - public static class Person { - private String firstName; - private String lastName; - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - } - -} 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 deleted file mode 100644 index de66680d75..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.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 AbstractTestUI { - - 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/tests/components/grid/GridDetailsLayoutExpand.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpand.java deleted file mode 100644 index f0e5606995..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -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 AbstractTestUI { - - @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/tests/components/grid/GridDetailsLocation.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLocation.java deleted file mode 100644 index aac4deedc8..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsLocation.java +++ /dev/null @@ -1,115 +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.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.util.Person; -import com.vaadin.tests.util.PersonContainer; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.Component; -import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; -import com.vaadin.ui.TextField; -import com.vaadin.ui.UI; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.themes.ValoTheme; -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; - -@Theme(ValoTheme.THEME_NAME) -public class GridDetailsLocation extends UI { - - private final DetailsGenerator detailsGenerator = new DetailsGenerator() { - @Override - public Component getDetails(RowReference rowReference) { - Person person = (Person) rowReference.getItemId(); - Label label = new Label( - person.getFirstName() + " " + person.getLastName()); - // currently the decorator row doesn't change its height when the - // content height is different. - label.setHeight("30px"); - return label; - } - }; - - private TextField numberTextField; - private Grid grid; - - @Override - protected void init(VaadinRequest request) { - - Layout layout = new VerticalLayout(); - - grid = new Grid(PersonContainer.createWithTestData(1000)); - grid.setSelectionMode(SelectionMode.NONE); - layout.addComponent(grid); - - final CheckBox checkbox = new CheckBox("Details generator"); - checkbox.addValueChangeListener(event -> { - if (checkbox.getValue()) { - grid.setDetailsGenerator(detailsGenerator); - } else { - grid.setDetailsGenerator(DetailsGenerator.NULL); - } - }); - layout.addComponent(checkbox); - - numberTextField = new TextField("Row"); - numberTextField.setImmediate(true); - layout.addComponent(numberTextField); - - layout.addComponent( - new Button("Toggle and scroll", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - toggle(); - scrollTo(); - } - })); - layout.addComponent( - new Button("Scroll and toggle", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - scrollTo(); - toggle(); - } - })); - - setContent(layout); - } - - private void toggle() { - Object itemId = getItemId(); - boolean isVisible = grid.isDetailsVisible(itemId); - grid.setDetailsVisible(itemId, !isVisible); - } - - private void scrollTo() { - grid.scrollTo(getItemId()); - } - - private Object getItemId() { - int row = Integer.parseInt(numberTextField.getValue()); - Object itemId = grid.getContainerDataSource().getIdByIndex(row); - return itemId; - } - -} 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 deleted file mode 100644 index 50d5bc5419..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -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 AbstractTestUI { - - @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 - public String getDescription() { - 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/components/grid/GridDisabledMultiselect.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDisabledMultiselect.java deleted file mode 100644 index 7fcfcf3373..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDisabledMultiselect.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.vaadin.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.v7.ui.Grid; - -public class GridDisabledMultiselect extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.addColumn("foo", String.class); - grid.addRow("bar"); - grid.setSelectionMode(Grid.SelectionMode.SINGLE); - addComponent(grid); - - addButton("Multi", new Button.ClickListener() { - @Override - public void buttonClick(Button.ClickEvent event) { - grid.setSelectionMode(Grid.SelectionMode.MULTI); - } - }); - - addButton("Disable", new Button.ClickListener() { - @Override - public void buttonClick(Button.ClickEvent event) { - grid.setEnabled(!grid.isEnabled()); - } - }); - } -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java deleted file mode 100644 index eaa2c4fa1d..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragAndDrop.java +++ /dev/null @@ -1,62 +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.components.grid; - -import java.util.Arrays; -import java.util.List; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; - -@SuppressWarnings("serial") -public class GridDragAndDrop extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - - List columnIds = Arrays.asList("Hello", "this", "are", - "multiple", "columns", "plus", "these", "resemble", "a", - "group", "here", "no", "more"); - - Grid grid = new Grid(); - - for (String columnId : columnIds) { - grid.addColumn(columnId); - } - - for (int i = 0; i < 100; i++) { - grid.addRow(columnIds.toArray()); - } - - grid.setColumnReorderingAllowed(true); - - grid.setFrozenColumnCount(1); - grid.setSelectionMode(Grid.SelectionMode.MULTI); - - addComponent(grid); - } - - @Override - protected String getTestDescription() { - return "Start dragging a column header and move left and right.
The drop indicator should appear exactly on the lines between column headers."; - } - - @Override - protected Integer getTicketNumber() { - return 18925; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java deleted file mode 100644 index 82dfc6b24e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolled.java +++ /dev/null @@ -1,51 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Layout; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridDragSelectionWhileScrolled extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Layout layout = new VerticalLayout(); - - HorizontalLayout spacer = new HorizontalLayout(); - spacer.setHeight("1000px"); - layout.addComponent(spacer); - - PersonTestGrid grid = new PersonTestGrid(100); - grid.setSelectionMode(SelectionMode.MULTI); - layout.addComponent(grid); - - addComponent(layout); - } - - @Override - protected Integer getTicketNumber() { - return 17895; - } - - @Override - protected String getTestDescription() { - return "Drag selecting rows in Grid malfunctions if page is scrolled"; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java deleted file mode 100644 index a689fa9e1a..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java +++ /dev/null @@ -1,53 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.ComboBox; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridEditingWithNoScrollBars extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.addColumn("foo", String.class); - grid.addColumn("bar", String.class); - for (int i = 0; i < 10; ++i) { - grid.addRow("foo", "" + (i % 3 + 1)); - } - - ComboBox stCombo = new ComboBox(); - stCombo.addItem("" + 1); - stCombo.addItem("" + 2); - stCombo.addItem("" + 3); - stCombo.setNullSelectionAllowed(false); - stCombo.setSizeFull(); - - Column stCol = grid.getColumn("bar"); - stCol.setEditorField(stCombo); - - grid.setSelectionMode(SelectionMode.SINGLE); - grid.setEditorEnabled(true); - grid.setSizeFull(); - - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorConverterNotFound.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorConverterNotFound.java deleted file mode 100644 index 1432af13e4..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorConverterNotFound.java +++ /dev/null @@ -1,56 +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.components.grid; - -import com.vaadin.server.ErrorHandler; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.v7.ui.Grid; - -public class GridEditorConverterNotFound extends AbstractTestUIWithLog { - - class Foo { - } - - @Override - protected void setup(VaadinRequest request) { - - Grid grid = new Grid(); - - grid.addColumn("foo", Foo.class); - grid.addRow(new Foo()); - grid.setEditorEnabled(true); - grid.setErrorHandler(new ErrorHandler() { - - @Override - public void error(com.vaadin.server.ErrorEvent event) { - log(event.getThrowable().toString()); - } - }); - - addComponent(grid); - } - - @Override - protected Integer getTicketNumber() { - return 17935; - } - - @Override - protected String getTestDescription() { - return "Grid should gracefully handle bind failures when opening editor"; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.java deleted file mode 100644 index e10e76e78b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.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.tests.components.grid; - -import java.util.HashSet; -import java.util.Set; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.fieldgroup.ComplexPerson; -import com.vaadin.ui.Button; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.ui.ComboBox; -import com.vaadin.v7.ui.CustomField; -import com.vaadin.v7.ui.Grid; - -@Theme("valo") -public class GridEditorCustomField extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new PersonTestGrid(100); - grid.setWidth("800px"); - grid.setColumns("firstName", "lastName", "address.city"); - grid.setEditorEnabled(true); - Set cities = new HashSet<>(); - for (Object o : grid.getContainerDataSource().getItemIds()) { - ComplexPerson p = (ComplexPerson) o; - cities.add(p.getAddress().getCity()); - } - CustomCitySelect cityEditor = new CustomCitySelect( - cities.toArray(new String[cities.size()])); - grid.getColumn("address.city").setEditorField(cityEditor); - addComponent(grid); - } - - public static class CustomCitySelect extends CustomField { - private HorizontalLayout fieldLayout; - private String[] values; - private ComboBox cityComboBox; - - public CustomCitySelect(String... values) { - this.values = values; - } - - @Override - protected Component initContent() { - fieldLayout = new HorizontalLayout(); - fieldLayout.setWidth("100%"); - - cityComboBox = new ComboBox(); - for (String value : values) { - cityComboBox.addItem(value); - } - fieldLayout.addComponent(cityComboBox); - fieldLayout.setExpandRatio(cityComboBox, 1.0f); - - Button addCountryButton = new Button("New"); - fieldLayout.addComponent(addCountryButton); - - return fieldLayout; - } - - @Override - public Class getType() { - return String.class; - } - - @Override - protected void setInternalValue(String newValue) { - super.setInternalValue(newValue); - if (cityComboBox == null) { - return; - } - cityComboBox.setValue(newValue); - } - - @Override - public String getInternalValue() { - if (cityComboBox == null) { - return null; - } - return (String) cityComboBox.getValue(); - } - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUI.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUI.java deleted file mode 100644 index d502e6ab1f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUI.java +++ /dev/null @@ -1,43 +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.components.grid; - -import com.vaadin.tests.util.PersonContainer; -import com.vaadin.v7.ui.Grid; - -public class GridEditorFrozenColumnsUI extends GridEditorUI { - - @Override - protected Grid createGrid(PersonContainer container) { - Grid grid = super.createGrid(container); - - grid.setFrozenColumnCount(2); - - grid.setWidth("600px"); - - return grid; - } - - @Override - protected Integer getTicketNumber() { - return 16727; - } - - @Override - protected String getTestDescription() { - return "Frozen columns should also freeze cells in editor."; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorMultiselect.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorMultiselect.java deleted file mode 100644 index 7374596c0b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorMultiselect.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.vaadin.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; - -public class GridEditorMultiselect extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - - grid.addColumn("name"); - grid.addColumn("age", Integer.class); - - for (int i = 0; i < 30; i++) { - grid.addRow("name " + i, i); - } - - grid.setEditorEnabled(true); - grid.setSelectionMode(Grid.SelectionMode.MULTI); - - addComponent(grid); - } - - @Override - protected Integer getTicketNumber() { - return 17132; - } - - @Override - public String getDescription() { - return "Grid Multiselect: Edit mode allows invalid selection"; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorUI.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorUI.java deleted file mode 100644 index 6abcf8cfc4..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorUI.java +++ /dev/null @@ -1,53 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.PersonContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.PasswordField; -import com.vaadin.v7.ui.TextField; - -public class GridEditorUI extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - PersonContainer container = PersonContainer.createWithTestData(); - - addComponent(createGrid(container)); - } - - protected Grid createGrid(PersonContainer container) { - Grid grid = new Grid(container); - - // Don't use address since there's no converter - grid.removeColumn("address"); - - grid.setEditorEnabled(true); - - grid.getColumn("firstName").setEditorField(new PasswordField()); - - TextField lastNameField = (TextField) grid.getColumn("lastName") - .getEditorField(); - lastNameField.setMaxLength(50); - - grid.getColumn("phoneNumber").getEditorField().setReadOnly(true); - - return grid; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridExtensionCommunication.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridExtensionCommunication.java deleted file mode 100644 index a8c7009562..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridExtensionCommunication.java +++ /dev/null @@ -1,69 +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.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.MouseEventDetails; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridClickExtensionConnector.GridClickServerRpc; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.AbstractGridExtension; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; - -@Widgetset(TestingWidgetSet.NAME) -public class GridExtensionCommunication extends AbstractTestUIWithLog { - - public class GridClickExtension extends AbstractGridExtension { - - public GridClickExtension(Grid grid) { - super(grid); - registerRpc(new GridClickServerRpc() { - - @Override - public void click(String row, String column, - MouseEventDetails click) { - Object itemId = getItemId(row); - Column col = getColumn(column); - - Item person = getParentGrid().getContainerDataSource() - .getItem(itemId); - - log("Click on Person " - + person.getItemProperty("firstName").getValue() - + " " - + person.getItemProperty("lastName").getValue() - + " on column " + col.toString()); - log("MouseEventDetails: " + click.getButtonName() + " (" - + click.getClientX() + ", " + click.getClientY() - + ")"); - } - }); - } - } - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new PersonTestGrid(50); - grid.setSelectionMode(SelectionMode.NONE); - new GridClickExtension(grid); - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridFastAsyncUpdate.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridFastAsyncUpdate.java deleted file mode 100644 index a5a41ff690..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridFastAsyncUpdate.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.vaadin.tests.components.grid; - -import java.util.Calendar; -import java.util.Random; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.logging.Level; - -import com.vaadin.annotations.Push; -import com.vaadin.annotations.Theme; -import com.vaadin.event.SelectionEvent; -import com.vaadin.event.SelectionEvent.SelectionListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.VerticalLayout; -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.SelectionMode; - -@Push -@Theme("valo") -@SuppressWarnings("serial") -public class GridFastAsyncUpdate extends AbstractTestUI { - - private final Runnable addRowsTask = new Runnable() { - @Override - public void run() { - System.out.println("Logging..."); - try { - Random random = new Random(); - while (!Thread.currentThread().isInterrupted()) { - Thread.sleep(random.nextInt(100)); - - GridFastAsyncUpdate.this.access(new Runnable() { - @SuppressWarnings("unchecked") - @Override - public void run() { - - ++counter; - Item item = container.addItem(counter); - item.getItemProperty("sequenceNumber") - .setValue(String.valueOf(counter)); - item.getItemProperty("millis") - .setValue(String.valueOf(Calendar - .getInstance().getTimeInMillis() - - loggingStart)); - item.getItemProperty("level") - .setValue(Level.INFO.toString()); - item.getItemProperty("message").setValue("Message"); - if (grid != null && !scrollLock) { - grid.scrollToEnd(); - } - } - }); - } - } catch (InterruptedException e) { - System.out.println("logging thread interrupted"); - } - } - }; - - private int counter; - - private Grid grid; - private IndexedContainer container; - private long loggingStart; - private volatile boolean scrollLock = false; - - @Override - protected void setup(VaadinRequest vaadinRequest) { - final VerticalLayout layout = new VerticalLayout(); - layout.setSizeFull(); - layout.setMargin(true); - addComponent(layout); - - HorizontalLayout buttons = new HorizontalLayout(); - layout.addComponent(buttons); - - final ExecutorService logExecutor = Executors.newSingleThreadExecutor(); - - final Button logButton = new Button("Start logging"); - logButton.addClickListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - if ("Start logging".equals(logButton.getCaption())) { - loggingStart = Calendar.getInstance().getTimeInMillis(); - logExecutor.submit(addRowsTask); - logButton.setCaption("Stop logging"); - } else { - System.out.println("Stop logging..."); - try { - logExecutor.shutdownNow(); - } catch (Exception e) { - e.printStackTrace(); - } - logButton.setCaption("Start logging"); - } - } - }); - buttons.addComponent(logButton); - - final Button scrollButton = new Button("Stop scrolling"); - scrollButton.addClickListener(new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - if (!scrollLock) { - System.out.println("Stop scrolling"); - scrollButton.setCaption("Start scrolling"); - scrollLock = true; - } else { - System.out.println("Start scrolling"); - scrollButton.setCaption("Stop scrolling"); - scrollLock = false; - } - } - }); - buttons.addComponent(scrollButton); - - container = new IndexedContainer(); - container.addContainerProperty("sequenceNumber", String.class, null); - container.addContainerProperty("millis", String.class, null); - container.addContainerProperty("level", String.class, null); - container.addContainerProperty("message", String.class, null); - - grid = new Grid(container); - grid.setWidth("100%"); - grid.setImmediate(true); - grid.setSelectionMode(SelectionMode.SINGLE); - grid.addSelectionListener(new SelectionListener() { - @Override - public void select(final SelectionEvent event) { - if (grid.getSelectedRow() != null) { - disableScroll(); - } - } - }); - - layout.addComponent(grid); - layout.setExpandRatio(grid, 1.0f); - } - - protected void disableScroll() { - scrollLock = true; - } -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridGeneratedProperties.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridGeneratedProperties.java deleted file mode 100644 index 4c0aa04a93..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridGeneratedProperties.java +++ /dev/null @@ -1,165 +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.components.grid; - -import com.vaadin.data.sort.Sort; -import com.vaadin.data.sort.SortOrder; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.data.Container.Filter; -import com.vaadin.v7.data.Container.Filterable; -import com.vaadin.v7.data.Container.Indexed; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.GeneratedPropertyContainer; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.data.util.PropertyValueGenerator; -import com.vaadin.v7.data.util.filter.Compare; -import com.vaadin.v7.data.util.filter.UnsupportedFilterException; -import com.vaadin.v7.ui.Grid; - -public class GridGeneratedProperties extends AbstractTestUI { - - private GeneratedPropertyContainer container; - static double MILES_CONVERSION = 0.6214d; - private Filter filter = new Compare.Greater("miles", 1d); - - @Override - protected void setup(VaadinRequest request) { - container = new GeneratedPropertyContainer(createContainer()); - Grid grid = new Grid(container); - addComponent(grid); - - container.addGeneratedProperty("miles", - new PropertyValueGenerator() { - - @Override - public Double getValue(Item item, Object itemId, - Object propertyId) { - return (Double) item.getItemProperty("km").getValue() - * MILES_CONVERSION; - } - - @Override - public Class getType() { - return Double.class; - } - - @Override - public Filter modifyFilter(Filter filter) - throws UnsupportedFilterException { - if (filter instanceof Compare.Greater) { - Double value = (Double) ((Compare.Greater) filter) - .getValue(); - value = value / MILES_CONVERSION; - return new Compare.Greater("km", value); - } - return super.modifyFilter(filter); - } - }); - - final Button filterButton = new Button("Add filter"); - filterButton.addClickListener(new ClickListener() { - - boolean active = false; - - @Override - public void buttonClick(ClickEvent event) { - if (active) { - ((Filterable) container).removeContainerFilter(filter); - filterButton.setCaption("Add filter"); - active = false; - return; - } - ((Filterable) container).addContainerFilter(filter); - filterButton.setCaption("Remove filter"); - active = true; - } - }); - - container.addGeneratedProperty("foo", - new PropertyValueGenerator() { - - @Override - public String getValue(Item item, Object itemId, - Object propertyId) { - return item.getItemProperty("foo").getValue() + " " - + item.getItemProperty("bar").getValue(); - } - - @Override - public Class getType() { - return String.class; - } - }); - container.removeContainerProperty("bar"); - container.addGeneratedProperty("baz", - new PropertyValueGenerator() { - - @Override - public Integer getValue(Item item, Object itemId, - Object propertyId) { - return (Integer) item.getItemProperty("bar").getValue(); - } - - @Override - public Class getType() { - return Integer.class; - } - - @Override - public SortOrder[] getSortProperties(SortOrder order) { - return Sort.by("bar", order.getDirection()).build() - .toArray(new SortOrder[1]); - } - }); - - addComponent(filterButton); - grid.sort(Sort.by("km").then("bar", SortDirection.DESCENDING)); - } - - private Indexed createContainer() { - Indexed container = new IndexedContainer(); - container.addContainerProperty("foo", String.class, "foo"); - container.addContainerProperty("bar", Integer.class, 0); - // km contains double values from 0.0 to 2.0 - container.addContainerProperty("km", Double.class, 0); - - for (int i = 0; i <= 100; ++i) { - Object itemId = container.addItem(); - Item item = container.getItem(itemId); - item.getItemProperty("foo").setValue("foo"); - item.getItemProperty("bar").setValue(i); - item.getItemProperty("km").setValue(i / 5.0d); - } - - return container; - } - - @Override - protected String getTestDescription() { - return "A Grid with GeneratedPropertyContainer"; - } - - @Override - protected Integer getTicketNumber() { - return 13334; - } - -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java deleted file mode 100644 index 3c9ff31ab8..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java +++ /dev/null @@ -1,135 +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.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.ui.TextField; -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; - -@Theme("valo") -public class GridHeaderFooterComponents extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.setWidth("800px"); - grid.setContainerDataSource(createContainer()); - grid.setFooterVisible(true); - final HeaderRow defaultRow = grid.getDefaultHeaderRow(); - final HeaderRow toggleVisibilityRow = grid.appendHeaderRow(); - final Grid.HeaderRow filterRow = grid.appendHeaderRow(); - - final FooterRow footerRow = grid.addFooterRowAt(0); - final FooterRow toggleVisibilityFooterRow = grid.addFooterRowAt(0); - final FooterRow filterFooterRow = grid.addFooterRowAt(0); - - // Set up a filter for all columns - for (final Object pid : grid.getContainerDataSource() - .getContainerPropertyIds()) { - final Grid.HeaderCell headerCell = filterRow.getCell(pid); - final Grid.FooterCell footerCell = filterFooterRow.getCell(pid); - - headerCell.setComponent(createTextField(pid)); - footerCell.setComponent(createTextField(pid)); - - toggleVisibilityRow.getCell(pid).setComponent( - new Button("Toggle field", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - Component c = headerCell.getComponent(); - c.setVisible(!c.isVisible()); - } - })); - toggleVisibilityFooterRow.getCell(pid).setComponent( - new Button("Toggle field", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - Component c = footerCell.getComponent(); - c.setVisible(!c.isVisible()); - } - })); - } - addComponent(grid); - - addRemoveHeaderRow(grid, defaultRow); - addRemoveHeaderRow(grid, filterRow); - addRemoveHeaderRow(grid, toggleVisibilityRow); - - addRemoveFooterRow(grid, footerRow); - addRemoveFooterRow(grid, filterFooterRow); - addRemoveFooterRow(grid, toggleVisibilityFooterRow); - - // Hide first field initially - filterRow.getCell("string").getComponent().setVisible(false); - filterFooterRow.getCell("string").getComponent().setVisible(false); - } - - private void addRemoveHeaderRow(final Grid grid, final HeaderRow row) { - row.getCell("action") - .setComponent(new Button("Remove row", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.removeHeaderRow(row); - } - })); - - } - - private void addRemoveFooterRow(final Grid grid, final FooterRow row) { - row.getCell("action") - .setComponent(new Button("Remove row", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.removeFooterRow(row); - } - })); - - } - - private IndexedContainer createContainer() { - IndexedContainer ic = new IndexedContainer(); - ic.addContainerProperty("action", String.class, ""); - ic.addContainerProperty("string", String.class, "Hello world"); - ic.addContainerProperty("int", int.class, 13); - ic.addContainerProperty("double", double.class, 5.2f); - - for (int i = 0; i < 5; i++) { - ic.addItem(); - } - return ic; - } - - private TextField createTextField(final Object pid) { - TextField filterField = new TextField(); - filterField.setColumns(8); - filterField.setValue("Filter: " + pid); - filterField.addValueChangeListener(listener -> { - log("value change for field in " + pid + " to " - + listener.getValue()); - }); - return filterField; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFormatChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFormatChange.java deleted file mode 100644 index aa5366d8d3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFormatChange.java +++ /dev/null @@ -1,183 +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.components.grid; - -import java.io.Serializable; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.HeaderRow; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.Grid.SelectionModel; -import com.vaadin.v7.ui.renderers.NumberRenderer; - -public class GridHeaderFormatChange extends AbstractTestUI { - - private static final long serialVersionUID = -2787771187365766027L; - - private HeaderRow row; - - public class Person implements Serializable { - private static final long serialVersionUID = -7995927620756317000L; - - String firstName; - String lastName; - String streetAddress; - Integer zipCode; - String city; - - public Person(String firstName, String lastName, String streetAddress, - Integer zipCode, String city) { - this.firstName = firstName; - this.lastName = lastName; - this.streetAddress = streetAddress; - this.zipCode = zipCode; - this.city = city; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getStreetAddress() { - return streetAddress; - } - - public void setStreetAddress(String streetAddress) { - this.streetAddress = streetAddress; - } - - public Integer getZipCode() { - return zipCode; - } - - public void setZipCode(Integer zipCode) { - this.zipCode = zipCode; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - } - - @Override - protected void setup(VaadinRequest request) { - BeanItemContainer datasource = new BeanItemContainer( - Person.class); - final Grid grid; - - datasource.addItem(new Person("Rudolph", "Reindeer", "Ruukinkatu 2-4", - 20540, "Turku")); - - grid = new Grid(datasource); - grid.setWidth("600px"); - grid.getColumn("zipCode").setRenderer(new NumberRenderer()); - grid.setColumnOrder("firstName", "lastName", "streetAddress", "zipCode", - "city"); - grid.setSelectionMode(SelectionMode.SINGLE); - addComponent(grid); - - Button showHide = new Button("Hide firstName", - new Button.ClickListener() { - private static final long serialVersionUID = 8107530972693788705L; - - @Override - public void buttonClick(ClickEvent event) { - if (grid.getColumn("firstName") != null) { - grid.removeColumn("firstName"); - event.getButton().setCaption("Show firstName"); - } else { - grid.addColumn("firstName"); - grid.setColumnOrder("firstName", "lastName", - "streetAddress", "zipCode", "city"); - - event.getButton().setCaption("Hide firstName"); - } - } - }); - showHide.setId("show_hide"); - - Button selectionMode = new Button("Set multiselect", - new Button.ClickListener() { - private static final long serialVersionUID = 8107530972693788705L; - - @Override - public void buttonClick(ClickEvent event) { - if (grid.getSelectionModel() instanceof SelectionModel.Single) { - grid.setSelectionMode(SelectionMode.MULTI); - } else { - grid.setSelectionMode(SelectionMode.SINGLE); - } - } - }); - selectionMode.setId("selection_mode"); - - Button join = new Button("Add Join header column", - new Button.ClickListener() { - private static final long serialVersionUID = -5330801275551280623L; - - @Override - public void buttonClick(ClickEvent event) { - if (row == null) { - row = grid.prependHeaderRow(); - if (grid.getColumn("firstName") != null) { - row.join("firstName", "lastName") - .setText("Full Name"); - } - row.join("streetAddress", "zipCode", "city") - .setText("Address"); - } else { - grid.removeHeaderRow(row); - row = null; - } - } - }); - join.setId("join"); - addComponent(new HorizontalLayout(showHide, selectionMode, join)); - } - - @Override - protected String getTestDescription() { - return "Grid for testing header re-rendering."; - } - - @Override - protected Integer getTicketNumber() { - return 17131; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderStyleNames.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderStyleNames.java deleted file mode 100644 index 2daa56c6f4..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderStyleNames.java +++ /dev/null @@ -1,107 +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.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.components.beanitemcontainer.BeanItemContainerGenerator; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.FooterCell; -import com.vaadin.v7.ui.Grid.FooterRow; -import com.vaadin.v7.ui.Grid.HeaderCell; -import com.vaadin.v7.ui.Grid.HeaderRow; -import com.vaadin.v7.ui.Grid.SelectionMode; - -@Theme("valo") -public class GridHeaderStyleNames extends AbstractTestUIWithLog { - - private HeaderCell ageHeaderCell; - private HeaderCell mergedCityCountryCell; - private FooterCell ageFooterCell; - private HeaderRow headerRow; - private FooterRow footerRow; - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.MULTI); - grid.setContainerDataSource( - BeanItemContainerGenerator.createContainer(100)); - - ageHeaderCell = grid.getDefaultHeaderRow().getCell("age"); - grid.getDefaultHeaderRow().setStyleName("foo"); - headerRow = grid.prependHeaderRow(); - mergedCityCountryCell = headerRow.join("city", "country"); - mergedCityCountryCell.setText("Merged cell"); - addComponent(grid); - - footerRow = grid.appendFooterRow(); - ageFooterCell = footerRow.getCell("age"); - - getPage().getStyles().add( - ".age {background-image: linear-gradient(to bottom,green 2%, #efefef 98%) !important;}"); - getPage().getStyles().add( - ".valo .v-grid-header .v-grid-cell.city-country {background-image: linear-gradient(to bottom,yellow 2%, #efefef 98%) !important;}"); - getPage().getStyles().add( - ".valo .v-grid-footer .v-grid-cell.age-footer {background-image: linear-gradient(to bottom,blue 2%, #efefef 98%) !important;}"); - getPage().getStyles().add( - ".valo .v-grid .v-grid-row.custom-row > * {background-image: linear-gradient(to bottom,purple 2%, #efefef 98%);}"); - - setCellStyles(true); - setRowStyles(true); - - Button b = new Button("Toggle styles"); - b.addClickListener(new ClickListener() { - private boolean stylesOn = true; - - @Override - public void buttonClick(ClickEvent event) { - setCellStyles(!stylesOn); - setRowStyles(!stylesOn); - stylesOn = !stylesOn; - } - }); - addComponent(b); - } - - protected void setCellStyles(boolean set) { - if (set) { - ageHeaderCell.setStyleName("age"); - ageFooterCell.setStyleName("age-footer"); - mergedCityCountryCell.setStyleName("city-country"); - } else { - ageHeaderCell.setStyleName(null); - ageFooterCell.setStyleName(null); - mergedCityCountryCell.setStyleName(null); - } - - } - - protected void setRowStyles(boolean set) { - if (set) { - headerRow.setStyleName("custom-row"); - footerRow.setStyleName("custom-row"); - } else { - headerRow.setStyleName(null); - footerRow.setStyleName(null); - } - - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeight.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeight.java deleted file mode 100644 index f5caf9431e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeight.java +++ /dev/null @@ -1,189 +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.components.grid; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.data.Property.ValueChangeListener; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.v7.shared.ui.grid.HeightMode; -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.OptionGroup; - -/** - * Tests that Grid gets correct height based on height mode, and resizes - * properly with details row if height is undefined. - * - * @author Vaadin Ltd - */ -public class GridHeight extends AbstractTestUI { - - static final String FULL = "Full"; - static final String UNDEFINED = "Undefined"; - static final String PX100 = "100px"; - static final Integer ROW3 = 3; - - static final Object[] gridHeights = { FULL, UNDEFINED, ROW3 }; - static final String[] gridWidths = { FULL, UNDEFINED }; - static final String[] detailsRowHeights = { FULL, UNDEFINED, PX100 }; - - private Grid grid; - private Map detailsLayouts = new HashMap(); - private OptionGroup detailsHeightSelector; - - @Override - protected void setup(VaadinRequest request) { - - grid = new Grid(); - grid.addColumn("name", String.class); - grid.addColumn("born", Integer.class); - - grid.addRow("Nicolaus Copernicus", 1543); - grid.addRow("Galileo Galilei", 1564); - for (int i = 0; i < 1; ++i) { - grid.addRow("Johannes Kepler", 1571); - } - - grid.setDetailsGenerator(new DetailsGenerator() { - @Override - public Component getDetails(final RowReference rowReference) { - if (!detailsLayouts.containsKey(rowReference.getItemId())) { - createDetailsLayout(rowReference.getItemId()); - } - return detailsLayouts.get(rowReference.getItemId()); - } - }); - - grid.addItemClickListener(new ItemClickListener() { - @Override - public void itemClick(final ItemClickEvent event) { - final Object itemId = event.getItemId(); - grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); - } - }); - - addComponent(createOptionLayout()); - addComponent(grid); - } - - private void createDetailsLayout(Object itemId) { - VerticalLayout detailsLayout = new VerticalLayout(); - setDetailsHeight(detailsLayout, detailsHeightSelector.getValue()); - detailsLayout.setWidth("100%"); - - Label lbl1 = new Label("details row"); - lbl1.setId("lbl1"); - lbl1.setSizeUndefined(); - detailsLayout.addComponent(lbl1); - detailsLayout.setComponentAlignment(lbl1, Alignment.MIDDLE_CENTER); - - detailsLayouts.put(itemId, detailsLayout); - } - - private Component createOptionLayout() { - HorizontalLayout optionLayout = new HorizontalLayout(); - OptionGroup gridHeightSelector = new OptionGroup("Grid height", - Arrays. asList(gridHeights)); - gridHeightSelector.setId("gridHeightSelector"); - gridHeightSelector.setItemCaption(ROW3, ROW3 + " rows"); - gridHeightSelector.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Object value = event.getProperty().getValue(); - if (UNDEFINED.equals(value)) { - grid.setHeightUndefined(); - grid.setHeightMode(HeightMode.UNDEFINED); - } else if (FULL.equals(value)) { - grid.setHeight("100%"); - grid.setHeightMode(HeightMode.CSS); - } else if (ROW3.equals(value)) { - grid.setHeightByRows(ROW3); - grid.setHeightMode(HeightMode.ROW); - } - } - }); - gridHeightSelector.setValue(UNDEFINED); - optionLayout.addComponent(gridHeightSelector); - - OptionGroup gridWidthSelector = new OptionGroup("Grid width", - Arrays.asList(gridWidths)); - gridWidthSelector.setId("gridWidthSelector"); - gridWidthSelector.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Object value = event.getProperty().getValue(); - if (UNDEFINED.equals(value)) { - grid.setWidthUndefined(); - } else if (FULL.equals(value)) { - grid.setWidth("100%"); - } - } - }); - gridWidthSelector.setValue(UNDEFINED); - optionLayout.addComponent(gridWidthSelector); - - detailsHeightSelector = new OptionGroup("Details row height", - Arrays.asList(detailsRowHeights)); - detailsHeightSelector.setId("detailsHeightSelector"); - detailsHeightSelector.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Object value = event.getProperty().getValue(); - for (VerticalLayout detailsLayout : detailsLayouts.values()) { - setDetailsHeight(detailsLayout, value); - } - } - }); - detailsHeightSelector.setValue(PX100); - optionLayout.addComponent(detailsHeightSelector); - return optionLayout; - } - - private void setDetailsHeight(VerticalLayout detailsLayout, Object value) { - if (UNDEFINED.equals(value)) { - detailsLayout.setHeightUndefined(); - } else if (FULL.equals(value)) { - detailsLayout.setHeight("100%"); - } else if (PX100.equals(value)) { - detailsLayout.setHeight(PX100); - } - } - - @Override - protected String getTestDescription() { - return "Grid with undefined height should display all rows and resize when details row is opened." - + "
Grid with full height is always 400px high regardless or details row." - + "
Grid with row height should always be the height of those rows regardless of details row."; - } - - @Override - protected Integer getTicketNumber() { - return 19690; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInGridLayout.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInGridLayout.java deleted file mode 100644 index ed3b280e88..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInGridLayout.java +++ /dev/null @@ -1,60 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.Grid; - -public class GridInGridLayout extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final VerticalLayout layout = new VerticalLayout(); - final CssLayout cssLayout = new CssLayout(); - cssLayout.setWidth("100%"); - layout.setHeight("320px"); - layout.setMargin(true); - addComponent(cssLayout); - cssLayout.addComponent(layout); - - final Grid grid = new Grid(); - grid.setSizeFull(); - for (int i = 0; i < 20; i++) { - Grid.Column column = grid.addColumn("" + i); - column.setHidable(true); - column.setEditable(true); - } - grid.setEditorEnabled(true); - grid.setColumnReorderingAllowed(true); - for (int i = 0; i < 300; i++) { - grid.addRow("Foo", "Bar", "far", "bar", "bar", "Foo", "Bar", "Bar", - "bar", "bar", "Foo", "Bar", "Bar", "bar", "bar", "Foo", - "Bar", "Bar", "bar", "bar"); - - } - layout.addComponent(grid); - grid.setHeight("300px"); - grid.setWidth("400px"); - } - - @Override - protected Integer getTicketNumber() { - return 18698; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java deleted file mode 100644 index 185eb14927..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInTabSheet.java +++ /dev/null @@ -1,94 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Label; -import com.vaadin.ui.TabSheet; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.CellReference; -import com.vaadin.v7.ui.Grid.CellStyleGenerator; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridInTabSheet extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - TabSheet sheet = new TabSheet(); - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.MULTI); - grid.addColumn("count", Integer.class); - for (Integer i = 0; i < 3; ++i) { - grid.addRow(i); - } - - sheet.addTab(grid, "Grid"); - sheet.addTab(new Label("Hidden"), "Label"); - - addComponent(sheet); - addComponent(new Button("Add row to Grid", new Button.ClickListener() { - - private Integer k = 0; - - @Override - public void buttonClick(ClickEvent event) { - grid.addRow(100 + (k++)); - } - })); - addComponent( - new Button("Remove row from Grid", new Button.ClickListener() { - - private Integer k = 0; - - @Override - public void buttonClick(ClickEvent event) { - Object firstItemId = grid.getContainerDataSource() - .firstItemId(); - if (firstItemId != null) { - grid.getContainerDataSource() - .removeItem(firstItemId); - } - } - })); - addComponent(new Button("Add CellStyleGenerator", - new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.setCellStyleGenerator(new CellStyleGenerator() { - @Override - public String getStyle( - CellReference cellReference) { - int rowIndex = ((Integer) cellReference - .getItemId()).intValue(); - Object propertyId = cellReference - .getPropertyId(); - if (rowIndex % 4 == 1) { - return null; - } else if (rowIndex % 4 == 3 - && "Column 1".equals(propertyId)) { - return null; - } - return propertyId.toString().replace(' ', '_'); - } - }); - } - })); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInWindowResize.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridInWindowResize.java deleted file mode 100644 index 2187cfa8f3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInWindowResize.java +++ /dev/null @@ -1,72 +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.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -@Theme("valo") -public class GridInWindowResize extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid g = new Grid(); - IndexedContainer cont = new IndexedContainer(); - for (int j = 0; j < 3; j++) { - cont.addContainerProperty("" + j, String.class, ""); - } - - for (int k = 0; k < 100; k++) { - Item addItem = cont.addItem(k); - for (int j = 0; j < 3; j++) { - addItem.getItemProperty("" + j).setValue(1 + ""); - } - } - g.setContainerDataSource(cont); - g.setSizeFull(); - - VerticalLayout vl = new VerticalLayout(g); - vl.setSizeFull(); - Button resize = new Button("resize"); - VerticalLayout vl2 = new VerticalLayout(vl, resize); - vl2.setSizeFull(); - - final Window w = new Window(null, vl2); - addWindow(w); - - w.center(); - w.setModal(true); - w.setWidth("600px"); - w.setHeight("400px"); - - resize.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - w.setWidth("400px"); - } - }); - - } -} 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 deleted file mode 100644 index 2a32f4f09c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumns.java +++ /dev/null @@ -1,36 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.fieldgroup.ComplexPerson; -import com.vaadin.v7.ui.Grid; - -public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setContainerDataSource(ComplexPerson.createContainer(100)); - grid.setColumns("firstName", "lastName", "age"); - grid.getColumn("firstName").setHidden(true).setHidable(true); - grid.getColumn("lastName").setHidable(true); - grid.getColumn("age").setHidden(true).setHidable(true); - - addComponent(grid); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridItemSetChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridItemSetChange.java deleted file mode 100644 index f01ffb192e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridItemSetChange.java +++ /dev/null @@ -1,69 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.Person; -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 GridItemSetChange extends AbstractTestUI { - - public static class SneakyBeanContainer extends BeanItemContainer { - - private Person p = new Person("Foo", "Bar", "", "", "", 0, ""); - - public SneakyBeanContainer() throws IllegalArgumentException { - super(Person.class); - addItem(p); - } - - public void reset() { - internalRemoveAllItems(); - p.setLastName("Baz"); - internalAddItemAtEnd(p, createBeanItem(p), false); - fireItemSetChange(); - } - } - - @Override - protected void setup(VaadinRequest request) { - final SneakyBeanContainer c = new SneakyBeanContainer(); - Grid g = new Grid(c); - g.setColumns("firstName", "lastName"); - addComponent(g); - addComponent(new Button("Reset", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - c.reset(); - } - })); - addComponent(new Button("Modify", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - c.getItem(c.firstItemId()).getItemProperty("lastName") - .setValue("Spam"); - } - })); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java deleted file mode 100644 index cb3242d0e0..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridLayoutDetailsRow.java +++ /dev/null @@ -1,95 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Component; -import com.vaadin.ui.GridLayout; -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 that details row displays GridLayout contents properly. - * - * @author Vaadin Ltd - */ -public class GridLayoutDetailsRow extends AbstractTestUI { - - @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 GridLayout detailsLayout = new GridLayout(); - detailsLayout.setSizeFull(); - detailsLayout.setHeightUndefined(); - - final Label lbl1 = new Label("test1"); - lbl1.setId("lbl1"); - lbl1.setWidth("200px"); - detailsLayout.addComponent(lbl1); - - final Label lbl2 = new Label("test2"); - lbl2.setId("lbl2"); - detailsLayout.addComponent(lbl2); - - final Label lbl3 = new Label("test3"); - lbl3.setId("lbl3"); - detailsLayout.addComponent(lbl3); - - final Label lbl4 = new Label("test4"); - lbl4.setId("lbl4"); - detailsLayout.addComponent(lbl4); - - 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 String getTestDescription() { - return "GridLayout as part of Grid detail row should be correctly computed/displayed."; - } - - @Override - protected Integer getTicketNumber() { - return 18619; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectionOnInit.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectionOnInit.java deleted file mode 100644 index 148e6fd30f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectionOnInit.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.tests.components.grid; - -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.ui.Grid; -import com.vaadin.v7.ui.Grid.MultiSelectionModel; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridMultiSelectionOnInit extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.addColumn("foo", String.class); - grid.addRow("Foo 1"); - grid.addRow("Foo 2"); - grid.setSelectionMode(SelectionMode.MULTI); - addComponent(grid); - - addComponent(new Button("Select rows", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - ((MultiSelectionModel) grid.getSelectionModel()).setSelected( - grid.getContainerDataSource().getItemIds()); - } - })); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectionScrollBar.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectionScrollBar.java deleted file mode 100644 index 7272e2fcf0..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridMultiSelectionScrollBar.java +++ /dev/null @@ -1,34 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; - -public class GridMultiSelectionScrollBar extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.addColumn("X").setWidth(39.25d); - grid.addColumn("Hello"); - grid.addColumn("World"); - grid.setFrozenColumnCount(1); - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererChange.java deleted file mode 100644 index f5a1fedd2a..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRendererChange.java +++ /dev/null @@ -1,68 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.renderers.ButtonRenderer; -import com.vaadin.v7.ui.renderers.HtmlRenderer; -import com.vaadin.v7.ui.renderers.TextRenderer; - -public class GridRendererChange extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - - final Grid grid = new Grid(); - grid.setColumns("num", "foo"); - grid.getColumn("num").setRenderer(new ButtonRenderer()); - - for (int i = 0; i < 1000; i++) { - grid.addRow(String.format("line %d", i), "" + i); - } - - Button button = new Button("Set ButtonRenderer", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getColumn("num").setRenderer(new ButtonRenderer()); - } - }); - - Button buttonHtml = new Button("Set HTMLRenderer", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getColumn("num").setRenderer(new HtmlRenderer()); - } - }); - - Button buttonText = new Button("Set TextRenderer", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.getColumn("num").setRenderer(new TextRenderer()); - } - }); - - addComponent(new HorizontalLayout(button, buttonHtml, buttonText)); - addComponent(grid); - } -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridReplaceContainer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridReplaceContainer.java deleted file mode 100644 index c3d70de313..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridReplaceContainer.java +++ /dev/null @@ -1,94 +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.components.grid; - -import com.vaadin.event.SelectionEvent; -import com.vaadin.event.SelectionEvent.SelectionListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.v7.data.Container.Indexed; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridReplaceContainer extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.SINGLE); - grid.setContainerDataSource(createContainer()); - grid.addSelectionListener(new SelectionListener() { - - @Override - public void select(SelectionEvent event) { - Bean selected = (Bean) grid.getSelectedRow(); - if (selected != null) { - log("Now selected: " + selected.getData()); - } else { - log("Now selected: null"); - } - - } - }); - addComponent(grid); - Button b = new Button("Re-set data source", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.setContainerDataSource(createContainer()); - } - }); - addComponent(b); - } - - public static class Bean { - private int id; - private String data; - - public Bean(int id, String data) { - this.id = id; - this.data = data; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - } - - private Indexed createContainer() { - BeanItemContainer bic = new BeanItemContainer(Bean.class); - bic.addBean(new Bean(1, "First item")); - bic.addBean(new Bean(2, "Second item")); - bic.addBean(new Bean(3, "Third item")); - return bic; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeAndScroll.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeAndScroll.java deleted file mode 100644 index 39b8d46105..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeAndScroll.java +++ /dev/null @@ -1,68 +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.components.grid; - -import com.vaadin.event.SelectionEvent; -import com.vaadin.event.SelectionEvent.SelectionListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.VerticalLayout; -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.SelectionMode; - -public class GridResizeAndScroll extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - VerticalLayout content = new VerticalLayout(); - addComponent(content); - - final Grid g = new Grid(); - content.setHeight("500px"); - content.addComponent(g); - - IndexedContainer cont = new IndexedContainer(); - for (int j = 0; j < 3; j++) { - cont.addContainerProperty("" + j, String.class, ""); - } - - for (int k = 0; k < 50; k++) { - Item addItem = cont.addItem(k); - for (int j = 0; j < 3; j++) { - addItem.getItemProperty("" + j).setValue("cell " + k + " " + j); - } - } - g.setContainerDataSource(cont); - g.setSizeFull(); - - g.setSelectionMode(SelectionMode.MULTI); - - g.addSelectionListener(new SelectionListener() { - - @Override - public void select(SelectionEvent event) { - if (g.getSelectedRows().isEmpty()) { - g.setHeight("100%"); - } else { - g.setHeight("50%"); - } - } - }); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeHiddenColumn.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeHiddenColumn.java deleted file mode 100644 index beaa051bb3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeHiddenColumn.java +++ /dev/null @@ -1,64 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.fieldgroup.ComplexPerson; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.ColumnResizeEvent; -import com.vaadin.v7.ui.Grid.ColumnResizeListener; - -@SuppressWarnings("serial") -public class GridResizeHiddenColumn extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setContainerDataSource(ComplexPerson.createContainer(100)); - grid.setColumns("firstName", "lastName", "gender", "birthDate"); - grid.getColumn("firstName").setHidable(true); - grid.getColumn("lastName").setHidable(true).setHidden(true); - grid.getColumn("gender").setHidable(true).setHidden(true); - grid.getColumn("birthDate").setHidable(true); - - addComponent(grid); - - grid.addColumnResizeListener(new ColumnResizeListener() { - @Override - public void columnResize(ColumnResizeEvent event) { - log(String.format("Column resized: id=%s, width=%s", - event.getColumn().getPropertyId(), - event.getColumn().getWidth())); - } - }); - } - - @Override - protected String getTestDescription() { - return "Resize columns and then make hidden column visible. The originally hidden column should have an extended width."; - } - - @Override - protected Integer getTicketNumber() { - return 19826; - } - - @Override - public String getDescription() { - return "Tests resize when columns with undefined width (-1) are hidden"; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.java deleted file mode 100644 index f4b04233b5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridResizeTerror.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.tests.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.util.ResizeTerrorizer; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.ui.UI; -import com.vaadin.v7.ui.Grid; - -@Widgetset(TestingWidgetSet.NAME) -public class GridResizeTerror extends UI { - @Override - protected void init(VaadinRequest request) { - Grid grid = new Grid(); - - int cols = 10; - Object[] data = new Object[cols]; - - for (int i = 0; i < cols; i++) { - grid.addColumn("Col " + i); - data[i] = "Data " + i; - } - - for (int i = 0; i < 500; i++) { - grid.addRow(data); - } - - ResizeTerrorizer terrorizer = new ResizeTerrorizer(grid); - setContent(terrorizer); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRowHeightChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridRowHeightChange.java deleted file mode 100644 index 091cc45ff3..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridRowHeightChange.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.vaadin.tests.components.grid; - -import java.util.Arrays; -import java.util.List; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.TabSheet; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.shared.ui.grid.HeightMode; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.NativeSelect; - -public class GridRowHeightChange extends AbstractTestUI { - - private final List themes = Arrays.asList("valo", "reindeer", - "runo", "chameleon", "base"); - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - - // create column and fill rows - grid.addColumn("Header"); - for (int i = 1; i <= 10; i++) { - grid.addRow("row_" + i); - } - - // set height mode and height - grid.setHeightMode(HeightMode.ROW); - grid.setHeightByRows(10); - - // create a tabsheet with one tab and place grid inside - VerticalLayout tab = new VerticalLayout(); - TabSheet tabSheet = new TabSheet(); - tabSheet.setWidthUndefined(); - tabSheet.addTab(tab, "Tab"); - tab.addComponent(grid); - - // Theme selector - NativeSelect themeSelector = new NativeSelect("Theme selector", themes); - themeSelector.select("reindeer"); - themeSelector.setNullSelectionAllowed(false); - themeSelector - .addValueChangeListener(new Property.ValueChangeListener() { - @Override - public void valueChange(Property.ValueChangeEvent event) { - setTheme((String) event.getProperty().getValue()); - } - }); - - VerticalLayout layout = new VerticalLayout(); - layout.setSpacing(true); - layout.setSizeUndefined(); - - layout.addComponent(themeSelector); - layout.addComponent(tabSheet); - - addComponent(layout); - } - - @Override - protected String getTestDescription() { - return "Test if Grid's height is adjusted when HeightMode.ROW and row height is recalculated.
" - + "When loading is complete, all 10 rows should be visible with all themes."; - } - - @Override - protected Integer getTicketNumber() { - return 20104; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollToLineWhileResizing.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollToLineWhileResizing.java deleted file mode 100644 index 340b7df91d..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrollToLineWhileResizing.java +++ /dev/null @@ -1,73 +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.components.grid; - -import com.vaadin.event.SelectionEvent; -import com.vaadin.event.SelectionEvent.SelectionListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.VerticalSplitPanel; -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.SelectionMode; - -public class GridScrollToLineWhileResizing extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - - final VerticalSplitPanel vsp = new VerticalSplitPanel(); - vsp.setWidth(500, Unit.PIXELS); - vsp.setHeight(500, Unit.PIXELS); - vsp.setSplitPosition(100, Unit.PERCENTAGE); - addComponent(vsp); - - IndexedContainer indexedContainer = new IndexedContainer(); - indexedContainer.addContainerProperty("column1", String.class, ""); - - for (int i = 0; i < 100; i++) { - Item addItem = indexedContainer.addItem(i); - addItem.getItemProperty("column1").setValue("cell" + i); - } - - final Grid grid = new Grid(indexedContainer); - grid.setSizeFull(); - - grid.setSelectionMode(SelectionMode.SINGLE); - grid.addSelectionListener(new SelectionListener() { - - @Override - public void select(SelectionEvent event) { - vsp.setSplitPosition(50, Unit.PERCENTAGE); - grid.scrollTo(event.getSelected().iterator().next()); - } - }); - - vsp.setFirstComponent(grid); - } - - @Override - protected String getTestDescription() { - return "Tests scrollToLine while moving SplitPanel split position to resize the Grid on the same round-trip."; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolling.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolling.java deleted file mode 100644 index 8ed3f4e9f8..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridScrolling.java +++ /dev/null @@ -1,112 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.shared.ui.grid.ScrollDestination; -import com.vaadin.v7.ui.Grid; - -@SuppressWarnings("serial") -public class GridScrolling extends AbstractTestUI { - - private Grid grid; - - private IndexedContainer ds; - - @Override - @SuppressWarnings("unchecked") - protected void setup(VaadinRequest request) { - // Build data source - ds = new IndexedContainer(); - - for (int col = 0; col < 5; col++) { - ds.addContainerProperty("col" + col, String.class, ""); - } - - for (int row = 0; row < 65536; row++) { - Item item = ds.addItem(Integer.valueOf(row)); - for (int col = 0; col < 5; col++) { - item.getItemProperty("col" + col) - .setValue("(" + row + ", " + col + ")"); - } - } - - grid = new Grid(ds); - - HorizontalLayout hl = new HorizontalLayout(); - hl.addComponent(grid); - hl.setMargin(true); - hl.setSpacing(true); - - VerticalLayout vl = new VerticalLayout(); - vl.setSpacing(true); - - // Add scroll buttons - Button scrollUpButton = new Button("Top", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.scrollToStart(); - } - }); - scrollUpButton.setSizeFull(); - vl.addComponent(scrollUpButton); - - for (int i = 1; i < 7; ++i) { - final int row = (ds.size() / 7) * i; - Button scrollButton = new Button("Scroll to row " + row, - new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.scrollTo(Integer.valueOf(row), - ScrollDestination.MIDDLE); - } - }); - scrollButton.setSizeFull(); - vl.addComponent(scrollButton); - } - - Button scrollDownButton = new Button("Bottom", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.scrollToEnd(); - } - }); - scrollDownButton.setSizeFull(); - vl.addComponent(scrollDownButton); - - hl.addComponent(vl); - addComponent(hl); - } - - @Override - protected String getTestDescription() { - return "Test Grid programmatic scrolling features"; - } - - @Override - protected Integer getTicketNumber() { - return 13327; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllCell.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllCell.java deleted file mode 100644 index 21d02e656c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllCell.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.vaadin.tests.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; - -@Theme("valo") -public class GridSelectAllCell extends AbstractTestUI { - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - - grid.addColumn("foo", String.class); - grid.addRow("bar"); - - grid.setSelectionMode(Grid.SelectionMode.MULTI); - - addComponent(grid); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java deleted file mode 100644 index 01a4ad7532..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSidebarPosition.java +++ /dev/null @@ -1,70 +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.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.v7.ui.Grid; - -@Theme("valo") -public class GridSidebarPosition extends AbstractTestUI { - - static final String POPUP_ABOVE = "above"; - static final String POPUP_WINDOW_MOVED_UP = "movedup"; - static final String POPUP_WINDOW_HEIGHT = "windowheight"; - - @Override - protected void setup(VaadinRequest request) { - HorizontalLayout hl = new HorizontalLayout(); - hl.setSpacing(true); - hl.setHeight("100%"); - setContent(hl); - Grid grid = new Grid("Popup window height"); - grid.setId(POPUP_WINDOW_HEIGHT); - grid.setWidth("100px"); - for (int i = 0; i < 30; i++) { - grid.addColumn( - "This is a really really really really long column name " - + i) - .setHidable(true); - } - hl.addComponent(grid); - - grid = new Grid("Popup moved up"); - grid.setId(POPUP_WINDOW_MOVED_UP); - grid.setWidth("100px"); - grid.setHeight("400px"); - for (int i = 0; i < 15; i++) { - grid.addColumn("Column " + i).setHidable(true); - } - hl.addComponent(grid); - hl.setComponentAlignment(grid, Alignment.BOTTOM_LEFT); - - grid = new Grid("Popup above"); - grid.setId(POPUP_ABOVE); - grid.setWidth("100px"); - grid.setHeight("200px"); - for (int i = 0; i < 10; i++) { - grid.addColumn("Column " + i).setHidable(true); - } - hl.addComponent(grid); - hl.setComponentAlignment(grid, Alignment.BOTTOM_LEFT); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java deleted file mode 100644 index 2ed98f0ae4..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSingleColumn.java +++ /dev/null @@ -1,60 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -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.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridSingleColumn extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - - IndexedContainer indexedContainer = new IndexedContainer(); - indexedContainer.addContainerProperty("column1", String.class, ""); - - for (int i = 0; i < 100; i++) { - Item addItem = indexedContainer.addItem(i); - addItem.getItemProperty("column1").setValue("cell"); - } - - Grid grid = new Grid(indexedContainer); - grid.setSelectionMode(SelectionMode.NONE); - - Column column = grid.getColumn("column1"); - - column.setHeaderCaption("Header"); - - addComponent(grid); - grid.scrollTo(grid.getContainerDataSource().getIdByIndex(50)); - } - - @Override - protected String getTestDescription() { - return "Tests a single column grid"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSortIndicator.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSortIndicator.java deleted file mode 100644 index 3559b67970..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSortIndicator.java +++ /dev/null @@ -1,96 +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.components.grid; - -import java.util.ArrayList; -import java.util.List; - -import com.vaadin.data.sort.SortOrder; -import com.vaadin.event.SortEvent; -import com.vaadin.event.SortEvent.SortListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; - -/* - * Test UI for checking that sort indicators of a Grid are updated when the sort order is changed by a - * SortListener. - */ -public class GridSortIndicator extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - final Grid g = getGrid(); - addComponent(g); - g.addSortListener(new SortListener() { - private SortDirection oldSortDirection = null; - - @Override - public void sort(SortEvent event) { - List currentSortOrder = new ArrayList( - event.getSortOrder()); - if (currentSortOrder.size() == 1) { - // If the name column was clicked, set a new sort order for - // both columns. Otherwise, revert to oldSortDirection if it - // is not null. - List newSortOrder = new ArrayList(); - SortDirection newSortDirection = oldSortDirection; - if (currentSortOrder.get(0).getPropertyId() - .equals("Name")) { - newSortDirection = SortDirection.ASCENDING.equals( - oldSortDirection) ? SortDirection.DESCENDING - : SortDirection.ASCENDING; - } - if (newSortDirection != null) { - newSortOrder - .add(new SortOrder("Name", newSortDirection)); - newSortOrder - .add(new SortOrder("Value", newSortDirection)); - g.setSortOrder(newSortOrder); - } - oldSortDirection = newSortDirection; - } - } - }); - } - - private final Grid getGrid() { - Grid g = new Grid(); - g.addColumn("Name"); - g.addColumn("Value", Integer.class); - g.addRow(new Object[] { "a", 4 }); - g.addRow(new Object[] { "b", 5 }); - g.addRow(new Object[] { "c", 3 }); - g.addRow(new Object[] { "a", 6 }); - g.addRow(new Object[] { "a", 2 }); - g.addRow(new Object[] { "c", 7 }); - g.addRow(new Object[] { "b", 1 }); - return g; - } - - @Override - public String getTestDescription() { - return "When the first column is the primary sort column, both columns should have " - + "a sort indicator with the same sort direction. Clicking on the right column " - + "in that state should have no effect."; - } - - @Override - public Integer getTicketNumber() { - return 17440; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSubPixelProblemWrapping.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSubPixelProblemWrapping.java deleted file mode 100644 index a67c923d34..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSubPixelProblemWrapping.java +++ /dev/null @@ -1,96 +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.components.grid; - -import java.util.Random; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -@Theme("valo") -public class GridSubPixelProblemWrapping extends AbstractTestUI { - - Random r = new Random(); - - public static class DataObject { - String foo; - String Bar; - - public DataObject(Random r) { - foo = r.nextInt() + ""; - Bar = r.nextInt() + ""; - } - - public DataObject(String foo, String bar) { - this.foo = foo; - Bar = bar; - } - - public String getFoo() { - return foo; - } - - public void setFoo(String foo) { - this.foo = foo; - } - - public String getBar() { - return Bar; - } - - public void setBar(String bar) { - Bar = bar; - } - - } - - Button button = new Button("Click", new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - addDAO(); - } - }); - - private BeanItemContainer container; - private int counter = 0; - - @Override - protected void setup(VaadinRequest request) { - addComponent(button); - container = new BeanItemContainer(DataObject.class); - container.addBean(new DataObject("Foo", "Bar")); - Grid grid = new Grid(container); - grid.getColumn("foo").setWidth(248.525); - grid.setSelectionMode(SelectionMode.SINGLE); - grid.setEditorEnabled(true); - grid.setWidth("500px"); - - addComponent(grid); - } - - private void addDAO() { - counter++; - container.addBean(new DataObject("Foo" + counter, "Bar" + counter)); - - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSwitchRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSwitchRenderers.java deleted file mode 100644 index 9ced5d90af..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSwitchRenderers.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.vaadin.tests.components.grid; - -import java.util.List; -import java.util.Random; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.CheckBox; -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.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.renderers.HtmlRenderer; -import com.vaadin.v7.ui.renderers.TextRenderer; - -@SuppressWarnings("serial") -@Theme("valo") -public class GridSwitchRenderers extends AbstractTestUIWithLog { - private static final int MANUALLY_FORMATTED_COLUMNS = 1; - private static final int COLUMNS = 3; - private static final int ROWS = 1000; - private static final String EXPANSION_COLUMN_ID = "Column 0"; - - private IndexedContainer ds; - - @Override - protected void setup(VaadinRequest request) { - ds = new IndexedContainer() { - @Override - public List getItemIds(int startIndex, int numberOfIds) { - log("Requested items " + startIndex + " - " - + (startIndex + numberOfIds)); - return super.getItemIds(startIndex, numberOfIds); - } - }; - - { - ds.addContainerProperty(EXPANSION_COLUMN_ID, String.class, ""); - - int col = MANUALLY_FORMATTED_COLUMNS; - for (; col < COLUMNS; col++) { - ds.addContainerProperty(getColumnProperty(col), String.class, - ""); - } - } - - Random rand = new Random(); - rand.setSeed(13334); - for (int row = 0; row < ROWS; row++) { - Item item = ds.addItem(Integer.valueOf(row)); - fillRow("" + row, item); - item.getItemProperty(getColumnProperty(1)).setReadOnly(true); - } - - final Grid grid = new Grid(ds); - grid.setWidth("100%"); - - grid.getColumn(EXPANSION_COLUMN_ID).setWidth(50); - for (int col = MANUALLY_FORMATTED_COLUMNS; col < COLUMNS; col++) { - grid.getColumn(getColumnProperty(col)).setWidth(300); - grid.getColumn(getColumnProperty(col)) - .setRenderer(new TextRenderer()); - } - - grid.setSelectionMode(SelectionMode.NONE); - addComponent(grid); - - final CheckBox changeRenderer = new CheckBox( - "SetHtmlRenderer for Column 2", false); - changeRenderer.addValueChangeListener(event -> { - Column column = grid.getColumn(getColumnProperty(1)); - if (changeRenderer.getValue()) { - column.setRenderer(new HtmlRenderer()); - } else { - column.setRenderer(new TextRenderer()); - } - grid.markAsDirty(); - }); - addComponent(changeRenderer); - } - - @SuppressWarnings("unchecked") - private void fillRow(String content, Item item) { - int col = MANUALLY_FORMATTED_COLUMNS; - - for (; col < COLUMNS; col++) { - item.getItemProperty(getColumnProperty(col)) - .setValue("(" + content + ", " + col + ")"); - } - } - - private static String getColumnProperty(int c) { - return "Column " + c; - } - -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridThemeChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridThemeChange.java deleted file mode 100644 index 4b0da38036..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridThemeChange.java +++ /dev/null @@ -1,59 +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.components.grid; - -import java.util.Arrays; -import java.util.List; - -import com.vaadin.event.SelectionEvent; -import com.vaadin.event.SelectionEvent.SelectionListener; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridThemeChange extends AbstractTestUI { - private final List themes = Arrays.asList("valo", "reindeer", - "runo", "chameleon", "base"); - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.SINGLE); - - grid.addColumn("Theme"); - for (String theme : themes) { - Object itemId = grid.addRow(theme); - if (theme.equals(getTheme())) { - grid.select(itemId); - } - } - - grid.addSelectionListener(new SelectionListener() { - @Override - public void select(SelectionEvent event) { - Object selectedItemId = grid.getSelectedRow(); - Object theme = grid.getContainerDataSource() - .getItem(selectedItemId).getItemProperty("Theme") - .getValue(); - setTheme(String.valueOf(theme)); - } - }); - - addComponent(grid); - - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridThemeUI.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridThemeUI.java deleted file mode 100644 index 825f42d214..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridThemeUI.java +++ /dev/null @@ -1,148 +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.components.grid; - -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.fieldgroup.ComplexPerson; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.data.Property.ValueChangeListener; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.data.validator.IntegerRangeValidator; -import com.vaadin.v7.ui.ComboBox; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.NativeSelect; -import com.vaadin.v7.ui.renderers.DateRenderer; - -@Theme("valo") -public class GridThemeUI extends AbstractTestUIWithLog { - - private Grid grid; - - protected static String[] columns = new String[] { "firstName", "lastName", - "gender", "birthDate", "age", "alive", "address.streetAddress", - "address.postalCode", "address.city", "address.country" }; - - protected BeanItemContainer container = ComplexPerson - .createContainer(100);; - { - container.addNestedContainerBean("address"); - } - protected ComboBox formType; - - private Component active = null; - - @Override - protected void setup(VaadinRequest request) { - setLocale(new Locale("en", "US")); - - final NativeSelect pageSelect = new NativeSelect("Page"); - pageSelect.setImmediate(true); - pageSelect.setId("page"); - addComponent(pageSelect); - - pageSelect.addItem(new Editor()); - pageSelect.addItem(new HeaderFooter()); - - pageSelect.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - if (active != null) { - removeComponent(active); - } - active = (Component) pageSelect.getValue(); - addComponent(active); - } - }); - pageSelect.setNullSelectionAllowed(false); - pageSelect.setValue(pageSelect.getItemIds().iterator().next()); - - } - - public class Editor extends Grid { - @Override - public String toString() { - return "Editor"; - }; - - public Editor() { - setContainerDataSource(container); - setColumnOrder((Object[]) columns); - removeColumn("salary"); - setEditorEnabled(true); - getColumn("lastName").setEditable(false); - setSizeFull(); - getColumn("age").getEditorField().addValidator( - new IntegerRangeValidator("Must be between 0 and 100", 0, - 100)); - getColumn("birthDate").setRenderer(new DateRenderer( - DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US))); - } - } - - public class HeaderFooter extends Grid { - @Override - public String toString() { - return getClass().getSimpleName(); - }; - - public HeaderFooter() { - setContainerDataSource(container); - setColumnOrder((Object[]) columns); - HeaderRow row = addHeaderRowAt(0); - row.join("firstName", "lastName").setHtml("Name"); - Button b = new Button("The address, yo"); - b.addClickListener(new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - HeaderRow row = addHeaderRowAt(0); - List pids = new ArrayList(); - for (Column c : getColumns()) { - pids.add(c.getPropertyId()); - } - row.join(pids.toArray()).setText("The big header"); - } - }); - b.setSizeFull(); - row.join("address.streetAddress", "address.postalCode", - "address.city", "address.country").setComponent(b); - // TODO: revert back to 25 when #16597 is fixed.. - getColumn("age").setWidth(42); - removeColumn("salary"); - setEditorEnabled(true); - setSizeFull(); - getColumn("age").getEditorField().addValidator( - new IntegerRangeValidator("Must be between 0 and 100", 0, - 100)); - getColumn("birthDate").setRenderer(new DateRenderer( - DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US))); - - addFooterRowAt(0); - } - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWidgetRendererChange.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWidgetRendererChange.java deleted file mode 100644 index fcf8638e42..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWidgetRendererChange.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.tests.components.grid; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridRendererChangeWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -@Widgetset(TestingWidgetSet.NAME) -public class GridWidgetRendererChange extends UI { - - @Override - protected void init(VaadinRequest request) { - setContent(new TestWidgetComponent(GridRendererChangeWidget.class)); - } - -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWidthIncrease.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWidthIncrease.java deleted file mode 100644 index 4d7ec80e20..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWidthIncrease.java +++ /dev/null @@ -1,48 +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.components.grid; - -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.ui.Grid; - -public class GridWidthIncrease extends AbstractTestUI { - - public static int COLUMN_COUNT = 5; - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - Object[] rowData = new String[COLUMN_COUNT]; - for (int i = 0; i < COLUMN_COUNT; ++i) { - grid.addColumn("Column " + i, String.class); - rowData[i] = "Foo (0, " + i + ")"; - } - grid.addRow(rowData); - grid.setWidth(400 + "px"); - addComponent(grid); - addComponent( - new Button("Increase Grid Width", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.setWidth((grid.getWidth() + 50) + "px"); - } - })); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithBrokenRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithBrokenRenderer.java deleted file mode 100644 index 5a72daccee..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithBrokenRenderer.java +++ /dev/null @@ -1,43 +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.components.grid; - -import com.vaadin.server.ClassResource; -import com.vaadin.server.Resource; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.tests.integration.FlagSeResource; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.renderers.ImageRenderer; - -public class GridWithBrokenRenderer extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.addColumn("short", String.class); - grid.addColumn("icon", Resource.class); - grid.addColumn("country", String.class); - - grid.getColumn("icon").setRenderer(new ImageRenderer()); - addComponent(grid); - - grid.addRow("FI", new ClassResource("fi.gif"), "Finland"); - grid.addRow("SE", new FlagSeResource(), "Sweden"); - - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithLabelEditor.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithLabelEditor.java deleted file mode 100644 index f80f219c95..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithLabelEditor.java +++ /dev/null @@ -1,154 +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.components.grid; - -import java.util.Collection; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.data.Validator; -import com.vaadin.v7.data.Validator.InvalidValueException; -import com.vaadin.v7.ui.Field; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Label; - -public class GridWithLabelEditor extends AbstractTestUI { - - public class LabelEditor extends Label implements Field { - - @Override - public void focus() { - super.focus(); - } - - @Override - public boolean isInvalidCommitted() { - return false; - } - - @Override - public void setInvalidCommitted(boolean isCommitted) { - } - - @Override - public void commit() throws SourceException, InvalidValueException { - } - - @Override - public void discard() throws SourceException { - } - - @Override - public void setBuffered(boolean buffered) { - } - - @Override - public boolean isBuffered() { - return false; - } - - @Override - public boolean isModified() { - return false; - } - - @Override - public void addValidator(Validator validator) { - } - - @Override - public void removeValidator(Validator validator) { - } - - @Override - public void removeAllValidators() { - } - - @Override - public Collection getValidators() { - return null; - } - - @Override - public boolean isValid() { - return true; - } - - @Override - public void validate() throws InvalidValueException { - } - - @Override - public boolean isInvalidAllowed() { - return false; - } - - @Override - public void setInvalidAllowed(boolean invalidValueAllowed) - throws UnsupportedOperationException { - } - - @Override - public int getTabIndex() { - return -1; - } - - @Override - public void setTabIndex(int tabIndex) { - } - - @Override - public boolean isRequired() { - return false; - } - - @Override - public void setRequired(boolean required) { - } - - @Override - public void setRequiredError(String requiredMessage) { - } - - @Override - public String getRequiredError() { - return null; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public void clear() { - } - - } - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - addComponent(grid); - - grid.setEditorEnabled(true); - grid.addColumn("Foo", String.class).setEditorField(new LabelEditor()); - grid.addRow("FooFoo"); - - grid.editItem(grid.getContainerDataSource().firstItemId()); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRenderer.java deleted file mode 100644 index 283989e0b7..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRenderer.java +++ /dev/null @@ -1,34 +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.components.grid; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.PersonContainer; -import com.vaadin.v7.ui.Grid; - -@Theme("valo") -public class GridWithoutRenderer extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setContainerDataSource(PersonContainer.createWithTestData()); - addComponent(grid); - - } -} 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 deleted file mode 100644 index fe57d0dbbe..0000000000 --- a/uitest/src/main/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class InitialFrozenColumns extends AbstractTestUI { - - @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/main/java/com/vaadin/tests/components/grid/IntArrayRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/IntArrayRenderer.java deleted file mode 100644 index 3b864a786e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/IntArrayRenderer.java +++ /dev/null @@ -1,24 +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.components.grid; - -import com.vaadin.v7.ui.Grid.AbstractRenderer; - -public class IntArrayRenderer extends AbstractRenderer { - public IntArrayRenderer() { - super(int[].class, ""); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java deleted file mode 100644 index 628871a824..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptRenderers.java +++ /dev/null @@ -1,79 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -public class JavaScriptRenderers extends AbstractTestUI { - - public static class MyBean { - private int integer; - private String string; - - public MyBean(int integer, String string) { - super(); - this.integer = integer; - this.string = string; - } - - public int getInteger() { - return integer; - } - - public void setInteger(int integer) { - this.integer = integer; - } - - public String getString() { - return string; - } - - public void setString(String string) { - this.string = string; - } - } - - @Override - protected void setup(VaadinRequest request) { - IndexedContainer container = new IndexedContainer(); - container.addContainerProperty("id", Integer.class, Integer.valueOf(0)); - container.addContainerProperty("bean", MyBean.class, null); - container.addContainerProperty("string", String.class, ""); - - for (int i = 0; i < 1000; i++) { - Integer itemId = Integer.valueOf(i); - Item item = container.addItem(itemId); - item.getItemProperty("id").setValue(itemId); - item.getItemProperty("bean") - .setValue(new MyBean(i + 1, Integer.toString(i - 1))); - item.getItemProperty("string").setValue("string" + i); - } - - Grid grid = new Grid(container); - - grid.getColumn("bean").setRenderer(new MyBeanJSRenderer()); - grid.getColumn("bean").setWidth(250); - - grid.getColumn("string").setRenderer(new JavaScriptStringRenderer()); - - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptStringRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptStringRenderer.java deleted file mode 100644 index e0e35f7e7f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/JavaScriptStringRenderer.java +++ /dev/null @@ -1,29 +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.components.grid; - -import com.vaadin.annotations.JavaScript; -import com.vaadin.v7.ui.renderers.AbstractJavaScriptRenderer; - -@JavaScript("JavaScriptStringRenderer.js") -public class JavaScriptStringRenderer - extends AbstractJavaScriptRenderer { - - protected JavaScriptStringRenderer() { - super(String.class); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/MyBeanJSRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/MyBeanJSRenderer.java deleted file mode 100644 index 075d51992f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/MyBeanJSRenderer.java +++ /dev/null @@ -1,34 +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.components.grid; - -import com.vaadin.annotations.JavaScript; -import com.vaadin.tests.components.grid.JavaScriptRenderers.MyBean; -import com.vaadin.v7.ui.renderers.AbstractJavaScriptRenderer; - -/** - * - * @since - * @author Vaadin Ltd - */ -@JavaScript("myBeanJsRenderer.js") -public class MyBeanJSRenderer extends AbstractJavaScriptRenderer { - - public MyBeanJSRenderer() { - super(MyBean.class, ""); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/NullHeaders.java b/uitest/src/main/java/com/vaadin/tests/components/grid/NullHeaders.java deleted file mode 100644 index 398edfa713..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/NullHeaders.java +++ /dev/null @@ -1,40 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.v7.ui.Grid; - -public class NullHeaders extends AbstractTestUIWithLog { - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - grid.addColumn("country", String.class); - grid.addColumn("foo", String.class); - grid.addColumn("bar", Integer.class); - - grid.getColumn("country").setHeaderCaption(null); - grid.getColumn("foo").setHeaderCaption(""); - grid.getColumn("bar").setHeaderCaption(null); - grid.addRow("Finland", "foo", 1); - grid.addRow("Swaziland", "bar", 2); - grid.addRow("Japan", "baz", 3); - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/NullRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/NullRenderers.java deleted file mode 100644 index 78fac58fda..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/NullRenderers.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.tests.components.grid; - -import java.util.Date; -import java.util.Locale; - -import com.vaadin.server.Resource; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.renderers.ButtonRenderer; -import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickEvent; -import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickListener; -import com.vaadin.v7.ui.renderers.DateRenderer; -import com.vaadin.v7.ui.renderers.HtmlRenderer; -import com.vaadin.v7.ui.renderers.ImageRenderer; -import com.vaadin.v7.ui.renderers.NumberRenderer; -import com.vaadin.v7.ui.renderers.ProgressBarRenderer; -import com.vaadin.v7.ui.renderers.TextRenderer; - -@SuppressWarnings("all") -public class NullRenderers extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - IndexedContainer container = new IndexedContainer(); - - container.addContainerProperty(TextRenderer.class, String.class, null); - container.addContainerProperty(HtmlRenderer.class, String.class, null); - container.addContainerProperty(DateRenderer.class, Date.class, null); - container.addContainerProperty(NumberRenderer.class, Number.class, - null); - - container.addContainerProperty(ProgressBarRenderer.class, Double.class, - null); - container.addContainerProperty(ButtonRenderer.class, String.class, - null); - container.addContainerProperty(ImageRenderer.class, Resource.class, - null); - - container.addItem(); - - final Grid gridDefaults = new Grid(container); - - gridDefaults.setId("test-grid-defaults"); - gridDefaults.setSelectionMode(SelectionMode.NONE); - gridDefaults.setWidth("100%"); - - gridDefaults.getColumn(TextRenderer.class) - .setRenderer(new TextRenderer("-- No Text --")); - gridDefaults.getColumn(HtmlRenderer.class) - .setRenderer(new HtmlRenderer("-- No Jokes --")); - gridDefaults.getColumn(DateRenderer.class).setRenderer( - new DateRenderer("%s", Locale.getDefault(), "-- Never --")); - gridDefaults.getColumn(NumberRenderer.class).setRenderer( - new NumberRenderer("%s", Locale.getDefault(), "-- Nothing --")); - - gridDefaults.getColumn(ProgressBarRenderer.class) - .setRenderer(new ProgressBarRenderer()); - - gridDefaults.getColumn(ButtonRenderer.class) - .setRenderer(new ButtonRenderer(new RendererClickListener() { - @Override - public void click(RendererClickEvent event) { - } - }, "-- No Control --")); - - gridDefaults.getColumn(ImageRenderer.class) - .setRenderer(new ImageRenderer(new RendererClickListener() { - - @Override - public void click(RendererClickEvent event) { - } - })); - - addComponent(gridDefaults); - - final Grid gridNoDefaults = new Grid(container); - - gridNoDefaults.setId("test-grid"); - gridNoDefaults.setSelectionMode(SelectionMode.NONE); - gridNoDefaults.setWidth("100%"); - - gridNoDefaults.getColumn(TextRenderer.class) - .setRenderer(new TextRenderer()); - gridNoDefaults.getColumn(HtmlRenderer.class) - .setRenderer(new HtmlRenderer()); - gridNoDefaults.getColumn(DateRenderer.class) - .setRenderer(new DateRenderer()); - gridNoDefaults.getColumn(NumberRenderer.class) - .setRenderer(new NumberRenderer()); - - gridNoDefaults.getColumn(ProgressBarRenderer.class) - .setRenderer(new ProgressBarRenderer()); - - gridNoDefaults.getColumn(ButtonRenderer.class) - .setRenderer(new ButtonRenderer(new RendererClickListener() { - @Override - public void click(RendererClickEvent event) { - } - })); - - gridNoDefaults.getColumn(ImageRenderer.class) - .setRenderer(new ImageRenderer(new RendererClickListener() { - - @Override - public void click(RendererClickEvent event) { - } - })); - - addComponent(gridNoDefaults); - } - - @Override - protected String getTestDescription() { - return "Tests the functionality of widget-based renderers"; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(13334); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/PersonTestGrid.java b/uitest/src/main/java/com/vaadin/tests/components/grid/PersonTestGrid.java deleted file mode 100644 index e5eae89d48..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/PersonTestGrid.java +++ /dev/null @@ -1,30 +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.components.grid; - -import com.vaadin.tests.fieldgroup.ComplexPerson; -import com.vaadin.v7.data.util.BeanItemContainer; -import com.vaadin.v7.ui.Grid; - -public class PersonTestGrid extends Grid { - - public PersonTestGrid(int size) { - BeanItemContainer container = ComplexPerson - .createContainer(size); - container.addNestedContainerBean("address"); - setContainerDataSource(container); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/ProgrammaticEditorControl.java b/uitest/src/main/java/com/vaadin/tests/components/grid/ProgrammaticEditorControl.java deleted file mode 100644 index bd0f1ae662..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/ProgrammaticEditorControl.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.vaadin.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -@SuppressWarnings("serial") -// @Push -public class ProgrammaticEditorControl extends AbstractTestUIWithLog { - - private Grid grid; - private IndexedContainer container = new IndexedContainer(); - - @Override - protected void setup(VaadinRequest request) { - container.addContainerProperty("name", String.class, null); - container.addItem("test").getItemProperty("name").setValue("test"); - grid = new Grid(); - grid.setContainerDataSource(container); - grid.setEditorEnabled(true); - addComponent(grid); - - Button button = new Button("Edit", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.editItem("test"); - } - }); - addComponent(button); - Button button2 = new Button("Cancel", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.cancelEditor(); - } - }); - addComponent(button2); - - } - -} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/RowAwareRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/RowAwareRenderer.java deleted file mode 100644 index 7aa5fc35fa..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/RowAwareRenderer.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.tests.components.grid; - -import com.vaadin.tests.widgetset.client.grid.RowAwareRendererConnector.RowAwareRendererRpc; -import com.vaadin.ui.Label; -import com.vaadin.v7.ui.Grid.AbstractRenderer; - -public class RowAwareRenderer extends AbstractRenderer { - public RowAwareRenderer(final Label debugLabel) { - super(Void.class, ""); - registerRpc(new RowAwareRendererRpc() { - @Override - public void clicky(String key) { - Object itemId = getItemId(key); - debugLabel.setValue("key: " + key + ", itemId: " + itemId); - } - }); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/SelectDuringInit.java b/uitest/src/main/java/com/vaadin/tests/components/grid/SelectDuringInit.java deleted file mode 100644 index a5c7f988cb..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/SelectDuringInit.java +++ /dev/null @@ -1,40 +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.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class SelectDuringInit extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.setSelectionMode(SelectionMode.MULTI); - - grid.addColumn("value"); - grid.addRow("row 1"); - grid.addRow("row 2"); - grid.addRow("row 3"); - - grid.select(Integer.valueOf(2)); - - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/SortableHeaderStyles.java b/uitest/src/main/java/com/vaadin/tests/components/grid/SortableHeaderStyles.java deleted file mode 100644 index 4c711689a5..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/SortableHeaderStyles.java +++ /dev/null @@ -1,66 +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.components.grid; - -import java.util.Collection; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.util.PersonContainer; -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.Column; -import com.vaadin.v7.ui.OptionGroup; - -@Theme("valo") -public class SortableHeaderStyles extends AbstractTestUI { - - @Override - protected void setup(VaadinRequest request) { - getPage().getStyles().add( - ".valo .v-grid-header th.v-grid-cell.sortable { font-weight: bold;}"); - - PersonContainer container = PersonContainer.createWithTestData(); - - Collection sortableContainerPropertyIds = container - .getSortableContainerPropertyIds(); - - final OptionGroup sortableSelector = new OptionGroup("Sortable columns", - sortableContainerPropertyIds); - sortableSelector.setMultiSelect(true); - sortableSelector.setValue(sortableContainerPropertyIds); - - final Grid grid = new Grid(container); - - sortableSelector.addValueChangeListener(new ValueChangeListener() { - @Override - public void valueChange(ValueChangeEvent event) { - Collection sortableCols = (Collection) sortableSelector - .getValue(); - for (Column column : grid.getColumns()) { - column.setSortable( - sortableCols.contains(column.getPropertyId())); - } - } - }); - - addComponent(sortableSelector); - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/WidgetRenderers.java b/uitest/src/main/java/com/vaadin/tests/components/grid/WidgetRenderers.java deleted file mode 100644 index 476fa98f8b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/WidgetRenderers.java +++ /dev/null @@ -1,118 +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.components.grid; - -import com.vaadin.server.Resource; -import com.vaadin.server.ThemeResource; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.NativeButton; -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.SelectionMode; -import com.vaadin.v7.ui.renderers.ButtonRenderer; -import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickEvent; -import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickListener; -import com.vaadin.v7.ui.renderers.ImageRenderer; -import com.vaadin.v7.ui.renderers.ProgressBarRenderer; - -@SuppressWarnings("all") -public class WidgetRenderers extends AbstractTestUI { - - static final String PROPERTY_ID = "property id"; - - @Override - protected void setup(VaadinRequest request) { - IndexedContainer container = new IndexedContainer(); - - container.addContainerProperty(ProgressBarRenderer.class, Double.class, - null); - container.addContainerProperty(ButtonRenderer.class, String.class, - null); - container.addContainerProperty(ImageRenderer.class, Resource.class, - null); - container.addContainerProperty(PROPERTY_ID, String.class, null); - - final Item item = container.getItem(container.addItem()); - - item.getItemProperty(ProgressBarRenderer.class).setValue(0.3); - item.getItemProperty(ButtonRenderer.class).setValue("Click"); - item.getItemProperty(ImageRenderer.class) - .setValue(new ThemeResource("window/img/close.png")); - item.getItemProperty(PROPERTY_ID).setValue("Click"); - - final Grid grid = new Grid(container); - - grid.setId("test-grid"); - grid.setSelectionMode(SelectionMode.NONE); - - grid.getColumn(ProgressBarRenderer.class) - .setRenderer(new ProgressBarRenderer()); - - grid.getColumn(ButtonRenderer.class) - .setRenderer(new ButtonRenderer(new RendererClickListener() { - @Override - public void click(RendererClickEvent event) { - item.getItemProperty(ButtonRenderer.class) - .setValue("Clicked!"); - } - })); - - grid.getColumn(ImageRenderer.class) - .setRenderer(new ImageRenderer(new RendererClickListener() { - - @Override - public void click(RendererClickEvent event) { - item.getItemProperty(ImageRenderer.class).setValue( - new ThemeResource("window/img/maximize.png")); - } - })); - - grid.getColumn(PROPERTY_ID) - .setRenderer(new ButtonRenderer(new RendererClickListener() { - @Override - public void click(RendererClickEvent event) { - item.getItemProperty(PROPERTY_ID) - .setValue(event.getPropertyId()); - } - })); - - addComponent(grid); - - addComponent(new NativeButton("Change column order", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - grid.setColumnOrder(ImageRenderer.class, - ProgressBarRenderer.class, - ButtonRenderer.class); - } - })); - } - - @Override - protected String getTestDescription() { - return "Tests the functionality of widget-based renderers"; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(13334); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeatures.java deleted file mode 100644 index 12feb17656..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeatures.java +++ /dev/null @@ -1,36 +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.components.grid.basicfeatures; - -import com.vaadin.annotations.Title; -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.EscalatorBasicClientFeaturesWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -@Widgetset(TestingWidgetSet.NAME) -@Title("Escalator basic client features") -public class EscalatorBasicClientFeatures extends UI { - - @Override - public void init(VaadinRequest request) { - setContent(new TestWidgetComponent( - EscalatorBasicClientFeaturesWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java deleted file mode 100644 index 5d74f80e2b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorUpdaterUi.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.tests.components.grid.basicfeatures; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.EscalatorBasicClientFeaturesWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -@Widgetset(TestingWidgetSet.NAME) -public class EscalatorUpdaterUi extends UI { - - @Override - protected void init(VaadinRequest request) { - setContent(new TestWidgetComponent( - EscalatorBasicClientFeaturesWidget.UpdaterLifetimeWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeatures.java deleted file mode 100644 index fe13b77310..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeatures.java +++ /dev/null @@ -1,40 +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.components.grid.basicfeatures; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -/** - * Initializer shell for GridClientBasicFeatures test application - * - * @since - * @author Vaadin Ltd - */ -@Widgetset(TestingWidgetSet.NAME) -public class GridBasicClientFeatures extends UI { - - @Override - protected void init(VaadinRequest request) { - setContent( - new TestWidgetComponent(GridBasicClientFeaturesWidget.class)); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java deleted file mode 100644 index f18b6408b8..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ /dev/null @@ -1,1630 +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.components.grid.basicfeatures; - -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Random; - -import com.vaadin.data.sort.Sort; -import com.vaadin.data.sort.SortOrder; -import com.vaadin.event.SelectionEvent; -import com.vaadin.event.SelectionEvent.SelectionListener; -import com.vaadin.event.SortEvent; -import com.vaadin.event.SortEvent.SortListener; -import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.tests.components.AbstractComponentTest; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.Component; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Notification; -import com.vaadin.ui.Panel; -import com.vaadin.v7.data.Container.Filter; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.Property; -import com.vaadin.v7.data.Property.ValueChangeEvent; -import com.vaadin.v7.data.Property.ValueChangeListener; -import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.event.ItemClickEvent; -import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; -import com.vaadin.v7.shared.ui.grid.GridStaticCellType; -import com.vaadin.v7.shared.ui.grid.HeightMode; -import com.vaadin.v7.ui.Field; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.CellDescriptionGenerator; -import com.vaadin.v7.ui.Grid.CellReference; -import com.vaadin.v7.ui.Grid.CellStyleGenerator; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.ColumnReorderEvent; -import com.vaadin.v7.ui.Grid.ColumnReorderListener; -import com.vaadin.v7.ui.Grid.ColumnResizeEvent; -import com.vaadin.v7.ui.Grid.ColumnResizeListener; -import com.vaadin.v7.ui.Grid.ColumnVisibilityChangeEvent; -import com.vaadin.v7.ui.Grid.ColumnVisibilityChangeListener; -import com.vaadin.v7.ui.Grid.DetailsGenerator; -import com.vaadin.v7.ui.Grid.FooterCell; -import com.vaadin.v7.ui.Grid.HeaderCell; -import com.vaadin.v7.ui.Grid.HeaderRow; -import com.vaadin.v7.ui.Grid.MultiSelectionModel; -import com.vaadin.v7.ui.Grid.RowDescriptionGenerator; -import com.vaadin.v7.ui.Grid.RowReference; -import com.vaadin.v7.ui.Grid.RowStyleGenerator; -import com.vaadin.v7.ui.Grid.SelectionMode; -import com.vaadin.v7.ui.Grid.SelectionModel; -import com.vaadin.v7.ui.renderers.DateRenderer; -import com.vaadin.v7.ui.renderers.HtmlRenderer; -import com.vaadin.v7.ui.renderers.NumberRenderer; - -/** - * Tests the basic features like columns, footers and headers - * - * @since - * @author Vaadin Ltd - */ -public class GridBasicFeatures extends AbstractComponentTest { - - public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4"; - public static final String ROW_STYLE_GENERATOR_NONE = "None"; - public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS = "Row numbers"; - public static final String ROW_STYLE_GENERATOR_EMPTY = "Empty string"; - public static final String ROW_STYLE_GENERATOR_NULL = "Null"; - public static final String CELL_STYLE_GENERATOR_NONE = "None"; - public static final String CELL_STYLE_GENERATOR_PROPERTY_TO_STRING = "Property to string"; - public static final String CELL_STYLE_GENERATOR_SPECIAL = "Special for 1/4 Column 1"; - public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string"; - public static final String CELL_STYLE_GENERATOR_NULL = "Null"; - private static final int MANUALLY_FORMATTED_COLUMNS = 5; - public static final int COLUMNS = 12; - public static final int EDITABLE_COLUMNS = COLUMNS - 1; - public static final int ROWS = 1000; - - private int containerDelay = 0; - - private boolean singleSelectAllowDeselect = true; - - private IndexedContainer ds; - private Grid grid; - private SelectionListener selectionListener = new SelectionListener() { - - @Override - public void select(SelectionEvent event) { - Iterator iter = event.getAdded().iterator(); - Object addedRow = (iter.hasNext() ? iter.next() : "none"); - iter = event.getRemoved().iterator(); - Object removedRow = (iter.hasNext() ? iter.next() : "none"); - log("SelectionEvent: Added " + addedRow + ", Removed " - + removedRow); - } - }; - - private ItemClickListener itemClickListener = new ItemClickListener() { - - @Override - public void itemClick(ItemClickEvent event) { - log("Item " + (event.isDoubleClick() ? "double " : "") + "click on " - + event.getPropertyId() + ", item " + event.getItemId()); - } - }; - - private RowDescriptionGenerator rowDescriptionGenerator = new RowDescriptionGenerator() { - - @Override - public String getDescription(RowReference row) { - return "Row tooltip for row " + row.getItemId(); - } - }; - - private CellDescriptionGenerator cellDescriptionGenerator = new CellDescriptionGenerator() { - - @Override - public String getDescription(CellReference cell) { - if ("Column 0".equals(cell.getPropertyId())) { - return "Cell tooltip for row " + cell.getItemId() - + ", column 0"; - } else { - return null; - } - } - }; - - private ItemClickListener editorOpeningItemClickListener = new ItemClickListener() { - - @Override - public void itemClick(ItemClickEvent event) { - grid.editItem(event.getItemId()); - } - }; - - private ValueChangeListener reactiveValueChanger = new ValueChangeListener() { - @Override - @SuppressWarnings("unchecked") - public void valueChange(ValueChangeEvent event) { - Object id = grid.getEditedItemId(); - grid.getContainerDataSource().getContainerProperty(id, "Column 2") - .setValue("Modified"); - } - }; - - private ColumnReorderListener columnReorderListener = new ColumnReorderListener() { - - @Override - public void columnReorder(ColumnReorderEvent event) { - log("Columns reordered, userOriginated: " - + event.isUserOriginated()); - } - }; - - private ColumnVisibilityChangeListener columnVisibilityListener = new ColumnVisibilityChangeListener() { - @Override - public void columnVisibilityChanged(ColumnVisibilityChangeEvent event) { - log("Visibility changed: "// - + "propertyId: " + event.getColumn().getPropertyId() // - + ", isHidden: " + event.getColumn().isHidden() // - + ", userOriginated: " + event.isUserOriginated()); - } - }; - - private final DetailsGenerator detailedDetailsGenerator = new DetailsGenerator() { - @Override - public Component getDetails(final RowReference rowReference) { - CssLayout cssLayout = new CssLayout(); - cssLayout.setHeight("200px"); - cssLayout.setWidth("100%"); - - Item item = rowReference.getItem(); - for (Object propertyId : item.getItemPropertyIds()) { - Property prop = item.getItemProperty(propertyId); - String string = prop.getValue().toString(); - cssLayout.addComponent(new Label(string)); - } - - final int rowIndex = grid.getContainerDataSource() - .indexOfId(rowReference.getItemId()); - ClickListener clickListener = new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - Notification.show("You clicked on the " - + "button in the details for " + "row " + rowIndex); - } - }; - cssLayout.addComponent(new Button("Press me", clickListener)); - return cssLayout; - } - }; - - private final DetailsGenerator watchingDetailsGenerator = new DetailsGenerator() { - private int id = 0; - - @Override - public Component getDetails(RowReference rowReference) { - return new Label("You are watching item id " - + rowReference.getItemId() + " (" + (id++) + ")"); - } - }; - - private Map detailsMap = new HashMap(); - - private final DetailsGenerator persistingDetailsGenerator = new DetailsGenerator() { - - @Override - public Component getDetails(RowReference rowReference) { - Object itemId = rowReference.getItemId(); - if (!detailsMap.containsKey(itemId)) { - - Panel panel = new Panel(); - panel.setContent(new Label("One")); - detailsMap.put(itemId, panel); - } - return detailsMap.get(itemId); - } - }; - - @Override - @SuppressWarnings("unchecked") - protected Grid constructComponent() { - - // Build data source - ds = new IndexedContainer() { - @Override - public List getItemIds(int startIndex, int numberOfIds) { - log("Requested items " + startIndex + " - " - + (startIndex + numberOfIds)); - if (containerDelay > 0) { - try { - Thread.sleep(containerDelay); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - return super.getItemIds(startIndex, numberOfIds); - } - }; - - { - int col = 0; - for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; col++) { - ds.addContainerProperty(getColumnProperty(col), String.class, - ""); - } - - ds.addContainerProperty(getColumnProperty(col++), Integer.class, - Integer.valueOf(0)); - ds.addContainerProperty(getColumnProperty(col++), Date.class, - new Date()); - ds.addContainerProperty(getColumnProperty(col++), String.class, ""); - - // Random numbers - ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0); - ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0); - - } - - { - Random rand = new Random(); - rand.setSeed(13334); - long timestamp = 0; - for (int row = 0; row < ROWS; row++) { - Item item = ds.addItem(Integer.valueOf(row)); - int col = 0; - for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; col++) { - item.getItemProperty(getColumnProperty(col)) - .setValue("(" + row + ", " + col + ")"); - } - item.getItemProperty(getColumnProperty(1)).setReadOnly(true); - - item.getItemProperty(getColumnProperty(col++)) - .setValue(Integer.valueOf(row)); - item.getItemProperty(getColumnProperty(col++)) - .setValue(new Date(timestamp)); - timestamp += 91250000; // a bit over a day, just to get - // variation - item.getItemProperty(getColumnProperty(col++)) - .setValue("" + row + ""); - - // Random numbers - item.getItemProperty(getColumnProperty(col++)) - .setValue(rand.nextInt()); - // Random between 0 - 5 to test multisorting - item.getItemProperty(getColumnProperty(col++)) - .setValue(rand.nextInt(5)); - } - } - - // Create grid - Grid grid = new Grid(ds); - - { - int col = grid.getContainerDataSource().getContainerPropertyIds() - .size() - MANUALLY_FORMATTED_COLUMNS; - grid.getColumn(getColumnProperty(col++)) - .setRenderer(new NumberRenderer( - new DecimalFormat("0,000.00", DecimalFormatSymbols - .getInstance(new Locale("fi", "FI"))))); - - grid.getColumn(getColumnProperty(col++)).setRenderer( - new DateRenderer(new SimpleDateFormat("dd.MM.yy HH:mm"))); - grid.getColumn(getColumnProperty(col++)) - .setRenderer(new HtmlRenderer()); - grid.getColumn(getColumnProperty(col++)) - .setRenderer(new NumberRenderer()); - grid.getColumn(getColumnProperty(col++)) - .setRenderer(new NumberRenderer()); - } - - // Create footer - grid.appendFooterRow(); - grid.setFooterVisible(false); - - // Add footer values (header values are automatically created) - for (int col = 0; col < COLUMNS; col++) { - grid.getFooterRow(0).getCell(getColumnProperty(col)) - .setText("Footer " + col); - } - - // Set varying column widths - for (int col = 0; col < COLUMNS; col++) { - Column column = grid.getColumn(getColumnProperty(col)); - column.setWidth(100 + col * 50); - column.setHidable(isColumnHidableByDefault(col)); - } - - grid.addSortListener(new SortListener() { - @Override - public void sort(SortEvent event) { - log("SortEvent: isUserOriginated? " + event.isUserOriginated()); - } - }); - - grid.addColumnResizeListener(new ColumnResizeListener() { - @Override - public void columnResize(ColumnResizeEvent event) { - log("ColumnResizeEvent: isUserOriginated? " - + event.isUserOriginated()); - } - }); - - grid.setSelectionMode(SelectionMode.NONE); - - grid.getColumn(getColumnProperty(2)).getEditorField().setReadOnly(true); - grid.getColumn(getColumnProperty(3)).setEditable(false); - - createGridActions(); - - createColumnActions(); - - createPropertyActions(); - - createHeaderActions(); - - createFooterActions(); - - createRowActions(); - - createEditorActions(); - - addHeightActions(); - - addFilterActions(); - - addInternalActions(); - - createDetailsActions(); - - this.grid = grid; - return grid; - } - - protected boolean isColumnHidableByDefault(int col) { - return false; - } - - protected boolean isColumnHiddenByDefault(int col) { - return false; - } - - private void addInternalActions() { - createClickAction("Update column order without updating client", - "Internals", new Command() { - @Override - public void execute(Grid grid, Void value, Object data) { - List columns = grid.getColumns(); - grid.setColumnOrder(columns.get(1).getPropertyId(), - columns.get(0).getPropertyId()); - grid.getUI().getConnectorTracker().markClean(grid); - } - }, null); - } - - private void addFilterActions() { - createBooleanAction("Column 1 starts with \"(23\"", "Filter", false, - new Command() { - Filter filter = new Filter() { - @Override - public boolean passesFilter(Object itemId, Item item) { - return item.getItemProperty("Column 1").getValue() - .toString().startsWith("(23"); - } - - @Override - public boolean appliesToProperty(Object propertyId) { - return propertyId.equals("Column 1"); - } - }; - - @Override - public void execute(Grid grid, Boolean value, Object data) { - if (value) { - ds.addContainerFilter(filter); - } else { - ds.removeContainerFilter(filter); - } - } - }); - - createBooleanAction("Impassable filter", "Filter", false, - new Command() { - Filter filter = new Filter() { - @Override - public boolean passesFilter(Object itemId, Item item) { - return false; - } - - @Override - public boolean appliesToProperty(Object propertyId) { - return true; - } - }; - - @Override - public void execute(Grid c, Boolean value, Object data) { - if (value) { - ds.addContainerFilter(filter); - } else { - ds.removeContainerFilter(filter); - } - } - }); - } - - protected void createGridActions() { - - LinkedHashMap primaryStyleNames = new LinkedHashMap(); - primaryStyleNames.put("v-grid", "v-grid"); - primaryStyleNames.put("v-escalator", "v-escalator"); - primaryStyleNames.put("my-grid", "my-grid"); - - createMultiClickAction("Primary style name", "State", primaryStyleNames, - new Command() { - - @Override - public void execute(Grid grid, String value, Object data) { - grid.setPrimaryStyleName(value); - - } - }, primaryStyleNames.get("v-grid")); - - LinkedHashMap selectionModes = new LinkedHashMap(); - selectionModes.put("single", SelectionMode.SINGLE); - selectionModes.put("multi", SelectionMode.MULTI); - selectionModes.put("none", SelectionMode.NONE); - createSelectAction("Selection mode", "State", selectionModes, "none", - new Command() { - @Override - public void execute(Grid grid, SelectionMode selectionMode, - Object data) { - grid.setSelectionMode(selectionMode); - if (selectionMode == SelectionMode.SINGLE) { - grid.addSelectionListener(selectionListener); - - ((SelectionModel.Single) grid.getSelectionModel()) - .setDeselectAllowed( - singleSelectAllowDeselect); - } else { - grid.removeSelectionListener(selectionListener); - } - } - }); - - LinkedHashMap selectionLimits = new LinkedHashMap(); - selectionLimits.put("2", Integer.valueOf(2)); - selectionLimits.put("1000", Integer.valueOf(1000)); - selectionLimits.put("Integer.MAX_VALUE", - Integer.valueOf(Integer.MAX_VALUE)); - createSelectAction("Selection limit", "State", selectionLimits, "1000", - new Command() { - @Override - public void execute(Grid grid, Integer limit, Object data) { - if (!(grid - .getSelectionModel() instanceof MultiSelectionModel)) { - grid.setSelectionMode(SelectionMode.MULTI); - } - - ((MultiSelectionModel) grid.getSelectionModel()) - .setSelectionLimit(limit.intValue()); - } - }); - - LinkedHashMap> sortableProperties = new LinkedHashMap>(); - for (Object propertyId : ds.getSortableContainerPropertyIds()) { - sortableProperties.put(propertyId + ", ASC", - Sort.by(propertyId).build()); - sortableProperties.put(propertyId + ", DESC", - Sort.by(propertyId, SortDirection.DESCENDING).build()); - } - createSelectAction("Sort by column", "State", sortableProperties, - "Column 9, ascending", new Command>() { - @Override - public void execute(Grid grid, List sortOrder, - Object data) { - grid.setSortOrder(sortOrder); - } - }); - - createBooleanAction("Reverse Grid Columns", "State", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - List ids = new ArrayList(); - ids.addAll(ds.getContainerPropertyIds()); - if (!value) { - c.setColumnOrder(ids.toArray()); - } else { - Object[] idsArray = new Object[ids.size()]; - for (int i = 0; i < ids.size(); ++i) { - idsArray[i] = ids.get((ids.size() - 1) - i); - } - c.setColumnOrder(idsArray); - } - } - }); - - LinkedHashMap cellStyleGenerators = new LinkedHashMap(); - LinkedHashMap rowStyleGenerators = new LinkedHashMap(); - rowStyleGenerators.put(ROW_STYLE_GENERATOR_NONE, null); - rowStyleGenerators.put(ROW_STYLE_GENERATOR_ROW_NUMBERS, - new RowStyleGenerator() { - @Override - public String getStyle(RowReference rowReference) { - return "row" + rowReference.getItemId(); - } - }); - rowStyleGenerators.put(ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4, - new RowStyleGenerator() { - @Override - public String getStyle(RowReference rowReference) { - int rowIndex = ((Integer) rowReference.getItemId()) - .intValue(); - - if (rowIndex % 4 == 0) { - return null; - } else { - return "row" + rowReference.getItemId(); - } - } - }); - rowStyleGenerators.put(ROW_STYLE_GENERATOR_EMPTY, - new RowStyleGenerator() { - - @Override - public String getStyle(RowReference rowReference) { - return ""; - } - }); - rowStyleGenerators.put(ROW_STYLE_GENERATOR_NULL, - new RowStyleGenerator() { - - @Override - public String getStyle(RowReference rowReference) { - return null; - } - }); - cellStyleGenerators.put(CELL_STYLE_GENERATOR_NONE, null); - cellStyleGenerators.put(CELL_STYLE_GENERATOR_PROPERTY_TO_STRING, - new CellStyleGenerator() { - @Override - public String getStyle(CellReference cellReference) { - return cellReference.getPropertyId().toString() - .replace(' ', '-'); - } - }); - cellStyleGenerators.put(CELL_STYLE_GENERATOR_SPECIAL, - new CellStyleGenerator() { - @Override - public String getStyle(CellReference cellReference) { - int rowIndex = ((Integer) cellReference.getItemId()) - .intValue(); - Object propertyId = cellReference.getPropertyId(); - if (rowIndex % 4 == 1) { - return null; - } else if (rowIndex % 4 == 3 - && "Column 1".equals(propertyId)) { - return null; - } - return propertyId.toString().replace(' ', '_'); - } - }); - cellStyleGenerators.put(CELL_STYLE_GENERATOR_EMPTY, - new CellStyleGenerator() { - @Override - public String getStyle(CellReference cellReference) { - return ""; - } - }); - cellStyleGenerators.put(CELL_STYLE_GENERATOR_NULL, - new CellStyleGenerator() { - @Override - public String getStyle(CellReference cellReference) { - return null; - } - }); - - createSelectAction("Row style generator", "State", rowStyleGenerators, - CELL_STYLE_GENERATOR_NONE, - new Command() { - @Override - public void execute(Grid grid, RowStyleGenerator generator, - Object data) { - grid.setRowStyleGenerator(generator); - } - }); - - createSelectAction("Cell style generator", "State", cellStyleGenerators, - CELL_STYLE_GENERATOR_NONE, - new Command() { - @Override - public void execute(Grid grid, CellStyleGenerator generator, - Object data) { - grid.setCellStyleGenerator(generator); - } - }); - - createBooleanAction("Row description generator", "State", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - c.setRowDescriptionGenerator( - value ? rowDescriptionGenerator : null); - } - }); - - createBooleanAction("Cell description generator", "State", false, - new Command() { - @Override - public void execute(Grid c, Boolean value, Object data) { - c.setCellDescriptionGenerator( - value ? cellDescriptionGenerator : null); - } - }); - - LinkedHashMap frozenOptions = new LinkedHashMap(); - for (int i = -1; i <= COLUMNS; i++) { - frozenOptions.put(String.valueOf(i), Integer.valueOf(i)); - } - /* - * This line below is a workaround for a FF24 bug regarding submenu - * handling - it makes the sub menu wider. - */ - frozenOptions.put("-1 for unfreezing selection column", -1); - createSelectAction("Frozen column count", "State", frozenOptions, "0", - new Command() { - @Override - public void execute(Grid c, Integer value, Object data) { - c.setFrozenColumnCount(value.intValue()); - } - }); - - LinkedHashMap containerDelayValues = new LinkedHashMap(); - for (int delay : new int[] { 0, 500, 2000, 10000 }) { - containerDelayValues.put(String.valueOf(delay), - Integer.valueOf(delay)); - } - - createSelectAction("Container delay", "State", containerDelayValues, - "0", new Command() { - @Override - public void execute(Grid grid, Integer delay, Object data) { - containerDelay = delay.intValue(); - } - }); - - createBooleanAction("ItemClickListener", "State", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - if (!value) { - c.removeItemClickListener(itemClickListener); - } else { - c.addItemClickListener(itemClickListener); - } - } - - }); - - createBooleanAction("EditorOpeningItemClickListener", "State", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - if (!value) { - c.removeItemClickListener( - editorOpeningItemClickListener); - } else { - c.addItemClickListener( - editorOpeningItemClickListener); - } - } - - }); - createBooleanAction("ReactiveValueChanger", "State", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - Field targetField = grid.getEditorFieldGroup() - .getField("Column 0"); - if (targetField != null) { - if (!value) { - targetField.removeValueChangeListener( - reactiveValueChanger); - } else { - targetField.addValueChangeListener( - reactiveValueChanger); - } - } - } - - }); - createBooleanAction("ColumnReorderListener", "State", false, - new Command() { - - @Override - public void execute(Grid grid, Boolean value, Object data) { - if (value) { - grid.addColumnReorderListener( - columnReorderListener); - } else { - grid.removeColumnReorderListener( - columnReorderListener); - } - } - }); - createBooleanAction("ColumnVisibilityChangeListener", "State", false, - new Command() { - @Override - public void execute(Grid grid, Boolean value, Object data) { - if (value) { - grid.addColumnVisibilityChangeListener( - columnVisibilityListener); - } else { - grid.removeColumnVisibilityChangeListener( - columnVisibilityListener); - } - } - }); - createBooleanAction("Single select allow deselect", "State", - singleSelectAllowDeselect, new Command() { - @Override - public void execute(Grid c, Boolean value, Object data) { - singleSelectAllowDeselect = value.booleanValue(); - - SelectionModel model = c.getSelectionModel(); - if (model instanceof SelectionModel.Single) { - ((SelectionModel.Single) model).setDeselectAllowed( - singleSelectAllowDeselect); - } - } - }); - createBooleanAction("Column Reordering Allowed", "State", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - c.setColumnReorderingAllowed(value); - } - }); - - createClickAction("Select all", "State", new Command() { - @Override - public void execute(Grid c, String value, Object data) { - SelectionModel selectionModel = c.getSelectionModel(); - if (selectionModel instanceof SelectionModel.Multi) { - ((SelectionModel.Multi) selectionModel).selectAll(); - } - } - }, null); - - createClickAction("Select none", "State", new Command() { - @Override - public void execute(Grid c, String value, Object data) { - SelectionModel selectionModel = c.getSelectionModel(); - if (selectionModel instanceof SelectionModel.Multi) { - ((SelectionModel.Multi) selectionModel).deselectAll(); - } - } - }, null); - } - - protected void createHeaderActions() { - createCategory("Header", null); - - createBooleanAction("Visible", "Header", true, - new Command() { - - @Override - public void execute(Grid grid, Boolean value, Object data) { - grid.setHeaderVisible(value); - } - }); - - LinkedHashMap defaultRows = new LinkedHashMap(); - defaultRows.put("Top", "Top"); - defaultRows.put("Bottom", "Bottom"); - defaultRows.put("Unset", "Unset"); - - createMultiClickAction("Default row", "Header", defaultRows, - new Command() { - - @Override - public void execute(Grid grid, String value, Object data) { - HeaderRow defaultRow = null; - if (value.equals("Top")) { - defaultRow = grid.getHeaderRow(0); - } else if (value.equals("Bottom")) { - defaultRow = grid - .getHeaderRow(grid.getHeaderRowCount() - 1); - } - grid.setDefaultHeaderRow(defaultRow); - } - - }, defaultRows.get("Top")); - - createClickAction("Prepend row", "Header", new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.prependHeaderRow(); - } - - }, null); - createClickAction("Append row", "Header", new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.appendHeaderRow(); - } - - }, null); - - createClickAction("Remove top row", "Header", - new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.removeHeaderRow(0); - } - - }, null); - createClickAction("Remove bottom row", "Header", - new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.removeHeaderRow(grid.getHeaderRowCount() - 1); - } - - }, null); - } - - protected void createFooterActions() { - createCategory("Footer", null); - - createBooleanAction("Visible", "Footer", false, - new Command() { - - @Override - public void execute(Grid grid, Boolean value, Object data) { - grid.setFooterVisible(value); - } - }); - - createClickAction("Prepend row", "Footer", new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.prependFooterRow(); - } - - }, null); - createClickAction("Append row", "Footer", new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.appendFooterRow(); - } - - }, null); - - createClickAction("Remove top row", "Footer", - new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.removeFooterRow(0); - } - - }, null); - createClickAction("Remove bottom row", "Footer", - new Command() { - - @Override - public void execute(Grid grid, Object value, Object data) { - grid.removeFooterRow(grid.getFooterRowCount() - 1); - } - - }, null); - } - - @SuppressWarnings("boxing") - protected void createColumnActions() { - createCategory("Columns", null); - for (int c = 0; c < COLUMNS; c++) { - final int index = c; - createCategory(getColumnProperty(c), "Columns"); - - createClickAction("Add / Remove", getColumnProperty(c), - new Command() { - - boolean wasHidable; - boolean wasHidden; - String wasColumnHidingToggleCaption; - - @Override - public void execute(Grid grid, String value, - Object data) { - String columnProperty = getColumnProperty( - (Integer) data); - Column column = grid.getColumn(columnProperty); - if (column == null) { - column = grid.addColumn(columnProperty); - column.setHidable(wasHidable); - column.setHidden(wasHidden); - column.setHidingToggleCaption( - wasColumnHidingToggleCaption); - } else { - wasHidable = column.isHidable(); - wasHidden = column.isHidden(); - wasColumnHidingToggleCaption = column - .getHidingToggleCaption(); - grid.removeColumn(columnProperty); - } - } - }, null, c); - createClickAction("Move left", getColumnProperty(c), - new Command() { - - @Override - public void execute(Grid grid, String value, - Object data) { - final String columnProperty = getColumnProperty( - (Integer) data); - List cols = grid.getColumns(); - List reordered = new ArrayList(); - boolean addAsLast = false; - for (int i = 0; i < cols.size(); i++) { - Column col = cols.get(i); - if (col.getPropertyId() - .equals(columnProperty)) { - if (i == 0) { - addAsLast = true; - } else { - reordered.add(i - 1, columnProperty); - } - } else { - reordered.add(col.getPropertyId()); - } - } - if (addAsLast) { - reordered.add(columnProperty); - } - grid.setColumnOrder(reordered.toArray()); - } - }, null, c); - - createBooleanAction("Sortable", getColumnProperty(c), true, - new Command() { - - @Override - public void execute(Grid grid, Boolean value, - Object columnIndex) { - Object propertyId = getColumnProperty( - (Integer) columnIndex); - Column column = grid.getColumn(propertyId); - column.setSortable(value); - } - }, c); - - createBooleanAction("Resizable", getColumnProperty(c), true, - new Command() { - - @Override - public void execute(Grid grid, Boolean value, - Object columnIndex) { - Object propertyId = getColumnProperty( - (Integer) columnIndex); - Column column = grid.getColumn(propertyId); - column.setResizable(value); - } - }, c); - - createBooleanAction("Hidable", getColumnProperty(c), - isColumnHidableByDefault(c), new Command() { - @Override - public void execute(Grid c, Boolean hidable, - Object propertyId) { - grid.getColumn(propertyId).setHidable(hidable); - } - }, getColumnProperty(c)); - - createBooleanAction("Hidden", getColumnProperty(c), - isColumnHiddenByDefault(c), new Command() { - @Override - public void execute(Grid c, Boolean hidden, - Object propertyId) { - grid.getColumn(propertyId).setHidden(hidden); - } - }, getColumnProperty(c)); - createClickAction("Change hiding toggle caption", - getColumnProperty(c), new Command() { - int count = 0; - - @Override - public void execute(Grid grid, String value, - Object data) { - final String columnProperty = getColumnProperty( - (Integer) data); - grid.getColumn(columnProperty) - .setHidingToggleCaption(columnProperty - + " caption " + count++); - } - }, null, c); - - createClickAction("Change header caption", getColumnProperty(c), - new Command() { - int count = 0; - - @Override - public void execute(Grid grid, String value, - Object data) { - final String columnProperty = getColumnProperty( - (Integer) data); - grid.getColumn(columnProperty).setHeaderCaption( - columnProperty + " header " + count++); - } - }, null, c); - - createCategory("Column " + c + " Width", getColumnProperty(c)); - - createClickAction("Auto", "Column " + c + " Width", - new Command() { - - @Override - public void execute(Grid grid, Integer value, - Object columnIndex) { - Object propertyId = getColumnProperty( - (Integer) columnIndex); - Column column = grid.getColumn(propertyId); - column.setWidthUndefined(); - } - }, -1, c); - - createClickAction("25.5px", "Column " + c + " Width", - new Command() { - @Override - public void execute(Grid grid, Void value, - Object columnIndex) { - grid.getColumns().get((Integer) columnIndex) - .setWidth(25.5); - } - }, null, c); - - for (int w = 50; w < 300; w += 50) { - createClickAction(w + "px", "Column " + c + " Width", - new Command() { - - @Override - public void execute(Grid grid, Integer value, - Object columnIndex) { - Object propertyId = getColumnProperty( - (Integer) columnIndex); - Column column = grid.getColumn(propertyId); - column.setWidth(value); - } - }, w, c); - } - - LinkedHashMap defaultRows = new LinkedHashMap(); - defaultRows.put("Text Header", GridStaticCellType.TEXT); - defaultRows.put("Html Header ", GridStaticCellType.HTML); - defaultRows.put("Widget Header", GridStaticCellType.WIDGET); - - createMultiClickAction("Header Type", getColumnProperty(c), - defaultRows, new Command() { - - @Override - public void execute(Grid grid, GridStaticCellType value, - Object columnIndex) { - final Object propertyId = getColumnProperty( - (Integer) columnIndex); - final HeaderCell cell = grid.getDefaultHeaderRow() - .getCell(propertyId); - switch (value) { - case TEXT: - cell.setText("Text Header"); - break; - case HTML: - cell.setHtml("HTML Header"); - break; - case WIDGET: - cell.setComponent(new Button("Button Header", - new ClickListener() { - - @Override - public void buttonClick( - ClickEvent event) { - log("Button clicked!"); - } - })); - default: - break; - } - } - - }, c); - - defaultRows = new LinkedHashMap(); - defaultRows.put("Text Footer", GridStaticCellType.TEXT); - defaultRows.put("Html Footer", GridStaticCellType.HTML); - defaultRows.put("Widget Footer", GridStaticCellType.WIDGET); - - createMultiClickAction("Footer Type", getColumnProperty(c), - defaultRows, new Command() { - - @Override - public void execute(Grid grid, GridStaticCellType value, - Object columnIndex) { - final Object propertyId = getColumnProperty( - (Integer) columnIndex); - final FooterCell cell = grid.getFooterRow(0) - .getCell(propertyId); - switch (value) { - case TEXT: - cell.setText("Text Footer"); - break; - case HTML: - cell.setHtml("HTML Footer"); - break; - case WIDGET: - cell.setComponent(new Button("Button Footer", - new ClickListener() { - - @Override - public void buttonClick( - ClickEvent event) { - log("Button clicked!"); - } - })); - default: - break; - } - } - - }, c); - } - - createClickAction("All columns auto width", "Columns", - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - for (Column col : grid.getColumns()) { - col.setWidthUndefined(); - } - - } - }, null); - - createBooleanAction("All columns hidable", "Columns", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - for (Column col : grid.getColumns()) { - col.setHidable(value); - } - - } - }); - createBooleanAction("All columns resizable", "Columns", false, - new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - for (Column col : grid.getColumns()) { - col.setResizable(value); - } - - } - }); - - createClickAction("All columns expanding, Col 0 has max width of 30px", - "Columns", new Command() { - - @Override - public void execute(Grid c, Boolean value, Object data) { - for (Column col : grid.getColumns()) { - col.setWidthUndefined(); - } - grid.getColumns().get(0).setMaximumWidth(30); - } - }, null); - } - - private static String getColumnProperty(int c) { - return "Column " + c; - } - - protected void createPropertyActions() { - createCategory("Properties", null); - - createBooleanAction("Prepend property", "Properties", false, - new Command() { - private final Object propertyId = new Object(); - - @Override - public void execute(Grid c, Boolean enable, Object data) { - if (enable.booleanValue()) { - ds.addContainerProperty(propertyId, String.class, - "property value"); - grid.getColumn(propertyId) - .setHeaderCaption("new property"); - grid.setColumnOrder(propertyId); - } else { - ds.removeContainerProperty(propertyId); - } - } - }, null); - } - - protected void createRowActions() { - createCategory("Body rows", null); - - class NewRowCommand implements Command { - private final int index; - - public NewRowCommand() { - this(0); - } - - public NewRowCommand(int index) { - this.index = index; - } - - @Override - public void execute(Grid c, String value, Object data) { - Item item = ds.addItemAt(index, new Object()); - for (int i = 0; i < COLUMNS; i++) { - Class type = ds.getType(getColumnProperty(i)); - if (String.class.isAssignableFrom(type)) { - Property itemProperty = getProperty(item, i); - itemProperty.setValue("newcell: " + i); - } else if (Integer.class.isAssignableFrom(type)) { - Property itemProperty = getProperty(item, i); - itemProperty.setValue(Integer.valueOf(i)); - } else { - // let the default value be taken implicitly. - } - } - } - - private Property getProperty(Item item, - int i) { - @SuppressWarnings("unchecked") - Property itemProperty = item - .getItemProperty(getColumnProperty(i)); - return itemProperty; - } - } - final NewRowCommand newRowCommand = new NewRowCommand(); - - createClickAction("Add 18 rows", "Body rows", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - for (int i = 0; i < 18; i++) { - newRowCommand.execute(c, value, data); - } - } - }, null); - - createClickAction("Add first row", "Body rows", newRowCommand, null); - - createClickAction("Add third row", "Body rows", new NewRowCommand(2), - null); - - createClickAction("Remove first row", "Body rows", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - Object firstItemId = ds.getIdByIndex(0); - ds.removeItem(firstItemId); - } - }, null); - - createClickAction("Remove 18 first rows", "Body rows", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - for (int i = 0; i < 18; i++) { - Object firstItemId = ds.getIdByIndex(0); - ds.removeItem(firstItemId); - } - } - }, null); - - createClickAction("Modify first row (getItemProperty)", "Body rows", - new Command() { - @SuppressWarnings("unchecked") - @Override - public void execute(Grid c, String value, Object data) { - Object firstItemId = ds.getIdByIndex(0); - Item item = ds.getItem(firstItemId); - for (int i = 0; i < COLUMNS; i++) { - Property property = item - .getItemProperty(getColumnProperty(i)); - if (property.getType().equals(String.class)) { - ((Property) property) - .setValue("modified: " + i); - } - } - } - }, null); - - createClickAction("Modify first row (getContainerProperty)", - "Body rows", new Command() { - @SuppressWarnings("unchecked") - @Override - public void execute(Grid c, String value, Object data) { - Object firstItemId = ds.getIdByIndex(0); - for (Object containerPropertyId : ds - .getContainerPropertyIds()) { - Property property = ds.getContainerProperty( - firstItemId, containerPropertyId); - if (property.getType().equals(String.class)) { - ((Property) property).setValue( - "modified: " + containerPropertyId); - } - } - } - }, null); - - createBooleanAction("Select first row", "Body rows", false, - new Command() { - @Override - public void execute(Grid grid, Boolean select, - Object data) { - final Object firstItemId = grid.getContainerDataSource() - .firstItemId(); - if (select.booleanValue()) { - grid.select(firstItemId); - } else { - grid.deselect(firstItemId); - } - } - }); - - createClickAction("Remove all rows", "Body rows", - new Command() { - @SuppressWarnings("unchecked") - @Override - public void execute(Grid c, String value, Object data) { - ds.removeAllItems(); - } - }, null); - - createClickAction("Remove selected rows", "Body rows", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - // Usually you'd deselect all the rows before removing - // them. It is done this way to test for #19152 - for (Object itemId : c.getSelectedRows()) { - ds.removeItem(itemId); - } - c.select(null); - } - }, null); - } - - protected void createEditorActions() { - createBooleanAction("Enabled", "Editor", false, - new Command() { - @Override - public void execute(Grid c, Boolean value, Object data) { - c.setEditorEnabled(value); - } - }); - - createBooleanAction("Buffered mode", "Editor", true, - new Command() { - @Override - public void execute(Grid c, Boolean value, Object data) { - c.setEditorBuffered(value); - } - }); - - createClickAction("Edit item 5", "Editor", new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.editItem(5); - } - }, null); - - createClickAction("Edit item 100", "Editor", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.editItem(100); - } - }, null); - createClickAction("Save", "Editor", new Command() { - @Override - public void execute(Grid c, String value, Object data) { - try { - c.saveEditor(); - } catch (CommitException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }, null); - createClickAction("Cancel edit", "Editor", new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.cancelEditor(); - } - }, null); - - createClickAction("Change save caption", "Editor", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.setEditorSaveCaption("ǝʌɐS"); - } - }, null); - - createClickAction("Change cancel caption", "Editor", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.setEditorCancelCaption("ʃǝɔuɐↃ"); - } - }, null); - - } - - @SuppressWarnings("boxing") - protected void addHeightActions() { - createCategory("Height by Rows", "Size"); - - createBooleanAction("HeightMode Row", "Size", false, - new Command() { - @Override - public void execute(Grid c, Boolean heightModeByRows, - Object data) { - c.setHeightMode(heightModeByRows ? HeightMode.ROW - : HeightMode.CSS); - } - }, null); - - addActionForHeightByRows(1d / 3d); - addActionForHeightByRows(2d / 3d); - - for (double i = 1; i < 5; i++) { - addActionForHeightByRows(i); - addActionForHeightByRows(i + 1d / 3d); - addActionForHeightByRows(i + 2d / 3d); - } - - Command sizeCommand = new Command() { - @Override - public void execute(Grid grid, String height, Object data) { - grid.setHeight(height); - } - }; - - createCategory("Height", "Size"); - // header 20px + scrollbar 16px = 36px baseline - createClickAction("86px (no drag scroll select)", "Height", sizeCommand, - "86px"); - createClickAction("96px (drag scroll select limit)", "Height", - sizeCommand, "96px"); - createClickAction("106px (drag scroll select enabled)", "Height", - sizeCommand, "106px"); - } - - private void addActionForHeightByRows(final Double i) { - DecimalFormat df = new DecimalFormat("0.00"); - createClickAction(df.format(i) + " rows", "Height by Rows", - new Command() { - @Override - public void execute(Grid c, String value, Object data) { - c.setHeightByRows(i); - } - }, null); - } - - private void createDetailsActions() { - Command swapDetailsGenerator = new Command() { - @Override - public void execute(Grid c, DetailsGenerator generator, - Object data) { - grid.setDetailsGenerator(generator); - } - }; - - Command openOrCloseItemId = new Command() { - @Override - @SuppressWarnings("boxing") - public void execute(Grid g, Boolean visible, Object itemId) { - g.setDetailsVisible(itemId, visible); - } - }; - - createCategory("Generators", "Details"); - createClickAction("NULL", "Generators", swapDetailsGenerator, - DetailsGenerator.NULL); - createClickAction("\"Watching\"", "Generators", swapDetailsGenerator, - watchingDetailsGenerator); - createClickAction("Detailed", "Generators", swapDetailsGenerator, - detailedDetailsGenerator); - createClickAction("Persisting", "Generators", swapDetailsGenerator, - persistingDetailsGenerator); - - createClickAction("- Change Component", "Generators", - new Command() { - @Override - public void execute(Grid c, Void value, Object data) { - for (Object id : detailsMap.keySet()) { - Panel panel = detailsMap.get(id); - Label label = (Label) panel.getContent(); - if (label.getValue().equals("One")) { - panel.setContent(new Label("Two")); - } else { - panel.setContent(new Label("One")); - } - } - } - }, null); - - createClickAction("Toggle firstItemId", "Details", - new Command() { - @Override - public void execute(Grid g, Void value, Object data) { - Object firstItemId = g.getContainerDataSource() - .firstItemId(); - boolean toggle = g.isDetailsVisible(firstItemId); - g.setDetailsVisible(firstItemId, !toggle); - g.setDetailsVisible(firstItemId, toggle); - } - }, null); - - createBooleanAction("Open firstItemId", "Details", false, - openOrCloseItemId, ds.firstItemId()); - - createBooleanAction("Open 1", "Details", false, openOrCloseItemId, - ds.getIdByIndex(1)); - - createBooleanAction("Open 995", "Details", false, openOrCloseItemId, - ds.getIdByIndex(995)); - } - - @Override - protected Integer getTicketNumber() { - return 12829; - } - - @Override - protected Class getTestClass() { - return Grid.class; - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesValo.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesValo.java deleted file mode 100644 index 9b70634f4c..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesValo.java +++ /dev/null @@ -1,28 +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.components.grid.basicfeatures; - -import com.vaadin.annotations.Theme; -import com.vaadin.ui.themes.ValoTheme; - -@Theme(ValoTheme.THEME_NAME) -public class GridBasicFeaturesValo extends GridBasicFeatures { - @Override - @Deprecated - public String getTheme() { - return ValoTheme.THEME_NAME; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSources.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSources.java deleted file mode 100644 index 11ca97c40b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSources.java +++ /dev/null @@ -1,32 +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.components.grid.basicfeatures; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridClientDataSourcesWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -@Widgetset(TestingWidgetSet.NAME) -public class GridClientDataSources extends UI { - - @Override - protected void init(VaadinRequest request) { - setContent(new TestWidgetComponent(GridClientDataSourcesWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridClientHeightByRowOnInit.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridClientHeightByRowOnInit.java deleted file mode 100644 index afbe3fcbbb..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridClientHeightByRowOnInit.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures; - -import com.vaadin.annotations.Theme; -import com.vaadin.annotations.Title; -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridHeightByRowOnInitWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -@Theme("valo") -@Title("Client Grid height by row on init") -@Widgetset(TestingWidgetSet.NAME) -public class GridClientHeightByRowOnInit extends UI { - @Override - protected void init(VaadinRequest request) { - setContent(new TestWidgetComponent(GridHeightByRowOnInitWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java deleted file mode 100644 index e66e0004f2..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRenderer.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.tests.components.grid.basicfeatures; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridDefaultTextRendererWidget; -import com.vaadin.tests.widgetset.server.TestWidgetComponent; -import com.vaadin.ui.UI; - -@Widgetset(TestingWidgetSet.NAME) -public class GridDefaultTextRenderer extends UI { - - @Override - protected void init(VaadinRequest request) { - setContent( - new TestWidgetComponent(GridDefaultTextRendererWidget.class)); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridHeightByRowOnInit.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridHeightByRowOnInit.java deleted file mode 100644 index bd43bc5065..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridHeightByRowOnInit.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.tests.components.grid.basicfeatures; - -import com.vaadin.annotations.Theme; -import com.vaadin.annotations.Title; -import com.vaadin.server.VaadinRequest; -import com.vaadin.ui.UI; -import com.vaadin.ui.themes.ValoTheme; -import com.vaadin.v7.data.Container; -import com.vaadin.v7.shared.ui.grid.HeightMode; -import com.vaadin.v7.ui.Grid; - -@Title("Server Grid height by row on init") -@Theme(ValoTheme.THEME_NAME) -public class GridHeightByRowOnInit extends UI { - - private static final String PROPERTY = "Property"; - - @Override - protected void init(VaadinRequest request) { - final Grid grid = new Grid(); - Container.Indexed container = grid.getContainerDataSource(); - container.addContainerProperty(PROPERTY, String.class, ""); - - container.addItem("A").getItemProperty(PROPERTY).setValue("A"); - container.addItem("B").getItemProperty(PROPERTY).setValue("B"); - container.addItem("C").getItemProperty(PROPERTY).setValue("C"); - container.addItem("D").getItemProperty(PROPERTY).setValue("D"); - container.addItem("E").getItemProperty(PROPERTY).setValue("E"); - - grid.setHeightMode(HeightMode.ROW); - grid.setHeightByRows(5); - - setContent(grid); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridSidebarFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridSidebarFeatures.java deleted file mode 100644 index 59ad62d756..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridSidebarFeatures.java +++ /dev/null @@ -1,24 +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.components.grid.basicfeatures; - -public class GridSidebarFeatures extends GridBasicFeatures { - - @Override - protected boolean isColumnHidableByDefault(int col) { - return true; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.java deleted file mode 100644 index 6e3559b9aa..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicators.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.tests.components.grid.basicfeatures; - -import com.vaadin.data.sort.Sort; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.v7.data.Container; -import com.vaadin.v7.data.Item; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -public class GridSortingIndicators extends AbstractTestUI { - - private static int FOO_MIN = 4; - private static int BAR_MULTIPLIER = 3; - private static int BAZ_MAX = 132; - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(createContainer()); - addComponent(grid); - grid.sort(Sort.by("foo").then("bar", SortDirection.DESCENDING) - .then("baz")); - - addComponent(new Button("Reverse sorting", new Button.ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - grid.sort(Sort.by("baz", SortDirection.DESCENDING).then("bar") - .then("foo", SortDirection.DESCENDING)); - } - })); - } - - private Container.Indexed createContainer() { - IndexedContainer container = new IndexedContainer(); - container.addContainerProperty("foo", Integer.class, 0); - container.addContainerProperty("bar", Integer.class, 0); - container.addContainerProperty("baz", Integer.class, 0); - for (int i = 0; i < 10; ++i) { - Item item = container.getItem(container.addItem()); - item.getItemProperty("foo").setValue(FOO_MIN + i); - item.getItemProperty("baz").setValue(BAZ_MAX - i); - item.getItemProperty("bar").setValue(BAR_MULTIPLIER * i); - } - return container; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/server/GridClearContainer.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/server/GridClearContainer.java deleted file mode 100644 index a8c7cb0428..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/server/GridClearContainer.java +++ /dev/null @@ -1,72 +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.components.grid.basicfeatures.server; - -import com.vaadin.annotations.Theme; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.data.util.IndexedContainer; -import com.vaadin.v7.ui.Grid; - -/** - * Tests that removing and adding rows doesn't cause an infinite loop in the - * browser. - * - * @author Vaadin Ltd - */ -@Theme("valo") -public class GridClearContainer extends AbstractTestUIWithLog { - - private IndexedContainer ic; - - @Override - protected void setup(VaadinRequest request) { - final Grid grid = new Grid(); - ic = new IndexedContainer(); - ic.addContainerProperty("Col 1", String.class, "default"); - ic.addItem("Row 1"); - ic.addItem("Row 2"); - grid.setContainerDataSource(ic); - - Button b = new Button("Clear and re-add", new ClickListener() { - - @SuppressWarnings("unchecked") - @Override - public void buttonClick(ClickEvent event) { - ic.removeAllItems(); - ic.addItem("Row 3").getItemProperty("Col 1") - .setValue("Updated value 1"); - ic.addItem("Row 4").getItemProperty("Col 1") - .setValue("Updated value 2"); - } - }); - addComponent(b); - addComponent(grid); - } - - @Override - protected String getTestDescription() { - return "Tests that removing and adding rows doesn't cause an infinite loop in the browser."; - } - - @Override - protected Integer getTicketNumber() { - return 16747; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java b/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java deleted file mode 100644 index 7c09385cb0..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridDeclarativeBasicFeatures.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.tests.components.grid.declarative; - -import com.vaadin.annotations.Theme; -import com.vaadin.tests.components.DeclarativeTestUI; -import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; - -@SuppressWarnings("serial") -@Theme("valo") -@DeclarativeUI("GridBasicFeatures.html") -public class GridDeclarativeBasicFeatures extends DeclarativeTestUI { - -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridDeclarativeMultiSelect.java b/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridDeclarativeMultiSelect.java deleted file mode 100644 index a84b446f6d..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridDeclarativeMultiSelect.java +++ /dev/null @@ -1,26 +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.components.grid.declarative; - -import com.vaadin.annotations.Theme; -import com.vaadin.tests.components.DeclarativeTestUI; -import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; - -@Theme("valo") -@SuppressWarnings("serial") -@DeclarativeUI("GridMultiSelect.html") -public class GridDeclarativeMultiSelect extends DeclarativeTestUI { -} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridItemEditor.java b/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridItemEditor.java deleted file mode 100644 index cbddcd9e59..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/declarative/GridItemEditor.java +++ /dev/null @@ -1,23 +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.components.grid.declarative; - -import com.vaadin.tests.components.DeclarativeTestUI; -import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; - -@DeclarativeUI("GridItemEditor.html") -public class GridItemEditor extends DeclarativeTestUI { -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java deleted file mode 100644 index d4fccfc494..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java +++ /dev/null @@ -1,824 +0,0 @@ -package com.vaadin.tests.widgetset.client.grid; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.Duration; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.TableCellElement; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HTML; -import com.vaadin.v7.client.widget.escalator.EscalatorUpdater; -import com.vaadin.v7.client.widget.escalator.FlyweightCell; -import com.vaadin.v7.client.widget.escalator.Row; -import com.vaadin.v7.client.widget.escalator.RowContainer; -import com.vaadin.v7.client.widget.escalator.RowContainer.BodyRowContainer; -import com.vaadin.v7.client.widget.escalator.Spacer; -import com.vaadin.v7.client.widget.escalator.SpacerUpdater; -import com.vaadin.v7.client.widgets.Escalator; -import com.vaadin.v7.shared.ui.grid.ScrollDestination; - -public class EscalatorBasicClientFeaturesWidget - extends PureGWTTestApplication { - - public static class LogWidget extends Composite { - - private static final int MAX_LOG = 9; - - private final HTML html = new HTML(); - private final List logs = new ArrayList(); - private Escalator escalator; - - public LogWidget() { - initWidget(html); - getElement().setId("log"); - } - - public void setEscalator(Escalator escalator) { - this.escalator = escalator; - } - - public void updateDebugLabel() { - int headers = escalator.getHeader().getRowCount(); - int bodys = escalator.getBody().getRowCount(); - int footers = escalator.getFooter().getRowCount(); - int columns = escalator.getColumnConfiguration().getColumnCount(); - - while (logs.size() > MAX_LOG) { - logs.remove(0); - } - - String logString = "
"; - for (String log : logs) { - logString += log + "
"; - } - - html.setHTML("Columns: " + columns + "
" + // - "Header rows: " + headers + "
" + // - "Body rows: " + bodys + "
" + // - "Footer rows: " + footers + "
" + // - logString); - } - - public void log(String string) { - logs.add((Duration.currentTimeMillis() % 10000) + ": " + string); - } - } - - public static class UpdaterLifetimeWidget - extends EscalatorBasicClientFeaturesWidget { - - private final EscalatorUpdater debugUpdater = new EscalatorUpdater() { - @Override - public void preAttach(Row row, - Iterable cellsToAttach) { - log("preAttach", cellsToAttach); - } - - @Override - public void postAttach(Row row, - Iterable attachedCells) { - log("postAttach", attachedCells); - } - - @Override - public void update(Row row, Iterable cellsToUpdate) { - log("update", cellsToUpdate); - } - - @Override - public void preDetach(Row row, - Iterable cellsToDetach) { - log("preDetach", cellsToDetach); - } - - @Override - public void postDetach(Row row, - Iterable detachedCells) { - log("postDetach", detachedCells); - } - - private void log(String methodName, Iterable cells) { - if (!cells.iterator().hasNext()) { - return; - } - - TableCellElement cellElement = cells.iterator().next() - .getElement(); - boolean isAttached = cellElement.getParentElement() != null - && cellElement.getParentElement() - .getParentElement() != null; - logWidget.log( - methodName + ": elementIsAttached == " + isAttached); - } - }; - - public UpdaterLifetimeWidget() { - super(); - escalator.getHeader().setEscalatorUpdater(debugUpdater); - escalator.getBody().setEscalatorUpdater(debugUpdater); - escalator.getFooter().setEscalatorUpdater(debugUpdater); - } - } - - private static final String COLUMNS_AND_ROWS_MENU = "Columns and Rows"; - private static final String GENERAL_MENU = "General"; - private static final String FEATURES_MENU = "Features"; - - private static abstract class TestEscalatorUpdater - implements EscalatorUpdater { - - @Override - public void preAttach(Row row, Iterable cellsToAttach) { - // noop - } - - @Override - public void postAttach(Row row, Iterable attachedCells) { - // noop - } - - @Override - public void preDetach(Row row, Iterable cellsToDetach) { - // noop - } - - @Override - public void postDetach(Row row, Iterable detachedCells) { - // noop - } - } - - private class Data { - private int columnCounter = 0; - private int rowCounter = 0; - private final List columns = new ArrayList(); - private final List rows = new ArrayList(); - - @SuppressWarnings("boxing") - public void insertRows(final int offset, final int amount) { - final List newRows = new ArrayList(); - for (int i = 0; i < amount; i++) { - newRows.add(rowCounter++); - } - rows.addAll(offset, newRows); - } - - @SuppressWarnings("boxing") - public void insertColumns(final int offset, final int amount) { - final List newColumns = new ArrayList(); - for (int i = 0; i < amount; i++) { - newColumns.add(columnCounter++); - } - columns.addAll(offset, newColumns); - } - - public EscalatorUpdater createHeaderUpdater() { - return new TestEscalatorUpdater() { - @Override - public void update(final Row row, - final Iterable cellsToUpdate) { - for (final FlyweightCell cell : cellsToUpdate) { - final Integer columnName = columns - .get(cell.getColumn()); - cell.getElement().setInnerText("Header " + columnName); - - if (colspan == Colspan.NORMAL) { - if (cell.getColumn() % 2 == 0) { - cell.setColSpan(2); - } - } else if (colspan == Colspan.CRAZY) { - if (cell.getColumn() % 3 == 0) { - cell.setColSpan(2); - } - } - } - } - }; - } - - public EscalatorUpdater createFooterUpdater() { - return new TestEscalatorUpdater() { - @Override - public void update(final Row row, - final Iterable cellsToUpdate) { - for (final FlyweightCell cell : cellsToUpdate) { - final Integer columnName = columns - .get(cell.getColumn()); - cell.getElement().setInnerText("Footer " + columnName); - - if (colspan == Colspan.NORMAL) { - if (cell.getColumn() % 2 == 0) { - cell.setColSpan(2); - } - } else if (colspan == Colspan.CRAZY) { - if (cell.getColumn() % 3 == 1) { - cell.setColSpan(2); - } - } - } - } - }; - } - - public EscalatorUpdater createBodyUpdater() { - return new TestEscalatorUpdater() { - - public void renderCell(final FlyweightCell cell) { - final Integer columnName = columns.get(cell.getColumn()); - final Integer rowName = rows.get(cell.getRow()); - String cellInfo = columnName + "," + rowName; - - if (cell.getColumn() > 0) { - cell.getElement().setInnerText("Cell: " + cellInfo); - } else { - cell.getElement().setInnerText( - "Row " + cell.getRow() + ": " + cellInfo); - } - - if (colspan == Colspan.NORMAL) { - if (cell.getColumn() % 2 == 0) { - cell.setColSpan(2); - } - } else if (colspan == Colspan.CRAZY) { - if (cell.getColumn() % 3 == cell.getRow() % 3) { - cell.setColSpan(2); - } - } - } - - @Override - public void update(final Row row, - final Iterable cellsToUpdate) { - for (final FlyweightCell cell : cellsToUpdate) { - renderCell(cell); - } - } - }; - } - - public void removeRows(final int offset, final int amount) { - for (int i = 0; i < amount; i++) { - rows.remove(offset); - } - } - - public void removeColumns(final int offset, final int amount) { - for (int i = 0; i < amount; i++) { - columns.remove(offset); - } - } - } - - protected final Escalator escalator; - private final Data data = new Data(); - - private enum Colspan { - NONE, NORMAL, CRAZY; - } - - private Colspan colspan = Colspan.NONE; - protected final LogWidget logWidget = new LogWidget(); - - public EscalatorBasicClientFeaturesWidget() { - super(new EscalatorProxy()); - escalator = getTestedWidget(); - logWidget.setEscalator(escalator); - - ((EscalatorProxy) escalator).setLogWidget(logWidget); - addNorth(logWidget, 200); - - final RowContainer header = escalator.getHeader(); - header.setEscalatorUpdater(data.createHeaderUpdater()); - - final RowContainer footer = escalator.getFooter(); - footer.setEscalatorUpdater(data.createFooterUpdater()); - - escalator.getBody().setEscalatorUpdater(data.createBodyUpdater()); - - setWidth("500px"); - setHeight("500px"); - - escalator.getElement().getStyle().setZIndex(0); - addNorth(escalator, 500); - - createGeneralMenu(); - createColumnMenu(); - createHeaderRowsMenu(); - createBodyRowsMenu(); - createFooterRowsMenu(); - createColumnsAndRowsMenu(); - createFrozenMenu(); - createColspanMenu(); - createSpacerMenu(); - } - - private void createFrozenMenu() { - String[] menupath = { FEATURES_MENU, "Frozen columns" }; - addMenuCommand("Freeze 1 column", new ScheduledCommand() { - @Override - public void execute() { - escalator.getColumnConfiguration().setFrozenColumnCount(1); - } - }, menupath); - addMenuCommand("Freeze 0 columns", new ScheduledCommand() { - @Override - public void execute() { - escalator.getColumnConfiguration().setFrozenColumnCount(0); - } - }, menupath); - } - - private void createColspanMenu() { - String[] menupath = { FEATURES_MENU, "Column spanning" }; - addMenuCommand("Apply normal colspan", new ScheduledCommand() { - @Override - public void execute() { - colspan = Colspan.NORMAL; - refreshEscalator(); - } - }, menupath); - addMenuCommand("Apply crazy colspan", new ScheduledCommand() { - @Override - public void execute() { - colspan = Colspan.CRAZY; - refreshEscalator(); - } - }, menupath); - addMenuCommand("Apply no colspan", new ScheduledCommand() { - @Override - public void execute() { - colspan = Colspan.NONE; - refreshEscalator(); - } - }, menupath); - } - - private void createColumnsAndRowsMenu() { - String[] menupath = { COLUMNS_AND_ROWS_MENU }; - addMenuCommand("Add one of each row", new ScheduledCommand() { - @Override - public void execute() { - insertRows(escalator.getHeader(), 0, 1); - insertRows(escalator.getBody(), 0, 1); - insertRows(escalator.getFooter(), 0, 1); - } - }, menupath); - addMenuCommand("Remove one of each row", new ScheduledCommand() { - @Override - public void execute() { - removeRows(escalator.getHeader(), 0, 1); - removeRows(escalator.getBody(), 0, 1); - removeRows(escalator.getFooter(), 0, 1); - } - }, menupath); - } - - private void createGeneralMenu() { - String[] menupath = { GENERAL_MENU }; - - addMenuCommand("Detach Escalator", new ScheduledCommand() { - @Override - public void execute() { - escalator.removeFromParent(); - } - }, menupath); - - addMenuCommand("Attach Escalator", new ScheduledCommand() { - @Override - public void execute() { - if (!escalator.isAttached()) { - addNorth(escalator, 500); - } - } - }, menupath); - - addMenuCommand("Clear (columns, then rows)", new ScheduledCommand() { - @Override - public void execute() { - resetColRow(); - } - }, menupath); - addMenuCommand("Clear (rows, then columns)", new ScheduledCommand() { - @Override - public void execute() { - resetRowCol(); - } - }, menupath); - addMenuCommand("Populate Escalator (columns, then rows)", - new ScheduledCommand() { - @Override - public void execute() { - resetColRow(); - insertColumns(0, 10); - insertRows(escalator.getHeader(), 0, 1); - insertRows(escalator.getBody(), 0, 100); - insertRows(escalator.getFooter(), 0, 1); - } - }, menupath); - addMenuCommand("Populate Escalator (rows, then columns)", - new ScheduledCommand() { - @Override - public void execute() { - resetColRow(); - insertRows(escalator.getHeader(), 0, 1); - insertRows(escalator.getBody(), 0, 100); - insertRows(escalator.getFooter(), 0, 1); - insertColumns(0, 10); - } - }, menupath); - - createSizeMenu(); - } - - private void createSizeMenu() { - String[] menupath = new String[] { "General", "Size" }; - - addSizeMenuItem(null, "height", menupath); - addSizeMenuItem("200px", "height", menupath); - addSizeMenuItem("400px", "height", menupath); - addSizeMenuItem(null, "width", menupath); - addSizeMenuItem("200px", "width", menupath); - addSizeMenuItem("400px", "width", menupath); - } - - private void addSizeMenuItem(final String size, final String direction, - String[] menupath) { - final String title = (size != null ? size : "undefined"); - addMenuCommand(title + " " + direction, new ScheduledCommand() { - @Override - public void execute() { - if (direction.equals("height")) { - escalator.setHeight(size); - } else { - escalator.setWidth(size); - } - } - }, menupath); - } - - private void createColumnMenu() { - String[] menupath = { COLUMNS_AND_ROWS_MENU, "Columns" }; - addMenuCommand("Add one column to beginning", new ScheduledCommand() { - @Override - public void execute() { - insertColumns(0, 1); - } - }, menupath); - addMenuCommand("Add one column to end", new ScheduledCommand() { - @Override - public void execute() { - insertColumns( - escalator.getColumnConfiguration().getColumnCount(), 1); - } - }, menupath); - addMenuCommand("Add ten columns", new ScheduledCommand() { - @Override - public void execute() { - insertColumns(0, 10); - } - }, menupath); - addMenuCommand("Remove one column from beginning", - new ScheduledCommand() { - @Override - public void execute() { - removeColumns(0, 1); - } - }, menupath); - addMenuCommand("Remove one column from end", new ScheduledCommand() { - @Override - public void execute() { - removeColumns( - escalator.getColumnConfiguration().getColumnCount() - 1, - 1); - } - }, menupath); - - addMenuCommand("Refresh first column", new ScheduledCommand() { - @Override - public void execute() { - escalator.getColumnConfiguration().refreshColumns(0, 1); - } - }, menupath); - - addMenuCommand("Resize first column to max width", - new ScheduledCommand() { - @Override - public void execute() { - escalator.getColumnConfiguration().setColumnWidth(0, - -1); - } - }, menupath); - - addMenuCommand("Resize first column to 100 px", new ScheduledCommand() { - @Override - public void execute() { - escalator.getColumnConfiguration().setColumnWidth(0, 100); - } - }, menupath); - } - - private void createHeaderRowsMenu() { - String[] menupath = { COLUMNS_AND_ROWS_MENU, "Header Rows" }; - createRowsMenu(escalator.getHeader(), menupath); - } - - private void createFooterRowsMenu() { - String[] menupath = { COLUMNS_AND_ROWS_MENU, "Footer Rows" }; - createRowsMenu(escalator.getFooter(), menupath); - } - - private void createBodyRowsMenu() { - String[] menupath = { COLUMNS_AND_ROWS_MENU, "Body Rows" }; - createRowsMenu(escalator.getBody(), menupath); - - addMenuCommand("Add 5 rows to top", new ScheduledCommand() { - @Override - public void execute() { - insertRows(escalator.getBody(), 0, 5); - } - }, menupath); - addMenuCommand("Add 50 rows to top", new ScheduledCommand() { - @Override - public void execute() { - insertRows(escalator.getBody(), 0, 50); - } - }, menupath); - addMenuCommand("Remove 5 rows from bottom", new ScheduledCommand() { - @Override - public void execute() { - removeRows(escalator.getBody(), - escalator.getBody().getRowCount() - 5, 5); - } - }, menupath); - addMenuCommand("Remove 50 rows from bottom", new ScheduledCommand() { - @Override - public void execute() { - removeRows(escalator.getBody(), - escalator.getBody().getRowCount() - 50, 50); - } - }, menupath); - addMenuCommand("Remove 50 rows from almost bottom", - new ScheduledCommand() { - @Override - public void execute() { - removeRows(escalator.getBody(), - escalator.getBody().getRowCount() - 60, 50); - } - }, menupath); - addMenuCommand("Remove all, insert 30 and scroll 40px", - new ScheduledCommand() { - @Override - public void execute() { - removeRows(escalator.getBody(), 0, - escalator.getBody().getRowCount()); - insertRows(escalator.getBody(), 0, 30); - escalator.setScrollTop(40); - } - }, menupath); - - String[] scrollToRowMenuPath = new String[menupath.length + 1]; - System.arraycopy(menupath, 0, scrollToRowMenuPath, 0, menupath.length); - scrollToRowMenuPath[scrollToRowMenuPath.length - 1] = "Scroll to..."; - for (int i = 0; i < 100; i += 25) { - final int rowIndex = i; - addMenuCommand("Row " + i, new ScheduledCommand() { - @Override - public void execute() { - escalator.scrollToRow(rowIndex, ScrollDestination.ANY, 0); - } - }, scrollToRowMenuPath); - } - - addMenuCommand("Set 20px default height", new ScheduledCommand() { - @Override - public void execute() { - escalator.getBody().setDefaultRowHeight(20); - } - }, menupath); - } - - private void createRowsMenu(final RowContainer container, - String[] menupath) { - addMenuCommand("Add one row to beginning", new ScheduledCommand() { - @Override - public void execute() { - int offset = 0; - int number = 1; - insertRows(container, offset, number); - } - }, menupath); - addMenuCommand("Add one row to end", new ScheduledCommand() { - @Override - public void execute() { - int offset = container.getRowCount(); - int number = 1; - insertRows(container, offset, number); - } - }, menupath); - addMenuCommand("Remove one row from beginning", new ScheduledCommand() { - @Override - public void execute() { - int offset = 0; - int number = 1; - removeRows(container, offset, number); - } - }, menupath); - addMenuCommand("Remove one row from end", new ScheduledCommand() { - @Override - public void execute() { - int offset = container.getRowCount() - 1; - int number = 1; - removeRows(container, offset, number); - } - }, menupath); - addMenuCommand("Remove all rows", new ScheduledCommand() { - @Override - public void execute() { - if (container.getRowCount() > 0) { - removeRows(container, 0, container.getRowCount()); - } - } - }, menupath); - } - - private void createSpacerMenu() { - String[] menupath = { "Features", "Spacers" }; - - addMenuCommand("Swap Spacer Updater", new ScheduledCommand() { - private final SpacerUpdater CUSTOM = new SpacerUpdater() { - @Override - public void destroy(Spacer spacer) { - spacer.getElement().setInnerText(""); - } - - @Override - public void init(Spacer spacer) { - spacer.getElement() - .setInnerText("Spacer for row " + spacer.getRow()); - } - }; - - @Override - public void execute() { - BodyRowContainer body = escalator.getBody(); - - if (SpacerUpdater.NULL.equals(body.getSpacerUpdater())) { - body.setSpacerUpdater(CUSTOM); - } else { - body.setSpacerUpdater(SpacerUpdater.NULL); - } - } - }, menupath); - - addMenuCommand("Focusable Updater", new ScheduledCommand() { - @Override - public void execute() { - escalator.getBody().setSpacerUpdater(new SpacerUpdater() { - @Override - public void init(Spacer spacer) { - spacer.getElement().appendChild(DOM.createInputText()); - } - - @Override - public void destroy(Spacer spacer) { - spacer.getElement().removeAllChildren(); - } - }); - } - }, menupath); - - createSpacersMenuForRow(-1, menupath); - createSpacersMenuForRow(1, menupath); - createSpacersMenuForRow(50, menupath); - createSpacersMenuForRow(99, menupath); - } - - private void createSpacersMenuForRow(final int rowIndex, - String[] menupath) { - menupath = new String[] { menupath[0], menupath[1], "Row " + rowIndex }; - addMenuCommand("Set 100px", new ScheduledCommand() { - @Override - public void execute() { - escalator.getBody().setSpacer(rowIndex, 100); - } - }, menupath); - addMenuCommand("Set 50px", new ScheduledCommand() { - @Override - public void execute() { - escalator.getBody().setSpacer(rowIndex, 50); - } - }, menupath); - addMenuCommand("Remove", new ScheduledCommand() { - @Override - public void execute() { - escalator.getBody().setSpacer(rowIndex, -1); - } - }, menupath); - addMenuCommand("Scroll here (ANY, 0)", new ScheduledCommand() { - @Override - public void execute() { - escalator.scrollToSpacer(rowIndex, ScrollDestination.ANY, 0); - } - }, menupath); - addMenuCommand("Scroll here row+spacer below (ANY, 0)", - new ScheduledCommand() { - @Override - public void execute() { - escalator.scrollToRowAndSpacer(rowIndex, - ScrollDestination.ANY, 0); - } - }, menupath); - } - - private void insertRows(final RowContainer container, int offset, - int number) { - if (container == escalator.getBody()) { - data.insertRows(offset, number); - escalator.getBody().insertRows(offset, number); - } else { - container.insertRows(offset, number); - } - } - - private void removeRows(final RowContainer container, int offset, - int number) { - if (container == escalator.getBody()) { - data.removeRows(offset, number); - escalator.getBody().removeRows(offset, number); - } else { - container.removeRows(offset, number); - } - } - - private void insertColumns(final int offset, final int number) { - data.insertColumns(offset, number); - escalator.getColumnConfiguration().insertColumns(offset, number); - } - - private void removeColumns(final int offset, final int number) { - data.removeColumns(offset, number); - escalator.getColumnConfiguration().removeColumns(offset, number); - } - - private void resetColRow() { - if (escalator.getColumnConfiguration().getColumnCount() > 0) { - removeColumns(0, - escalator.getColumnConfiguration().getColumnCount()); - } - if (escalator.getFooter().getRowCount() > 0) { - removeRows(escalator.getFooter(), 0, - escalator.getFooter().getRowCount()); - } - - if (escalator.getBody().getRowCount() > 0) { - removeRows(escalator.getBody(), 0, - escalator.getBody().getRowCount()); - } - - if (escalator.getHeader().getRowCount() > 0) { - removeRows(escalator.getHeader(), 0, - escalator.getHeader().getRowCount()); - } - } - - private void resetRowCol() { - if (escalator.getFooter().getRowCount() > 0) { - removeRows(escalator.getFooter(), 0, - escalator.getFooter().getRowCount()); - } - - if (escalator.getBody().getRowCount() > 0) { - removeRows(escalator.getBody(), 0, - escalator.getBody().getRowCount()); - } - - if (escalator.getHeader().getRowCount() > 0) { - removeRows(escalator.getHeader(), 0, - escalator.getHeader().getRowCount()); - } - - if (escalator.getColumnConfiguration().getColumnCount() > 0) { - removeColumns(0, - escalator.getColumnConfiguration().getColumnCount()); - } - } - - private void refreshEscalator() { - if (escalator.getHeader().getRowCount() > 0) { - escalator.getHeader().refreshRows(0, - escalator.getHeader().getRowCount()); - } - - if (escalator.getBody().getRowCount() > 0) { - escalator.getBody().refreshRows(0, - escalator.getBody().getRowCount()); - } - - if (escalator.getFooter().getRowCount() > 0) { - escalator.getFooter().refreshRows(0, - escalator.getFooter().getRowCount()); - } - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java deleted file mode 100644 index f8c459efd8..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java +++ /dev/null @@ -1,259 +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.grid; - -import java.util.Map; - -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.TableRowElement; -import com.google.gwt.dom.client.TableSectionElement; -import com.vaadin.tests.widgetset.client.grid.EscalatorBasicClientFeaturesWidget.LogWidget; -import com.vaadin.v7.client.widget.escalator.Cell; -import com.vaadin.v7.client.widget.escalator.ColumnConfiguration; -import com.vaadin.v7.client.widget.escalator.EscalatorUpdater; -import com.vaadin.v7.client.widget.escalator.RowContainer; -import com.vaadin.v7.client.widget.escalator.RowContainer.BodyRowContainer; -import com.vaadin.v7.client.widget.escalator.SpacerUpdater; -import com.vaadin.v7.client.widgets.Escalator; - -public class EscalatorProxy extends Escalator { - private class ColumnConfigurationProxy implements ColumnConfiguration { - private ColumnConfiguration columnConfiguration; - - public ColumnConfigurationProxy( - ColumnConfiguration columnConfiguration) { - this.columnConfiguration = columnConfiguration; - } - - @Override - public void removeColumns(int index, int numberOfColumns) - throws IndexOutOfBoundsException, IllegalArgumentException { - columnConfiguration.removeColumns(index, numberOfColumns); - logWidget.log("removeColumns " + index + ", " + numberOfColumns); - logWidget.updateDebugLabel(); - } - - @Override - public void insertColumns(int index, int numberOfColumns) - throws IndexOutOfBoundsException, IllegalArgumentException { - columnConfiguration.insertColumns(index, numberOfColumns); - logWidget.log("insertColumns " + index + ", " + numberOfColumns); - logWidget.updateDebugLabel(); - } - - @Override - public int getColumnCount() { - return columnConfiguration.getColumnCount(); - } - - @Override - public void setFrozenColumnCount(int count) - throws IllegalArgumentException { - columnConfiguration.setFrozenColumnCount(count); - } - - @Override - public int getFrozenColumnCount() { - return columnConfiguration.getFrozenColumnCount(); - } - - @Override - public void setColumnWidth(int index, double px) - throws IllegalArgumentException { - columnConfiguration.setColumnWidth(index, px); - } - - @Override - public double getColumnWidth(int index) - throws IllegalArgumentException { - return columnConfiguration.getColumnWidth(index); - } - - @Override - public double getColumnWidthActual(int index) - throws IllegalArgumentException { - return columnConfiguration.getColumnWidthActual(index); - } - - @Override - public void refreshColumns(int index, int numberOfColumns) - throws IndexOutOfBoundsException, IllegalArgumentException { - columnConfiguration.refreshColumns(index, numberOfColumns); - } - - @Override - public void setColumnWidths(Map indexWidthMap) - throws IllegalArgumentException { - columnConfiguration.setColumnWidths(indexWidthMap); - } - } - - private class BodyRowContainerProxy extends RowContainerProxy - implements BodyRowContainer { - private BodyRowContainer rowContainer; - - public BodyRowContainerProxy(BodyRowContainer rowContainer) { - super(rowContainer); - this.rowContainer = rowContainer; - } - - @Override - public void setSpacer(int rowIndex, double height) - throws IllegalArgumentException { - rowContainer.setSpacer(rowIndex, height); - } - - @Override - public void setSpacerUpdater(SpacerUpdater spacerUpdater) - throws IllegalArgumentException { - rowContainer.setSpacerUpdater(spacerUpdater); - } - - @Override - public SpacerUpdater getSpacerUpdater() { - return rowContainer.getSpacerUpdater(); - } - } - - private class RowContainerProxy implements RowContainer { - private final RowContainer rowContainer; - - public RowContainerProxy(RowContainer rowContainer) { - this.rowContainer = rowContainer; - } - - @Override - public EscalatorUpdater getEscalatorUpdater() { - return rowContainer.getEscalatorUpdater(); - } - - @Override - public void setEscalatorUpdater(EscalatorUpdater escalatorUpdater) - throws IllegalArgumentException { - rowContainer.setEscalatorUpdater(escalatorUpdater); - } - - @Override - public void removeRows(int index, int numberOfRows) - throws IndexOutOfBoundsException, IllegalArgumentException { - rowContainer.removeRows(index, numberOfRows); - logWidget.log(rowContainer.getClass().getSimpleName() - + " removeRows " + index + ", " + numberOfRows); - logWidget.updateDebugLabel(); - } - - @Override - public void insertRows(int index, int numberOfRows) - throws IndexOutOfBoundsException, IllegalArgumentException { - rowContainer.insertRows(index, numberOfRows); - logWidget.log(rowContainer.getClass().getSimpleName() - + " insertRows " + index + ", " + numberOfRows); - logWidget.updateDebugLabel(); - } - - @Override - public void refreshRows(int index, int numberOfRows) - throws IndexOutOfBoundsException, IllegalArgumentException { - rowContainer.refreshRows(index, numberOfRows); - logWidget.log(rowContainer.getClass().getSimpleName() - + " refreshRows " + index + ", " + numberOfRows); - } - - @Override - public int getRowCount() { - return rowContainer.getRowCount(); - } - - @Override - public void setDefaultRowHeight(double px) - throws IllegalArgumentException { - rowContainer.setDefaultRowHeight(px); - } - - @Override - public double getDefaultRowHeight() { - return rowContainer.getDefaultRowHeight(); - } - - @Override - public Cell getCell(Element element) { - return rowContainer.getCell(element); - } - - @Override - public TableRowElement getRowElement(int index) - throws IndexOutOfBoundsException, IllegalStateException { - return rowContainer.getRowElement(index); - } - - @Override - public TableSectionElement getElement() { - return rowContainer.getElement(); - } - - } - - private RowContainer headerProxy = null; - private BodyRowContainer bodyProxy = null; - private RowContainer footerProxy = null; - private ColumnConfiguration columnProxy = null; - private LogWidget logWidget; - - @Override - public RowContainer getHeader() { - if (headerProxy == null) { - headerProxy = new RowContainerProxy(super.getHeader()); - } - return headerProxy; - } - - @Override - public RowContainer getFooter() { - if (footerProxy == null) { - footerProxy = new RowContainerProxy(super.getFooter()); - } - return footerProxy; - } - - @Override - public BodyRowContainer getBody() { - if (bodyProxy == null) { - bodyProxy = new BodyRowContainerProxy(super.getBody()); - } - return bodyProxy; - } - - @Override - public ColumnConfiguration getColumnConfiguration() { - if (columnProxy == null) { - columnProxy = new ColumnConfigurationProxy( - super.getColumnConfiguration()); - } - return columnProxy; - } - - public void setLogWidget(LogWidget logWidget) { - this.logWidget = logWidget; - logWidget.updateDebugLabel(); - } - - @Override - public void setScrollTop(double scrollTop) { - logWidget.log("setScrollTop " + scrollTop); - logWidget.updateDebugLabel(); - super.setScrollTop(scrollTop); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java deleted file mode 100644 index 7edba039e1..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridBasicClientFeaturesWidget.java +++ /dev/null @@ -1,1634 +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.grid; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.logging.Logger; - -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.ContextMenuEvent; -import com.google.gwt.event.dom.client.ContextMenuHandler; -import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.FlowPanel; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.MenuItem; -import com.google.gwt.user.client.ui.MenuItemSeparator; -import com.google.gwt.user.client.ui.TextBox; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.client.data.DataSource; -import com.vaadin.client.data.DataSource.RowHandle; -import com.vaadin.client.ui.VLabel; -import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget.Data; -import com.vaadin.v7.client.renderers.DateRenderer; -import com.vaadin.v7.client.renderers.HtmlRenderer; -import com.vaadin.v7.client.renderers.NumberRenderer; -import com.vaadin.v7.client.renderers.Renderer; -import com.vaadin.v7.client.renderers.TextRenderer; -import com.vaadin.v7.client.widget.grid.CellReference; -import com.vaadin.v7.client.widget.grid.CellStyleGenerator; -import com.vaadin.v7.client.widget.grid.DetailsGenerator; -import com.vaadin.v7.client.widget.grid.EditorHandler; -import com.vaadin.v7.client.widget.grid.EventCellReference; -import com.vaadin.v7.client.widget.grid.RendererCellReference; -import com.vaadin.v7.client.widget.grid.RowReference; -import com.vaadin.v7.client.widget.grid.RowStyleGenerator; -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widget.grid.datasources.ListSorter; -import com.vaadin.v7.client.widget.grid.events.BodyKeyDownHandler; -import com.vaadin.v7.client.widget.grid.events.BodyKeyPressHandler; -import com.vaadin.v7.client.widget.grid.events.BodyKeyUpHandler; -import com.vaadin.v7.client.widget.grid.events.ColumnReorderEvent; -import com.vaadin.v7.client.widget.grid.events.ColumnReorderHandler; -import com.vaadin.v7.client.widget.grid.events.ColumnVisibilityChangeEvent; -import com.vaadin.v7.client.widget.grid.events.ColumnVisibilityChangeHandler; -import com.vaadin.v7.client.widget.grid.events.FooterKeyDownHandler; -import com.vaadin.v7.client.widget.grid.events.FooterKeyPressHandler; -import com.vaadin.v7.client.widget.grid.events.FooterKeyUpHandler; -import com.vaadin.v7.client.widget.grid.events.GridKeyDownEvent; -import com.vaadin.v7.client.widget.grid.events.GridKeyPressEvent; -import com.vaadin.v7.client.widget.grid.events.GridKeyUpEvent; -import com.vaadin.v7.client.widget.grid.events.HeaderKeyDownHandler; -import com.vaadin.v7.client.widget.grid.events.HeaderKeyPressHandler; -import com.vaadin.v7.client.widget.grid.events.HeaderKeyUpHandler; -import com.vaadin.v7.client.widget.grid.events.ScrollEvent; -import com.vaadin.v7.client.widget.grid.events.ScrollHandler; -import com.vaadin.v7.client.widget.grid.selection.SelectionModel; -import com.vaadin.v7.client.widget.grid.selection.SelectionModel.None; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.Column; -import com.vaadin.v7.client.widgets.Grid.FooterRow; -import com.vaadin.v7.client.widgets.Grid.HeaderRow; -import com.vaadin.v7.client.widgets.Grid.SelectionMode; -import com.vaadin.v7.shared.ui.grid.ScrollDestination; - -/** - * Grid basic client features test application. - * - * @since - * @author Vaadin Ltd - */ -public class GridBasicClientFeaturesWidget - extends PureGWTTestApplication>> { - public static final String ROW_STYLE_GENERATOR_NONE = "None"; - public static final String ROW_STYLE_GENERATOR_ROW_INDEX = "Row numbers"; - public static final String ROW_STYLE_GENERATOR_EVERY_THIRD = "Every third"; - - public static final String CELL_STYLE_GENERATOR_NONE = "None"; - public static final String CELL_STYLE_GENERATOR_SIMPLE = "Simple"; - public static final String CELL_STYLE_GENERATOR_COL_INDEX = "Column index"; - - public static enum Renderers { - TEXT_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER; - } - - private class TestEditorHandler implements EditorHandler> { - - private Map, TextBox> widgets = new HashMap, TextBox>(); - - private Label log = new Label(); - - { - log.addStyleName("grid-editor-log"); - addSouth(log, 20); - } - - @Override - public void bind(EditorRequest> request) { - List rowData = ds.getRow(request.getRowIndex()); - - boolean hasSelectionColumn = !(grid - .getSelectionModel() instanceof None); - for (int i = 0; i < rowData.size(); i++) { - int columnIndex = hasSelectionColumn ? i + 1 : i; - getWidget(columnIndex).setText(rowData.get(i).value.toString()); - } - request.success(); - } - - @Override - public void cancel(EditorRequest> request) { - log.setText("Row " + request.getRowIndex() + " edit cancelled"); - } - - @Override - public void save(EditorRequest> request) { - if (secondEditorError) { - request.failure( - "Syntethic fail of editor in column 2. " - + "This message is so long that it doesn't fit into its box", - Collections.>> singleton( - grid.getColumn(2))); - return; - } - try { - log.setText("Row " + request.getRowIndex() + " edit committed"); - List rowData = ds.getRow(request.getRowIndex()); - - int i = 0; - for (; i < COLUMNS - MANUALLY_FORMATTED_COLUMNS; i++) { - rowData.get(i).value = getWidget(i).getText(); - } - - rowData.get(i).value = Integer - .valueOf(getWidget(i++).getText()); - rowData.get(i).value = new Date(getWidget(i++).getText()); - rowData.get(i).value = getWidget(i++).getText(); - rowData.get(i).value = Integer - .valueOf(getWidget(i++).getText()); - rowData.get(i).value = Integer - .valueOf(getWidget(i++).getText()); - - // notify data source of changes - ds.asList().set(request.getRowIndex(), rowData); - request.success(); - } catch (Exception e) { - Logger.getLogger(getClass().getName()).warning(e.toString()); - request.failure(null, null); - } - } - - @Override - public TextBox getWidget(Grid.Column> column) { - if (grid.getColumns().indexOf(column) == 0 - && !(grid.getSelectionModel() instanceof None)) { - return null; - } - - TextBox w = widgets.get(column); - if (w == null) { - w = new TextBox(); - w.getElement().getStyle().setMargin(0, Unit.PX); - widgets.put(column, w); - } - return w; - } - - private TextBox getWidget(int i) { - return getWidget(grid.getColumn(i)); - } - } - - private static final int MANUALLY_FORMATTED_COLUMNS = 5; - public static final int COLUMNS = 12; - public static final int ROWS = 1000; - - private final Grid> grid; - private List> data; - private final ListDataSource> ds; - private final ListSorter> sorter; - - private boolean secondEditorError = false; - - /** - * Our basic data object - */ - public final static class Data { - Object value; - } - - /** - * @since - * @return - */ - private List> createData(int rowCount) { - List> dataList = new ArrayList>(); - Random rand = new Random(); - rand.setSeed(13334); - long timestamp = 0; - for (int row = 0; row < rowCount; row++) { - - List datarow = createDataRow(COLUMNS); - dataList.add(datarow); - Data d; - - int col = 0; - for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) { - d = datarow.get(col); - d.value = "(" + row + ", " + col + ")"; - } - - d = datarow.get(col++); - d.value = Integer.valueOf(row); - - d = datarow.get(col++); - d.value = new Date(timestamp); - timestamp += 91250000; // a bit over a day, just to get - // variation - - d = datarow.get(col++); - d.value = "" + row + ""; - - d = datarow.get(col++); - d.value = Integer.valueOf(rand.nextInt()); - - d = datarow.get(col++); - d.value = Integer.valueOf(rand.nextInt(5)); - } - - return dataList; - } - - /** - * Convenience method for creating a list of Data objects to be used as a - * Row in the data source - * - * @param cols - * number of columns (items) to include in the row - * @return - */ - private List createDataRow(int cols) { - List list = new ArrayList(cols); - for (int i = 0; i < cols; ++i) { - list.add(new Data()); - } - return list; - } - - @SuppressWarnings("unchecked") - public GridBasicClientFeaturesWidget() { - super(new Grid>()); - - // Initialize data source - data = createData(ROWS); - - ds = new ListDataSource>(data); - grid = getTestedWidget(); - grid.getElement().setId("testComponent"); - grid.setDataSource(ds); - grid.addSelectAllHandler(ds.getSelectAllHandler()); - grid.setSelectionMode(SelectionMode.NONE); - grid.setEditorHandler(new TestEditorHandler()); - - sorter = new ListSorter>(grid); - - // Create a bunch of grid columns - - // Data source layout: - // text (String) * (COLUMNS - MANUALLY_FORMATTED_COLUMNS + 1) | - // rownumber (Integer) | some date (Date) | row number as HTML (String) - // | random value (Integer) - - int col = 0; - - // Text times COLUMNS - MANUALLY_FORMATTED_COLUMNS - for (col = 0; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) { - - final int c = col; - - Grid.Column> column = new Grid.Column>( - createRenderer(Renderers.TEXT_RENDERER)) { - @Override - public String getValue(List row) { - return (String) row.get(c).value; - } - }; - - column.setWidth(50 + c * 25); - column.setHeaderCaption("Header (0," + c + ")"); - - grid.addColumn(column); - } - - // Integer row number - { - final int c = col++; - Grid.Column> column = new Grid.Column>( - createRenderer(Renderers.NUMBER_RENDERER)) { - @Override - public Integer getValue(List row) { - return (Integer) row.get(c).value; - } - }; - grid.addColumn(column); - column.setHeaderCaption("Header (0," + c + ")"); - } - - // Some date - { - final int c = col++; - Grid.Column> column = new Grid.Column>( - createRenderer(Renderers.DATE_RENDERER)) { - @Override - public Date getValue(List row) { - return (Date) row.get(c).value; - } - }; - grid.addColumn(column); - column.setHeaderCaption("Header (0," + c + ")"); - } - - // Row number as a HTML string - { - final int c = col++; - Grid.Column> column = new Grid.Column>( - createRenderer(Renderers.HTML_RENDERER)) { - @Override - public String getValue(List row) { - return (String) row.get(c).value; - } - }; - grid.addColumn(column); - column.setHeaderCaption("Header (0," + c + ")"); - } - - // Random integer value - { - final int c = col++; - Grid.Column> column = new Grid.Column>( - createRenderer(Renderers.NUMBER_RENDERER)) { - @Override - public Integer getValue(List row) { - return (Integer) row.get(c).value; - } - }; - grid.addColumn(column); - column.setHeaderCaption("Header (0," + c + ")"); - } - - // Random integer value between 0 and 5 - { - final int c = col++; - Grid.Column> column = new Grid.Column>( - createRenderer(Renderers.NUMBER_RENDERER)) { - @Override - public Integer getValue(List row) { - return (Integer) row.get(c).value; - } - }; - grid.addColumn(column); - column.setHeaderCaption("Header (0," + c + ")"); - } - - grid.getColumn(3).setEditable(false); - - HeaderRow row = grid.getDefaultHeaderRow(); - for (int i = 0; i < col; ++i) { - String caption = "Header (0," + i + ")"; - Grid.Column column = grid.getColumn(i); - // Lets use some different cell types - if (i % 3 == 0) { - // No-op - } else if (i % 2 == 0) { - row.getCell(column).setHtml("" + caption + ""); - } else { - row.getCell(column).setWidget(new HTML(caption)); - } - } - ++headerCounter; - - // - // Populate the menu - // - - createStateMenu(); - createColumnsMenu(); - createHeaderMenu(); - createFooterMenu(); - createEditorMenu(); - createInternalsMenu(); - createDataSourceMenu(); - createDetailsMenu(); - createSidebarMenu(); - - grid.getElement().getStyle().setZIndex(0); - - // - // Composite wrapping for grid. - // - boolean isComposite = Window.Location.getParameter("composite") != null; - if (isComposite) { - addNorth(new Composite() { - { - initWidget(grid); - } - }, 400); - } else { - addNorth(grid, 400); - } - - createKeyHandlers(); - } - - private void createInternalsMenu() { - String[] listenersPath = { "Component", "Internals", "Listeners" }; - final Label label = new Label(); - addSouth(label, 20); - - addMenuCommand("Add scroll listener", new ScheduledCommand() { - private HandlerRegistration scrollHandler = null; - - @Override - public void execute() { - if (scrollHandler != null) { - return; - } - scrollHandler = grid.addScrollHandler(new ScrollHandler() { - @Override - public void onScroll(ScrollEvent event) { - @SuppressWarnings("hiding") - final Grid grid = (Grid) event.getSource(); - label.setText("scrollTop: " + grid.getScrollTop() - + ", scrollLeft: " + grid.getScrollLeft()); - } - }); - } - }, listenersPath); - addMenuCommand("Add ColumnReorder listener", new ScheduledCommand() { - private HandlerRegistration columnReorderHandler = null; - - @Override - public void execute() { - if (columnReorderHandler != null) { - return; - } - final Label columnOrderLabel = new Label(); - columnOrderLabel.getElement().setId("columnreorder"); - addLineEnd(columnOrderLabel, 300); - columnReorderHandler = grid.addColumnReorderHandler( - new ColumnReorderHandler>() { - - private int eventIndex = 0; - - @Override - public void onColumnReorder( - ColumnReorderEvent> event) { - columnOrderLabel.getElement().setAttribute( - "columns", "" + (++eventIndex)); - } - }); - } - }, listenersPath); - addMenuCommand("Add Column Visibility Change listener", - new ScheduledCommand() { - private HandlerRegistration columnVisibilityHandler = null; - - @Override - public void execute() { - if (columnVisibilityHandler != null) { - return; - } - final Label columnOrderLabel = new Label(); - columnOrderLabel.getElement().setId("columnvisibility"); - addLineEnd(columnOrderLabel, 250); - ColumnVisibilityChangeHandler handler = new ColumnVisibilityChangeHandler>() { - - private int eventIndex = 0; - - @Override - public void onVisibilityChange( - ColumnVisibilityChangeEvent> event) { - columnOrderLabel.getElement().setAttribute( - "counter", "" + (++eventIndex)); - columnOrderLabel.getElement().setAttribute( - "useroriginated", (Boolean.toString( - event.isUserOriginated()))); - columnOrderLabel.getElement().setAttribute( - "ishidden", - (Boolean.toString(event.isHidden()))); - columnOrderLabel.getElement().setAttribute( - "columnindex", "" + grid.getColumns() - .indexOf(event.getColumn())); - } - }; - - columnVisibilityHandler = grid - .addColumnVisibilityChangeHandler(handler); - } - }, listenersPath); - addMenuCommand("Add context menu listener", new ScheduledCommand() { - - HandlerRegistration handler = null; - ContextMenuHandler contextMenuHandler = new ContextMenuHandler() { - - @Override - public void onContextMenu(ContextMenuEvent event) { - event.preventDefault(); - final String location; - EventCellReference cellRef = grid.getEventCell(); - if (cellRef.isHeader()) { - location = "header"; - } else if (cellRef.isBody()) { - location = "body"; - } else if (cellRef.isFooter()) { - location = "footer"; - } else { - location = "somewhere"; - } - - getLogger().info("Prevented opening a context menu in grid " - + location); - } - }; - - @Override - public void execute() { - if (handler != null) { - grid.unsinkEvents(Event.ONCONTEXTMENU); - handler.removeHandler(); - } else { - grid.sinkEvents(Event.ONCONTEXTMENU); - handler = grid.addDomHandler(contextMenuHandler, - ContextMenuEvent.getType()); - } - } - - }, listenersPath); - } - - private void createStateMenu() { - String[] selectionModePath = { "Component", "State", "Selection mode" }; - String[] primaryStyleNamePath = { "Component", "State", - "Primary Stylename" }; - String[] rowStyleGeneratorNamePath = { "Component", "State", - "Row style generator" }; - String[] cellStyleGeneratorNamePath = { "Component", "State", - "Cell style generator" }; - - addMenuCommand("multi", new ScheduledCommand() { - @Override - public void execute() { - grid.setSelectionMode(SelectionMode.MULTI); - } - }, selectionModePath); - - addMenuCommand("single", new ScheduledCommand() { - @Override - public void execute() { - grid.setSelectionMode(SelectionMode.SINGLE); - } - }, selectionModePath); - - addMenuCommand("single (no deselect)", new ScheduledCommand() { - @Override - public void execute() { - grid.setSelectionMode(SelectionMode.SINGLE); - ((SelectionModel.Single) grid.getSelectionModel()) - .setDeselectAllowed(false); - } - }, selectionModePath); - - addMenuCommand("none", new ScheduledCommand() { - @Override - public void execute() { - grid.setSelectionMode(SelectionMode.NONE); - } - }, selectionModePath); - - addMenuCommand("v-grid", new ScheduledCommand() { - @Override - public void execute() { - grid.setStylePrimaryName("v-grid"); - - } - }, primaryStyleNamePath); - - addMenuCommand("v-escalator", new ScheduledCommand() { - @Override - public void execute() { - grid.setStylePrimaryName("v-escalator"); - - } - }, primaryStyleNamePath); - - addMenuCommand("v-custom-style", new ScheduledCommand() { - @Override - public void execute() { - grid.setStylePrimaryName("v-custom-style"); - - } - }, primaryStyleNamePath); - - addMenuCommand("Edit and refresh Row 0", new ScheduledCommand() { - @Override - public void execute() { - DataSource> ds = grid.getDataSource(); - RowHandle> rowHandle = ds.getHandle(ds.getRow(0)); - rowHandle.getRow().get(0).value = "Foo"; - rowHandle.updateRow(); - } - }, "Component", "State"); - - addMenuCommand("Delayed edit of Row 0", new ScheduledCommand() { - @Override - public void execute() { - DataSource> ds = grid.getDataSource(); - final RowHandle> rowHandle = ds - .getHandle(ds.getRow(0)); - - new Timer() { - @Override - public void run() { - rowHandle.getRow().get(0).value = "Bar"; - rowHandle.updateRow(); - } - - }.schedule(5000); - } - }, "Component", "State"); - - addMenuCommand(ROW_STYLE_GENERATOR_NONE, new ScheduledCommand() { - @Override - public void execute() { - grid.setRowStyleGenerator(null); - } - }, rowStyleGeneratorNamePath); - - addMenuCommand(ROW_STYLE_GENERATOR_EVERY_THIRD, new ScheduledCommand() { - @Override - public void execute() { - grid.setRowStyleGenerator(new RowStyleGenerator>() { - - @Override - public String getStyle( - RowReference> rowReference) { - if (rowReference.getRowIndex() % 3 == 0) { - return "third"; - } else { - // First manual col is integer - Integer value = (Integer) rowReference.getRow().get( - COLUMNS - MANUALLY_FORMATTED_COLUMNS).value; - return value.toString(); - } - } - }); - - } - }, rowStyleGeneratorNamePath); - - addMenuCommand(ROW_STYLE_GENERATOR_ROW_INDEX, new ScheduledCommand() { - @Override - public void execute() { - grid.setRowStyleGenerator(new RowStyleGenerator>() { - - @Override - public String getStyle( - RowReference> rowReference) { - return Integer.toString(rowReference.getRowIndex()); - } - }); - - } - }, rowStyleGeneratorNamePath); - - addMenuCommand(CELL_STYLE_GENERATOR_NONE, new ScheduledCommand() { - @Override - public void execute() { - grid.setCellStyleGenerator(null); - } - }, cellStyleGeneratorNamePath); - - addMenuCommand(CELL_STYLE_GENERATOR_SIMPLE, new ScheduledCommand() { - @Override - public void execute() { - grid.setCellStyleGenerator( - new CellStyleGenerator>() { - - @Override - public String getStyle( - CellReference> cellReference) { - Grid.Column> column = cellReference - .getColumn(); - if (column == grid.getColumn(2)) { - return "two"; - } else if (column == grid.getColumn( - COLUMNS - MANUALLY_FORMATTED_COLUMNS)) { - // First manual col is integer - Integer value = (Integer) column - .getValue(cellReference.getRow()); - return value.toString(); - - } else { - return null; - } - } - }); - } - }, cellStyleGeneratorNamePath); - addMenuCommand(CELL_STYLE_GENERATOR_COL_INDEX, new ScheduledCommand() { - @Override - public void execute() { - grid.setCellStyleGenerator( - new CellStyleGenerator>() { - - @Override - public String getStyle( - CellReference> cellReference) { - return cellReference.getRowIndex() + "_" - + grid.getColumns().indexOf( - cellReference.getColumn()); - } - }); - } - }, cellStyleGeneratorNamePath); - - for (int i = -1; i <= COLUMNS; i++) { - final int index = i; - // Including dummy "columns" prefix because TB fails to select item - // if it's too narrow - addMenuCommand(Integer.toString(index) + " columns", - new ScheduledCommand() { - @Override - public void execute() { - grid.setFrozenColumnCount(index); - } - }, "Component", "State", "Frozen column count"); - } - - addMenuCommand("Enabled", new ScheduledCommand() { - - @Override - public void execute() { - grid.setEnabled(!grid.isEnabled()); - } - }, "Component", "State"); - addMenuCommand("Reverse grid columns", new ScheduledCommand() { - - @Override - public void execute() { - List columns = new ArrayList(grid.getColumns()); - Collections.reverse(columns); - grid.setColumnOrder( - columns.toArray(new Column[columns.size()])); - } - }, "Component", "State"); - addMenuCommand("Column Reordering", new ScheduledCommand() { - - @Override - public void execute() { - grid.setColumnReorderingAllowed( - !grid.isColumnReorderingAllowed()); - } - }, "Component", "State"); - addMenuCommand("250px", new ScheduledCommand() { - - @Override - public void execute() { - grid.setWidth("250px"); - } - }, "Component", "State", "Width"); - addMenuCommand("500px", new ScheduledCommand() { - - @Override - public void execute() { - grid.setWidth("500px"); - } - }, "Component", "State", "Width"); - addMenuCommand("750px", new ScheduledCommand() { - - @Override - public void execute() { - grid.setWidth("750px"); - } - }, "Component", "State", "Width"); - addMenuCommand("1000px", new ScheduledCommand() { - - @Override - public void execute() { - grid.setWidth("1000px"); - } - }, "Component", "State", "Width"); - - createScrollToRowMenu(); - } - - private void createScrollToRowMenu() { - String[] menupath = new String[] { "Component", "State", "Scroll to...", - null }; - - for (int i = 0; i < ROWS; i += 100) { - menupath[3] = "Row " + i + "..."; - for (final ScrollDestination scrollDestination : ScrollDestination - .values()) { - final int row = i; - addMenuCommand("Destination " + scrollDestination, - new ScheduledCommand() { - @Override - public void execute() { - grid.scrollToRow(row, scrollDestination); - } - }, menupath); - } - } - - int i = ROWS - 1; - menupath[3] = "Row " + i + "..."; - for (final ScrollDestination scrollDestination : ScrollDestination - .values()) { - final int row = i; - addMenuCommand("Destination " + scrollDestination, - new ScheduledCommand() { - @Override - public void execute() { - grid.scrollToRow(row, scrollDestination); - } - }, menupath); - } - - } - - private void createColumnsMenu() { - - for (int i = 0; i < COLUMNS; i++) { - final int index = i; - final Grid.Column> column = grid.getColumn(index); - addMenuCommand("Sortable", new ScheduledCommand() { - @Override - public void execute() { - column.setSortable(!column.isSortable()); - } - }, "Component", "Columns", "Column " + i); - addMenuCommand("Hidden", new ScheduledCommand() { - @Override - public void execute() { - column.setHidden(!column.isHidden()); - } - }, "Component", "Columns", "Column " + i); - addMenuCommand("Hidable", new ScheduledCommand() { - @Override - public void execute() { - column.setHidable(!column.isHidable()); - } - }, "Component", "Columns", "Column " + i); - addMenuCommand("auto", new ScheduledCommand() { - @Override - public void execute() { - column.setWidth(-1); - } - }, "Component", "Columns", "Column " + i, "Width"); - addMenuCommand("50px", new ScheduledCommand() { - @Override - public void execute() { - column.setWidth(50); - } - }, "Component", "Columns", "Column " + i, "Width"); - addMenuCommand("200px", new ScheduledCommand() { - @Override - public void execute() { - column.setWidth(200); - } - }, "Component", "Columns", "Column " + i, "Width"); - - // Header types - addMenuCommand("Text Header", new ScheduledCommand() { - @Override - public void execute() { - column.setHeaderCaption("Text Header"); - } - }, "Component", "Columns", "Column " + i, "Header Type"); - addMenuCommand("HTML Header", new ScheduledCommand() { - @Override - public void execute() { - grid.getHeaderRow(0).getCell(column) - .setHtml("HTML Header"); - } - }, "Component", "Columns", "Column " + i, "Header Type"); - addMenuCommand("Widget Header", new ScheduledCommand() { - @Override - public void execute() { - final Button button = new Button("Button Header"); - button.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - button.setText("Clicked"); - } - }); - grid.getHeaderRow(0).getCell(column).setWidget(button); - } - }, "Component", "Columns", "Column " + i, "Header Type"); - - // Footer types - addMenuCommand("Text Footer", new ScheduledCommand() { - @Override - public void execute() { - grid.getFooterRow(0).getCell(column).setText("Text Footer"); - } - }, "Component", "Columns", "Column " + i, "Footer Type"); - addMenuCommand("HTML Footer", new ScheduledCommand() { - @Override - public void execute() { - grid.getFooterRow(0).getCell(column) - .setHtml("HTML Footer"); - } - }, "Component", "Columns", "Column " + i, "Footer Type"); - addMenuCommand("Widget Footer", new ScheduledCommand() { - @Override - public void execute() { - final Button button = new Button("Button Footer"); - button.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - button.setText("Clicked"); - } - }); - grid.getFooterRow(0).getCell(column).setWidget(button); - } - }, "Component", "Columns", "Column " + i, "Footer Type"); - - // Renderer throwing exceptions - addMenuCommand("Broken renderer", new ScheduledCommand() { - @Override - public void execute() { - final Renderer originalRenderer = (Renderer) column - .getRenderer(); - - column.setRenderer(new Renderer() { - @Override - public void render(RendererCellReference cell, - Object data) { - if (cell.getRowIndex() == cell.getColumnIndex()) { - throw new RuntimeException("I'm broken"); - } - originalRenderer.render(cell, data); - } - }); - } - }, "Component", "Columns", "Column " + i); - addMenuCommand("Move column left", new ScheduledCommand() { - - @SuppressWarnings("unchecked") - @Override - public void execute() { - List>> cols = grid.getColumns(); - ArrayList reordered = new ArrayList(cols); - final int index = cols.indexOf(column); - if (index == 0) { - Column> col = reordered.remove(0); - reordered.add(col); - } else { - Column> col = reordered.remove(index); - reordered.add(index - 1, col); - } - grid.setColumnOrder( - reordered.toArray(new Column[reordered.size()])); - } - }, "Component", "Columns", "Column " + i); - } - } - - private int headerCounter = 0; - private int footerCounter = 0; - - private void setHeaderTexts(HeaderRow row) { - for (int i = 0; i < COLUMNS; ++i) { - String caption = "Header (" + headerCounter + "," + i + ")"; - - // Lets use some different cell types - if (i % 3 == 0) { - row.getCell(grid.getColumn(i)).setText(caption); - } else if (i % 2 == 0) { - row.getCell(grid.getColumn(i)) - .setHtml("" + caption + ""); - } else { - row.getCell(grid.getColumn(i)).setWidget(new HTML(caption)); - } - } - headerCounter++; - } - - private void setFooterTexts(FooterRow row) { - for (int i = 0; i < COLUMNS; ++i) { - String caption = "Footer (" + footerCounter + "," + i + ")"; - - // Lets use some different cell types - if (i % 3 == 0) { - row.getCell(grid.getColumn(i)).setText(caption); - } else if (i % 2 == 0) { - row.getCell(grid.getColumn(i)) - .setHtml("" + caption + ""); - } else { - row.getCell(grid.getColumn(i)).setWidget(new HTML(caption)); - } - } - footerCounter++; - } - - private void createHeaderMenu() { - final String[] menuPath = { "Component", "Header" }; - - addMenuCommand("Visible", new ScheduledCommand() { - @Override - public void execute() { - grid.setHeaderVisible(!grid.isHeaderVisible()); - } - }, menuPath); - - addMenuCommand("Top", new ScheduledCommand() { - @Override - public void execute() { - grid.setDefaultHeaderRow(grid.getHeaderRow(0)); - } - }, "Component", "Header", "Default row"); - addMenuCommand("Bottom", new ScheduledCommand() { - @Override - public void execute() { - grid.setDefaultHeaderRow( - grid.getHeaderRow(grid.getHeaderRowCount() - 1)); - } - }, "Component", "Header", "Default row"); - addMenuCommand("Unset", new ScheduledCommand() { - @Override - public void execute() { - grid.setDefaultHeaderRow(null); - } - }, "Component", "Header", "Default row"); - - addMenuCommand("Prepend row", new ScheduledCommand() { - @Override - public void execute() { - configureHeaderRow(grid.prependHeaderRow()); - } - }, menuPath); - addMenuCommand("Append row", new ScheduledCommand() { - @Override - public void execute() { - configureHeaderRow(grid.appendHeaderRow()); - } - }, menuPath); - addMenuCommand("Remove top row", new ScheduledCommand() { - @Override - public void execute() { - grid.removeHeaderRow(0); - } - }, menuPath); - addMenuCommand("Remove bottom row", new ScheduledCommand() { - @Override - public void execute() { - grid.removeHeaderRow(grid.getHeaderRowCount() - 1); - } - }, menuPath); - - } - - private void configureHeaderRow(final HeaderRow row) { - setHeaderTexts(row); - String rowTitle = "Row " + grid.getHeaderRowCount(); - final String[] menuPath = { "Component", "Header", rowTitle }; - - addMenuCommand("Join column cells 0, 1", new ScheduledCommand() { - - @Override - public void execute() { - row.join(row.getCell(grid.getColumn(0)), - row.getCell(grid.getColumn(1))) - .setText("Join column cells 0, 1"); - - } - }, menuPath); - - addMenuCommand("Join columns 1, 2", new ScheduledCommand() { - - @Override - public void execute() { - row.join(grid.getColumn(1), grid.getColumn(2)) - .setText("Join columns 1, 2"); - ; - - } - }, menuPath); - - addMenuCommand("Join columns 3, 4, 5", new ScheduledCommand() { - - @Override - public void execute() { - row.join(grid.getColumn(3), grid.getColumn(4), - grid.getColumn(5)).setText("Join columns 3, 4, 5"); - - } - }, menuPath); - - addMenuCommand("Join all columns", new ScheduledCommand() { - - @Override - public void execute() { - row.join(grid.getColumns() - .toArray(new Grid.Column[grid.getColumnCount()])) - .setText("Join all columns"); - ; - - } - }, menuPath); - } - - private void createFooterMenu() { - final String[] menuPath = { "Component", "Footer" }; - - addMenuCommand("Visible", new ScheduledCommand() { - @Override - public void execute() { - grid.setFooterVisible(!grid.isFooterVisible()); - } - }, menuPath); - - addMenuCommand("Prepend row", new ScheduledCommand() { - @Override - public void execute() { - configureFooterRow(grid.prependFooterRow()); - } - }, menuPath); - addMenuCommand("Append row", new ScheduledCommand() { - @Override - public void execute() { - configureFooterRow(grid.appendFooterRow()); - } - }, menuPath); - addMenuCommand("Remove top row", new ScheduledCommand() { - @Override - public void execute() { - grid.removeFooterRow(0); - } - }, menuPath); - addMenuCommand("Remove bottom row", new ScheduledCommand() { - @Override - public void execute() { - assert grid.getFooterRowCount() > 0; - grid.removeFooterRow(grid.getFooterRowCount() - 1); - } - }, menuPath); - } - - private void createEditorMenu() { - addMenuCommand("Enabled", new ScheduledCommand() { - @Override - public void execute() { - grid.setEditorEnabled(!grid.isEditorEnabled()); - } - }, "Component", "Editor"); - - addMenuCommand("Edit row 5", new ScheduledCommand() { - @Override - public void execute() { - grid.editRow(5); - } - }, "Component", "Editor"); - - addMenuCommand("Edit row 100", new ScheduledCommand() { - @Override - public void execute() { - grid.editRow(100); - } - }, "Component", "Editor"); - - addMenuCommand("Save", new ScheduledCommand() { - @Override - public void execute() { - grid.saveEditor(); - } - }, "Component", "Editor"); - - addMenuCommand("Cancel edit", new ScheduledCommand() { - @Override - public void execute() { - grid.cancelEditor(); - } - }, "Component", "Editor"); - - addMenuCommand("Change Save Caption", new ScheduledCommand() { - @Override - public void execute() { - grid.setEditorSaveCaption("ǝʌɐS"); - } - }, "Component", "Editor"); - - addMenuCommand("Change Cancel Caption", new ScheduledCommand() { - @Override - public void execute() { - grid.setEditorCancelCaption("ʃǝɔuɐↃ"); - } - }, "Component", "Editor"); - - addMenuCommand("Toggle second editor error", new ScheduledCommand() { - @Override - public void execute() { - secondEditorError = !secondEditorError; - } - }, "Component", "Editor"); - } - - private void configureFooterRow(final FooterRow row) { - setFooterTexts(row); - String rowTitle = "Row " + grid.getFooterRowCount(); - final String[] menuPath = { "Component", "Footer", rowTitle }; - - addMenuCommand("Join column cells 0, 1", new ScheduledCommand() { - - @Override - public void execute() { - row.join(row.getCell(grid.getColumn(0)), - row.getCell(grid.getColumn(1))) - .setText("Join column cells 0, 1"); - - } - }, menuPath); - - addMenuCommand("Join columns 1, 2", new ScheduledCommand() { - - @Override - public void execute() { - row.join(grid.getColumn(1), grid.getColumn(2)) - .setText("Join columns 1, 2"); - ; - - } - }, menuPath); - - addMenuCommand("Join all columns", new ScheduledCommand() { - - @Override - public void execute() { - row.join(grid.getColumns() - .toArray(new Grid.Column[grid.getColumnCount()])) - .setText("Join all columns"); - ; - - } - }, menuPath); - } - - private void createDataSourceMenu() { - final String[] menuPath = { "Component", "DataSource" }; - - addMenuCommand("Reset with 100 rows of Data", new ScheduledCommand() { - @Override - public void execute() { - ds.asList().clear(); - data = createData(100); - ds.asList().addAll(data); - } - }, menuPath); - - addMenuCommand("Reset with " + ROWS + " rows of Data", - new ScheduledCommand() { - @Override - public void execute() { - ds.asList().clear(); - data = createData(ROWS); - ds.asList().addAll(data); - } - }, menuPath); - } - - /** - * Creates a renderer for a {@link Renderers} - */ - @SuppressWarnings("rawtypes") - private final Renderer createRenderer(Renderers renderer) { - switch (renderer) { - case TEXT_RENDERER: - return new TextRenderer(); - - case HTML_RENDERER: - return new HtmlRenderer() { - - @Override - public void render(RendererCellReference cell, - String htmlString) { - super.render(cell, "" + htmlString + ""); - } - }; - - case NUMBER_RENDERER: - return new NumberRenderer(); - - case DATE_RENDERER: - return new DateRenderer(); - - default: - return new TextRenderer(); - } - } - - /** - * Creates a collection of handlers for all the grid key events - */ - private void createKeyHandlers() { - final List labels = new ArrayList(); - for (int i = 0; i < 9; ++i) { - VLabel tmp = new VLabel(); - addNorth(tmp, 20); - labels.add(tmp); - } - - // Key Down Events - grid.addBodyKeyDownHandler(new BodyKeyDownHandler() { - private final VLabel label = labels.get(0); - - @Override - public void onKeyDown(GridKeyDownEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - grid.addHeaderKeyDownHandler(new HeaderKeyDownHandler() { - private final VLabel label = labels.get(1); - - @Override - public void onKeyDown(GridKeyDownEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - grid.addFooterKeyDownHandler(new FooterKeyDownHandler() { - private final VLabel label = labels.get(2); - - @Override - public void onKeyDown(GridKeyDownEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - // Key Up Events - grid.addBodyKeyUpHandler(new BodyKeyUpHandler() { - private final VLabel label = labels.get(3); - - @Override - public void onKeyUp(GridKeyUpEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - grid.addHeaderKeyUpHandler(new HeaderKeyUpHandler() { - private final VLabel label = labels.get(4); - - @Override - public void onKeyUp(GridKeyUpEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - grid.addFooterKeyUpHandler(new FooterKeyUpHandler() { - private final VLabel label = labels.get(5); - - @Override - public void onKeyUp(GridKeyUpEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - // Key Press Events - grid.addBodyKeyPressHandler(new BodyKeyPressHandler() { - private final VLabel label = labels.get(6); - - @Override - public void onKeyPress(GridKeyPressEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - grid.addHeaderKeyPressHandler(new HeaderKeyPressHandler() { - private final VLabel label = labels.get(7); - - @Override - public void onKeyPress(GridKeyPressEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - grid.addFooterKeyPressHandler(new FooterKeyPressHandler() { - private final VLabel label = labels.get(8); - - @Override - public void onKeyPress(GridKeyPressEvent event) { - CellReference focused = event.getFocusedCell(); - updateLabel(label, event.toDebugString(), focused.getRowIndex(), - focused.getColumnIndex()); - } - }); - - } - - private void updateLabel(VLabel label, String output, int object, - int column) { - String coords = "(" + object + ", " + column + ")"; - label.setText(coords + " " + output); - } - - private void createDetailsMenu() { - String[] menupath = new String[] { "Component", "Row details" }; - addMenuCommand("Set generator", new ScheduledCommand() { - @Override - public void execute() { - grid.setDetailsGenerator(new DetailsGenerator() { - @Override - public Widget getDetails(int rowIndex) { - FlowPanel panel = new FlowPanel(); - - final Label label = new Label("Row: " + rowIndex + "."); - Button button = new Button("Button", - new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - label.setText("clicked"); - } - }); - - panel.add(label); - panel.add(button); - return panel; - } - }); - } - }, menupath); - - addMenuCommand("Set faulty generator", new ScheduledCommand() { - @Override - public void execute() { - grid.setDetailsGenerator(new DetailsGenerator() { - @Override - public Widget getDetails(int rowIndex) { - throw new RuntimeException("This is by design."); - } - }); - } - }, menupath); - - addMenuCommand("Set empty generator", new ScheduledCommand() { - @Override - public void execute() { - grid.setDetailsGenerator(new DetailsGenerator() { - /* - * While this is functionally equivalent to the NULL - * generator, it's good to be explicit, since the behavior - * isn't strictly tied between them. NULL generator might be - * changed to render something different by default, and an - * empty generator might behave differently also in the - * future. - */ - - @Override - public Widget getDetails(int rowIndex) { - return null; - } - }); - } - }, menupath); - - String[] togglemenupath = new String[] { menupath[0], menupath[1], - "Toggle details for..." }; - for (int i : new int[] { 0, 1, 100, 200, 300, 400, 500, 600, 700, 800, - 900, 999 }) { - final int rowIndex = i; - addMenuCommand("Row " + rowIndex, new ScheduledCommand() { - boolean visible = false; - - @Override - public void execute() { - visible = !visible; - grid.setDetailsVisible(rowIndex, visible); - } - }, togglemenupath); - } - - } - - private static Logger getLogger() { - return Logger.getLogger(GridBasicClientFeaturesWidget.class.getName()); - } - - private void createSidebarMenu() { - String[] menupath = new String[] { "Component", "Sidebar" }; - - final List customMenuItems = new ArrayList(); - final List separators = new ArrayList(); - - addMenuCommand("Add item to end", new ScheduledCommand() { - @Override - public void execute() { - MenuItem item = createSidebarMenuItem(customMenuItems.size()); - customMenuItems.add(item); - grid.getSidebarMenu().addItem(item); - } - }, menupath); - - addMenuCommand("Add item before index 1", new ScheduledCommand() { - @Override - public void execute() { - MenuItem item = createSidebarMenuItem(customMenuItems.size()); - customMenuItems.add(item); - grid.getSidebarMenu().insertItem(item, 1); - } - }, menupath); - - addMenuCommand("Remove last added item", new ScheduledCommand() { - @Override - public void execute() { - grid.getSidebarMenu().removeItem( - customMenuItems.remove(customMenuItems.size() - 1)); - } - }, menupath); - - addMenuCommand("Add separator to end", new ScheduledCommand() { - @Override - public void execute() { - MenuItemSeparator separator = new MenuItemSeparator(); - separators.add(separator); - grid.getSidebarMenu().addSeparator(separator); - } - }, menupath); - - addMenuCommand("Add separator before index 1", new ScheduledCommand() { - @Override - public void execute() { - MenuItemSeparator separator = new MenuItemSeparator(); - separators.add(separator); - grid.getSidebarMenu().insertSeparator(separator, 1); - } - }, menupath); - - addMenuCommand("Remove last added separator", new ScheduledCommand() { - @Override - public void execute() { - grid.getSidebarMenu().removeSeparator( - separators.remove(separators.size() - 1)); - } - }, menupath); - - addMenuCommand("Toggle sidebar visibility", new ScheduledCommand() { - @Override - public void execute() { - grid.setSidebarOpen(!grid.isSidebarOpen()); - } - }, menupath); - - addMenuCommand("Open sidebar and disable grid", new ScheduledCommand() { - @Override - public void execute() { - grid.setSidebarOpen(true); - - Scheduler.get() - .scheduleFixedDelay(new Scheduler.RepeatingCommand() { - @Override - public boolean execute() { - if (grid.isSidebarOpen()) { - grid.setEnabled(false); - - return false; - } - - return true; - } - }, 250); - } - }, menupath); - } - - private MenuItem createSidebarMenuItem(final int index) { - final MenuItem menuItem = new MenuItem("Custom menu item " + index, - new ScheduledCommand() { - @Override - public void execute() { - if (index % 2 == 0) { - grid.setSidebarOpen(false); - } - getLogger().info("Menu item " + index + " selected"); - } - }); - return menuItem; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridCellFocusOnResetSizeWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridCellFocusOnResetSizeWidget.java deleted file mode 100644 index 6c96c6d8a4..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridCellFocusOnResetSizeWidget.java +++ /dev/null @@ -1,117 +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.grid; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.ui.Button; -import com.vaadin.client.data.DataChangeHandler; -import com.vaadin.client.data.DataSource; -import com.vaadin.shared.Registration; -import com.vaadin.v7.client.renderers.HtmlRenderer; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.SelectionMode; - -public class GridCellFocusOnResetSizeWidget - extends PureGWTTestApplication> { - - private Grid grid; - - private final class MyDataSource implements DataSource { - List rows = new ArrayList(); - int ROWS_MAX = 10; - int size = ROWS_MAX; - DataChangeHandler handler = null; - { - for (int i = 0; i < ROWS_MAX; ++i) { - rows.add(new String[] { "Foo " + i }); - } - } - - @Override - public void ensureAvailability(int firstRowIndex, int numberOfRows) { - handler.dataAvailable(firstRowIndex, numberOfRows); - } - - @Override - public int size() { - return size; - } - - @Override - public Registration addDataChangeHandler( - DataChangeHandler dataChangeHandler) { - handler = dataChangeHandler; - return null; - } - - @Override - public RowHandle getHandle(final String[] rowData) { - return null; - } - - @Override - public String[] getRow(int rowIndex) { - if (rowIndex < size && rowIndex >= 0) { - return rows.get(rowIndex); - } - return null; - } - - public void changeSize() { - size--; - if (size < ROWS_MAX / 2) { - size = ROWS_MAX; - } - handler.resetDataAndSize(size); - } - } - - private class Col extends Grid.Column { - public Col(String header) { - super(header, new HtmlRenderer()); - } - - @Override - public String getValue(String[] row) { - int index = grid.getColumns().indexOf(this); - return "" + String.valueOf(row[index]) + ""; - } - } - - public GridCellFocusOnResetSizeWidget() { - super(new Grid()); - grid = getTestedWidget(); - grid.setSelectionMode(SelectionMode.NONE); - grid.setWidth("300px"); - grid.addColumn(new Col("Foo")); - final MyDataSource dataSource = new MyDataSource(); - grid.setDataSource(dataSource); - Button widget = new Button("Change Container Size"); - widget.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - dataSource.changeSize(); - } - }); - addNorth(grid, 400); - addNorth(widget, 50); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClickExtensionConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClickExtensionConnector.java deleted file mode 100644 index 318d7dd3ed..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClickExtensionConnector.java +++ /dev/null @@ -1,67 +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.grid; - -import com.vaadin.client.MouseEventDetailsBuilder; -import com.vaadin.client.ServerConnector; -import com.vaadin.client.extensions.AbstractExtensionConnector; -import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.communication.ServerRpc; -import com.vaadin.shared.ui.Connect; -import com.vaadin.tests.components.grid.GridExtensionCommunication.GridClickExtension; -import com.vaadin.v7.client.connectors.GridConnector; -import com.vaadin.v7.client.widget.grid.CellReference; -import com.vaadin.v7.client.widget.grid.events.BodyClickHandler; -import com.vaadin.v7.client.widget.grid.events.GridClickEvent; -import com.vaadin.v7.client.widgets.Grid; - -import elemental.json.JsonObject; - -@Connect(GridClickExtension.class) -public class GridClickExtensionConnector extends AbstractExtensionConnector { - public interface GridClickServerRpc extends ServerRpc { - - public void click(String row, String column, MouseEventDetails click); - } - - @Override - protected void extend(ServerConnector target) { - Grid grid = getParent().getWidget(); - grid.addBodyClickHandler(new BodyClickHandler() { - - @Override - public void onClick(GridClickEvent event) { - CellReference cellRef = event.getTargetCell(); - - // Gather needed information. - String rowKey = getParent() - .getRowKey((JsonObject) cellRef.getRow()); - String columnId = getParent().getColumnId(cellRef.getColumn()); - MouseEventDetails clickDetails = MouseEventDetailsBuilder - .buildMouseEventDetails(event.getNativeEvent()); - - getRpcProxy(GridClickServerRpc.class).click(rowKey, columnId, - clickDetails); - } - }); - } - - @Override - public GridConnector getParent() { - return (GridConnector) super.getParent(); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java deleted file mode 100644 index d6b6182659..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java +++ /dev/null @@ -1,383 +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.grid; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.List; - -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Element; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.Window.Location; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.HasWidgets; -import com.vaadin.client.data.DataChangeHandler; -import com.vaadin.client.data.DataSource; -import com.vaadin.client.ui.AbstractComponentConnector; -import com.vaadin.shared.Registration; -import com.vaadin.shared.ui.Connect; -import com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers; -import com.vaadin.v7.client.renderers.ComplexRenderer; -import com.vaadin.v7.client.renderers.DateRenderer; -import com.vaadin.v7.client.renderers.HtmlRenderer; -import com.vaadin.v7.client.renderers.NumberRenderer; -import com.vaadin.v7.client.renderers.Renderer; -import com.vaadin.v7.client.renderers.TextRenderer; -import com.vaadin.v7.client.renderers.WidgetRenderer; -import com.vaadin.v7.client.widget.grid.CellReference; -import com.vaadin.v7.client.widget.grid.RendererCellReference; -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widget.grid.datasources.ListSorter; -import com.vaadin.v7.client.widget.grid.sort.Sort; -import com.vaadin.v7.client.widget.grid.sort.SortEvent; -import com.vaadin.v7.client.widget.grid.sort.SortHandler; -import com.vaadin.v7.client.widget.grid.sort.SortOrder; -import com.vaadin.v7.client.widgets.Grid; - -@Connect(GridClientColumnRenderers.GridController.class) -public class GridClientColumnRendererConnector - extends AbstractComponentConnector { - - public static enum Renderers { - TEXT_RENDERER, WIDGET_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER, CPLX_RENDERER; - } - - /** - * Datasource for simulating network latency - */ - private class DelayedDataSource implements DataSource { - - private DataSource ds; - private int firstRowIndex = -1; - private int numberOfRows; - private DataChangeHandler dataChangeHandler; - private int latency; - - public DelayedDataSource(DataSource ds, int latency) { - this.ds = ds; - this.latency = latency; - } - - @Override - public void ensureAvailability(final int firstRowIndex, - final int numberOfRows) { - new Timer() { - - @Override - public void run() { - DelayedDataSource.this.firstRowIndex = firstRowIndex; - DelayedDataSource.this.numberOfRows = numberOfRows; - dataChangeHandler.dataUpdated(firstRowIndex, numberOfRows); - dataChangeHandler.dataAvailable(firstRowIndex, - numberOfRows); - } - }.schedule(latency); - } - - @Override - public String getRow(int rowIndex) { - if (rowIndex >= firstRowIndex - && rowIndex <= firstRowIndex + numberOfRows) { - return ds.getRow(rowIndex); - } - return null; - } - - @Override - public int size() { - return ds.size(); - } - - @Override - public Registration addDataChangeHandler( - DataChangeHandler dataChangeHandler) { - this.dataChangeHandler = dataChangeHandler; - return null; - } - - @Override - public RowHandle getHandle(String row) { - // TODO Auto-generated method stub (henrik paul: 17.6.) - return null; - } - } - - @Override - protected void init() { - Grid grid = getWidget(); - grid.setSelectionMode(Grid.SelectionMode.NONE); - - // Generated some column data - List columnData = new ArrayList(); - for (int i = 0; i < 100; i++) { - columnData.add(String.valueOf(i)); - } - - // Provide data as data source - if (Location.getParameter("latency") != null) { - grid.setDataSource(new DelayedDataSource( - new ListDataSource(columnData), - Integer.parseInt(Location.getParameter("latency")))); - } else { - grid.setDataSource(new ListDataSource(columnData)); - } - - // Add a column to display the data in - Grid.Column c = createColumnWithRenderer( - Renderers.TEXT_RENDERER); - grid.addColumn(c); - grid.getDefaultHeaderRow().getCell(c).setText("Column 1"); - - // Add another column with a custom complex renderer - c = createColumnWithRenderer(Renderers.CPLX_RENDERER); - grid.addColumn(c); - grid.getDefaultHeaderRow().getCell(c).setText("Column 2"); - - // Add method for testing sort event firing - grid.addSortHandler(new SortHandler() { - @Override - public void sort(SortEvent event) { - Element console = Document.get() - .getElementById("testDebugConsole"); - String text = "Client-side sort event received
" - + "Columns: " + event.getOrder().size() + ", order: "; - for (SortOrder order : event.getOrder()) { - String columnHeader = getWidget().getDefaultHeaderRow() - .getCell(order.getColumn()).getText(); - text += columnHeader + ": " - + order.getDirection().toString(); - } - console.setInnerHTML(text); - } - }); - - // Handle RPC calls - registerRpc(GridClientColumnRendererRpc.class, - new GridClientColumnRendererRpc() { - - @Override - public void addColumn(Renderers renderer) { - - Grid.Column column; - if (renderer == Renderers.NUMBER_RENDERER) { - column = createNumberColumnWithRenderer(renderer); - } else if (renderer == Renderers.DATE_RENDERER) { - column = createDateColumnWithRenderer(renderer); - } else { - column = createColumnWithRenderer(renderer); - } - getWidget().addColumn(column); - - getWidget().getDefaultHeaderRow().getCell(column) - .setText("Column " + String.valueOf( - getWidget().getColumnCount() + 1)); - } - - @Override - public void detachAttach() { - - // Detach - HasWidgets parent = (HasWidgets) getWidget() - .getParent(); - parent.remove(getWidget()); - - // Re-attach - parent.add(getWidget()); - } - - @Override - public void triggerClientSorting() { - getWidget().sort(Sort.by(getWidget().getColumn(0))); - } - - @Override - @SuppressWarnings("unchecked") - public void triggerClientSortingTest() { - Grid grid = getWidget(); - ListSorter sorter = new ListSorter( - grid); - - // Make sorter sort the numbers in natural order - sorter.setComparator( - (Grid.Column) grid.getColumn(0), - new Comparator() { - @Override - public int compare(String o1, String o2) { - return Integer.parseInt(o1) - - Integer.parseInt(o2); - } - }); - - // Sort along column 0 in ascending order - grid.sort(grid.getColumn(0)); - - // Remove the sorter once we're done - sorter.removeFromGrid(); - } - - @Override - @SuppressWarnings("unchecked") - public void shuffle() { - Grid grid = getWidget(); - ListSorter shuffler = new ListSorter( - grid); - - // Make shuffler return random order - shuffler.setComparator( - (Grid.Column) grid.getColumn(0), - new Comparator() { - @Override - public int compare(String o1, String o2) { - return com.google.gwt.user.client.Random - .nextInt(3) - 1; - } - }); - - // "Sort" (actually shuffle) along column 0 - grid.sort(grid.getColumn(0)); - - // Remove the shuffler when we're done so that it - // doesn't interfere with further operations - shuffler.removeFromGrid(); - } - }); - } - - /** - * Creates a a renderer for a {@link Renderers} - */ - private Renderer createRenderer(Renderers renderer) { - switch (renderer) { - case TEXT_RENDERER: - return new TextRenderer(); - - case WIDGET_RENDERER: - return new WidgetRenderer() { - - @Override - public Button createWidget() { - final Button button = new Button(""); - button.addClickHandler(new ClickHandler() { - - @Override - public void onClick(ClickEvent event) { - button.setText("Clicked"); - } - }); - return button; - } - - @Override - public void render(RendererCellReference cell, String data, - Button button) { - button.setHTML(data); - } - }; - - case HTML_RENDERER: - return new HtmlRenderer() { - - @Override - public void render(RendererCellReference cell, - String htmlString) { - super.render(cell, "" + htmlString + ""); - } - }; - - case NUMBER_RENDERER: - return new NumberRenderer(); - - case DATE_RENDERER: - return new DateRenderer(); - - case CPLX_RENDERER: - return new ComplexRenderer() { - - @Override - public void init(RendererCellReference cell) { - } - - @Override - public void render(RendererCellReference cell, String data) { - cell.getElement().setInnerHTML("" + data + ""); - cell.getElement().getStyle().clearBackgroundColor(); - } - - @Override - public void setContentVisible(RendererCellReference cell, - boolean hasData) { - - // Visualize content visible property - cell.getElement().getStyle() - .setBackgroundColor(hasData ? "green" : "red"); - - super.setContentVisible(cell, hasData); - } - - @Override - public boolean onActivate(CellReference cell) { - cell.getElement().setInnerHTML("Activated!"); - return true; - } - }; - - default: - return new TextRenderer(); - } - } - - private Grid.Column createColumnWithRenderer( - Renderers renderer) { - return new Grid.Column(createRenderer(renderer)) { - - @Override - public String getValue(String row) { - return row; - } - }; - } - - private Grid.Column createNumberColumnWithRenderer( - Renderers renderer) { - return new Grid.Column(createRenderer(renderer)) { - - @Override - public Number getValue(String row) { - return Long.parseLong(row); - } - }; - } - - private Grid.Column createDateColumnWithRenderer( - Renderers renderer) { - return new Grid.Column(createRenderer(renderer)) { - - @Override - public Date getValue(String row) { - return new Date(); - } - }; - } - - @Override - public Grid getWidget() { - return (Grid) super.getWidget(); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java deleted file mode 100644 index 0e9fd373a1..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java +++ /dev/null @@ -1,48 +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.grid; - -import com.vaadin.shared.communication.ClientRpc; -import com.vaadin.tests.widgetset.client.grid.GridClientColumnRendererConnector.Renderers; - -public interface GridClientColumnRendererRpc extends ClientRpc { - - /** - * Adds a new column with a specific renderer to the grid - * - */ - void addColumn(Renderers renderer); - - /** - * Detaches and attaches the client side Grid - */ - void detachAttach(); - - /** - * Used for client-side sorting API test - */ - void triggerClientSorting(); - - /** - * @since - */ - void triggerClientSortingTest(); - - /** - * @since - */ - void shuffle(); -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java deleted file mode 100644 index 1a36a18ce1..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClientDataSourcesWidget.java +++ /dev/null @@ -1,221 +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.grid; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.vaadin.client.data.AbstractRemoteDataSource; -import com.vaadin.v7.client.renderers.TextRenderer; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.SelectionMode; - -public class GridClientDataSourcesWidget - extends PureGWTTestApplication> { - - private interface RestCallback { - void onResponse(RestishDataSource.Backend.Result result); - } - - /** - * This is an emulated datasource that has a back-end that changes size - * constantly. The back-end is unable to actively push data to Grid. - * Instead, with each row request, in addition to its row payload it tells - * how many rows it contains in total. - * - * A plausible response from this REST-like api would be: - * - *
-     * 
-     * GET /foos/4..8
-     *
-     * {
-     *     "resultsize": 4,
-     *     "data": [
-     *         [4, "foo IV"],
-     *         [5, "foo V"],
-     *         [6, "foo VI"]
-     *         [7, "foo VII"]
-     *     ],
-     *     "totalrows": 100
-     * }
-     * 
-     * 
- * - * In this case, the size of Grid needs to be updated to be able to show 100 - * rows in total (no more, no less). - * - * This class - *
    - *
  1. gets initialized - *
  2. asks for its size - *
  3. updates Grid once the reply is received - *
  4. as the Grid fetches more data, the total row count is dynamically - * updated. - *
- */ - private class RestishDataSource extends AbstractRemoteDataSource { - /** - * Pretend like this class doesn't exist. It just simulates a backend - * somewhere. - *

- * It's scoped inside the RDS class only because it's tied to that. - */ - private class Backend { - public class Result { - public int size; - public List rows; - } - - private int size = 200; - private int modCount = 0; - - public void query(int firstRowIndex, int numberOfRows, - final RestCallback callback) { - final Result result = new Result(); - result.size = size; - result.rows = fetchRows(firstRowIndex, numberOfRows); - - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - callback.onResponse(result); - } - }); - - } - - private List fetchRows(int firstRowIndex, - int numberOfRows) { - List rows = new ArrayList(); - for (int i = 0; i < numberOfRows; i++) { - String id = String.valueOf(firstRowIndex + i); - rows.add(new String[] { id, - "cell " + id + " #" + modCount }); - } - return rows; - } - - public void pushRowChanges(int rows) { - size += rows; - pushRowChanges(); - } - - public void pushRowChanges() { - modCount++; - - // push "something happened" to datasource "over the wire": - resetDataAndSize(size); - } - - public void addRows(int rowcount) { - modCount++; - size += rowcount; - } - } - - final Backend backend; - - public RestishDataSource() { - backend = new Backend(); - } - - @Override - protected void requestRows(int firstRowIndex, int numberOfRows, - final RequestRowsCallback callback) { - - backend.query(firstRowIndex, numberOfRows, new RestCallback() { - @Override - public void onResponse(Backend.Result result) { - callback.onResponse(result.rows, result.size); - } - }); - } - - @Override - public Object getRowKey(String[] row) { - return row[0]; - } - } - - private final Grid grid; - - private RestishDataSource restishDataSource; - - private final ScheduledCommand setRestishCommand = new ScheduledCommand() { - @Override - public void execute() { - for (Grid.Column column : grid.getColumns()) { - grid.removeColumn(column); - } - - restishDataSource = new RestishDataSource(); - grid.setDataSource(restishDataSource); - grid.addColumn(new Grid.Column("column", - new TextRenderer()) { - - @Override - public String getValue(String[] row) { - return row[1]; - } - }); - } - }; - - public GridClientDataSourcesWidget() { - super(new Grid()); - grid = getTestedWidget(); - - grid.getElement().getStyle().setZIndex(0); - grid.setHeight("400px"); - grid.setSelectionMode(SelectionMode.NONE); - addNorth(grid, 400); - - addMenuCommand("Use", setRestishCommand, "DataSources", "RESTish"); - addMenuCommand("Next request +10", new ScheduledCommand() { - @Override - public void execute() { - restishDataSource.backend.addRows(10); - } - }, "DataSources", "RESTish"); - addMenuCommand("Next request -10", new ScheduledCommand() { - @Override - public void execute() { - restishDataSource.backend.addRows(-10); - } - }, "DataSources", "RESTish"); - addMenuCommand("Push data change", new ScheduledCommand() { - @Override - public void execute() { - restishDataSource.backend.pushRowChanges(); - } - }, "DataSources", "RESTish"); - addMenuCommand("Push data change +10", new ScheduledCommand() { - @Override - public void execute() { - restishDataSource.backend.pushRowChanges(10); - } - }, "DataSources", "RESTish"); - addMenuCommand("Push data change -10", new ScheduledCommand() { - @Override - public void execute() { - restishDataSource.backend.pushRowChanges(-10); - } - }, "DataSources", "RESTish"); - } -} 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 deleted file mode 100644 index 6a9f3d717f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/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.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/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java deleted file mode 100644 index ed03ec470e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridDataChangeHandlerWidget.java +++ /dev/null @@ -1,120 +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.grid; - -import java.util.Arrays; -import java.util.List; - -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.RepeatingCommand; -import com.google.gwt.user.client.Timer; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.SimplePanel; -import com.vaadin.client.data.AbstractRemoteDataSource; -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.Column; - -public class GridDataChangeHandlerWidget extends Composite { - - private final SimplePanel panel = new SimplePanel(); - private final Grid grid = new Grid(); - - public static class DelayedDataSource extends ListDataSource { - - public DelayedDataSource(List datasource) { - super(datasource); - } - - @Override - public void ensureAvailability(final int firstRowIndex, - final int numberOfRows) { - new Timer() { - - @Override - public void run() { - actualEnsureAvailability(firstRowIndex, numberOfRows); - } - }.schedule(500); - } - - private void actualEnsureAvailability(int firstRowIndex, - int numberOfRows) { - super.ensureAvailability(firstRowIndex, numberOfRows); - } - } - - public static class RemoteDelayedDataSource - extends AbstractRemoteDataSource { - - private List rows; - - public RemoteDelayedDataSource(List datasource) { - super(); - rows = datasource; - } - - @Override - protected void requestRows(final int firstRowIndex, - final int numberOfRows, - final RequestRowsCallback callback) { - new Timer() { - - @Override - public void run() { - List requested = rows.subList(firstRowIndex, - numberOfRows); - callback.onResponse(requested, requested.size()); - } - }.schedule(500); - } - - @Override - public Object getRowKey(String row) { - return row; - } - - } - - public GridDataChangeHandlerWidget() { - initWidget(panel); - - panel.setWidget(grid); - grid.setDataSource(new RemoteDelayedDataSource( - Arrays.asList("A", "B", "C", "D", "E"))); - grid.addColumn(new Column("letter") { - @Override - public String getValue(String row) { - return row; - } - }); - Scheduler.get().scheduleFinally(new RepeatingCommand() { - - boolean run = false; - - @Override - public boolean execute() { - grid.setDataSource( - new DelayedDataSource(Arrays.asList("X", "Y", "Z"))); - if (run) { - return false; - } - run = true; - return true; - } - }); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java deleted file mode 100644 index 2ed5e17144..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridDefaultTextRendererWidget.java +++ /dev/null @@ -1,64 +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.grid; - -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.Column; -import com.vaadin.v7.client.widgets.Grid.SelectionMode; -import com.vaadin.v7.shared.ui.grid.HeightMode; - -public class GridDefaultTextRendererWidget - extends PureGWTTestApplication> { - /* - * This can't be null, because grid thinks that a row object of null means - * "data is still being fetched". - */ - private static final String NULL_STRING = ""; - - private Grid grid; - - public GridDefaultTextRendererWidget() { - super(new Grid()); - grid = getTestedWidget(); - - grid.setDataSource(new ListDataSource(NULL_STRING, "string")); - grid.addColumn(new Column() { - @Override - public String getValue(String row) { - if (!NULL_STRING.equals(row)) { - return row; - } else { - return null; - } - } - }); - - grid.addColumn(new Column() { - - @Override - public String getValue(String row) { - return "foo"; - } - - }); - - grid.setHeightByRows(2); - grid.setHeightMode(HeightMode.ROW); - grid.setSelectionMode(SelectionMode.NONE); - addNorth(grid, 500); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridHeightByRowOnInitWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridHeightByRowOnInitWidget.java deleted file mode 100644 index b740090c9e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridHeightByRowOnInitWidget.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.vaadin.tests.widgetset.client.grid; - -import java.util.Arrays; - -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.SimplePanel; -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.Column; -import com.vaadin.v7.shared.ui.grid.HeightMode; - -public class GridHeightByRowOnInitWidget extends Composite { - private final SimplePanel panel = new SimplePanel(); - private final Grid grid = new Grid(); - - public GridHeightByRowOnInitWidget() { - initWidget(panel); - - panel.setWidget(grid); - grid.setDataSource(new ListDataSource( - Arrays.asList("A", "B", "C", "D", "E"))); - grid.addColumn(new Column("letter") { - @Override - public String getValue(String row) { - return row; - } - }); - - grid.setHeightMode(HeightMode.ROW); - grid.setHeightByRows(5.0d); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridRendererChangeWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridRendererChangeWidget.java deleted file mode 100644 index 82ec1d9d67..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridRendererChangeWidget.java +++ /dev/null @@ -1,162 +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.grid; - -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.user.client.ui.Button; -import com.vaadin.v7.client.renderers.ButtonRenderer; -import com.vaadin.v7.client.renderers.TextRenderer; -import com.vaadin.v7.client.widget.grid.RendererCellReference; -import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; -import com.vaadin.v7.client.widgets.Grid; -import com.vaadin.v7.client.widgets.Grid.Column; - -public class GridRendererChangeWidget - extends PureGWTTestApplication> { - - public class MyButtonRenderer extends ButtonRenderer { - - private final Button widget = new Button(); - - private boolean hasInit = false; - private boolean hasBeenDestroyed = false; - private boolean wasAttached = false; - - @Override - public void init(RendererCellReference cell) { - if (hasInit || hasBeenDestroyed) { - throw new RuntimeException("Init in an unexpected state."); - } - super.init(cell); - - hasInit = true; - } - - @Override - public Button createWidget() { - return widget; - } - - @Override - public void render(RendererCellReference cell, String text, - Button button) { - if (!hasInit || hasBeenDestroyed) { - throw new RuntimeException("Render in an unexpected state."); - } - if (button != widget) { - throw new RuntimeException("Unexpected button instance"); - } - if (button.getParent() != getTestedWidget()) { - throw new RuntimeException("Button not attached!"); - } - - super.render(cell, text, button); - - wasAttached = true; - } - - @Override - public void destroy() { - if (!hasInit || !wasAttached) { - throw new RuntimeException("Destroy in an unexpected state"); - } - - super.destroy(); - - hasBeenDestroyed = true; - } - - public void verify() { - if (!hasInit) { - throw new RuntimeException("Failed. Not initialized"); - } else if (!wasAttached) { - throw new RuntimeException("Failed. Not attached"); - } else if (widget.getParent() != null) { - throw new RuntimeException("Failed. Not detached"); - } else if (!hasBeenDestroyed) { - throw new RuntimeException("Failed. Not destroyed"); - } - } - } - - public GridRendererChangeWidget() { - super(new Grid()); - String[] strArr = new String[] { "foo", "bar" }; - ListDataSource ds = new ListDataSource(strArr); - final Grid grid = getTestedWidget(); - grid.setDataSource(ds); - final Column first = new Column() { - - @Override - public String getValue(String[] row) { - return row[0]; - } - }; - grid.addColumn(first).setHeaderCaption("First") - .setRenderer(new MyButtonRenderer()); - final Column second = new Column() { - - @Override - public String getValue(String[] row) { - return row[1]; - } - }; - grid.addColumn(second).setHeaderCaption("Second") - .setRenderer(new MyButtonRenderer()); - - addMenuCommand("Change first renderer", new ScheduledCommand() { - - boolean isButton = true; - - @Override - public void execute() { - if (isButton) { - final MyButtonRenderer r = (MyButtonRenderer) first - .getRenderer(); - first.setRenderer(new TextRenderer()); - r.verify(); - } else { - first.setRenderer(new MyButtonRenderer()); - } - isButton = !isButton; - } - - }, "Component"); - addMenuCommand("Change second renderer", new ScheduledCommand() { - - boolean isButton = true; - - @Override - public void execute() { - if (isButton) { - MyButtonRenderer r = (MyButtonRenderer) second - .getRenderer(); - second.setRenderer(new TextRenderer()); - r.verify(); - } else { - second.setRenderer(new MyButtonRenderer()); - } - isButton = !isButton; - } - - }, "Component"); - - addNorth(grid, 600); - - grid.getElement().getStyle().setZIndex(0); - } - -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java deleted file mode 100644 index 76d9308f09..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/IntArrayRendererConnector.java +++ /dev/null @@ -1,47 +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.grid; - -import com.vaadin.shared.ui.Connect; -import com.vaadin.v7.client.connectors.AbstractGridRendererConnector; -import com.vaadin.v7.client.renderers.Renderer; -import com.vaadin.v7.client.widget.grid.RendererCellReference; - -@Connect(com.vaadin.tests.components.grid.IntArrayRenderer.class) -public class IntArrayRendererConnector - extends AbstractGridRendererConnector { - - public static class IntArrayRenderer implements Renderer { - private static final String JOINER = " :: "; - - @Override - public void render(RendererCellReference cell, int[] data) { - String text = ""; - for (int i : data) { - text += i + JOINER; - } - if (!text.isEmpty()) { - text = text.substring(0, text.length() - JOINER.length()); - } - cell.getElement().setInnerText(text); - } - } - - @Override - public IntArrayRenderer getRenderer() { - return (IntArrayRenderer) super.getRenderer(); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java deleted file mode 100644 index 7158b4927f..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/MySelectionModelConnector.java +++ /dev/null @@ -1,61 +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.grid; - -import com.vaadin.client.ServerConnector; -import com.vaadin.shared.ui.Connect; -import com.vaadin.tests.components.grid.GridCustomSelectionModel.MySelectionModel; -import com.vaadin.v7.client.connectors.MultiSelectionModelConnector; -import com.vaadin.v7.client.renderers.ComplexRenderer; -import com.vaadin.v7.client.widget.grid.selection.ClickSelectHandler; -import com.vaadin.v7.client.widget.grid.selection.SelectionModel.Multi; -import com.vaadin.v7.client.widgets.Grid; - -import elemental.json.JsonObject; - -@Connect(MySelectionModel.class) -public class MySelectionModelConnector extends MultiSelectionModelConnector { - - private ClickSelectHandler handler; - - @Override - protected void extend(ServerConnector target) { - super.extend(target); - handler = new ClickSelectHandler(getGrid()); - } - - @Override - public void onUnregister() { - super.onUnregister(); - handler.removeHandler(); - handler = null; - } - - @Override - protected Multi createSelectionModel() { - return new MySelectionModel(); - } - - public class MySelectionModel extends MultiSelectionModel { - - @Override - protected ComplexRenderer createSelectionColumnRenderer( - Grid grid) { - // No Selection Column. - return null; - } - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java deleted file mode 100644 index 34c475325e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.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.tests.widgetset.client.grid; - -import com.vaadin.shared.ui.Connect; -import com.vaadin.tests.widgetset.client.SimpleTestBean; -import com.vaadin.v7.client.connectors.AbstractGridRendererConnector; -import com.vaadin.v7.client.renderers.Renderer; -import com.vaadin.v7.client.widget.grid.RendererCellReference; - -@Connect(com.vaadin.tests.components.grid.BeanRenderer.class) -public class PojoRendererConnector - extends AbstractGridRendererConnector { - - public static class BeanRenderer implements Renderer { - @Override - public void render(RendererCellReference cell, SimpleTestBean bean) { - cell.getElement().setInnerText(bean.toString()); - } - } - - @Override - public BeanRenderer getRenderer() { - return (BeanRenderer) super.getRenderer(); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/PureGWTTestApplication.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/PureGWTTestApplication.java deleted file mode 100644 index 76eee3118b..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/PureGWTTestApplication.java +++ /dev/null @@ -1,309 +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.grid; - -import java.util.ArrayList; -import java.util.List; - -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.Style.Unit; -import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.ui.DockLayoutPanel; -import com.google.gwt.user.client.ui.LayoutPanel; -import com.google.gwt.user.client.ui.MenuBar; -import com.google.gwt.user.client.ui.Panel; -import com.vaadin.client.ui.SubPartAware; - -/** - * Pure GWT Test Application base for testing features of a single widget; - * provides a menu system and convenience method for adding items to it. - * - * @since - * @author Vaadin Ltd - */ -public abstract class PureGWTTestApplication extends DockLayoutPanel - implements SubPartAware { - - /** - * Class describing a menu item with an associated action - */ - public static class Command { - private final String title; - private final ScheduledCommand command; - - /** - * Creates a Command object, which is used as an action entry in the - * Menu - * - * @param t - * a title string - * @param cmd - * a scheduled command that is executed when this item is - * selected - */ - public Command(String t, ScheduledCommand cmd) { - title = t; - command = cmd; - } - - /** - * Returns the title of this command item - * - * @return a title string - */ - public final String getTitle() { - return title; - } - - /** - * Returns the actual scheduled command of this command item - * - * @return a scheduled command - */ - public final ScheduledCommand getCommand() { - return command; - } - } - - /** - * A menu object, providing a complete system for building a hierarchical - * menu bar system. - */ - public static class Menu { - - private final String title; - private final MenuBar menubar; - private final List

children; - private final List items; - - /** - * Create base-level menu, without a title. This is the root menu bar, - * which can be attached to a client application window. All other Menus - * should be added as child menus to this Menu, in order to maintain a - * nice hierarchy. - */ - private Menu() { - title = ""; - menubar = new MenuBar(); - menubar.getElement().setId("menu"); - children = new ArrayList(); - items = new ArrayList(); - } - - /** - * Create a sub-menu, with a title. - * - * @param title - */ - public Menu(String title) { - this.title = title; - menubar = new MenuBar(true); - children = new ArrayList(); - items = new ArrayList(); - } - - /** - * Return the GWT {@link MenuBar} object that provides the widget for - * this Menu - * - * @return a menubar object - */ - public MenuBar getMenuBar() { - return menubar; - } - - /** - * Returns the title of this menu entry - * - * @return a title string - */ - public String getTitle() { - return title; - } - - /** - * Adds a child menu entry to this menu. The title for this entry is - * taken from the Menu object argument. - * - * @param m - * another Menu object - */ - public void addChildMenu(Menu m) { - menubar.addItem(m.title, m.menubar); - children.add(m); - } - - /** - * Tests for the existence of a child menu by title at this level of the - * menu hierarchy - * - * @param title - * a title string - * @return true, if this menu has a direct child menu with the specified - * title, otherwise false - */ - public boolean hasChildMenu(String title) { - return getChildMenu(title) != null; - } - - /** - * Gets a reference to a child menu with a certain title, that is a - * direct child of this menu level. - * - * @param title - * a title string - * @return a Menu object with the specified title string, or null, if - * this menu doesn't have a direct child with the specified - * title. - */ - public Menu getChildMenu(String title) { - for (Menu m : children) { - if (m.title.equals(title)) { - return m; - } - } - return null; - } - - /** - * Adds a command item to the menu. When the entry is clicked, the - * command is executed. - * - * @param cmd - * a command object. - */ - public void addCommand(Command cmd) { - menubar.addItem(cmd.title, cmd.command); - items.add(cmd); - } - - /** - * Tests for the existence of a {@link Command} that is the direct child - * of this level of menu. - * - * @param title - * the command's title - * @return true, if this menu level includes a command item with the - * specified title. Otherwise false. - */ - public boolean hasCommand(String title) { - return getCommand(title) != null; - } - - /** - * Gets a reference to a {@link Command} item that is the direct child - * of this level of menu. - * - * @param title - * the command's title - * @return a command, if found in this menu level, otherwise null. - */ - public Command getCommand(String title) { - for (Command c : items) { - if (c.title.equals(title)) { - return c; - } - } - return null; - } - } - - /** - * Base level menu object, provides visible menu bar - */ - private final Menu menu; - private final T testedWidget; - - /** - * This constructor creates the basic menu bar and adds it to the top of the - * parent {@link DockLayoutPanel} - */ - protected PureGWTTestApplication(T widget) { - super(Unit.PX); - Panel menuPanel = new LayoutPanel(); - menu = new Menu(); - menuPanel.add(menu.getMenuBar()); - addNorth(menuPanel, 25); - testedWidget = widget; - } - - /** - * Connect an item to the menu structure - * - * @param cmd - * a scheduled command; see google's docs - * @param menupath - * path to the item - */ - public void addMenuCommand(String title, ScheduledCommand cmd, - String... menupath) { - Menu m = createMenuPath(menupath); - - m.addCommand(new Command(title, cmd)); - } - - /** - * Create a menu path, if one doesn't already exist, and return the last - * menu in the series. - * - * @param path - * a varargs list or array of strings describing a menu path, - * e.g. "File", "Recent", "User Files", which would result in the - * File menu having a submenu called "Recent" which would have a - * submenu called "User Files". - * @return the last Menu object specified by the path - */ - private Menu createMenuPath(String... path) { - Menu m = menu; - - for (String p : path) { - Menu sub = m.getChildMenu(p); - - if (sub == null) { - sub = new Menu(p); - m.addChildMenu(sub); - } - m = sub; - } - - return m; - } - - @Override - public Element getSubPartElement(String subPart) { - if (testedWidget instanceof SubPartAware) { - return ((SubPartAware) testedWidget).getSubPartElement(subPart); - } - return null; - } - - @Override - public String getSubPartName(Element subElement) { - if (testedWidget instanceof SubPartAware) { - return ((SubPartAware) testedWidget).getSubPartName(subElement); - } - return null; - } - - /** - * Gets the tested widget. - * - * @return tested widget - */ - public T getTestedWidget() { - return testedWidget; - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java deleted file mode 100644 index 9ebb0ba738..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java +++ /dev/null @@ -1,80 +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.grid; - -import java.util.Arrays; -import java.util.Collection; - -import com.google.gwt.dom.client.BrowserEvents; -import com.google.gwt.dom.client.DivElement; -import com.google.gwt.dom.client.NativeEvent; -import com.google.gwt.user.client.DOM; -import com.vaadin.shared.communication.ServerRpc; -import com.vaadin.shared.ui.Connect; -import com.vaadin.v7.client.connectors.AbstractGridRendererConnector; -import com.vaadin.v7.client.renderers.ComplexRenderer; -import com.vaadin.v7.client.renderers.Renderer; -import com.vaadin.v7.client.widget.grid.CellReference; -import com.vaadin.v7.client.widget.grid.RendererCellReference; - -import elemental.json.JsonObject; - -@Connect(com.vaadin.tests.components.grid.RowAwareRenderer.class) -public class RowAwareRendererConnector - extends AbstractGridRendererConnector { - public interface RowAwareRendererRpc extends ServerRpc { - void clicky(String key); - } - - public class RowAwareRenderer extends ComplexRenderer { - - @Override - public Collection getConsumedEvents() { - return Arrays.asList(BrowserEvents.CLICK); - } - - @Override - public void init(RendererCellReference cell) { - DivElement div = DivElement.as(DOM.createDiv()); - div.setAttribute("style", - "border: 1px solid red; background: pink;"); - div.setInnerText("Click me!"); - cell.getElement().appendChild(div); - } - - @Override - public void render(RendererCellReference cell, Void data) { - // NOOP - } - - @Override - public boolean onBrowserEvent(CellReference cell, - NativeEvent event) { - String key = getRowKey((JsonObject) cell.getRow()); - getRpcProxy(RowAwareRendererRpc.class).clicky(key); - cell.getElement().setInnerText( - "row: " + cell.getRowIndex() + ", key: " + key); - return true; - } - } - - @Override - protected Renderer createRenderer() { - // cannot use the default createRenderer as RowAwareRenderer needs a - // reference to its connector - it has no "real" no-argument constructor - return new RowAwareRenderer(); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/EscalatorBasicClientFeaturesWidget.java new file mode 100644 index 0000000000..a4a5ed0ee1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/EscalatorBasicClientFeaturesWidget.java @@ -0,0 +1,824 @@ +package com.vaadin.tests.widgetset.client.v7.grid; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.core.client.Duration; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.TableCellElement; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; +import com.vaadin.v7.client.widget.escalator.EscalatorUpdater; +import com.vaadin.v7.client.widget.escalator.FlyweightCell; +import com.vaadin.v7.client.widget.escalator.Row; +import com.vaadin.v7.client.widget.escalator.RowContainer; +import com.vaadin.v7.client.widget.escalator.RowContainer.BodyRowContainer; +import com.vaadin.v7.client.widget.escalator.Spacer; +import com.vaadin.v7.client.widget.escalator.SpacerUpdater; +import com.vaadin.v7.client.widgets.Escalator; +import com.vaadin.v7.shared.ui.grid.ScrollDestination; + +public class EscalatorBasicClientFeaturesWidget + extends PureGWTTestApplication { + + public static class LogWidget extends Composite { + + private static final int MAX_LOG = 9; + + private final HTML html = new HTML(); + private final List logs = new ArrayList(); + private Escalator escalator; + + public LogWidget() { + initWidget(html); + getElement().setId("log"); + } + + public void setEscalator(Escalator escalator) { + this.escalator = escalator; + } + + public void updateDebugLabel() { + int headers = escalator.getHeader().getRowCount(); + int bodys = escalator.getBody().getRowCount(); + int footers = escalator.getFooter().getRowCount(); + int columns = escalator.getColumnConfiguration().getColumnCount(); + + while (logs.size() > MAX_LOG) { + logs.remove(0); + } + + String logString = "
"; + for (String log : logs) { + logString += log + "
"; + } + + html.setHTML("Columns: " + columns + "
" + // + "Header rows: " + headers + "
" + // + "Body rows: " + bodys + "
" + // + "Footer rows: " + footers + "
" + // + logString); + } + + public void log(String string) { + logs.add((Duration.currentTimeMillis() % 10000) + ": " + string); + } + } + + public static class UpdaterLifetimeWidget + extends EscalatorBasicClientFeaturesWidget { + + private final EscalatorUpdater debugUpdater = new EscalatorUpdater() { + @Override + public void preAttach(Row row, + Iterable cellsToAttach) { + log("preAttach", cellsToAttach); + } + + @Override + public void postAttach(Row row, + Iterable attachedCells) { + log("postAttach", attachedCells); + } + + @Override + public void update(Row row, Iterable cellsToUpdate) { + log("update", cellsToUpdate); + } + + @Override + public void preDetach(Row row, + Iterable cellsToDetach) { + log("preDetach", cellsToDetach); + } + + @Override + public void postDetach(Row row, + Iterable detachedCells) { + log("postDetach", detachedCells); + } + + private void log(String methodName, Iterable cells) { + if (!cells.iterator().hasNext()) { + return; + } + + TableCellElement cellElement = cells.iterator().next() + .getElement(); + boolean isAttached = cellElement.getParentElement() != null + && cellElement.getParentElement() + .getParentElement() != null; + logWidget.log( + methodName + ": elementIsAttached == " + isAttached); + } + }; + + public UpdaterLifetimeWidget() { + super(); + escalator.getHeader().setEscalatorUpdater(debugUpdater); + escalator.getBody().setEscalatorUpdater(debugUpdater); + escalator.getFooter().setEscalatorUpdater(debugUpdater); + } + } + + private static final String COLUMNS_AND_ROWS_MENU = "Columns and Rows"; + private static final String GENERAL_MENU = "General"; + private static final String FEATURES_MENU = "Features"; + + private static abstract class TestEscalatorUpdater + implements EscalatorUpdater { + + @Override + public void preAttach(Row row, Iterable cellsToAttach) { + // noop + } + + @Override + public void postAttach(Row row, Iterable attachedCells) { + // noop + } + + @Override + public void preDetach(Row row, Iterable cellsToDetach) { + // noop + } + + @Override + public void postDetach(Row row, Iterable detachedCells) { + // noop + } + } + + private class Data { + private int columnCounter = 0; + private int rowCounter = 0; + private final List columns = new ArrayList(); + private final List rows = new ArrayList(); + + @SuppressWarnings("boxing") + public void insertRows(final int offset, final int amount) { + final List newRows = new ArrayList(); + for (int i = 0; i < amount; i++) { + newRows.add(rowCounter++); + } + rows.addAll(offset, newRows); + } + + @SuppressWarnings("boxing") + public void insertColumns(final int offset, final int amount) { + final List newColumns = new ArrayList(); + for (int i = 0; i < amount; i++) { + newColumns.add(columnCounter++); + } + columns.addAll(offset, newColumns); + } + + public EscalatorUpdater createHeaderUpdater() { + return new TestEscalatorUpdater() { + @Override + public void update(final Row row, + final Iterable cellsToUpdate) { + for (final FlyweightCell cell : cellsToUpdate) { + final Integer columnName = columns + .get(cell.getColumn()); + cell.getElement().setInnerText("Header " + columnName); + + if (colspan == Colspan.NORMAL) { + if (cell.getColumn() % 2 == 0) { + cell.setColSpan(2); + } + } else if (colspan == Colspan.CRAZY) { + if (cell.getColumn() % 3 == 0) { + cell.setColSpan(2); + } + } + } + } + }; + } + + public EscalatorUpdater createFooterUpdater() { + return new TestEscalatorUpdater() { + @Override + public void update(final Row row, + final Iterable cellsToUpdate) { + for (final FlyweightCell cell : cellsToUpdate) { + final Integer columnName = columns + .get(cell.getColumn()); + cell.getElement().setInnerText("Footer " + columnName); + + if (colspan == Colspan.NORMAL) { + if (cell.getColumn() % 2 == 0) { + cell.setColSpan(2); + } + } else if (colspan == Colspan.CRAZY) { + if (cell.getColumn() % 3 == 1) { + cell.setColSpan(2); + } + } + } + } + }; + } + + public EscalatorUpdater createBodyUpdater() { + return new TestEscalatorUpdater() { + + public void renderCell(final FlyweightCell cell) { + final Integer columnName = columns.get(cell.getColumn()); + final Integer rowName = rows.get(cell.getRow()); + String cellInfo = columnName + "," + rowName; + + if (cell.getColumn() > 0) { + cell.getElement().setInnerText("Cell: " + cellInfo); + } else { + cell.getElement().setInnerText( + "Row " + cell.getRow() + ": " + cellInfo); + } + + if (colspan == Colspan.NORMAL) { + if (cell.getColumn() % 2 == 0) { + cell.setColSpan(2); + } + } else if (colspan == Colspan.CRAZY) { + if (cell.getColumn() % 3 == cell.getRow() % 3) { + cell.setColSpan(2); + } + } + } + + @Override + public void update(final Row row, + final Iterable cellsToUpdate) { + for (final FlyweightCell cell : cellsToUpdate) { + renderCell(cell); + } + } + }; + } + + public void removeRows(final int offset, final int amount) { + for (int i = 0; i < amount; i++) { + rows.remove(offset); + } + } + + public void removeColumns(final int offset, final int amount) { + for (int i = 0; i < amount; i++) { + columns.remove(offset); + } + } + } + + protected final Escalator escalator; + private final Data data = new Data(); + + private enum Colspan { + NONE, NORMAL, CRAZY; + } + + private Colspan colspan = Colspan.NONE; + protected final LogWidget logWidget = new LogWidget(); + + public EscalatorBasicClientFeaturesWidget() { + super(new EscalatorProxy()); + escalator = getTestedWidget(); + logWidget.setEscalator(escalator); + + ((EscalatorProxy) escalator).setLogWidget(logWidget); + addNorth(logWidget, 200); + + final RowContainer header = escalator.getHeader(); + header.setEscalatorUpdater(data.createHeaderUpdater()); + + final RowContainer footer = escalator.getFooter(); + footer.setEscalatorUpdater(data.createFooterUpdater()); + + escalator.getBody().setEscalatorUpdater(data.createBodyUpdater()); + + setWidth("500px"); + setHeight("500px"); + + escalator.getElement().getStyle().setZIndex(0); + addNorth(escalator, 500); + + createGeneralMenu(); + createColumnMenu(); + createHeaderRowsMenu(); + createBodyRowsMenu(); + createFooterRowsMenu(); + createColumnsAndRowsMenu(); + createFrozenMenu(); + createColspanMenu(); + createSpacerMenu(); + } + + private void createFrozenMenu() { + String[] menupath = { FEATURES_MENU, "Frozen columns" }; + addMenuCommand("Freeze 1 column", new ScheduledCommand() { + @Override + public void execute() { + escalator.getColumnConfiguration().setFrozenColumnCount(1); + } + }, menupath); + addMenuCommand("Freeze 0 columns", new ScheduledCommand() { + @Override + public void execute() { + escalator.getColumnConfiguration().setFrozenColumnCount(0); + } + }, menupath); + } + + private void createColspanMenu() { + String[] menupath = { FEATURES_MENU, "Column spanning" }; + addMenuCommand("Apply normal colspan", new ScheduledCommand() { + @Override + public void execute() { + colspan = Colspan.NORMAL; + refreshEscalator(); + } + }, menupath); + addMenuCommand("Apply crazy colspan", new ScheduledCommand() { + @Override + public void execute() { + colspan = Colspan.CRAZY; + refreshEscalator(); + } + }, menupath); + addMenuCommand("Apply no colspan", new ScheduledCommand() { + @Override + public void execute() { + colspan = Colspan.NONE; + refreshEscalator(); + } + }, menupath); + } + + private void createColumnsAndRowsMenu() { + String[] menupath = { COLUMNS_AND_ROWS_MENU }; + addMenuCommand("Add one of each row", new ScheduledCommand() { + @Override + public void execute() { + insertRows(escalator.getHeader(), 0, 1); + insertRows(escalator.getBody(), 0, 1); + insertRows(escalator.getFooter(), 0, 1); + } + }, menupath); + addMenuCommand("Remove one of each row", new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getHeader(), 0, 1); + removeRows(escalator.getBody(), 0, 1); + removeRows(escalator.getFooter(), 0, 1); + } + }, menupath); + } + + private void createGeneralMenu() { + String[] menupath = { GENERAL_MENU }; + + addMenuCommand("Detach Escalator", new ScheduledCommand() { + @Override + public void execute() { + escalator.removeFromParent(); + } + }, menupath); + + addMenuCommand("Attach Escalator", new ScheduledCommand() { + @Override + public void execute() { + if (!escalator.isAttached()) { + addNorth(escalator, 500); + } + } + }, menupath); + + addMenuCommand("Clear (columns, then rows)", new ScheduledCommand() { + @Override + public void execute() { + resetColRow(); + } + }, menupath); + addMenuCommand("Clear (rows, then columns)", new ScheduledCommand() { + @Override + public void execute() { + resetRowCol(); + } + }, menupath); + addMenuCommand("Populate Escalator (columns, then rows)", + new ScheduledCommand() { + @Override + public void execute() { + resetColRow(); + insertColumns(0, 10); + insertRows(escalator.getHeader(), 0, 1); + insertRows(escalator.getBody(), 0, 100); + insertRows(escalator.getFooter(), 0, 1); + } + }, menupath); + addMenuCommand("Populate Escalator (rows, then columns)", + new ScheduledCommand() { + @Override + public void execute() { + resetColRow(); + insertRows(escalator.getHeader(), 0, 1); + insertRows(escalator.getBody(), 0, 100); + insertRows(escalator.getFooter(), 0, 1); + insertColumns(0, 10); + } + }, menupath); + + createSizeMenu(); + } + + private void createSizeMenu() { + String[] menupath = new String[] { "General", "Size" }; + + addSizeMenuItem(null, "height", menupath); + addSizeMenuItem("200px", "height", menupath); + addSizeMenuItem("400px", "height", menupath); + addSizeMenuItem(null, "width", menupath); + addSizeMenuItem("200px", "width", menupath); + addSizeMenuItem("400px", "width", menupath); + } + + private void addSizeMenuItem(final String size, final String direction, + String[] menupath) { + final String title = (size != null ? size : "undefined"); + addMenuCommand(title + " " + direction, new ScheduledCommand() { + @Override + public void execute() { + if (direction.equals("height")) { + escalator.setHeight(size); + } else { + escalator.setWidth(size); + } + } + }, menupath); + } + + private void createColumnMenu() { + String[] menupath = { COLUMNS_AND_ROWS_MENU, "Columns" }; + addMenuCommand("Add one column to beginning", new ScheduledCommand() { + @Override + public void execute() { + insertColumns(0, 1); + } + }, menupath); + addMenuCommand("Add one column to end", new ScheduledCommand() { + @Override + public void execute() { + insertColumns( + escalator.getColumnConfiguration().getColumnCount(), 1); + } + }, menupath); + addMenuCommand("Add ten columns", new ScheduledCommand() { + @Override + public void execute() { + insertColumns(0, 10); + } + }, menupath); + addMenuCommand("Remove one column from beginning", + new ScheduledCommand() { + @Override + public void execute() { + removeColumns(0, 1); + } + }, menupath); + addMenuCommand("Remove one column from end", new ScheduledCommand() { + @Override + public void execute() { + removeColumns( + escalator.getColumnConfiguration().getColumnCount() - 1, + 1); + } + }, menupath); + + addMenuCommand("Refresh first column", new ScheduledCommand() { + @Override + public void execute() { + escalator.getColumnConfiguration().refreshColumns(0, 1); + } + }, menupath); + + addMenuCommand("Resize first column to max width", + new ScheduledCommand() { + @Override + public void execute() { + escalator.getColumnConfiguration().setColumnWidth(0, + -1); + } + }, menupath); + + addMenuCommand("Resize first column to 100 px", new ScheduledCommand() { + @Override + public void execute() { + escalator.getColumnConfiguration().setColumnWidth(0, 100); + } + }, menupath); + } + + private void createHeaderRowsMenu() { + String[] menupath = { COLUMNS_AND_ROWS_MENU, "Header Rows" }; + createRowsMenu(escalator.getHeader(), menupath); + } + + private void createFooterRowsMenu() { + String[] menupath = { COLUMNS_AND_ROWS_MENU, "Footer Rows" }; + createRowsMenu(escalator.getFooter(), menupath); + } + + private void createBodyRowsMenu() { + String[] menupath = { COLUMNS_AND_ROWS_MENU, "Body Rows" }; + createRowsMenu(escalator.getBody(), menupath); + + addMenuCommand("Add 5 rows to top", new ScheduledCommand() { + @Override + public void execute() { + insertRows(escalator.getBody(), 0, 5); + } + }, menupath); + addMenuCommand("Add 50 rows to top", new ScheduledCommand() { + @Override + public void execute() { + insertRows(escalator.getBody(), 0, 50); + } + }, menupath); + addMenuCommand("Remove 5 rows from bottom", new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getBody(), + escalator.getBody().getRowCount() - 5, 5); + } + }, menupath); + addMenuCommand("Remove 50 rows from bottom", new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getBody(), + escalator.getBody().getRowCount() - 50, 50); + } + }, menupath); + addMenuCommand("Remove 50 rows from almost bottom", + new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getBody(), + escalator.getBody().getRowCount() - 60, 50); + } + }, menupath); + addMenuCommand("Remove all, insert 30 and scroll 40px", + new ScheduledCommand() { + @Override + public void execute() { + removeRows(escalator.getBody(), 0, + escalator.getBody().getRowCount()); + insertRows(escalator.getBody(), 0, 30); + escalator.setScrollTop(40); + } + }, menupath); + + String[] scrollToRowMenuPath = new String[menupath.length + 1]; + System.arraycopy(menupath, 0, scrollToRowMenuPath, 0, menupath.length); + scrollToRowMenuPath[scrollToRowMenuPath.length - 1] = "Scroll to..."; + for (int i = 0; i < 100; i += 25) { + final int rowIndex = i; + addMenuCommand("Row " + i, new ScheduledCommand() { + @Override + public void execute() { + escalator.scrollToRow(rowIndex, ScrollDestination.ANY, 0); + } + }, scrollToRowMenuPath); + } + + addMenuCommand("Set 20px default height", new ScheduledCommand() { + @Override + public void execute() { + escalator.getBody().setDefaultRowHeight(20); + } + }, menupath); + } + + private void createRowsMenu(final RowContainer container, + String[] menupath) { + addMenuCommand("Add one row to beginning", new ScheduledCommand() { + @Override + public void execute() { + int offset = 0; + int number = 1; + insertRows(container, offset, number); + } + }, menupath); + addMenuCommand("Add one row to end", new ScheduledCommand() { + @Override + public void execute() { + int offset = container.getRowCount(); + int number = 1; + insertRows(container, offset, number); + } + }, menupath); + addMenuCommand("Remove one row from beginning", new ScheduledCommand() { + @Override + public void execute() { + int offset = 0; + int number = 1; + removeRows(container, offset, number); + } + }, menupath); + addMenuCommand("Remove one row from end", new ScheduledCommand() { + @Override + public void execute() { + int offset = container.getRowCount() - 1; + int number = 1; + removeRows(container, offset, number); + } + }, menupath); + addMenuCommand("Remove all rows", new ScheduledCommand() { + @Override + public void execute() { + if (container.getRowCount() > 0) { + removeRows(container, 0, container.getRowCount()); + } + } + }, menupath); + } + + private void createSpacerMenu() { + String[] menupath = { "Features", "Spacers" }; + + addMenuCommand("Swap Spacer Updater", new ScheduledCommand() { + private final SpacerUpdater CUSTOM = new SpacerUpdater() { + @Override + public void destroy(Spacer spacer) { + spacer.getElement().setInnerText(""); + } + + @Override + public void init(Spacer spacer) { + spacer.getElement() + .setInnerText("Spacer for row " + spacer.getRow()); + } + }; + + @Override + public void execute() { + BodyRowContainer body = escalator.getBody(); + + if (SpacerUpdater.NULL.equals(body.getSpacerUpdater())) { + body.setSpacerUpdater(CUSTOM); + } else { + body.setSpacerUpdater(SpacerUpdater.NULL); + } + } + }, menupath); + + addMenuCommand("Focusable Updater", new ScheduledCommand() { + @Override + public void execute() { + escalator.getBody().setSpacerUpdater(new SpacerUpdater() { + @Override + public void init(Spacer spacer) { + spacer.getElement().appendChild(DOM.createInputText()); + } + + @Override + public void destroy(Spacer spacer) { + spacer.getElement().removeAllChildren(); + } + }); + } + }, menupath); + + createSpacersMenuForRow(-1, menupath); + createSpacersMenuForRow(1, menupath); + createSpacersMenuForRow(50, menupath); + createSpacersMenuForRow(99, menupath); + } + + private void createSpacersMenuForRow(final int rowIndex, + String[] menupath) { + menupath = new String[] { menupath[0], menupath[1], "Row " + rowIndex }; + addMenuCommand("Set 100px", new ScheduledCommand() { + @Override + public void execute() { + escalator.getBody().setSpacer(rowIndex, 100); + } + }, menupath); + addMenuCommand("Set 50px", new ScheduledCommand() { + @Override + public void execute() { + escalator.getBody().setSpacer(rowIndex, 50); + } + }, menupath); + addMenuCommand("Remove", new ScheduledCommand() { + @Override + public void execute() { + escalator.getBody().setSpacer(rowIndex, -1); + } + }, menupath); + addMenuCommand("Scroll here (ANY, 0)", new ScheduledCommand() { + @Override + public void execute() { + escalator.scrollToSpacer(rowIndex, ScrollDestination.ANY, 0); + } + }, menupath); + addMenuCommand("Scroll here row+spacer below (ANY, 0)", + new ScheduledCommand() { + @Override + public void execute() { + escalator.scrollToRowAndSpacer(rowIndex, + ScrollDestination.ANY, 0); + } + }, menupath); + } + + private void insertRows(final RowContainer container, int offset, + int number) { + if (container == escalator.getBody()) { + data.insertRows(offset, number); + escalator.getBody().insertRows(offset, number); + } else { + container.insertRows(offset, number); + } + } + + private void removeRows(final RowContainer container, int offset, + int number) { + if (container == escalator.getBody()) { + data.removeRows(offset, number); + escalator.getBody().removeRows(offset, number); + } else { + container.removeRows(offset, number); + } + } + + private void insertColumns(final int offset, final int number) { + data.insertColumns(offset, number); + escalator.getColumnConfiguration().insertColumns(offset, number); + } + + private void removeColumns(final int offset, final int number) { + data.removeColumns(offset, number); + escalator.getColumnConfiguration().removeColumns(offset, number); + } + + private void resetColRow() { + if (escalator.getColumnConfiguration().getColumnCount() > 0) { + removeColumns(0, + escalator.getColumnConfiguration().getColumnCount()); + } + if (escalator.getFooter().getRowCount() > 0) { + removeRows(escalator.getFooter(), 0, + escalator.getFooter().getRowCount()); + } + + if (escalator.getBody().getRowCount() > 0) { + removeRows(escalator.getBody(), 0, + escalator.getBody().getRowCount()); + } + + if (escalator.getHeader().getRowCount() > 0) { + removeRows(escalator.getHeader(), 0, + escalator.getHeader().getRowCount()); + } + } + + private void resetRowCol() { + if (escalator.getFooter().getRowCount() > 0) { + removeRows(escalator.getFooter(), 0, + escalator.getFooter().getRowCount()); + } + + if (escalator.getBody().getRowCount() > 0) { + removeRows(escalator.getBody(), 0, + escalator.getBody().getRowCount()); + } + + if (escalator.getHeader().getRowCount() > 0) { + removeRows(escalator.getHeader(), 0, + escalator.getHeader().getRowCount()); + } + + if (escalator.getColumnConfiguration().getColumnCount() > 0) { + removeColumns(0, + escalator.getColumnConfiguration().getColumnCount()); + } + } + + private void refreshEscalator() { + if (escalator.getHeader().getRowCount() > 0) { + escalator.getHeader().refreshRows(0, + escalator.getHeader().getRowCount()); + } + + if (escalator.getBody().getRowCount() > 0) { + escalator.getBody().refreshRows(0, + escalator.getBody().getRowCount()); + } + + if (escalator.getFooter().getRowCount() > 0) { + escalator.getFooter().refreshRows(0, + escalator.getFooter().getRowCount()); + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/EscalatorProxy.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/EscalatorProxy.java new file mode 100644 index 0000000000..fc6f240eb5 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/EscalatorProxy.java @@ -0,0 +1,259 @@ +/* + * 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.Map; + +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.TableRowElement; +import com.google.gwt.dom.client.TableSectionElement; +import com.vaadin.tests.widgetset.client.v7.grid.EscalatorBasicClientFeaturesWidget.LogWidget; +import com.vaadin.v7.client.widget.escalator.Cell; +import com.vaadin.v7.client.widget.escalator.ColumnConfiguration; +import com.vaadin.v7.client.widget.escalator.EscalatorUpdater; +import com.vaadin.v7.client.widget.escalator.RowContainer; +import com.vaadin.v7.client.widget.escalator.RowContainer.BodyRowContainer; +import com.vaadin.v7.client.widget.escalator.SpacerUpdater; +import com.vaadin.v7.client.widgets.Escalator; + +public class EscalatorProxy extends Escalator { + private class ColumnConfigurationProxy implements ColumnConfiguration { + private ColumnConfiguration columnConfiguration; + + public ColumnConfigurationProxy( + ColumnConfiguration columnConfiguration) { + this.columnConfiguration = columnConfiguration; + } + + @Override + public void removeColumns(int index, int numberOfColumns) + throws IndexOutOfBoundsException, IllegalArgumentException { + columnConfiguration.removeColumns(index, numberOfColumns); + logWidget.log("removeColumns " + index + ", " + numberOfColumns); + logWidget.updateDebugLabel(); + } + + @Override + public void insertColumns(int index, int numberOfColumns) + throws IndexOutOfBoundsException, IllegalArgumentException { + columnConfiguration.insertColumns(index, numberOfColumns); + logWidget.log("insertColumns " + index + ", " + numberOfColumns); + logWidget.updateDebugLabel(); + } + + @Override + public int getColumnCount() { + return columnConfiguration.getColumnCount(); + } + + @Override + public void setFrozenColumnCount(int count) + throws IllegalArgumentException { + columnConfiguration.setFrozenColumnCount(count); + } + + @Override + public int getFrozenColumnCount() { + return columnConfiguration.getFrozenColumnCount(); + } + + @Override + public void setColumnWidth(int index, double px) + throws IllegalArgumentException { + columnConfiguration.setColumnWidth(index, px); + } + + @Override + public double getColumnWidth(int index) + throws IllegalArgumentException { + return columnConfiguration.getColumnWidth(index); + } + + @Override + public double getColumnWidthActual(int index) + throws IllegalArgumentException { + return columnConfiguration.getColumnWidthActual(index); + } + + @Override + public void refreshColumns(int index, int numberOfColumns) + throws IndexOutOfBoundsException, IllegalArgumentException { + columnConfiguration.refreshColumns(index, numberOfColumns); + } + + @Override + public void setColumnWidths(Map indexWidthMap) + throws IllegalArgumentException { + columnConfiguration.setColumnWidths(indexWidthMap); + } + } + + private class BodyRowContainerProxy extends RowContainerProxy + implements BodyRowContainer { + private BodyRowContainer rowContainer; + + public BodyRowContainerProxy(BodyRowContainer rowContainer) { + super(rowContainer); + this.rowContainer = rowContainer; + } + + @Override + public void setSpacer(int rowIndex, double height) + throws IllegalArgumentException { + rowContainer.setSpacer(rowIndex, height); + } + + @Override + public void setSpacerUpdater(SpacerUpdater spacerUpdater) + throws IllegalArgumentException { + rowContainer.setSpacerUpdater(spacerUpdater); + } + + @Override + public SpacerUpdater getSpacerUpdater() { + return rowContainer.getSpacerUpdater(); + } + } + + private class RowContainerProxy implements RowContainer { + private final RowContainer rowContainer; + + public RowContainerProxy(RowContainer rowContainer) { + this.rowContainer = rowContainer; + } + + @Override + public EscalatorUpdater getEscalatorUpdater() { + return rowContainer.getEscalatorUpdater(); + } + + @Override + public void setEscalatorUpdater(EscalatorUpdater escalatorUpdater) + throws IllegalArgumentException { + rowContainer.setEscalatorUpdater(escalatorUpdater); + } + + @Override + public void removeRows(int index, int numberOfRows) + throws IndexOutOfBoundsException, IllegalArgumentException { + rowContainer.removeRows(index, numberOfRows); + logWidget.log(rowContainer.getClass().getSimpleName() + + " removeRows " + index + ", " + numberOfRows); + logWidget.updateDebugLabel(); + } + + @Override + public void insertRows(int index, int numberOfRows) + throws IndexOutOfBoundsException, IllegalArgumentException { + rowContainer.insertRows(index, numberOfRows); + logWidget.log(rowContainer.getClass().getSimpleName() + + " insertRows " + index + ", " + numberOfRows); + logWidget.updateDebugLabel(); + } + + @Override + public void refreshRows(int index, int numberOfRows) + throws IndexOutOfBoundsException, IllegalArgumentException { + rowContainer.refreshRows(index, numberOfRows); + logWidget.log(rowContainer.getClass().getSimpleName() + + " refreshRows " + index + ", " + numberOfRows); + } + + @Override + public int getRowCount() { + return rowContainer.getRowCount(); + } + + @Override + public void setDefaultRowHeight(double px) + throws IllegalArgumentException { + rowContainer.setDefaultRowHeight(px); + } + + @Override + public double getDefaultRowHeight() { + return rowContainer.getDefaultRowHeight(); + } + + @Override + public Cell getCell(Element element) { + return rowContainer.getCell(element); + } + + @Override + public TableRowElement getRowElement(int index) + throws IndexOutOfBoundsException, IllegalStateException { + return rowContainer.getRowElement(index); + } + + @Override + public TableSectionElement getElement() { + return rowContainer.getElement(); + } + + } + + private RowContainer headerProxy = null; + private BodyRowContainer bodyProxy = null; + private RowContainer footerProxy = null; + private ColumnConfiguration columnProxy = null; + private LogWidget logWidget; + + @Override + public RowContainer getHeader() { + if (headerProxy == null) { + headerProxy = new RowContainerProxy(super.getHeader()); + } + return headerProxy; + } + + @Override + public RowContainer getFooter() { + if (footerProxy == null) { + footerProxy = new RowContainerProxy(super.getFooter()); + } + return footerProxy; + } + + @Override + public BodyRowContainer getBody() { + if (bodyProxy == null) { + bodyProxy = new BodyRowContainerProxy(super.getBody()); + } + return bodyProxy; + } + + @Override + public ColumnConfiguration getColumnConfiguration() { + if (columnProxy == null) { + columnProxy = new ColumnConfigurationProxy( + super.getColumnConfiguration()); + } + return columnProxy; + } + + public void setLogWidget(LogWidget logWidget) { + this.logWidget = logWidget; + logWidget.updateDebugLabel(); + } + + @Override + public void setScrollTop(double scrollTop) { + logWidget.log("setScrollTop " + scrollTop); + logWidget.updateDebugLabel(); + super.setScrollTop(scrollTop); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridBasicClientFeaturesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridBasicClientFeaturesWidget.java new file mode 100644 index 0000000000..96e988b8ea --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridBasicClientFeaturesWidget.java @@ -0,0 +1,1634 @@ +/* + * 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.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.logging.Logger; + +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.ContextMenuEvent; +import com.google.gwt.event.dom.client.ContextMenuHandler; +import com.google.gwt.event.shared.HandlerRegistration; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.MenuItem; +import com.google.gwt.user.client.ui.MenuItemSeparator; +import com.google.gwt.user.client.ui.TextBox; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.data.DataSource; +import com.vaadin.client.data.DataSource.RowHandle; +import com.vaadin.client.ui.VLabel; +import com.vaadin.tests.widgetset.client.v7.grid.GridBasicClientFeaturesWidget.Data; +import com.vaadin.v7.client.renderers.DateRenderer; +import com.vaadin.v7.client.renderers.HtmlRenderer; +import com.vaadin.v7.client.renderers.NumberRenderer; +import com.vaadin.v7.client.renderers.Renderer; +import com.vaadin.v7.client.renderers.TextRenderer; +import com.vaadin.v7.client.widget.grid.CellReference; +import com.vaadin.v7.client.widget.grid.CellStyleGenerator; +import com.vaadin.v7.client.widget.grid.DetailsGenerator; +import com.vaadin.v7.client.widget.grid.EditorHandler; +import com.vaadin.v7.client.widget.grid.EventCellReference; +import com.vaadin.v7.client.widget.grid.RendererCellReference; +import com.vaadin.v7.client.widget.grid.RowReference; +import com.vaadin.v7.client.widget.grid.RowStyleGenerator; +import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; +import com.vaadin.v7.client.widget.grid.datasources.ListSorter; +import com.vaadin.v7.client.widget.grid.events.BodyKeyDownHandler; +import com.vaadin.v7.client.widget.grid.events.BodyKeyPressHandler; +import com.vaadin.v7.client.widget.grid.events.BodyKeyUpHandler; +import com.vaadin.v7.client.widget.grid.events.ColumnReorderEvent; +import com.vaadin.v7.client.widget.grid.events.ColumnReorderHandler; +import com.vaadin.v7.client.widget.grid.events.ColumnVisibilityChangeEvent; +import com.vaadin.v7.client.widget.grid.events.ColumnVisibilityChangeHandler; +import com.vaadin.v7.client.widget.grid.events.FooterKeyDownHandler; +import com.vaadin.v7.client.widget.grid.events.FooterKeyPressHandler; +import com.vaadin.v7.client.widget.grid.events.FooterKeyUpHandler; +import com.vaadin.v7.client.widget.grid.events.GridKeyDownEvent; +import com.vaadin.v7.client.widget.grid.events.GridKeyPressEvent; +import com.vaadin.v7.client.widget.grid.events.GridKeyUpEvent; +import com.vaadin.v7.client.widget.grid.events.HeaderKeyDownHandler; +import com.vaadin.v7.client.widget.grid.events.HeaderKeyPressHandler; +import com.vaadin.v7.client.widget.grid.events.HeaderKeyUpHandler; +import com.vaadin.v7.client.widget.grid.events.ScrollEvent; +import com.vaadin.v7.client.widget.grid.events.ScrollHandler; +import com.vaadin.v7.client.widget.grid.selection.SelectionModel; +import com.vaadin.v7.client.widget.grid.selection.SelectionModel.None; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.Column; +import com.vaadin.v7.client.widgets.Grid.FooterRow; +import com.vaadin.v7.client.widgets.Grid.HeaderRow; +import com.vaadin.v7.client.widgets.Grid.SelectionMode; +import com.vaadin.v7.shared.ui.grid.ScrollDestination; + +/** + * Grid basic client features test application. + * + * @since + * @author Vaadin Ltd + */ +public class GridBasicClientFeaturesWidget + extends PureGWTTestApplication>> { + public static final String ROW_STYLE_GENERATOR_NONE = "None"; + public static final String ROW_STYLE_GENERATOR_ROW_INDEX = "Row numbers"; + public static final String ROW_STYLE_GENERATOR_EVERY_THIRD = "Every third"; + + public static final String CELL_STYLE_GENERATOR_NONE = "None"; + public static final String CELL_STYLE_GENERATOR_SIMPLE = "Simple"; + public static final String CELL_STYLE_GENERATOR_COL_INDEX = "Column index"; + + public static enum Renderers { + TEXT_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER; + } + + private class TestEditorHandler implements EditorHandler> { + + private Map, TextBox> widgets = new HashMap, TextBox>(); + + private Label log = new Label(); + + { + log.addStyleName("grid-editor-log"); + addSouth(log, 20); + } + + @Override + public void bind(EditorRequest> request) { + List rowData = ds.getRow(request.getRowIndex()); + + boolean hasSelectionColumn = !(grid + .getSelectionModel() instanceof None); + for (int i = 0; i < rowData.size(); i++) { + int columnIndex = hasSelectionColumn ? i + 1 : i; + getWidget(columnIndex).setText(rowData.get(i).value.toString()); + } + request.success(); + } + + @Override + public void cancel(EditorRequest> request) { + log.setText("Row " + request.getRowIndex() + " edit cancelled"); + } + + @Override + public void save(EditorRequest> request) { + if (secondEditorError) { + request.failure( + "Syntethic fail of editor in column 2. " + + "This message is so long that it doesn't fit into its box", + Collections.>> singleton( + grid.getColumn(2))); + return; + } + try { + log.setText("Row " + request.getRowIndex() + " edit committed"); + List rowData = ds.getRow(request.getRowIndex()); + + int i = 0; + for (; i < COLUMNS - MANUALLY_FORMATTED_COLUMNS; i++) { + rowData.get(i).value = getWidget(i).getText(); + } + + rowData.get(i).value = Integer + .valueOf(getWidget(i++).getText()); + rowData.get(i).value = new Date(getWidget(i++).getText()); + rowData.get(i).value = getWidget(i++).getText(); + rowData.get(i).value = Integer + .valueOf(getWidget(i++).getText()); + rowData.get(i).value = Integer + .valueOf(getWidget(i++).getText()); + + // notify data source of changes + ds.asList().set(request.getRowIndex(), rowData); + request.success(); + } catch (Exception e) { + Logger.getLogger(getClass().getName()).warning(e.toString()); + request.failure(null, null); + } + } + + @Override + public TextBox getWidget(Grid.Column> column) { + if (grid.getColumns().indexOf(column) == 0 + && !(grid.getSelectionModel() instanceof None)) { + return null; + } + + TextBox w = widgets.get(column); + if (w == null) { + w = new TextBox(); + w.getElement().getStyle().setMargin(0, Unit.PX); + widgets.put(column, w); + } + return w; + } + + private TextBox getWidget(int i) { + return getWidget(grid.getColumn(i)); + } + } + + private static final int MANUALLY_FORMATTED_COLUMNS = 5; + public static final int COLUMNS = 12; + public static final int ROWS = 1000; + + private final Grid> grid; + private List> data; + private final ListDataSource> ds; + private final ListSorter> sorter; + + private boolean secondEditorError = false; + + /** + * Our basic data object + */ + public final static class Data { + Object value; + } + + /** + * @since + * @return + */ + private List> createData(int rowCount) { + List> dataList = new ArrayList>(); + Random rand = new Random(); + rand.setSeed(13334); + long timestamp = 0; + for (int row = 0; row < rowCount; row++) { + + List datarow = createDataRow(COLUMNS); + dataList.add(datarow); + Data d; + + int col = 0; + for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) { + d = datarow.get(col); + d.value = "(" + row + ", " + col + ")"; + } + + d = datarow.get(col++); + d.value = Integer.valueOf(row); + + d = datarow.get(col++); + d.value = new Date(timestamp); + timestamp += 91250000; // a bit over a day, just to get + // variation + + d = datarow.get(col++); + d.value = "" + row + ""; + + d = datarow.get(col++); + d.value = Integer.valueOf(rand.nextInt()); + + d = datarow.get(col++); + d.value = Integer.valueOf(rand.nextInt(5)); + } + + return dataList; + } + + /** + * Convenience method for creating a list of Data objects to be used as a + * Row in the data source + * + * @param cols + * number of columns (items) to include in the row + * @return + */ + private List createDataRow(int cols) { + List list = new ArrayList(cols); + for (int i = 0; i < cols; ++i) { + list.add(new Data()); + } + return list; + } + + @SuppressWarnings("unchecked") + public GridBasicClientFeaturesWidget() { + super(new Grid>()); + + // Initialize data source + data = createData(ROWS); + + ds = new ListDataSource>(data); + grid = getTestedWidget(); + grid.getElement().setId("testComponent"); + grid.setDataSource(ds); + grid.addSelectAllHandler(ds.getSelectAllHandler()); + grid.setSelectionMode(SelectionMode.NONE); + grid.setEditorHandler(new TestEditorHandler()); + + sorter = new ListSorter>(grid); + + // Create a bunch of grid columns + + // Data source layout: + // text (String) * (COLUMNS - MANUALLY_FORMATTED_COLUMNS + 1) | + // rownumber (Integer) | some date (Date) | row number as HTML (String) + // | random value (Integer) + + int col = 0; + + // Text times COLUMNS - MANUALLY_FORMATTED_COLUMNS + for (col = 0; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) { + + final int c = col; + + Grid.Column> column = new Grid.Column>( + createRenderer(Renderers.TEXT_RENDERER)) { + @Override + public String getValue(List row) { + return (String) row.get(c).value; + } + }; + + column.setWidth(50 + c * 25); + column.setHeaderCaption("Header (0," + c + ")"); + + grid.addColumn(column); + } + + // Integer row number + { + final int c = col++; + Grid.Column> column = new Grid.Column>( + createRenderer(Renderers.NUMBER_RENDERER)) { + @Override + public Integer getValue(List row) { + return (Integer) row.get(c).value; + } + }; + grid.addColumn(column); + column.setHeaderCaption("Header (0," + c + ")"); + } + + // Some date + { + final int c = col++; + Grid.Column> column = new Grid.Column>( + createRenderer(Renderers.DATE_RENDERER)) { + @Override + public Date getValue(List row) { + return (Date) row.get(c).value; + } + }; + grid.addColumn(column); + column.setHeaderCaption("Header (0," + c + ")"); + } + + // Row number as a HTML string + { + final int c = col++; + Grid.Column> column = new Grid.Column>( + createRenderer(Renderers.HTML_RENDERER)) { + @Override + public String getValue(List row) { + return (String) row.get(c).value; + } + }; + grid.addColumn(column); + column.setHeaderCaption("Header (0," + c + ")"); + } + + // Random integer value + { + final int c = col++; + Grid.Column> column = new Grid.Column>( + createRenderer(Renderers.NUMBER_RENDERER)) { + @Override + public Integer getValue(List row) { + return (Integer) row.get(c).value; + } + }; + grid.addColumn(column); + column.setHeaderCaption("Header (0," + c + ")"); + } + + // Random integer value between 0 and 5 + { + final int c = col++; + Grid.Column> column = new Grid.Column>( + createRenderer(Renderers.NUMBER_RENDERER)) { + @Override + public Integer getValue(List row) { + return (Integer) row.get(c).value; + } + }; + grid.addColumn(column); + column.setHeaderCaption("Header (0," + c + ")"); + } + + grid.getColumn(3).setEditable(false); + + HeaderRow row = grid.getDefaultHeaderRow(); + for (int i = 0; i < col; ++i) { + String caption = "Header (0," + i + ")"; + Grid.Column column = grid.getColumn(i); + // Lets use some different cell types + if (i % 3 == 0) { + // No-op + } else if (i % 2 == 0) { + row.getCell(column).setHtml("" + caption + ""); + } else { + row.getCell(column).setWidget(new HTML(caption)); + } + } + ++headerCounter; + + // + // Populate the menu + // + + createStateMenu(); + createColumnsMenu(); + createHeaderMenu(); + createFooterMenu(); + createEditorMenu(); + createInternalsMenu(); + createDataSourceMenu(); + createDetailsMenu(); + createSidebarMenu(); + + grid.getElement().getStyle().setZIndex(0); + + // + // Composite wrapping for grid. + // + boolean isComposite = Window.Location.getParameter("composite") != null; + if (isComposite) { + addNorth(new Composite() { + { + initWidget(grid); + } + }, 400); + } else { + addNorth(grid, 400); + } + + createKeyHandlers(); + } + + private void createInternalsMenu() { + String[] listenersPath = { "Component", "Internals", "Listeners" }; + final Label label = new Label(); + addSouth(label, 20); + + addMenuCommand("Add scroll listener", new ScheduledCommand() { + private HandlerRegistration scrollHandler = null; + + @Override + public void execute() { + if (scrollHandler != null) { + return; + } + scrollHandler = grid.addScrollHandler(new ScrollHandler() { + @Override + public void onScroll(ScrollEvent event) { + @SuppressWarnings("hiding") + final Grid grid = (Grid) event.getSource(); + label.setText("scrollTop: " + grid.getScrollTop() + + ", scrollLeft: " + grid.getScrollLeft()); + } + }); + } + }, listenersPath); + addMenuCommand("Add ColumnReorder listener", new ScheduledCommand() { + private HandlerRegistration columnReorderHandler = null; + + @Override + public void execute() { + if (columnReorderHandler != null) { + return; + } + final Label columnOrderLabel = new Label(); + columnOrderLabel.getElement().setId("columnreorder"); + addLineEnd(columnOrderLabel, 300); + columnReorderHandler = grid.addColumnReorderHandler( + new ColumnReorderHandler>() { + + private int eventIndex = 0; + + @Override + public void onColumnReorder( + ColumnReorderEvent> event) { + columnOrderLabel.getElement().setAttribute( + "columns", "" + (++eventIndex)); + } + }); + } + }, listenersPath); + addMenuCommand("Add Column Visibility Change listener", + new ScheduledCommand() { + private HandlerRegistration columnVisibilityHandler = null; + + @Override + public void execute() { + if (columnVisibilityHandler != null) { + return; + } + final Label columnOrderLabel = new Label(); + columnOrderLabel.getElement().setId("columnvisibility"); + addLineEnd(columnOrderLabel, 250); + ColumnVisibilityChangeHandler handler = new ColumnVisibilityChangeHandler>() { + + private int eventIndex = 0; + + @Override + public void onVisibilityChange( + ColumnVisibilityChangeEvent> event) { + columnOrderLabel.getElement().setAttribute( + "counter", "" + (++eventIndex)); + columnOrderLabel.getElement().setAttribute( + "useroriginated", (Boolean.toString( + event.isUserOriginated()))); + columnOrderLabel.getElement().setAttribute( + "ishidden", + (Boolean.toString(event.isHidden()))); + columnOrderLabel.getElement().setAttribute( + "columnindex", "" + grid.getColumns() + .indexOf(event.getColumn())); + } + }; + + columnVisibilityHandler = grid + .addColumnVisibilityChangeHandler(handler); + } + }, listenersPath); + addMenuCommand("Add context menu listener", new ScheduledCommand() { + + HandlerRegistration handler = null; + ContextMenuHandler contextMenuHandler = new ContextMenuHandler() { + + @Override + public void onContextMenu(ContextMenuEvent event) { + event.preventDefault(); + final String location; + EventCellReference cellRef = grid.getEventCell(); + if (cellRef.isHeader()) { + location = "header"; + } else if (cellRef.isBody()) { + location = "body"; + } else if (cellRef.isFooter()) { + location = "footer"; + } else { + location = "somewhere"; + } + + getLogger().info("Prevented opening a context menu in grid " + + location); + } + }; + + @Override + public void execute() { + if (handler != null) { + grid.unsinkEvents(Event.ONCONTEXTMENU); + handler.removeHandler(); + } else { + grid.sinkEvents(Event.ONCONTEXTMENU); + handler = grid.addDomHandler(contextMenuHandler, + ContextMenuEvent.getType()); + } + } + + }, listenersPath); + } + + private void createStateMenu() { + String[] selectionModePath = { "Component", "State", "Selection mode" }; + String[] primaryStyleNamePath = { "Component", "State", + "Primary Stylename" }; + String[] rowStyleGeneratorNamePath = { "Component", "State", + "Row style generator" }; + String[] cellStyleGeneratorNamePath = { "Component", "State", + "Cell style generator" }; + + addMenuCommand("multi", new ScheduledCommand() { + @Override + public void execute() { + grid.setSelectionMode(SelectionMode.MULTI); + } + }, selectionModePath); + + addMenuCommand("single", new ScheduledCommand() { + @Override + public void execute() { + grid.setSelectionMode(SelectionMode.SINGLE); + } + }, selectionModePath); + + addMenuCommand("single (no deselect)", new ScheduledCommand() { + @Override + public void execute() { + grid.setSelectionMode(SelectionMode.SINGLE); + ((SelectionModel.Single) grid.getSelectionModel()) + .setDeselectAllowed(false); + } + }, selectionModePath); + + addMenuCommand("none", new ScheduledCommand() { + @Override + public void execute() { + grid.setSelectionMode(SelectionMode.NONE); + } + }, selectionModePath); + + addMenuCommand("v-grid", new ScheduledCommand() { + @Override + public void execute() { + grid.setStylePrimaryName("v-grid"); + + } + }, primaryStyleNamePath); + + addMenuCommand("v-escalator", new ScheduledCommand() { + @Override + public void execute() { + grid.setStylePrimaryName("v-escalator"); + + } + }, primaryStyleNamePath); + + addMenuCommand("v-custom-style", new ScheduledCommand() { + @Override + public void execute() { + grid.setStylePrimaryName("v-custom-style"); + + } + }, primaryStyleNamePath); + + addMenuCommand("Edit and refresh Row 0", new ScheduledCommand() { + @Override + public void execute() { + DataSource> ds = grid.getDataSource(); + RowHandle> rowHandle = ds.getHandle(ds.getRow(0)); + rowHandle.getRow().get(0).value = "Foo"; + rowHandle.updateRow(); + } + }, "Component", "State"); + + addMenuCommand("Delayed edit of Row 0", new ScheduledCommand() { + @Override + public void execute() { + DataSource> ds = grid.getDataSource(); + final RowHandle> rowHandle = ds + .getHandle(ds.getRow(0)); + + new Timer() { + @Override + public void run() { + rowHandle.getRow().get(0).value = "Bar"; + rowHandle.updateRow(); + } + + }.schedule(5000); + } + }, "Component", "State"); + + addMenuCommand(ROW_STYLE_GENERATOR_NONE, new ScheduledCommand() { + @Override + public void execute() { + grid.setRowStyleGenerator(null); + } + }, rowStyleGeneratorNamePath); + + addMenuCommand(ROW_STYLE_GENERATOR_EVERY_THIRD, new ScheduledCommand() { + @Override + public void execute() { + grid.setRowStyleGenerator(new RowStyleGenerator>() { + + @Override + public String getStyle( + RowReference> rowReference) { + if (rowReference.getRowIndex() % 3 == 0) { + return "third"; + } else { + // First manual col is integer + Integer value = (Integer) rowReference.getRow().get( + COLUMNS - MANUALLY_FORMATTED_COLUMNS).value; + return value.toString(); + } + } + }); + + } + }, rowStyleGeneratorNamePath); + + addMenuCommand(ROW_STYLE_GENERATOR_ROW_INDEX, new ScheduledCommand() { + @Override + public void execute() { + grid.setRowStyleGenerator(new RowStyleGenerator>() { + + @Override + public String getStyle( + RowReference> rowReference) { + return Integer.toString(rowReference.getRowIndex()); + } + }); + + } + }, rowStyleGeneratorNamePath); + + addMenuCommand(CELL_STYLE_GENERATOR_NONE, new ScheduledCommand() { + @Override + public void execute() { + grid.setCellStyleGenerator(null); + } + }, cellStyleGeneratorNamePath); + + addMenuCommand(CELL_STYLE_GENERATOR_SIMPLE, new ScheduledCommand() { + @Override + public void execute() { + grid.setCellStyleGenerator( + new CellStyleGenerator>() { + + @Override + public String getStyle( + CellReference> cellReference) { + Grid.Column> column = cellReference + .getColumn(); + if (column == grid.getColumn(2)) { + return "two"; + } else if (column == grid.getColumn( + COLUMNS - MANUALLY_FORMATTED_COLUMNS)) { + // First manual col is integer + Integer value = (Integer) column + .getValue(cellReference.getRow()); + return value.toString(); + + } else { + return null; + } + } + }); + } + }, cellStyleGeneratorNamePath); + addMenuCommand(CELL_STYLE_GENERATOR_COL_INDEX, new ScheduledCommand() { + @Override + public void execute() { + grid.setCellStyleGenerator( + new CellStyleGenerator>() { + + @Override + public String getStyle( + CellReference> cellReference) { + return cellReference.getRowIndex() + "_" + + grid.getColumns().indexOf( + cellReference.getColumn()); + } + }); + } + }, cellStyleGeneratorNamePath); + + for (int i = -1; i <= COLUMNS; i++) { + final int index = i; + // Including dummy "columns" prefix because TB fails to select item + // if it's too narrow + addMenuCommand(Integer.toString(index) + " columns", + new ScheduledCommand() { + @Override + public void execute() { + grid.setFrozenColumnCount(index); + } + }, "Component", "State", "Frozen column count"); + } + + addMenuCommand("Enabled", new ScheduledCommand() { + + @Override + public void execute() { + grid.setEnabled(!grid.isEnabled()); + } + }, "Component", "State"); + addMenuCommand("Reverse grid columns", new ScheduledCommand() { + + @Override + public void execute() { + List columns = new ArrayList(grid.getColumns()); + Collections.reverse(columns); + grid.setColumnOrder( + columns.toArray(new Column[columns.size()])); + } + }, "Component", "State"); + addMenuCommand("Column Reordering", new ScheduledCommand() { + + @Override + public void execute() { + grid.setColumnReorderingAllowed( + !grid.isColumnReorderingAllowed()); + } + }, "Component", "State"); + addMenuCommand("250px", new ScheduledCommand() { + + @Override + public void execute() { + grid.setWidth("250px"); + } + }, "Component", "State", "Width"); + addMenuCommand("500px", new ScheduledCommand() { + + @Override + public void execute() { + grid.setWidth("500px"); + } + }, "Component", "State", "Width"); + addMenuCommand("750px", new ScheduledCommand() { + + @Override + public void execute() { + grid.setWidth("750px"); + } + }, "Component", "State", "Width"); + addMenuCommand("1000px", new ScheduledCommand() { + + @Override + public void execute() { + grid.setWidth("1000px"); + } + }, "Component", "State", "Width"); + + createScrollToRowMenu(); + } + + private void createScrollToRowMenu() { + String[] menupath = new String[] { "Component", "State", "Scroll to...", + null }; + + for (int i = 0; i < ROWS; i += 100) { + menupath[3] = "Row " + i + "..."; + for (final ScrollDestination scrollDestination : ScrollDestination + .values()) { + final int row = i; + addMenuCommand("Destination " + scrollDestination, + new ScheduledCommand() { + @Override + public void execute() { + grid.scrollToRow(row, scrollDestination); + } + }, menupath); + } + } + + int i = ROWS - 1; + menupath[3] = "Row " + i + "..."; + for (final ScrollDestination scrollDestination : ScrollDestination + .values()) { + final int row = i; + addMenuCommand("Destination " + scrollDestination, + new ScheduledCommand() { + @Override + public void execute() { + grid.scrollToRow(row, scrollDestination); + } + }, menupath); + } + + } + + private void createColumnsMenu() { + + for (int i = 0; i < COLUMNS; i++) { + final int index = i; + final Grid.Column> column = grid.getColumn(index); + addMenuCommand("Sortable", new ScheduledCommand() { + @Override + public void execute() { + column.setSortable(!column.isSortable()); + } + }, "Component", "Columns", "Column " + i); + addMenuCommand("Hidden", new ScheduledCommand() { + @Override + public void execute() { + column.setHidden(!column.isHidden()); + } + }, "Component", "Columns", "Column " + i); + addMenuCommand("Hidable", new ScheduledCommand() { + @Override + public void execute() { + column.setHidable(!column.isHidable()); + } + }, "Component", "Columns", "Column " + i); + addMenuCommand("auto", new ScheduledCommand() { + @Override + public void execute() { + column.setWidth(-1); + } + }, "Component", "Columns", "Column " + i, "Width"); + addMenuCommand("50px", new ScheduledCommand() { + @Override + public void execute() { + column.setWidth(50); + } + }, "Component", "Columns", "Column " + i, "Width"); + addMenuCommand("200px", new ScheduledCommand() { + @Override + public void execute() { + column.setWidth(200); + } + }, "Component", "Columns", "Column " + i, "Width"); + + // Header types + addMenuCommand("Text Header", new ScheduledCommand() { + @Override + public void execute() { + column.setHeaderCaption("Text Header"); + } + }, "Component", "Columns", "Column " + i, "Header Type"); + addMenuCommand("HTML Header", new ScheduledCommand() { + @Override + public void execute() { + grid.getHeaderRow(0).getCell(column) + .setHtml("HTML Header"); + } + }, "Component", "Columns", "Column " + i, "Header Type"); + addMenuCommand("Widget Header", new ScheduledCommand() { + @Override + public void execute() { + final Button button = new Button("Button Header"); + button.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + button.setText("Clicked"); + } + }); + grid.getHeaderRow(0).getCell(column).setWidget(button); + } + }, "Component", "Columns", "Column " + i, "Header Type"); + + // Footer types + addMenuCommand("Text Footer", new ScheduledCommand() { + @Override + public void execute() { + grid.getFooterRow(0).getCell(column).setText("Text Footer"); + } + }, "Component", "Columns", "Column " + i, "Footer Type"); + addMenuCommand("HTML Footer", new ScheduledCommand() { + @Override + public void execute() { + grid.getFooterRow(0).getCell(column) + .setHtml("HTML Footer"); + } + }, "Component", "Columns", "Column " + i, "Footer Type"); + addMenuCommand("Widget Footer", new ScheduledCommand() { + @Override + public void execute() { + final Button button = new Button("Button Footer"); + button.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + button.setText("Clicked"); + } + }); + grid.getFooterRow(0).getCell(column).setWidget(button); + } + }, "Component", "Columns", "Column " + i, "Footer Type"); + + // Renderer throwing exceptions + addMenuCommand("Broken renderer", new ScheduledCommand() { + @Override + public void execute() { + final Renderer originalRenderer = (Renderer) column + .getRenderer(); + + column.setRenderer(new Renderer() { + @Override + public void render(RendererCellReference cell, + Object data) { + if (cell.getRowIndex() == cell.getColumnIndex()) { + throw new RuntimeException("I'm broken"); + } + originalRenderer.render(cell, data); + } + }); + } + }, "Component", "Columns", "Column " + i); + addMenuCommand("Move column left", new ScheduledCommand() { + + @SuppressWarnings("unchecked") + @Override + public void execute() { + List>> cols = grid.getColumns(); + ArrayList reordered = new ArrayList(cols); + final int index = cols.indexOf(column); + if (index == 0) { + Column> col = reordered.remove(0); + reordered.add(col); + } else { + Column> col = reordered.remove(index); + reordered.add(index - 1, col); + } + grid.setColumnOrder( + reordered.toArray(new Column[reordered.size()])); + } + }, "Component", "Columns", "Column " + i); + } + } + + private int headerCounter = 0; + private int footerCounter = 0; + + private void setHeaderTexts(HeaderRow row) { + for (int i = 0; i < COLUMNS; ++i) { + String caption = "Header (" + headerCounter + "," + i + ")"; + + // Lets use some different cell types + if (i % 3 == 0) { + row.getCell(grid.getColumn(i)).setText(caption); + } else if (i % 2 == 0) { + row.getCell(grid.getColumn(i)) + .setHtml("" + caption + ""); + } else { + row.getCell(grid.getColumn(i)).setWidget(new HTML(caption)); + } + } + headerCounter++; + } + + private void setFooterTexts(FooterRow row) { + for (int i = 0; i < COLUMNS; ++i) { + String caption = "Footer (" + footerCounter + "," + i + ")"; + + // Lets use some different cell types + if (i % 3 == 0) { + row.getCell(grid.getColumn(i)).setText(caption); + } else if (i % 2 == 0) { + row.getCell(grid.getColumn(i)) + .setHtml("" + caption + ""); + } else { + row.getCell(grid.getColumn(i)).setWidget(new HTML(caption)); + } + } + footerCounter++; + } + + private void createHeaderMenu() { + final String[] menuPath = { "Component", "Header" }; + + addMenuCommand("Visible", new ScheduledCommand() { + @Override + public void execute() { + grid.setHeaderVisible(!grid.isHeaderVisible()); + } + }, menuPath); + + addMenuCommand("Top", new ScheduledCommand() { + @Override + public void execute() { + grid.setDefaultHeaderRow(grid.getHeaderRow(0)); + } + }, "Component", "Header", "Default row"); + addMenuCommand("Bottom", new ScheduledCommand() { + @Override + public void execute() { + grid.setDefaultHeaderRow( + grid.getHeaderRow(grid.getHeaderRowCount() - 1)); + } + }, "Component", "Header", "Default row"); + addMenuCommand("Unset", new ScheduledCommand() { + @Override + public void execute() { + grid.setDefaultHeaderRow(null); + } + }, "Component", "Header", "Default row"); + + addMenuCommand("Prepend row", new ScheduledCommand() { + @Override + public void execute() { + configureHeaderRow(grid.prependHeaderRow()); + } + }, menuPath); + addMenuCommand("Append row", new ScheduledCommand() { + @Override + public void execute() { + configureHeaderRow(grid.appendHeaderRow()); + } + }, menuPath); + addMenuCommand("Remove top row", new ScheduledCommand() { + @Override + public void execute() { + grid.removeHeaderRow(0); + } + }, menuPath); + addMenuCommand("Remove bottom row", new ScheduledCommand() { + @Override + public void execute() { + grid.removeHeaderRow(grid.getHeaderRowCount() - 1); + } + }, menuPath); + + } + + private void configureHeaderRow(final HeaderRow row) { + setHeaderTexts(row); + String rowTitle = "Row " + grid.getHeaderRowCount(); + final String[] menuPath = { "Component", "Header", rowTitle }; + + addMenuCommand("Join column cells 0, 1", new ScheduledCommand() { + + @Override + public void execute() { + row.join(row.getCell(grid.getColumn(0)), + row.getCell(grid.getColumn(1))) + .setText("Join column cells 0, 1"); + + } + }, menuPath); + + addMenuCommand("Join columns 1, 2", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumn(1), grid.getColumn(2)) + .setText("Join columns 1, 2"); + ; + + } + }, menuPath); + + addMenuCommand("Join columns 3, 4, 5", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumn(3), grid.getColumn(4), + grid.getColumn(5)).setText("Join columns 3, 4, 5"); + + } + }, menuPath); + + addMenuCommand("Join all columns", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumns() + .toArray(new Grid.Column[grid.getColumnCount()])) + .setText("Join all columns"); + ; + + } + }, menuPath); + } + + private void createFooterMenu() { + final String[] menuPath = { "Component", "Footer" }; + + addMenuCommand("Visible", new ScheduledCommand() { + @Override + public void execute() { + grid.setFooterVisible(!grid.isFooterVisible()); + } + }, menuPath); + + addMenuCommand("Prepend row", new ScheduledCommand() { + @Override + public void execute() { + configureFooterRow(grid.prependFooterRow()); + } + }, menuPath); + addMenuCommand("Append row", new ScheduledCommand() { + @Override + public void execute() { + configureFooterRow(grid.appendFooterRow()); + } + }, menuPath); + addMenuCommand("Remove top row", new ScheduledCommand() { + @Override + public void execute() { + grid.removeFooterRow(0); + } + }, menuPath); + addMenuCommand("Remove bottom row", new ScheduledCommand() { + @Override + public void execute() { + assert grid.getFooterRowCount() > 0; + grid.removeFooterRow(grid.getFooterRowCount() - 1); + } + }, menuPath); + } + + private void createEditorMenu() { + addMenuCommand("Enabled", new ScheduledCommand() { + @Override + public void execute() { + grid.setEditorEnabled(!grid.isEditorEnabled()); + } + }, "Component", "Editor"); + + addMenuCommand("Edit row 5", new ScheduledCommand() { + @Override + public void execute() { + grid.editRow(5); + } + }, "Component", "Editor"); + + addMenuCommand("Edit row 100", new ScheduledCommand() { + @Override + public void execute() { + grid.editRow(100); + } + }, "Component", "Editor"); + + addMenuCommand("Save", new ScheduledCommand() { + @Override + public void execute() { + grid.saveEditor(); + } + }, "Component", "Editor"); + + addMenuCommand("Cancel edit", new ScheduledCommand() { + @Override + public void execute() { + grid.cancelEditor(); + } + }, "Component", "Editor"); + + addMenuCommand("Change Save Caption", new ScheduledCommand() { + @Override + public void execute() { + grid.setEditorSaveCaption("ǝʌɐS"); + } + }, "Component", "Editor"); + + addMenuCommand("Change Cancel Caption", new ScheduledCommand() { + @Override + public void execute() { + grid.setEditorCancelCaption("ʃǝɔuɐↃ"); + } + }, "Component", "Editor"); + + addMenuCommand("Toggle second editor error", new ScheduledCommand() { + @Override + public void execute() { + secondEditorError = !secondEditorError; + } + }, "Component", "Editor"); + } + + private void configureFooterRow(final FooterRow row) { + setFooterTexts(row); + String rowTitle = "Row " + grid.getFooterRowCount(); + final String[] menuPath = { "Component", "Footer", rowTitle }; + + addMenuCommand("Join column cells 0, 1", new ScheduledCommand() { + + @Override + public void execute() { + row.join(row.getCell(grid.getColumn(0)), + row.getCell(grid.getColumn(1))) + .setText("Join column cells 0, 1"); + + } + }, menuPath); + + addMenuCommand("Join columns 1, 2", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumn(1), grid.getColumn(2)) + .setText("Join columns 1, 2"); + ; + + } + }, menuPath); + + addMenuCommand("Join all columns", new ScheduledCommand() { + + @Override + public void execute() { + row.join(grid.getColumns() + .toArray(new Grid.Column[grid.getColumnCount()])) + .setText("Join all columns"); + ; + + } + }, menuPath); + } + + private void createDataSourceMenu() { + final String[] menuPath = { "Component", "DataSource" }; + + addMenuCommand("Reset with 100 rows of Data", new ScheduledCommand() { + @Override + public void execute() { + ds.asList().clear(); + data = createData(100); + ds.asList().addAll(data); + } + }, menuPath); + + addMenuCommand("Reset with " + ROWS + " rows of Data", + new ScheduledCommand() { + @Override + public void execute() { + ds.asList().clear(); + data = createData(ROWS); + ds.asList().addAll(data); + } + }, menuPath); + } + + /** + * Creates a renderer for a {@link Renderers} + */ + @SuppressWarnings("rawtypes") + private final Renderer createRenderer(Renderers renderer) { + switch (renderer) { + case TEXT_RENDERER: + return new TextRenderer(); + + case HTML_RENDERER: + return new HtmlRenderer() { + + @Override + public void render(RendererCellReference cell, + String htmlString) { + super.render(cell, "" + htmlString + ""); + } + }; + + case NUMBER_RENDERER: + return new NumberRenderer(); + + case DATE_RENDERER: + return new DateRenderer(); + + default: + return new TextRenderer(); + } + } + + /** + * Creates a collection of handlers for all the grid key events + */ + private void createKeyHandlers() { + final List labels = new ArrayList(); + for (int i = 0; i < 9; ++i) { + VLabel tmp = new VLabel(); + addNorth(tmp, 20); + labels.add(tmp); + } + + // Key Down Events + grid.addBodyKeyDownHandler(new BodyKeyDownHandler() { + private final VLabel label = labels.get(0); + + @Override + public void onKeyDown(GridKeyDownEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + grid.addHeaderKeyDownHandler(new HeaderKeyDownHandler() { + private final VLabel label = labels.get(1); + + @Override + public void onKeyDown(GridKeyDownEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + grid.addFooterKeyDownHandler(new FooterKeyDownHandler() { + private final VLabel label = labels.get(2); + + @Override + public void onKeyDown(GridKeyDownEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + // Key Up Events + grid.addBodyKeyUpHandler(new BodyKeyUpHandler() { + private final VLabel label = labels.get(3); + + @Override + public void onKeyUp(GridKeyUpEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + grid.addHeaderKeyUpHandler(new HeaderKeyUpHandler() { + private final VLabel label = labels.get(4); + + @Override + public void onKeyUp(GridKeyUpEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + grid.addFooterKeyUpHandler(new FooterKeyUpHandler() { + private final VLabel label = labels.get(5); + + @Override + public void onKeyUp(GridKeyUpEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + // Key Press Events + grid.addBodyKeyPressHandler(new BodyKeyPressHandler() { + private final VLabel label = labels.get(6); + + @Override + public void onKeyPress(GridKeyPressEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + grid.addHeaderKeyPressHandler(new HeaderKeyPressHandler() { + private final VLabel label = labels.get(7); + + @Override + public void onKeyPress(GridKeyPressEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + grid.addFooterKeyPressHandler(new FooterKeyPressHandler() { + private final VLabel label = labels.get(8); + + @Override + public void onKeyPress(GridKeyPressEvent event) { + CellReference focused = event.getFocusedCell(); + updateLabel(label, event.toDebugString(), focused.getRowIndex(), + focused.getColumnIndex()); + } + }); + + } + + private void updateLabel(VLabel label, String output, int object, + int column) { + String coords = "(" + object + ", " + column + ")"; + label.setText(coords + " " + output); + } + + private void createDetailsMenu() { + String[] menupath = new String[] { "Component", "Row details" }; + addMenuCommand("Set generator", new ScheduledCommand() { + @Override + public void execute() { + grid.setDetailsGenerator(new DetailsGenerator() { + @Override + public Widget getDetails(int rowIndex) { + FlowPanel panel = new FlowPanel(); + + final Label label = new Label("Row: " + rowIndex + "."); + Button button = new Button("Button", + new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + label.setText("clicked"); + } + }); + + panel.add(label); + panel.add(button); + return panel; + } + }); + } + }, menupath); + + addMenuCommand("Set faulty generator", new ScheduledCommand() { + @Override + public void execute() { + grid.setDetailsGenerator(new DetailsGenerator() { + @Override + public Widget getDetails(int rowIndex) { + throw new RuntimeException("This is by design."); + } + }); + } + }, menupath); + + addMenuCommand("Set empty generator", new ScheduledCommand() { + @Override + public void execute() { + grid.setDetailsGenerator(new DetailsGenerator() { + /* + * While this is functionally equivalent to the NULL + * generator, it's good to be explicit, since the behavior + * isn't strictly tied between them. NULL generator might be + * changed to render something different by default, and an + * empty generator might behave differently also in the + * future. + */ + + @Override + public Widget getDetails(int rowIndex) { + return null; + } + }); + } + }, menupath); + + String[] togglemenupath = new String[] { menupath[0], menupath[1], + "Toggle details for..." }; + for (int i : new int[] { 0, 1, 100, 200, 300, 400, 500, 600, 700, 800, + 900, 999 }) { + final int rowIndex = i; + addMenuCommand("Row " + rowIndex, new ScheduledCommand() { + boolean visible = false; + + @Override + public void execute() { + visible = !visible; + grid.setDetailsVisible(rowIndex, visible); + } + }, togglemenupath); + } + + } + + private static Logger getLogger() { + return Logger.getLogger(GridBasicClientFeaturesWidget.class.getName()); + } + + private void createSidebarMenu() { + String[] menupath = new String[] { "Component", "Sidebar" }; + + final List customMenuItems = new ArrayList(); + final List separators = new ArrayList(); + + addMenuCommand("Add item to end", new ScheduledCommand() { + @Override + public void execute() { + MenuItem item = createSidebarMenuItem(customMenuItems.size()); + customMenuItems.add(item); + grid.getSidebarMenu().addItem(item); + } + }, menupath); + + addMenuCommand("Add item before index 1", new ScheduledCommand() { + @Override + public void execute() { + MenuItem item = createSidebarMenuItem(customMenuItems.size()); + customMenuItems.add(item); + grid.getSidebarMenu().insertItem(item, 1); + } + }, menupath); + + addMenuCommand("Remove last added item", new ScheduledCommand() { + @Override + public void execute() { + grid.getSidebarMenu().removeItem( + customMenuItems.remove(customMenuItems.size() - 1)); + } + }, menupath); + + addMenuCommand("Add separator to end", new ScheduledCommand() { + @Override + public void execute() { + MenuItemSeparator separator = new MenuItemSeparator(); + separators.add(separator); + grid.getSidebarMenu().addSeparator(separator); + } + }, menupath); + + addMenuCommand("Add separator before index 1", new ScheduledCommand() { + @Override + public void execute() { + MenuItemSeparator separator = new MenuItemSeparator(); + separators.add(separator); + grid.getSidebarMenu().insertSeparator(separator, 1); + } + }, menupath); + + addMenuCommand("Remove last added separator", new ScheduledCommand() { + @Override + public void execute() { + grid.getSidebarMenu().removeSeparator( + separators.remove(separators.size() - 1)); + } + }, menupath); + + addMenuCommand("Toggle sidebar visibility", new ScheduledCommand() { + @Override + public void execute() { + grid.setSidebarOpen(!grid.isSidebarOpen()); + } + }, menupath); + + addMenuCommand("Open sidebar and disable grid", new ScheduledCommand() { + @Override + public void execute() { + grid.setSidebarOpen(true); + + Scheduler.get() + .scheduleFixedDelay(new Scheduler.RepeatingCommand() { + @Override + public boolean execute() { + if (grid.isSidebarOpen()) { + grid.setEnabled(false); + + return false; + } + + return true; + } + }, 250); + } + }, menupath); + } + + private MenuItem createSidebarMenuItem(final int index) { + final MenuItem menuItem = new MenuItem("Custom menu item " + index, + new ScheduledCommand() { + @Override + public void execute() { + if (index % 2 == 0) { + grid.setSidebarOpen(false); + } + getLogger().info("Menu item " + index + " selected"); + } + }); + return menuItem; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridCellFocusOnResetSizeWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridCellFocusOnResetSizeWidget.java new file mode 100644 index 0000000000..ba598b6897 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridCellFocusOnResetSizeWidget.java @@ -0,0 +1,117 @@ +/* + * 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.List; + +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.ui.Button; +import com.vaadin.client.data.DataChangeHandler; +import com.vaadin.client.data.DataSource; +import com.vaadin.shared.Registration; +import com.vaadin.v7.client.renderers.HtmlRenderer; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.SelectionMode; + +public class GridCellFocusOnResetSizeWidget + extends PureGWTTestApplication> { + + private Grid grid; + + private final class MyDataSource implements DataSource { + List rows = new ArrayList(); + int ROWS_MAX = 10; + int size = ROWS_MAX; + DataChangeHandler handler = null; + { + for (int i = 0; i < ROWS_MAX; ++i) { + rows.add(new String[] { "Foo " + i }); + } + } + + @Override + public void ensureAvailability(int firstRowIndex, int numberOfRows) { + handler.dataAvailable(firstRowIndex, numberOfRows); + } + + @Override + public int size() { + return size; + } + + @Override + public Registration addDataChangeHandler( + DataChangeHandler dataChangeHandler) { + handler = dataChangeHandler; + return null; + } + + @Override + public RowHandle getHandle(final String[] rowData) { + return null; + } + + @Override + public String[] getRow(int rowIndex) { + if (rowIndex < size && rowIndex >= 0) { + return rows.get(rowIndex); + } + return null; + } + + public void changeSize() { + size--; + if (size < ROWS_MAX / 2) { + size = ROWS_MAX; + } + handler.resetDataAndSize(size); + } + } + + private class Col extends Grid.Column { + public Col(String header) { + super(header, new HtmlRenderer()); + } + + @Override + public String getValue(String[] row) { + int index = grid.getColumns().indexOf(this); + return "" + String.valueOf(row[index]) + ""; + } + } + + public GridCellFocusOnResetSizeWidget() { + super(new Grid()); + grid = getTestedWidget(); + grid.setSelectionMode(SelectionMode.NONE); + grid.setWidth("300px"); + grid.addColumn(new Col("Foo")); + final MyDataSource dataSource = new MyDataSource(); + grid.setDataSource(dataSource); + Button widget = new Button("Change Container Size"); + widget.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + dataSource.changeSize(); + } + }); + addNorth(grid, 400); + addNorth(widget, 50); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClickExtensionConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClickExtensionConnector.java new file mode 100644 index 0000000000..bc2fe71074 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClickExtensionConnector.java @@ -0,0 +1,67 @@ +/* + * 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 com.vaadin.client.MouseEventDetailsBuilder; +import com.vaadin.client.ServerConnector; +import com.vaadin.client.extensions.AbstractExtensionConnector; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.Connect; +import com.vaadin.v7.client.connectors.GridConnector; +import com.vaadin.v7.client.widget.grid.CellReference; +import com.vaadin.v7.client.widget.grid.events.BodyClickHandler; +import com.vaadin.v7.client.widget.grid.events.GridClickEvent; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.tests.components.grid.GridExtensionCommunication.GridClickExtension; + +import elemental.json.JsonObject; + +@Connect(GridClickExtension.class) +public class GridClickExtensionConnector extends AbstractExtensionConnector { + public interface GridClickServerRpc extends ServerRpc { + + public void click(String row, String column, MouseEventDetails click); + } + + @Override + protected void extend(ServerConnector target) { + Grid grid = getParent().getWidget(); + grid.addBodyClickHandler(new BodyClickHandler() { + + @Override + public void onClick(GridClickEvent event) { + CellReference cellRef = event.getTargetCell(); + + // Gather needed information. + String rowKey = getParent() + .getRowKey((JsonObject) cellRef.getRow()); + String columnId = getParent().getColumnId(cellRef.getColumn()); + MouseEventDetails clickDetails = MouseEventDetailsBuilder + .buildMouseEventDetails(event.getNativeEvent()); + + getRpcProxy(GridClickServerRpc.class).click(rowKey, columnId, + clickDetails); + } + }); + } + + @Override + public GridConnector getParent() { + return (GridConnector) super.getParent(); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientColumnRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientColumnRendererConnector.java new file mode 100644 index 0000000000..b7d6e03596 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientColumnRendererConnector.java @@ -0,0 +1,383 @@ +/* + * 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.Comparator; +import java.util.Date; +import java.util.List; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Element; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.Window.Location; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.HasWidgets; +import com.vaadin.client.data.DataChangeHandler; +import com.vaadin.client.data.DataSource; +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.shared.Registration; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.v7.grid.GridClientColumnRenderers; +import com.vaadin.v7.client.renderers.ComplexRenderer; +import com.vaadin.v7.client.renderers.DateRenderer; +import com.vaadin.v7.client.renderers.HtmlRenderer; +import com.vaadin.v7.client.renderers.NumberRenderer; +import com.vaadin.v7.client.renderers.Renderer; +import com.vaadin.v7.client.renderers.TextRenderer; +import com.vaadin.v7.client.renderers.WidgetRenderer; +import com.vaadin.v7.client.widget.grid.CellReference; +import com.vaadin.v7.client.widget.grid.RendererCellReference; +import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; +import com.vaadin.v7.client.widget.grid.datasources.ListSorter; +import com.vaadin.v7.client.widget.grid.sort.Sort; +import com.vaadin.v7.client.widget.grid.sort.SortEvent; +import com.vaadin.v7.client.widget.grid.sort.SortHandler; +import com.vaadin.v7.client.widget.grid.sort.SortOrder; +import com.vaadin.v7.client.widgets.Grid; + +@Connect(GridClientColumnRenderers.GridController.class) +public class GridClientColumnRendererConnector + extends AbstractComponentConnector { + + public static enum Renderers { + TEXT_RENDERER, WIDGET_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER, CPLX_RENDERER; + } + + /** + * Datasource for simulating network latency + */ + private class DelayedDataSource implements DataSource { + + private DataSource ds; + private int firstRowIndex = -1; + private int numberOfRows; + private DataChangeHandler dataChangeHandler; + private int latency; + + public DelayedDataSource(DataSource ds, int latency) { + this.ds = ds; + this.latency = latency; + } + + @Override + public void ensureAvailability(final int firstRowIndex, + final int numberOfRows) { + new Timer() { + + @Override + public void run() { + DelayedDataSource.this.firstRowIndex = firstRowIndex; + DelayedDataSource.this.numberOfRows = numberOfRows; + dataChangeHandler.dataUpdated(firstRowIndex, numberOfRows); + dataChangeHandler.dataAvailable(firstRowIndex, + numberOfRows); + } + }.schedule(latency); + } + + @Override + public String getRow(int rowIndex) { + if (rowIndex >= firstRowIndex + && rowIndex <= firstRowIndex + numberOfRows) { + return ds.getRow(rowIndex); + } + return null; + } + + @Override + public int size() { + return ds.size(); + } + + @Override + public Registration addDataChangeHandler( + DataChangeHandler dataChangeHandler) { + this.dataChangeHandler = dataChangeHandler; + return null; + } + + @Override + public RowHandle getHandle(String row) { + // TODO Auto-generated method stub (henrik paul: 17.6.) + return null; + } + } + + @Override + protected void init() { + Grid grid = getWidget(); + grid.setSelectionMode(Grid.SelectionMode.NONE); + + // Generated some column data + List columnData = new ArrayList(); + for (int i = 0; i < 100; i++) { + columnData.add(String.valueOf(i)); + } + + // Provide data as data source + if (Location.getParameter("latency") != null) { + grid.setDataSource(new DelayedDataSource( + new ListDataSource(columnData), + Integer.parseInt(Location.getParameter("latency")))); + } else { + grid.setDataSource(new ListDataSource(columnData)); + } + + // Add a column to display the data in + Grid.Column c = createColumnWithRenderer( + Renderers.TEXT_RENDERER); + grid.addColumn(c); + grid.getDefaultHeaderRow().getCell(c).setText("Column 1"); + + // Add another column with a custom complex renderer + c = createColumnWithRenderer(Renderers.CPLX_RENDERER); + grid.addColumn(c); + grid.getDefaultHeaderRow().getCell(c).setText("Column 2"); + + // Add method for testing sort event firing + grid.addSortHandler(new SortHandler() { + @Override + public void sort(SortEvent event) { + Element console = Document.get() + .getElementById("testDebugConsole"); + String text = "Client-side sort event received
" + + "Columns: " + event.getOrder().size() + ", order: "; + for (SortOrder order : event.getOrder()) { + String columnHeader = getWidget().getDefaultHeaderRow() + .getCell(order.getColumn()).getText(); + text += columnHeader + ": " + + order.getDirection().toString(); + } + console.setInnerHTML(text); + } + }); + + // Handle RPC calls + registerRpc(GridClientColumnRendererRpc.class, + new GridClientColumnRendererRpc() { + + @Override + public void addColumn(Renderers renderer) { + + Grid.Column column; + if (renderer == Renderers.NUMBER_RENDERER) { + column = createNumberColumnWithRenderer(renderer); + } else if (renderer == Renderers.DATE_RENDERER) { + column = createDateColumnWithRenderer(renderer); + } else { + column = createColumnWithRenderer(renderer); + } + getWidget().addColumn(column); + + getWidget().getDefaultHeaderRow().getCell(column) + .setText("Column " + String.valueOf( + getWidget().getColumnCount() + 1)); + } + + @Override + public void detachAttach() { + + // Detach + HasWidgets parent = (HasWidgets) getWidget() + .getParent(); + parent.remove(getWidget()); + + // Re-attach + parent.add(getWidget()); + } + + @Override + public void triggerClientSorting() { + getWidget().sort(Sort.by(getWidget().getColumn(0))); + } + + @Override + @SuppressWarnings("unchecked") + public void triggerClientSortingTest() { + Grid grid = getWidget(); + ListSorter sorter = new ListSorter( + grid); + + // Make sorter sort the numbers in natural order + sorter.setComparator( + (Grid.Column) grid.getColumn(0), + new Comparator() { + @Override + public int compare(String o1, String o2) { + return Integer.parseInt(o1) + - Integer.parseInt(o2); + } + }); + + // Sort along column 0 in ascending order + grid.sort(grid.getColumn(0)); + + // Remove the sorter once we're done + sorter.removeFromGrid(); + } + + @Override + @SuppressWarnings("unchecked") + public void shuffle() { + Grid grid = getWidget(); + ListSorter shuffler = new ListSorter( + grid); + + // Make shuffler return random order + shuffler.setComparator( + (Grid.Column) grid.getColumn(0), + new Comparator() { + @Override + public int compare(String o1, String o2) { + return com.google.gwt.user.client.Random + .nextInt(3) - 1; + } + }); + + // "Sort" (actually shuffle) along column 0 + grid.sort(grid.getColumn(0)); + + // Remove the shuffler when we're done so that it + // doesn't interfere with further operations + shuffler.removeFromGrid(); + } + }); + } + + /** + * Creates a a renderer for a {@link Renderers} + */ + private Renderer createRenderer(Renderers renderer) { + switch (renderer) { + case TEXT_RENDERER: + return new TextRenderer(); + + case WIDGET_RENDERER: + return new WidgetRenderer() { + + @Override + public Button createWidget() { + final Button button = new Button(""); + button.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + button.setText("Clicked"); + } + }); + return button; + } + + @Override + public void render(RendererCellReference cell, String data, + Button button) { + button.setHTML(data); + } + }; + + case HTML_RENDERER: + return new HtmlRenderer() { + + @Override + public void render(RendererCellReference cell, + String htmlString) { + super.render(cell, "" + htmlString + ""); + } + }; + + case NUMBER_RENDERER: + return new NumberRenderer(); + + case DATE_RENDERER: + return new DateRenderer(); + + case CPLX_RENDERER: + return new ComplexRenderer() { + + @Override + public void init(RendererCellReference cell) { + } + + @Override + public void render(RendererCellReference cell, String data) { + cell.getElement().setInnerHTML("" + data + ""); + cell.getElement().getStyle().clearBackgroundColor(); + } + + @Override + public void setContentVisible(RendererCellReference cell, + boolean hasData) { + + // Visualize content visible property + cell.getElement().getStyle() + .setBackgroundColor(hasData ? "green" : "red"); + + super.setContentVisible(cell, hasData); + } + + @Override + public boolean onActivate(CellReference cell) { + cell.getElement().setInnerHTML("Activated!"); + return true; + } + }; + + default: + return new TextRenderer(); + } + } + + private Grid.Column createColumnWithRenderer( + Renderers renderer) { + return new Grid.Column(createRenderer(renderer)) { + + @Override + public String getValue(String row) { + return row; + } + }; + } + + private Grid.Column createNumberColumnWithRenderer( + Renderers renderer) { + return new Grid.Column(createRenderer(renderer)) { + + @Override + public Number getValue(String row) { + return Long.parseLong(row); + } + }; + } + + private Grid.Column createDateColumnWithRenderer( + Renderers renderer) { + return new Grid.Column(createRenderer(renderer)) { + + @Override + public Date getValue(String row) { + return new Date(); + } + }; + } + + @Override + public Grid getWidget() { + return (Grid) super.getWidget(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientColumnRendererRpc.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientColumnRendererRpc.java new file mode 100644 index 0000000000..c2d74b8682 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientColumnRendererRpc.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.widgetset.client.v7.grid; + +import com.vaadin.shared.communication.ClientRpc; +import com.vaadin.tests.widgetset.client.v7.grid.GridClientColumnRendererConnector.Renderers; + +public interface GridClientColumnRendererRpc extends ClientRpc { + + /** + * Adds a new column with a specific renderer to the grid + * + */ + void addColumn(Renderers renderer); + + /** + * Detaches and attaches the client side Grid + */ + void detachAttach(); + + /** + * Used for client-side sorting API test + */ + void triggerClientSorting(); + + /** + * @since + */ + void triggerClientSortingTest(); + + /** + * @since + */ + void shuffle(); +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientDataSourcesWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientDataSourcesWidget.java new file mode 100644 index 0000000000..c70359c1c4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClientDataSourcesWidget.java @@ -0,0 +1,221 @@ +/* + * 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.List; + +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.vaadin.client.data.AbstractRemoteDataSource; +import com.vaadin.v7.client.renderers.TextRenderer; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.SelectionMode; + +public class GridClientDataSourcesWidget + extends PureGWTTestApplication> { + + private interface RestCallback { + void onResponse(RestishDataSource.Backend.Result result); + } + + /** + * This is an emulated datasource that has a back-end that changes size + * constantly. The back-end is unable to actively push data to Grid. + * Instead, with each row request, in addition to its row payload it tells + * how many rows it contains in total. + * + * A plausible response from this REST-like api would be: + * + *
+     * 
+     * GET /foos/4..8
+     *
+     * {
+     *     "resultsize": 4,
+     *     "data": [
+     *         [4, "foo IV"],
+     *         [5, "foo V"],
+     *         [6, "foo VI"]
+     *         [7, "foo VII"]
+     *     ],
+     *     "totalrows": 100
+     * }
+     * 
+     * 
+ * + * In this case, the size of Grid needs to be updated to be able to show 100 + * rows in total (no more, no less). + * + * This class + *
    + *
  1. gets initialized + *
  2. asks for its size + *
  3. updates Grid once the reply is received + *
  4. as the Grid fetches more data, the total row count is dynamically + * updated. + *
+ */ + private class RestishDataSource extends AbstractRemoteDataSource { + /** + * Pretend like this class doesn't exist. It just simulates a backend + * somewhere. + *

+ * It's scoped inside the RDS class only because it's tied to that. + */ + private class Backend { + public class Result { + public int size; + public List rows; + } + + private int size = 200; + private int modCount = 0; + + public void query(int firstRowIndex, int numberOfRows, + final RestCallback callback) { + final Result result = new Result(); + result.size = size; + result.rows = fetchRows(firstRowIndex, numberOfRows); + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + callback.onResponse(result); + } + }); + + } + + private List fetchRows(int firstRowIndex, + int numberOfRows) { + List rows = new ArrayList(); + for (int i = 0; i < numberOfRows; i++) { + String id = String.valueOf(firstRowIndex + i); + rows.add(new String[] { id, + "cell " + id + " #" + modCount }); + } + return rows; + } + + public void pushRowChanges(int rows) { + size += rows; + pushRowChanges(); + } + + public void pushRowChanges() { + modCount++; + + // push "something happened" to datasource "over the wire": + resetDataAndSize(size); + } + + public void addRows(int rowcount) { + modCount++; + size += rowcount; + } + } + + final Backend backend; + + public RestishDataSource() { + backend = new Backend(); + } + + @Override + protected void requestRows(int firstRowIndex, int numberOfRows, + final RequestRowsCallback callback) { + + backend.query(firstRowIndex, numberOfRows, new RestCallback() { + @Override + public void onResponse(Backend.Result result) { + callback.onResponse(result.rows, result.size); + } + }); + } + + @Override + public Object getRowKey(String[] row) { + return row[0]; + } + } + + private final Grid grid; + + private RestishDataSource restishDataSource; + + private final ScheduledCommand setRestishCommand = new ScheduledCommand() { + @Override + public void execute() { + for (Grid.Column column : grid.getColumns()) { + grid.removeColumn(column); + } + + restishDataSource = new RestishDataSource(); + grid.setDataSource(restishDataSource); + grid.addColumn(new Grid.Column("column", + new TextRenderer()) { + + @Override + public String getValue(String[] row) { + return row[1]; + } + }); + } + }; + + public GridClientDataSourcesWidget() { + super(new Grid()); + grid = getTestedWidget(); + + grid.getElement().getStyle().setZIndex(0); + grid.setHeight("400px"); + grid.setSelectionMode(SelectionMode.NONE); + addNorth(grid, 400); + + addMenuCommand("Use", setRestishCommand, "DataSources", "RESTish"); + addMenuCommand("Next request +10", new ScheduledCommand() { + @Override + public void execute() { + restishDataSource.backend.addRows(10); + } + }, "DataSources", "RESTish"); + addMenuCommand("Next request -10", new ScheduledCommand() { + @Override + public void execute() { + restishDataSource.backend.addRows(-10); + } + }, "DataSources", "RESTish"); + addMenuCommand("Push data change", new ScheduledCommand() { + @Override + public void execute() { + restishDataSource.backend.pushRowChanges(); + } + }, "DataSources", "RESTish"); + addMenuCommand("Push data change +10", new ScheduledCommand() { + @Override + public void execute() { + restishDataSource.backend.pushRowChanges(10); + } + }, "DataSources", "RESTish"); + addMenuCommand("Push data change -10", new ScheduledCommand() { + @Override + public void execute() { + restishDataSource.backend.pushRowChanges(-10); + } + }, "DataSources", "RESTish"); + } +} 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 new file mode 100644 index 0000000000..8752fd0768 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/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.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/tests/widgetset/client/v7/grid/GridDataChangeHandlerWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridDataChangeHandlerWidget.java new file mode 100644 index 0000000000..c90551dbf2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridDataChangeHandlerWidget.java @@ -0,0 +1,120 @@ +/* + * 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.Arrays; +import java.util.List; + +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.RepeatingCommand; +import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.SimplePanel; +import com.vaadin.client.data.AbstractRemoteDataSource; +import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.Column; + +public class GridDataChangeHandlerWidget extends Composite { + + private final SimplePanel panel = new SimplePanel(); + private final Grid grid = new Grid(); + + public static class DelayedDataSource extends ListDataSource { + + public DelayedDataSource(List datasource) { + super(datasource); + } + + @Override + public void ensureAvailability(final int firstRowIndex, + final int numberOfRows) { + new Timer() { + + @Override + public void run() { + actualEnsureAvailability(firstRowIndex, numberOfRows); + } + }.schedule(500); + } + + private void actualEnsureAvailability(int firstRowIndex, + int numberOfRows) { + super.ensureAvailability(firstRowIndex, numberOfRows); + } + } + + public static class RemoteDelayedDataSource + extends AbstractRemoteDataSource { + + private List rows; + + public RemoteDelayedDataSource(List datasource) { + super(); + rows = datasource; + } + + @Override + protected void requestRows(final int firstRowIndex, + final int numberOfRows, + final RequestRowsCallback callback) { + new Timer() { + + @Override + public void run() { + List requested = rows.subList(firstRowIndex, + numberOfRows); + callback.onResponse(requested, requested.size()); + } + }.schedule(500); + } + + @Override + public Object getRowKey(String row) { + return row; + } + + } + + public GridDataChangeHandlerWidget() { + initWidget(panel); + + panel.setWidget(grid); + grid.setDataSource(new RemoteDelayedDataSource( + Arrays.asList("A", "B", "C", "D", "E"))); + grid.addColumn(new Column("letter") { + @Override + public String getValue(String row) { + return row; + } + }); + Scheduler.get().scheduleFinally(new RepeatingCommand() { + + boolean run = false; + + @Override + public boolean execute() { + grid.setDataSource( + new DelayedDataSource(Arrays.asList("X", "Y", "Z"))); + if (run) { + return false; + } + run = true; + return true; + } + }); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridDefaultTextRendererWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridDefaultTextRendererWidget.java new file mode 100644 index 0000000000..dbeec1b0a7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridDefaultTextRendererWidget.java @@ -0,0 +1,64 @@ +/* + * 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 com.vaadin.v7.client.widget.grid.datasources.ListDataSource; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.Column; +import com.vaadin.v7.client.widgets.Grid.SelectionMode; +import com.vaadin.v7.shared.ui.grid.HeightMode; + +public class GridDefaultTextRendererWidget + extends PureGWTTestApplication> { + /* + * This can't be null, because grid thinks that a row object of null means + * "data is still being fetched". + */ + private static final String NULL_STRING = ""; + + private Grid grid; + + public GridDefaultTextRendererWidget() { + super(new Grid()); + grid = getTestedWidget(); + + grid.setDataSource(new ListDataSource(NULL_STRING, "string")); + grid.addColumn(new Column() { + @Override + public String getValue(String row) { + if (!NULL_STRING.equals(row)) { + return row; + } else { + return null; + } + } + }); + + grid.addColumn(new Column() { + + @Override + public String getValue(String row) { + return "foo"; + } + + }); + + grid.setHeightByRows(2); + grid.setHeightMode(HeightMode.ROW); + grid.setSelectionMode(SelectionMode.NONE); + addNorth(grid, 500); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridHeightByRowOnInitWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridHeightByRowOnInitWidget.java new file mode 100644 index 0000000000..7813b3312c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridHeightByRowOnInitWidget.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.widgetset.client.v7.grid; + +import java.util.Arrays; + +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.SimplePanel; +import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.Column; +import com.vaadin.v7.shared.ui.grid.HeightMode; + +public class GridHeightByRowOnInitWidget extends Composite { + private final SimplePanel panel = new SimplePanel(); + private final Grid grid = new Grid(); + + public GridHeightByRowOnInitWidget() { + initWidget(panel); + + panel.setWidget(grid); + grid.setDataSource(new ListDataSource( + Arrays.asList("A", "B", "C", "D", "E"))); + grid.addColumn(new Column("letter") { + @Override + public String getValue(String row) { + return row; + } + }); + + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(5.0d); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridRendererChangeWidget.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridRendererChangeWidget.java new file mode 100644 index 0000000000..854a08202c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridRendererChangeWidget.java @@ -0,0 +1,162 @@ +/* + * 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 com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.user.client.ui.Button; +import com.vaadin.v7.client.renderers.ButtonRenderer; +import com.vaadin.v7.client.renderers.TextRenderer; +import com.vaadin.v7.client.widget.grid.RendererCellReference; +import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.client.widgets.Grid.Column; + +public class GridRendererChangeWidget + extends PureGWTTestApplication> { + + public class MyButtonRenderer extends ButtonRenderer { + + private final Button widget = new Button(); + + private boolean hasInit = false; + private boolean hasBeenDestroyed = false; + private boolean wasAttached = false; + + @Override + public void init(RendererCellReference cell) { + if (hasInit || hasBeenDestroyed) { + throw new RuntimeException("Init in an unexpected state."); + } + super.init(cell); + + hasInit = true; + } + + @Override + public Button createWidget() { + return widget; + } + + @Override + public void render(RendererCellReference cell, String text, + Button button) { + if (!hasInit || hasBeenDestroyed) { + throw new RuntimeException("Render in an unexpected state."); + } + if (button != widget) { + throw new RuntimeException("Unexpected button instance"); + } + if (button.getParent() != getTestedWidget()) { + throw new RuntimeException("Button not attached!"); + } + + super.render(cell, text, button); + + wasAttached = true; + } + + @Override + public void destroy() { + if (!hasInit || !wasAttached) { + throw new RuntimeException("Destroy in an unexpected state"); + } + + super.destroy(); + + hasBeenDestroyed = true; + } + + public void verify() { + if (!hasInit) { + throw new RuntimeException("Failed. Not initialized"); + } else if (!wasAttached) { + throw new RuntimeException("Failed. Not attached"); + } else if (widget.getParent() != null) { + throw new RuntimeException("Failed. Not detached"); + } else if (!hasBeenDestroyed) { + throw new RuntimeException("Failed. Not destroyed"); + } + } + } + + public GridRendererChangeWidget() { + super(new Grid()); + String[] strArr = new String[] { "foo", "bar" }; + ListDataSource ds = new ListDataSource(strArr); + final Grid grid = getTestedWidget(); + grid.setDataSource(ds); + final Column first = new Column() { + + @Override + public String getValue(String[] row) { + return row[0]; + } + }; + grid.addColumn(first).setHeaderCaption("First") + .setRenderer(new MyButtonRenderer()); + final Column second = new Column() { + + @Override + public String getValue(String[] row) { + return row[1]; + } + }; + grid.addColumn(second).setHeaderCaption("Second") + .setRenderer(new MyButtonRenderer()); + + addMenuCommand("Change first renderer", new ScheduledCommand() { + + boolean isButton = true; + + @Override + public void execute() { + if (isButton) { + final MyButtonRenderer r = (MyButtonRenderer) first + .getRenderer(); + first.setRenderer(new TextRenderer()); + r.verify(); + } else { + first.setRenderer(new MyButtonRenderer()); + } + isButton = !isButton; + } + + }, "Component"); + addMenuCommand("Change second renderer", new ScheduledCommand() { + + boolean isButton = true; + + @Override + public void execute() { + if (isButton) { + MyButtonRenderer r = (MyButtonRenderer) second + .getRenderer(); + second.setRenderer(new TextRenderer()); + r.verify(); + } else { + second.setRenderer(new MyButtonRenderer()); + } + isButton = !isButton; + } + + }, "Component"); + + addNorth(grid, 600); + + grid.getElement().getStyle().setZIndex(0); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/IntArrayRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/IntArrayRendererConnector.java new file mode 100644 index 0000000000..28056c4b47 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/IntArrayRendererConnector.java @@ -0,0 +1,47 @@ +/* + * 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 com.vaadin.shared.ui.Connect; +import com.vaadin.v7.client.connectors.AbstractGridRendererConnector; +import com.vaadin.v7.client.renderers.Renderer; +import com.vaadin.v7.client.widget.grid.RendererCellReference; + +@Connect(com.vaadin.v7.tests.components.grid.IntArrayRenderer.class) +public class IntArrayRendererConnector + extends AbstractGridRendererConnector { + + public static class IntArrayRenderer implements Renderer { + private static final String JOINER = " :: "; + + @Override + public void render(RendererCellReference cell, int[] data) { + String text = ""; + for (int i : data) { + text += i + JOINER; + } + if (!text.isEmpty()) { + text = text.substring(0, text.length() - JOINER.length()); + } + cell.getElement().setInnerText(text); + } + } + + @Override + public IntArrayRenderer getRenderer() { + return (IntArrayRenderer) super.getRenderer(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/MySelectionModelConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/MySelectionModelConnector.java new file mode 100644 index 0000000000..9cd0a26ed6 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/MySelectionModelConnector.java @@ -0,0 +1,61 @@ +/* + * 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 com.vaadin.client.ServerConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.v7.client.connectors.MultiSelectionModelConnector; +import com.vaadin.v7.client.renderers.ComplexRenderer; +import com.vaadin.v7.client.widget.grid.selection.ClickSelectHandler; +import com.vaadin.v7.client.widget.grid.selection.SelectionModel.Multi; +import com.vaadin.v7.client.widgets.Grid; +import com.vaadin.v7.tests.components.grid.GridCustomSelectionModel.MySelectionModel; + +import elemental.json.JsonObject; + +@Connect(MySelectionModel.class) +public class MySelectionModelConnector extends MultiSelectionModelConnector { + + private ClickSelectHandler handler; + + @Override + protected void extend(ServerConnector target) { + super.extend(target); + handler = new ClickSelectHandler(getGrid()); + } + + @Override + public void onUnregister() { + super.onUnregister(); + handler.removeHandler(); + handler = null; + } + + @Override + protected Multi createSelectionModel() { + return new MySelectionModel(); + } + + public class MySelectionModel extends MultiSelectionModel { + + @Override + protected ComplexRenderer createSelectionColumnRenderer( + Grid grid) { + // No Selection Column. + return null; + } + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/PojoRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/PojoRendererConnector.java new file mode 100644 index 0000000000..fdbdd324a7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/PojoRendererConnector.java @@ -0,0 +1,39 @@ +/* + * 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 com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.client.SimpleTestBean; +import com.vaadin.v7.client.connectors.AbstractGridRendererConnector; +import com.vaadin.v7.client.renderers.Renderer; +import com.vaadin.v7.client.widget.grid.RendererCellReference; + +@Connect(com.vaadin.v7.tests.components.grid.BeanRenderer.class) +public class PojoRendererConnector + extends AbstractGridRendererConnector { + + public static class BeanRenderer implements Renderer { + @Override + public void render(RendererCellReference cell, SimpleTestBean bean) { + cell.getElement().setInnerText(bean.toString()); + } + } + + @Override + public BeanRenderer getRenderer() { + return (BeanRenderer) super.getRenderer(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/PureGWTTestApplication.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/PureGWTTestApplication.java new file mode 100644 index 0000000000..01b00b04cc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/PureGWTTestApplication.java @@ -0,0 +1,309 @@ +/* + * 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.List; + +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.ui.DockLayoutPanel; +import com.google.gwt.user.client.ui.LayoutPanel; +import com.google.gwt.user.client.ui.MenuBar; +import com.google.gwt.user.client.ui.Panel; +import com.vaadin.client.ui.SubPartAware; + +/** + * Pure GWT Test Application base for testing features of a single widget; + * provides a menu system and convenience method for adding items to it. + * + * @since + * @author Vaadin Ltd + */ +public abstract class PureGWTTestApplication extends DockLayoutPanel + implements SubPartAware { + + /** + * Class describing a menu item with an associated action + */ + public static class Command { + private final String title; + private final ScheduledCommand command; + + /** + * Creates a Command object, which is used as an action entry in the + * Menu + * + * @param t + * a title string + * @param cmd + * a scheduled command that is executed when this item is + * selected + */ + public Command(String t, ScheduledCommand cmd) { + title = t; + command = cmd; + } + + /** + * Returns the title of this command item + * + * @return a title string + */ + public final String getTitle() { + return title; + } + + /** + * Returns the actual scheduled command of this command item + * + * @return a scheduled command + */ + public final ScheduledCommand getCommand() { + return command; + } + } + + /** + * A menu object, providing a complete system for building a hierarchical + * menu bar system. + */ + public static class Menu { + + private final String title; + private final MenuBar menubar; + private final List

children; + private final List items; + + /** + * Create base-level menu, without a title. This is the root menu bar, + * which can be attached to a client application window. All other Menus + * should be added as child menus to this Menu, in order to maintain a + * nice hierarchy. + */ + private Menu() { + title = ""; + menubar = new MenuBar(); + menubar.getElement().setId("menu"); + children = new ArrayList(); + items = new ArrayList(); + } + + /** + * Create a sub-menu, with a title. + * + * @param title + */ + public Menu(String title) { + this.title = title; + menubar = new MenuBar(true); + children = new ArrayList(); + items = new ArrayList(); + } + + /** + * Return the GWT {@link MenuBar} object that provides the widget for + * this Menu + * + * @return a menubar object + */ + public MenuBar getMenuBar() { + return menubar; + } + + /** + * Returns the title of this menu entry + * + * @return a title string + */ + public String getTitle() { + return title; + } + + /** + * Adds a child menu entry to this menu. The title for this entry is + * taken from the Menu object argument. + * + * @param m + * another Menu object + */ + public void addChildMenu(Menu m) { + menubar.addItem(m.title, m.menubar); + children.add(m); + } + + /** + * Tests for the existence of a child menu by title at this level of the + * menu hierarchy + * + * @param title + * a title string + * @return true, if this menu has a direct child menu with the specified + * title, otherwise false + */ + public boolean hasChildMenu(String title) { + return getChildMenu(title) != null; + } + + /** + * Gets a reference to a child menu with a certain title, that is a + * direct child of this menu level. + * + * @param title + * a title string + * @return a Menu object with the specified title string, or null, if + * this menu doesn't have a direct child with the specified + * title. + */ + public Menu getChildMenu(String title) { + for (Menu m : children) { + if (m.title.equals(title)) { + return m; + } + } + return null; + } + + /** + * Adds a command item to the menu. When the entry is clicked, the + * command is executed. + * + * @param cmd + * a command object. + */ + public void addCommand(Command cmd) { + menubar.addItem(cmd.title, cmd.command); + items.add(cmd); + } + + /** + * Tests for the existence of a {@link Command} that is the direct child + * of this level of menu. + * + * @param title + * the command's title + * @return true, if this menu level includes a command item with the + * specified title. Otherwise false. + */ + public boolean hasCommand(String title) { + return getCommand(title) != null; + } + + /** + * Gets a reference to a {@link Command} item that is the direct child + * of this level of menu. + * + * @param title + * the command's title + * @return a command, if found in this menu level, otherwise null. + */ + public Command getCommand(String title) { + for (Command c : items) { + if (c.title.equals(title)) { + return c; + } + } + return null; + } + } + + /** + * Base level menu object, provides visible menu bar + */ + private final Menu menu; + private final T testedWidget; + + /** + * This constructor creates the basic menu bar and adds it to the top of the + * parent {@link DockLayoutPanel} + */ + protected PureGWTTestApplication(T widget) { + super(Unit.PX); + Panel menuPanel = new LayoutPanel(); + menu = new Menu(); + menuPanel.add(menu.getMenuBar()); + addNorth(menuPanel, 25); + testedWidget = widget; + } + + /** + * Connect an item to the menu structure + * + * @param cmd + * a scheduled command; see google's docs + * @param menupath + * path to the item + */ + public void addMenuCommand(String title, ScheduledCommand cmd, + String... menupath) { + Menu m = createMenuPath(menupath); + + m.addCommand(new Command(title, cmd)); + } + + /** + * Create a menu path, if one doesn't already exist, and return the last + * menu in the series. + * + * @param path + * a varargs list or array of strings describing a menu path, + * e.g. "File", "Recent", "User Files", which would result in the + * File menu having a submenu called "Recent" which would have a + * submenu called "User Files". + * @return the last Menu object specified by the path + */ + private Menu createMenuPath(String... path) { + Menu m = menu; + + for (String p : path) { + Menu sub = m.getChildMenu(p); + + if (sub == null) { + sub = new Menu(p); + m.addChildMenu(sub); + } + m = sub; + } + + return m; + } + + @Override + public Element getSubPartElement(String subPart) { + if (testedWidget instanceof SubPartAware) { + return ((SubPartAware) testedWidget).getSubPartElement(subPart); + } + return null; + } + + @Override + public String getSubPartName(Element subElement) { + if (testedWidget instanceof SubPartAware) { + return ((SubPartAware) testedWidget).getSubPartName(subElement); + } + return null; + } + + /** + * Gets the tested widget. + * + * @return tested widget + */ + public T getTestedWidget() { + return testedWidget; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/RowAwareRendererConnector.java b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/RowAwareRendererConnector.java new file mode 100644 index 0000000000..ff541b8741 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/RowAwareRendererConnector.java @@ -0,0 +1,80 @@ +/* + * 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.Arrays; +import java.util.Collection; + +import com.google.gwt.dom.client.BrowserEvents; +import com.google.gwt.dom.client.DivElement; +import com.google.gwt.dom.client.NativeEvent; +import com.google.gwt.user.client.DOM; +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.Connect; +import com.vaadin.v7.client.connectors.AbstractGridRendererConnector; +import com.vaadin.v7.client.renderers.ComplexRenderer; +import com.vaadin.v7.client.renderers.Renderer; +import com.vaadin.v7.client.widget.grid.CellReference; +import com.vaadin.v7.client.widget.grid.RendererCellReference; + +import elemental.json.JsonObject; + +@Connect(com.vaadin.v7.tests.components.grid.RowAwareRenderer.class) +public class RowAwareRendererConnector + extends AbstractGridRendererConnector { + public interface RowAwareRendererRpc extends ServerRpc { + void clicky(String key); + } + + public class RowAwareRenderer extends ComplexRenderer { + + @Override + public Collection getConsumedEvents() { + return Arrays.asList(BrowserEvents.CLICK); + } + + @Override + public void init(RendererCellReference cell) { + DivElement div = DivElement.as(DOM.createDiv()); + div.setAttribute("style", + "border: 1px solid red; background: pink;"); + div.setInnerText("Click me!"); + cell.getElement().appendChild(div); + } + + @Override + public void render(RendererCellReference cell, Void data) { + // NOOP + } + + @Override + public boolean onBrowserEvent(CellReference cell, + NativeEvent event) { + String key = getRowKey((JsonObject) cell.getRow()); + getRpcProxy(RowAwareRendererRpc.class).clicky(key); + cell.getElement().setInnerText( + "row: " + cell.getRowIndex() + ", key: " + key); + return true; + } + } + + @Override + protected Renderer createRenderer() { + // cannot use the default createRenderer as RowAwareRenderer needs a + // reference to its connector - it has no "real" no-argument constructor + return new RowAwareRenderer(); + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java b/uitest/src/main/java/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java deleted file mode 100644 index 459a36865e..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java +++ /dev/null @@ -1,158 +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.server.grid; - -import java.util.Arrays; - -import com.vaadin.annotations.Widgetset; -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.tests.widgetset.TestingWidgetSet; -import com.vaadin.tests.widgetset.client.grid.GridClientColumnRendererConnector.Renderers; -import com.vaadin.tests.widgetset.client.grid.GridClientColumnRendererRpc; -import com.vaadin.ui.AbstractComponent; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.CssLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.NativeButton; -import com.vaadin.ui.UI; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode; -import com.vaadin.v7.ui.NativeSelect; - -@Widgetset(TestingWidgetSet.NAME) -public class GridClientColumnRenderers extends UI { - - /** - * Controls the grid on the client side - */ - public static class GridController extends AbstractComponent { - - private GridClientColumnRendererRpc rpc() { - return getRpcProxy(GridClientColumnRendererRpc.class); - } - - /** - * Adds a new column with a renderer to the grid. - */ - public void addColumn(Renderers renderer) { - rpc().addColumn(renderer); - } - - /** - * Tests detaching and attaching grid - */ - public void detachAttach() { - rpc().detachAttach(); - } - - /** - * @since - */ - public void triggerClientSorting() { - rpc().triggerClientSorting(); - } - - /** - * @since - */ - public void triggerClientSortingTest() { - rpc().triggerClientSortingTest(); - } - - /** - * @since - */ - public void shuffle() { - rpc().shuffle(); - } - } - - @Override - protected void init(VaadinRequest request) { - final GridController controller = new GridController(); - final CssLayout controls = new CssLayout(); - final VerticalLayout content = new VerticalLayout(); - - content.addComponent(controller); - content.addComponent(controls); - setContent(content); - - final NativeSelect select = new NativeSelect("Add Column with Renderer", - Arrays.asList(Renderers.values())); - select.setItemCaptionMode(ItemCaptionMode.EXPLICIT); - for (Renderers renderer : Renderers.values()) { - select.setItemCaption(renderer, renderer.toString()); - } - select.setValue(Renderers.TEXT_RENDERER); - select.setNullSelectionAllowed(false); - controls.addComponent(select); - - NativeButton addColumnBtn = new NativeButton("Add"); - addColumnBtn.addClickListener(new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - Renderers renderer = (Renderers) select.getValue(); - controller.addColumn(renderer); - } - }); - controls.addComponent(addColumnBtn); - - NativeButton detachAttachBtn = new NativeButton("DetachAttach"); - detachAttachBtn.addClickListener(new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - controller.detachAttach(); - } - }); - controls.addComponent(detachAttachBtn); - - NativeButton shuffleButton = new NativeButton("Shuffle"); - shuffleButton.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - controller.shuffle(); - } - }); - controls.addComponent(shuffleButton); - - NativeButton sortButton = new NativeButton("Trigger sorting event"); - sortButton.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - controller.triggerClientSorting(); - } - }); - controls.addComponent(sortButton); - - NativeButton testSortingButton = new NativeButton("Test sorting"); - testSortingButton.addClickListener(new ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - controller.triggerClientSortingTest(); - } - }); - controls.addComponent(testSortingButton); - - Label console = new Label(); - console.setContentMode(ContentMode.HTML); - console.setId("testDebugConsole"); - content.addComponent(console); - } -} diff --git a/uitest/src/main/java/com/vaadin/tests/widgetset/server/v7/grid/GridClientColumnRenderers.java b/uitest/src/main/java/com/vaadin/tests/widgetset/server/v7/grid/GridClientColumnRenderers.java new file mode 100644 index 0000000000..584d3f31c3 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/server/v7/grid/GridClientColumnRenderers.java @@ -0,0 +1,158 @@ +/* + * 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.server.v7.grid; + +import java.util.Arrays; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridClientColumnRendererRpc; +import com.vaadin.tests.widgetset.client.v7.grid.GridClientColumnRendererConnector.Renderers; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode; +import com.vaadin.v7.ui.NativeSelect; + +@Widgetset(TestingWidgetSet.NAME) +public class GridClientColumnRenderers extends UI { + + /** + * Controls the grid on the client side + */ + public static class GridController extends AbstractComponent { + + private GridClientColumnRendererRpc rpc() { + return getRpcProxy(GridClientColumnRendererRpc.class); + } + + /** + * Adds a new column with a renderer to the grid. + */ + public void addColumn(Renderers renderer) { + rpc().addColumn(renderer); + } + + /** + * Tests detaching and attaching grid + */ + public void detachAttach() { + rpc().detachAttach(); + } + + /** + * @since + */ + public void triggerClientSorting() { + rpc().triggerClientSorting(); + } + + /** + * @since + */ + public void triggerClientSortingTest() { + rpc().triggerClientSortingTest(); + } + + /** + * @since + */ + public void shuffle() { + rpc().shuffle(); + } + } + + @Override + protected void init(VaadinRequest request) { + final GridController controller = new GridController(); + final CssLayout controls = new CssLayout(); + final VerticalLayout content = new VerticalLayout(); + + content.addComponent(controller); + content.addComponent(controls); + setContent(content); + + final NativeSelect select = new NativeSelect("Add Column with Renderer", + Arrays.asList(Renderers.values())); + select.setItemCaptionMode(ItemCaptionMode.EXPLICIT); + for (Renderers renderer : Renderers.values()) { + select.setItemCaption(renderer, renderer.toString()); + } + select.setValue(Renderers.TEXT_RENDERER); + select.setNullSelectionAllowed(false); + controls.addComponent(select); + + NativeButton addColumnBtn = new NativeButton("Add"); + addColumnBtn.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + Renderers renderer = (Renderers) select.getValue(); + controller.addColumn(renderer); + } + }); + controls.addComponent(addColumnBtn); + + NativeButton detachAttachBtn = new NativeButton("DetachAttach"); + detachAttachBtn.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + controller.detachAttach(); + } + }); + controls.addComponent(detachAttachBtn); + + NativeButton shuffleButton = new NativeButton("Shuffle"); + shuffleButton.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + controller.shuffle(); + } + }); + controls.addComponent(shuffleButton); + + NativeButton sortButton = new NativeButton("Trigger sorting event"); + sortButton.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + controller.triggerClientSorting(); + } + }); + controls.addComponent(sortButton); + + NativeButton testSortingButton = new NativeButton("Test sorting"); + testSortingButton.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + controller.triggerClientSortingTest(); + } + }); + controls.addComponent(testSortingButton); + + Label console = new Label(); + console.setContentMode(ContentMode.HTML); + console.setId("testDebugConsole"); + content.addComponent(console); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/BeanRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/BeanRenderer.java new file mode 100644 index 0000000000..c3036e93b4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/BeanRenderer.java @@ -0,0 +1,25 @@ +/* + * 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.tests.widgetset.client.SimpleTestBean; +import com.vaadin.v7.ui.Grid.AbstractRenderer; + +public class BeanRenderer extends AbstractRenderer { + public BeanRenderer() { + super(SimpleTestBean.class, ""); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/CustomRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/CustomRenderer.java new file mode 100644 index 0000000000..a8e8716ba2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/CustomRenderer.java @@ -0,0 +1,91 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.SimpleTestBean; +import com.vaadin.ui.Label; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.Property; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +@Widgetset(TestingWidgetSet.NAME) +public class CustomRenderer extends AbstractTestUI { + + private static final Object INT_ARRAY_PROPERTY = "int array"; + private static final Object VOID_PROPERTY = "void"; + private static final Object BEAN_PROPERTY = "pojo"; + + static final Object ITEM_ID = "itemId1"; + static final String DEBUG_LABEL_ID = "debuglabel"; + static final String INIT_DEBUG_LABEL_CAPTION = "Debug label placeholder"; + + @Override + protected void setup(VaadinRequest request) { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class, + new int[] {}); + container.addContainerProperty(VOID_PROPERTY, Void.class, null); + container.addContainerProperty(BEAN_PROPERTY, SimpleTestBean.class, + null); + + Item item = container.addItem(ITEM_ID); + + @SuppressWarnings("unchecked") + Property propertyIntArray = item + .getItemProperty(INT_ARRAY_PROPERTY); + propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 }); + + @SuppressWarnings("unchecked") + Property propertyPojo = item + .getItemProperty(BEAN_PROPERTY); + SimpleTestBean bean = new SimpleTestBean(); + bean.setValue(42); + propertyPojo.setValue(bean); + + Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION); + debugLabel.setId(DEBUG_LABEL_ID); + + Grid grid = new Grid(container); + + grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer()); + grid.getColumn(VOID_PROPERTY) + .setRenderer(new RowAwareRenderer(debugLabel)); + grid.getColumn(BEAN_PROPERTY).setRenderer(new BeanRenderer()); + + grid.setSelectionMode(SelectionMode.NONE); + + addComponent(grid); + addComponent(debugLabel); + } + + @Override + protected String getTestDescription() { + return "Verifies that renderers operating on other data than " + + "just Strings also work "; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(13334); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridAddAndRemoveDataOnInit.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridAddAndRemoveDataOnInit.java new file mode 100644 index 0000000000..afda4e01dc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridAddAndRemoveDataOnInit.java @@ -0,0 +1,62 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.v7.data.Container.Indexed; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +public class GridAddAndRemoveDataOnInit extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid gridAdd = new Grid(); + gridAdd.setHeight("240px"); + gridAdd.setWidth("140px"); + addComponent(gridAdd); + Indexed dataSource = gridAdd.getContainerDataSource(); + dataSource.addContainerProperty("foo", Integer.class, 0); + for (int i = 0; i < 10; ++i) { + Object id = dataSource.addItem(); + dataSource.getItem(id).getItemProperty("foo").setValue(i); + } + dataSource = new IndexedContainer(); + dataSource.addContainerProperty("bar", Integer.class, 0); + for (int i = 0; i < 10; ++i) { + Object id = dataSource.addItem(); + dataSource.getItem(id).getItemProperty("bar").setValue(i); + } + Grid gridRemove = new Grid(dataSource); + gridRemove.setHeight("150px"); + gridRemove.setWidth("140px"); + addComponent(gridRemove); + for (int i = 0; i < 5; ++i) { + dataSource.removeItem(dataSource.getIdByIndex(i)); + } + } + + @Override + protected String getTestDescription() { + return "Foo"; + } + + @Override + protected Integer getTicketNumber() { + return 13334; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridAddRow.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridAddRow.java new file mode 100644 index 0000000000..c6306a3281 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridAddRow.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.v7.tests.components.grid; + +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.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridAddRow extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.addColumn("firstName"); + grid.addColumn("age", Integer.class); + + grid.addRow("Lorem", Integer.valueOf(1)); + grid.addRow("Ipsum", Integer.valueOf(2)); + + addComponent(grid); + + addComponent(new Button("Add new row", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.addRow("Dolor", Integer.valueOf(3)); + } + })); + + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCellFocusOnResetSize.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCellFocusOnResetSize.java new file mode 100644 index 0000000000..c28ba2f607 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCellFocusOnResetSize.java @@ -0,0 +1,34 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridCellFocusOnResetSizeWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class GridCellFocusOnResetSize extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent( + new TestWidgetComponent(GridCellFocusOnResetSizeWidget.class)); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCheckBoxDisplay.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCheckBoxDisplay.java new file mode 100644 index 0000000000..a654406f1e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCheckBoxDisplay.java @@ -0,0 +1,91 @@ +/* + * 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.io.Serializable; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.ui.Grid; + +public class GridCheckBoxDisplay extends AbstractTestUI { + + private static final long serialVersionUID = -5575892909354637168L; + private BeanItemContainer todoContainer = new BeanItemContainer( + Todo.class); + + @Override + protected void setup(VaadinRequest request) { + todoContainer.addBean(new Todo("Done task", true)); + todoContainer.addBean(new Todo("Not done", false)); + + Grid grid = new Grid(todoContainer); + grid.setSizeFull(); + + grid.setColumnOrder("done", "task"); + grid.getColumn("done").setWidth(75); + grid.getColumn("task").setExpandRatio(1); + + grid.setSelectionMode(Grid.SelectionMode.SINGLE); + + grid.setEditorEnabled(true); + grid.setImmediate(true); + + getLayout().addComponent(grid); + getLayout().setExpandRatio(grid, 1); + + } + + @Override + protected Integer getTicketNumber() { + return 16976; + } + + @Override + public String getDescription() { + return "Verify that checkbox state is correct for all items in editor"; + } + + public class Todo implements Serializable { + private static final long serialVersionUID = -5961103142478316018L; + + private boolean done; + private String task = ""; + + public Todo(String task, boolean done) { + this.task = task; + this.done = done; + } + + public boolean isDone() { + return done; + } + + public void setDone(boolean done) { + this.done = done; + } + + public String getTask() { + return task; + } + + public void setTask(String task) { + this.task = task; + } + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridClientDataChangeHandler.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridClientDataChangeHandler.java new file mode 100644 index 0000000000..e803c857e7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridClientDataChangeHandler.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.v7.tests.components.grid; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridDataChangeHandlerWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class GridClientDataChangeHandler extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent( + new TestWidgetComponent(GridDataChangeHandlerWidget.class)); + } +} 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 new file mode 100644 index 0000000000..3c0f3f81c1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColspans.java @@ -0,0 +1,102 @@ +/* + * 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.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.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 AbstractTestUI { + + @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 new file mode 100644 index 0000000000..b4eb2dd727 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpand.java @@ -0,0 +1,46 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.Column; + +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("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 new file mode 100644 index 0000000000..653974078a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidth.java @@ -0,0 +1,63 @@ +/* + * 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.AbstractTestUI; +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 AbstractTestUI { + @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 new file mode 100644 index 0000000000..28327b7b45 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/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.v7.tests.components.grid; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +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 AbstractTestUI { + + @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 new file mode 100644 index 0000000000..81bc6ed0da --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnExpand.java @@ -0,0 +1,160 @@ +/* + * 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.AbstractTestUI; +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.ui.themes.Reindeer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.Column; + +@Theme(Reindeer.THEME_NAME) +public class GridColumnExpand extends AbstractTestUI { + 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 new file mode 100644 index 0000000000..7c0191d7c5 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculation.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.v7.tests.components.grid; + +import java.util.ArrayList; + +import com.vaadin.annotations.Theme; +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; + +@Theme("valo") +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 new file mode 100644 index 0000000000..c282ee046a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridColumnWidthsWithoutData.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.v7.tests.components.grid; + +import java.util.EnumSet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.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 AbstractTestUI { + + 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/GridCustomSelectionModel.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCustomSelectionModel.java new file mode 100644 index 0000000000..751e381752 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridCustomSelectionModel.java @@ -0,0 +1,37 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.v7.ui.Grid.MultiSelectionModel; + +@Widgetset(TestingWidgetSet.NAME) +public class GridCustomSelectionModel extends AbstractTestUI { + + public static class MySelectionModel extends MultiSelectionModel { + } + + @Override + protected void setup(VaadinRequest request) { + PersonTestGrid grid = new PersonTestGrid(500); + grid.setSelectionModel(new MySelectionModel()); + addComponent(grid); + } + +} 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 new file mode 100644 index 0000000000..98c204de46 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDataSourceReset.java @@ -0,0 +1,66 @@ +/* + * 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.AbstractTestUI; +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 AbstractTestUI { + + 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/GridDefaultSelectionMode.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDefaultSelectionMode.java new file mode 100644 index 0000000000..c455932ceb --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDefaultSelectionMode.java @@ -0,0 +1,94 @@ +/* + * 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.ui.Button.ClickListener; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.ui.Grid; + +public class GridDefaultSelectionMode extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Person person1 = new Person(); + person1.setFirstName("person"); + person1.setLastName("one"); + + Person person2 = new Person(); + person2.setFirstName("person"); + person2.setLastName("two"); + + ArrayList items = new ArrayList(); + items.add(person1); + items.add(person2); + + final BeanItemContainer container = new BeanItemContainer( + Person.class, items); + + final Grid grid = new Grid(); + grid.setContainerDataSource(container); + + VerticalLayout v = new VerticalLayout(); + + v.addComponent(new Button("Deselect on server", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.select(null); + } + })); + + v.addComponent(new Button("Select on server", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.select(person1); + } + })); + v.addComponent(grid); + + addComponent(v); + } + + public static class Person { + private String firstName; + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + } + +} 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 new file mode 100644 index 0000000000..888313e3b7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsDetach.java @@ -0,0 +1,150 @@ +/* + * 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.AbstractTestUI; +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 AbstractTestUI { + + 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 new file mode 100644 index 0000000000..87b6dfaabe --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLayoutExpand.java @@ -0,0 +1,105 @@ +/* + * 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.AbstractTestUI; +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 AbstractTestUI { + + @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 new file mode 100644 index 0000000000..5c00f0190c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsLocation.java @@ -0,0 +1,115 @@ +/* + * 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.util.Person; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.Label; +import com.vaadin.ui.Layout; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; +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; + +@Theme(ValoTheme.THEME_NAME) +public class GridDetailsLocation extends UI { + + private final DetailsGenerator detailsGenerator = new DetailsGenerator() { + @Override + public Component getDetails(RowReference rowReference) { + Person person = (Person) rowReference.getItemId(); + Label label = new Label( + person.getFirstName() + " " + person.getLastName()); + // currently the decorator row doesn't change its height when the + // content height is different. + label.setHeight("30px"); + return label; + } + }; + + private TextField numberTextField; + private Grid grid; + + @Override + protected void init(VaadinRequest request) { + + Layout layout = new VerticalLayout(); + + grid = new Grid(PersonContainer.createWithTestData(1000)); + grid.setSelectionMode(SelectionMode.NONE); + layout.addComponent(grid); + + final CheckBox checkbox = new CheckBox("Details generator"); + checkbox.addValueChangeListener(event -> { + if (checkbox.getValue()) { + grid.setDetailsGenerator(detailsGenerator); + } else { + grid.setDetailsGenerator(DetailsGenerator.NULL); + } + }); + layout.addComponent(checkbox); + + numberTextField = new TextField("Row"); + numberTextField.setImmediate(true); + layout.addComponent(numberTextField); + + layout.addComponent( + new Button("Toggle and scroll", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + toggle(); + scrollTo(); + } + })); + layout.addComponent( + new Button("Scroll and toggle", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + scrollTo(); + toggle(); + } + })); + + setContent(layout); + } + + private void toggle() { + Object itemId = getItemId(); + boolean isVisible = grid.isDetailsVisible(itemId); + grid.setDetailsVisible(itemId, !isVisible); + } + + private void scrollTo() { + grid.scrollTo(getItemId()); + } + + private Object getItemId() { + int row = Integer.parseInt(numberTextField.getValue()); + Object itemId = grid.getContainerDataSource().getIdByIndex(row); + return itemId; + } + +} 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 new file mode 100644 index 0000000000..c0fbc82af0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDetailsWidth.java @@ -0,0 +1,91 @@ +/* + * 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.AbstractTestUI; +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 AbstractTestUI { + + @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 + public String getDescription() { + 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/v7/tests/components/grid/GridDisabledMultiselect.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDisabledMultiselect.java new file mode 100644 index 0000000000..7a491237e8 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDisabledMultiselect.java @@ -0,0 +1,32 @@ +package com.vaadin.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.v7.ui.Grid; + +public class GridDisabledMultiselect extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.addColumn("foo", String.class); + grid.addRow("bar"); + grid.setSelectionMode(Grid.SelectionMode.SINGLE); + addComponent(grid); + + addButton("Multi", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + grid.setSelectionMode(Grid.SelectionMode.MULTI); + } + }); + + addButton("Disable", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + grid.setEnabled(!grid.isEnabled()); + } + }); + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragAndDrop.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragAndDrop.java new file mode 100644 index 0000000000..8260335d3f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragAndDrop.java @@ -0,0 +1,62 @@ +/* + * 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.Arrays; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Grid; + +@SuppressWarnings("serial") +public class GridDragAndDrop extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + List columnIds = Arrays.asList("Hello", "this", "are", + "multiple", "columns", "plus", "these", "resemble", "a", + "group", "here", "no", "more"); + + Grid grid = new Grid(); + + for (String columnId : columnIds) { + grid.addColumn(columnId); + } + + for (int i = 0; i < 100; i++) { + grid.addRow(columnIds.toArray()); + } + + grid.setColumnReorderingAllowed(true); + + grid.setFrozenColumnCount(1); + grid.setSelectionMode(Grid.SelectionMode.MULTI); + + addComponent(grid); + } + + @Override + protected String getTestDescription() { + return "Start dragging a column header and move left and right.
The drop indicator should appear exactly on the lines between column headers."; + } + + @Override + protected Integer getTicketNumber() { + return 18925; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragSelectionWhileScrolled.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragSelectionWhileScrolled.java new file mode 100644 index 0000000000..e591eeb769 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragSelectionWhileScrolled.java @@ -0,0 +1,51 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridDragSelectionWhileScrolled extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Layout layout = new VerticalLayout(); + + HorizontalLayout spacer = new HorizontalLayout(); + spacer.setHeight("1000px"); + layout.addComponent(spacer); + + PersonTestGrid grid = new PersonTestGrid(100); + grid.setSelectionMode(SelectionMode.MULTI); + layout.addComponent(grid); + + addComponent(layout); + } + + @Override + protected Integer getTicketNumber() { + return 17895; + } + + @Override + protected String getTestDescription() { + return "Drag selecting rows in Grid malfunctions if page is scrolled"; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBars.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBars.java new file mode 100644 index 0000000000..31328482a7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBars.java @@ -0,0 +1,53 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.v7.ui.ComboBox; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.Column; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridEditingWithNoScrollBars extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.addColumn("foo", String.class); + grid.addColumn("bar", String.class); + for (int i = 0; i < 10; ++i) { + grid.addRow("foo", "" + (i % 3 + 1)); + } + + ComboBox stCombo = new ComboBox(); + stCombo.addItem("" + 1); + stCombo.addItem("" + 2); + stCombo.addItem("" + 3); + stCombo.setNullSelectionAllowed(false); + stCombo.setSizeFull(); + + Column stCol = grid.getColumn("bar"); + stCol.setEditorField(stCombo); + + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setEditorEnabled(true); + grid.setSizeFull(); + + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFound.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFound.java new file mode 100644 index 0000000000..d224583c26 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFound.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.v7.tests.components.grid; + +import com.vaadin.server.ErrorHandler; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.v7.ui.Grid; + +public class GridEditorConverterNotFound extends AbstractTestUIWithLog { + + class Foo { + } + + @Override + protected void setup(VaadinRequest request) { + + Grid grid = new Grid(); + + grid.addColumn("foo", Foo.class); + grid.addRow(new Foo()); + grid.setEditorEnabled(true); + grid.setErrorHandler(new ErrorHandler() { + + @Override + public void error(com.vaadin.server.ErrorEvent event) { + log(event.getThrowable().toString()); + } + }); + + addComponent(grid); + } + + @Override + protected Integer getTicketNumber() { + return 17935; + } + + @Override + protected String getTestDescription() { + return "Grid should gracefully handle bind failures when opening editor"; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java new file mode 100644 index 0000000000..d356242a8b --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java @@ -0,0 +1,102 @@ +/* + * 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.HashSet; +import java.util.Set; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.v7.ui.ComboBox; +import com.vaadin.v7.ui.CustomField; +import com.vaadin.v7.ui.Grid; + +@Theme("valo") +public class GridEditorCustomField extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new PersonTestGrid(100); + grid.setWidth("800px"); + grid.setColumns("firstName", "lastName", "address.city"); + grid.setEditorEnabled(true); + Set cities = new HashSet<>(); + for (Object o : grid.getContainerDataSource().getItemIds()) { + ComplexPerson p = (ComplexPerson) o; + cities.add(p.getAddress().getCity()); + } + CustomCitySelect cityEditor = new CustomCitySelect( + cities.toArray(new String[cities.size()])); + grid.getColumn("address.city").setEditorField(cityEditor); + addComponent(grid); + } + + public static class CustomCitySelect extends CustomField { + private HorizontalLayout fieldLayout; + private String[] values; + private ComboBox cityComboBox; + + public CustomCitySelect(String... values) { + this.values = values; + } + + @Override + protected Component initContent() { + fieldLayout = new HorizontalLayout(); + fieldLayout.setWidth("100%"); + + cityComboBox = new ComboBox(); + for (String value : values) { + cityComboBox.addItem(value); + } + fieldLayout.addComponent(cityComboBox); + fieldLayout.setExpandRatio(cityComboBox, 1.0f); + + Button addCountryButton = new Button("New"); + fieldLayout.addComponent(addCountryButton); + + return fieldLayout; + } + + @Override + public Class getType() { + return String.class; + } + + @Override + protected void setInternalValue(String newValue) { + super.setInternalValue(newValue); + if (cityComboBox == null) { + return; + } + cityComboBox.setValue(newValue); + } + + @Override + public String getInternalValue() { + if (cityComboBox == null) { + return null; + } + return (String) cityComboBox.getValue(); + } + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUI.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUI.java new file mode 100644 index 0000000000..3732e70a6f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUI.java @@ -0,0 +1,43 @@ +/* + * 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.tests.util.PersonContainer; +import com.vaadin.v7.ui.Grid; + +public class GridEditorFrozenColumnsUI extends GridEditorUI { + + @Override + protected Grid createGrid(PersonContainer container) { + Grid grid = super.createGrid(container); + + grid.setFrozenColumnCount(2); + + grid.setWidth("600px"); + + return grid; + } + + @Override + protected Integer getTicketNumber() { + return 16727; + } + + @Override + protected String getTestDescription() { + return "Frozen columns should also freeze cells in editor."; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselect.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselect.java new file mode 100644 index 0000000000..047f1d7d84 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselect.java @@ -0,0 +1,35 @@ +package com.vaadin.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Grid; + +public class GridEditorMultiselect extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + + grid.addColumn("name"); + grid.addColumn("age", Integer.class); + + for (int i = 0; i < 30; i++) { + grid.addRow("name " + i, i); + } + + grid.setEditorEnabled(true); + grid.setSelectionMode(Grid.SelectionMode.MULTI); + + addComponent(grid); + } + + @Override + protected Integer getTicketNumber() { + return 17132; + } + + @Override + public String getDescription() { + return "Grid Multiselect: Edit mode allows invalid selection"; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorUI.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorUI.java new file mode 100644 index 0000000000..58f00a10b2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorUI.java @@ -0,0 +1,53 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.PasswordField; +import com.vaadin.v7.ui.TextField; + +public class GridEditorUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + PersonContainer container = PersonContainer.createWithTestData(); + + addComponent(createGrid(container)); + } + + protected Grid createGrid(PersonContainer container) { + Grid grid = new Grid(container); + + // Don't use address since there's no converter + grid.removeColumn("address"); + + grid.setEditorEnabled(true); + + grid.getColumn("firstName").setEditorField(new PasswordField()); + + TextField lastNameField = (TextField) grid.getColumn("lastName") + .getEditorField(); + lastNameField.setMaxLength(50); + + grid.getColumn("phoneNumber").getEditorField().setReadOnly(true); + + return grid; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunication.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunication.java new file mode 100644 index 0000000000..8ee87b1dc1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunication.java @@ -0,0 +1,69 @@ +/* + * 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.shared.MouseEventDetails; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridClickExtensionConnector.GridClickServerRpc; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.AbstractGridExtension; +import com.vaadin.v7.ui.Grid.Column; +import com.vaadin.v7.ui.Grid.SelectionMode; + +@Widgetset(TestingWidgetSet.NAME) +public class GridExtensionCommunication extends AbstractTestUIWithLog { + + public class GridClickExtension extends AbstractGridExtension { + + public GridClickExtension(Grid grid) { + super(grid); + registerRpc(new GridClickServerRpc() { + + @Override + public void click(String row, String column, + MouseEventDetails click) { + Object itemId = getItemId(row); + Column col = getColumn(column); + + Item person = getParentGrid().getContainerDataSource() + .getItem(itemId); + + log("Click on Person " + + person.getItemProperty("firstName").getValue() + + " " + + person.getItemProperty("lastName").getValue() + + " on column " + col.toString()); + log("MouseEventDetails: " + click.getButtonName() + " (" + + click.getClientX() + ", " + click.getClientY() + + ")"); + } + }); + } + } + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new PersonTestGrid(50); + grid.setSelectionMode(SelectionMode.NONE); + new GridClickExtension(grid); + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridFastAsyncUpdate.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridFastAsyncUpdate.java new file mode 100644 index 0000000000..4b5cb8fd48 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridFastAsyncUpdate.java @@ -0,0 +1,149 @@ +package com.vaadin.v7.tests.components.grid; + +import java.util.Calendar; +import java.util.Random; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.logging.Level; + +import com.vaadin.annotations.Push; +import com.vaadin.annotations.Theme; +import com.vaadin.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.VerticalLayout; +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.SelectionMode; + +@Push +@Theme("valo") +@SuppressWarnings("serial") +public class GridFastAsyncUpdate extends AbstractTestUI { + + private final Runnable addRowsTask = new Runnable() { + @Override + public void run() { + System.out.println("Logging..."); + try { + Random random = new Random(); + while (!Thread.currentThread().isInterrupted()) { + Thread.sleep(random.nextInt(100)); + + GridFastAsyncUpdate.this.access(new Runnable() { + @SuppressWarnings("unchecked") + @Override + public void run() { + + ++counter; + Item item = container.addItem(counter); + item.getItemProperty("sequenceNumber") + .setValue(String.valueOf(counter)); + item.getItemProperty("millis") + .setValue(String.valueOf(Calendar + .getInstance().getTimeInMillis() + - loggingStart)); + item.getItemProperty("level") + .setValue(Level.INFO.toString()); + item.getItemProperty("message").setValue("Message"); + if (grid != null && !scrollLock) { + grid.scrollToEnd(); + } + } + }); + } + } catch (InterruptedException e) { + System.out.println("logging thread interrupted"); + } + } + }; + + private int counter; + + private Grid grid; + private IndexedContainer container; + private long loggingStart; + private volatile boolean scrollLock = false; + + @Override + protected void setup(VaadinRequest vaadinRequest) { + final VerticalLayout layout = new VerticalLayout(); + layout.setSizeFull(); + layout.setMargin(true); + addComponent(layout); + + HorizontalLayout buttons = new HorizontalLayout(); + layout.addComponent(buttons); + + final ExecutorService logExecutor = Executors.newSingleThreadExecutor(); + + final Button logButton = new Button("Start logging"); + logButton.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + if ("Start logging".equals(logButton.getCaption())) { + loggingStart = Calendar.getInstance().getTimeInMillis(); + logExecutor.submit(addRowsTask); + logButton.setCaption("Stop logging"); + } else { + System.out.println("Stop logging..."); + try { + logExecutor.shutdownNow(); + } catch (Exception e) { + e.printStackTrace(); + } + logButton.setCaption("Start logging"); + } + } + }); + buttons.addComponent(logButton); + + final Button scrollButton = new Button("Stop scrolling"); + scrollButton.addClickListener(new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + if (!scrollLock) { + System.out.println("Stop scrolling"); + scrollButton.setCaption("Start scrolling"); + scrollLock = true; + } else { + System.out.println("Start scrolling"); + scrollButton.setCaption("Stop scrolling"); + scrollLock = false; + } + } + }); + buttons.addComponent(scrollButton); + + container = new IndexedContainer(); + container.addContainerProperty("sequenceNumber", String.class, null); + container.addContainerProperty("millis", String.class, null); + container.addContainerProperty("level", String.class, null); + container.addContainerProperty("message", String.class, null); + + grid = new Grid(container); + grid.setWidth("100%"); + grid.setImmediate(true); + grid.setSelectionMode(SelectionMode.SINGLE); + grid.addSelectionListener(new SelectionListener() { + @Override + public void select(final SelectionEvent event) { + if (grid.getSelectedRow() != null) { + disableScroll(); + } + } + }); + + layout.addComponent(grid); + layout.setExpandRatio(grid, 1.0f); + } + + protected void disableScroll() { + scrollLock = true; + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridGeneratedProperties.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridGeneratedProperties.java new file mode 100644 index 0000000000..c5dfcc67ab --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridGeneratedProperties.java @@ -0,0 +1,165 @@ +/* + * 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.data.sort.Sort; +import com.vaadin.data.sort.SortOrder; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.v7.data.Container.Filter; +import com.vaadin.v7.data.Container.Filterable; +import com.vaadin.v7.data.Container.Indexed; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.util.GeneratedPropertyContainer; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.data.util.PropertyValueGenerator; +import com.vaadin.v7.data.util.filter.Compare; +import com.vaadin.v7.data.util.filter.UnsupportedFilterException; +import com.vaadin.v7.ui.Grid; + +public class GridGeneratedProperties extends AbstractTestUI { + + private GeneratedPropertyContainer container; + static double MILES_CONVERSION = 0.6214d; + private Filter filter = new Compare.Greater("miles", 1d); + + @Override + protected void setup(VaadinRequest request) { + container = new GeneratedPropertyContainer(createContainer()); + Grid grid = new Grid(container); + addComponent(grid); + + container.addGeneratedProperty("miles", + new PropertyValueGenerator() { + + @Override + public Double getValue(Item item, Object itemId, + Object propertyId) { + return (Double) item.getItemProperty("km").getValue() + * MILES_CONVERSION; + } + + @Override + public Class getType() { + return Double.class; + } + + @Override + public Filter modifyFilter(Filter filter) + throws UnsupportedFilterException { + if (filter instanceof Compare.Greater) { + Double value = (Double) ((Compare.Greater) filter) + .getValue(); + value = value / MILES_CONVERSION; + return new Compare.Greater("km", value); + } + return super.modifyFilter(filter); + } + }); + + final Button filterButton = new Button("Add filter"); + filterButton.addClickListener(new ClickListener() { + + boolean active = false; + + @Override + public void buttonClick(ClickEvent event) { + if (active) { + ((Filterable) container).removeContainerFilter(filter); + filterButton.setCaption("Add filter"); + active = false; + return; + } + ((Filterable) container).addContainerFilter(filter); + filterButton.setCaption("Remove filter"); + active = true; + } + }); + + container.addGeneratedProperty("foo", + new PropertyValueGenerator() { + + @Override + public String getValue(Item item, Object itemId, + Object propertyId) { + return item.getItemProperty("foo").getValue() + " " + + item.getItemProperty("bar").getValue(); + } + + @Override + public Class getType() { + return String.class; + } + }); + container.removeContainerProperty("bar"); + container.addGeneratedProperty("baz", + new PropertyValueGenerator() { + + @Override + public Integer getValue(Item item, Object itemId, + Object propertyId) { + return (Integer) item.getItemProperty("bar").getValue(); + } + + @Override + public Class getType() { + return Integer.class; + } + + @Override + public SortOrder[] getSortProperties(SortOrder order) { + return Sort.by("bar", order.getDirection()).build() + .toArray(new SortOrder[1]); + } + }); + + addComponent(filterButton); + grid.sort(Sort.by("km").then("bar", SortDirection.DESCENDING)); + } + + private Indexed createContainer() { + Indexed container = new IndexedContainer(); + container.addContainerProperty("foo", String.class, "foo"); + container.addContainerProperty("bar", Integer.class, 0); + // km contains double values from 0.0 to 2.0 + container.addContainerProperty("km", Double.class, 0); + + for (int i = 0; i <= 100; ++i) { + Object itemId = container.addItem(); + Item item = container.getItem(itemId); + item.getItemProperty("foo").setValue("foo"); + item.getItemProperty("bar").setValue(i); + item.getItemProperty("km").setValue(i / 5.0d); + } + + return container; + } + + @Override + protected String getTestDescription() { + return "A Grid with GeneratedPropertyContainer"; + } + + @Override + protected Integer getTicketNumber() { + return 13334; + } + +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponents.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponents.java new file mode 100644 index 0000000000..ffcf312544 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponents.java @@ -0,0 +1,135 @@ +/* + * 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.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; +import com.vaadin.ui.TextField; +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; + +@Theme("valo") +public class GridHeaderFooterComponents extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.setWidth("800px"); + grid.setContainerDataSource(createContainer()); + grid.setFooterVisible(true); + final HeaderRow defaultRow = grid.getDefaultHeaderRow(); + final HeaderRow toggleVisibilityRow = grid.appendHeaderRow(); + final Grid.HeaderRow filterRow = grid.appendHeaderRow(); + + final FooterRow footerRow = grid.addFooterRowAt(0); + final FooterRow toggleVisibilityFooterRow = grid.addFooterRowAt(0); + final FooterRow filterFooterRow = grid.addFooterRowAt(0); + + // Set up a filter for all columns + for (final Object pid : grid.getContainerDataSource() + .getContainerPropertyIds()) { + final Grid.HeaderCell headerCell = filterRow.getCell(pid); + final Grid.FooterCell footerCell = filterFooterRow.getCell(pid); + + headerCell.setComponent(createTextField(pid)); + footerCell.setComponent(createTextField(pid)); + + toggleVisibilityRow.getCell(pid).setComponent( + new Button("Toggle field", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Component c = headerCell.getComponent(); + c.setVisible(!c.isVisible()); + } + })); + toggleVisibilityFooterRow.getCell(pid).setComponent( + new Button("Toggle field", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Component c = footerCell.getComponent(); + c.setVisible(!c.isVisible()); + } + })); + } + addComponent(grid); + + addRemoveHeaderRow(grid, defaultRow); + addRemoveHeaderRow(grid, filterRow); + addRemoveHeaderRow(grid, toggleVisibilityRow); + + addRemoveFooterRow(grid, footerRow); + addRemoveFooterRow(grid, filterFooterRow); + addRemoveFooterRow(grid, toggleVisibilityFooterRow); + + // Hide first field initially + filterRow.getCell("string").getComponent().setVisible(false); + filterFooterRow.getCell("string").getComponent().setVisible(false); + } + + private void addRemoveHeaderRow(final Grid grid, final HeaderRow row) { + row.getCell("action") + .setComponent(new Button("Remove row", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.removeHeaderRow(row); + } + })); + + } + + private void addRemoveFooterRow(final Grid grid, final FooterRow row) { + row.getCell("action") + .setComponent(new Button("Remove row", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.removeFooterRow(row); + } + })); + + } + + private IndexedContainer createContainer() { + IndexedContainer ic = new IndexedContainer(); + ic.addContainerProperty("action", String.class, ""); + ic.addContainerProperty("string", String.class, "Hello world"); + ic.addContainerProperty("int", int.class, 13); + ic.addContainerProperty("double", double.class, 5.2f); + + for (int i = 0; i < 5; i++) { + ic.addItem(); + } + return ic; + } + + private TextField createTextField(final Object pid) { + TextField filterField = new TextField(); + filterField.setColumns(8); + filterField.setValue("Filter: " + pid); + filterField.addValueChangeListener(listener -> { + log("value change for field in " + pid + " to " + + listener.getValue()); + }); + return filterField; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChange.java new file mode 100644 index 0000000000..1277257686 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChange.java @@ -0,0 +1,183 @@ +/* + * 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.io.Serializable; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.HeaderRow; +import com.vaadin.v7.ui.Grid.SelectionMode; +import com.vaadin.v7.ui.Grid.SelectionModel; +import com.vaadin.v7.ui.renderers.NumberRenderer; + +public class GridHeaderFormatChange extends AbstractTestUI { + + private static final long serialVersionUID = -2787771187365766027L; + + private HeaderRow row; + + public class Person implements Serializable { + private static final long serialVersionUID = -7995927620756317000L; + + String firstName; + String lastName; + String streetAddress; + Integer zipCode; + String city; + + public Person(String firstName, String lastName, String streetAddress, + Integer zipCode, String city) { + this.firstName = firstName; + this.lastName = lastName; + this.streetAddress = streetAddress; + this.zipCode = zipCode; + this.city = city; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getStreetAddress() { + return streetAddress; + } + + public void setStreetAddress(String streetAddress) { + this.streetAddress = streetAddress; + } + + public Integer getZipCode() { + return zipCode; + } + + public void setZipCode(Integer zipCode) { + this.zipCode = zipCode; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + } + + @Override + protected void setup(VaadinRequest request) { + BeanItemContainer datasource = new BeanItemContainer( + Person.class); + final Grid grid; + + datasource.addItem(new Person("Rudolph", "Reindeer", "Ruukinkatu 2-4", + 20540, "Turku")); + + grid = new Grid(datasource); + grid.setWidth("600px"); + grid.getColumn("zipCode").setRenderer(new NumberRenderer()); + grid.setColumnOrder("firstName", "lastName", "streetAddress", "zipCode", + "city"); + grid.setSelectionMode(SelectionMode.SINGLE); + addComponent(grid); + + Button showHide = new Button("Hide firstName", + new Button.ClickListener() { + private static final long serialVersionUID = 8107530972693788705L; + + @Override + public void buttonClick(ClickEvent event) { + if (grid.getColumn("firstName") != null) { + grid.removeColumn("firstName"); + event.getButton().setCaption("Show firstName"); + } else { + grid.addColumn("firstName"); + grid.setColumnOrder("firstName", "lastName", + "streetAddress", "zipCode", "city"); + + event.getButton().setCaption("Hide firstName"); + } + } + }); + showHide.setId("show_hide"); + + Button selectionMode = new Button("Set multiselect", + new Button.ClickListener() { + private static final long serialVersionUID = 8107530972693788705L; + + @Override + public void buttonClick(ClickEvent event) { + if (grid.getSelectionModel() instanceof SelectionModel.Single) { + grid.setSelectionMode(SelectionMode.MULTI); + } else { + grid.setSelectionMode(SelectionMode.SINGLE); + } + } + }); + selectionMode.setId("selection_mode"); + + Button join = new Button("Add Join header column", + new Button.ClickListener() { + private static final long serialVersionUID = -5330801275551280623L; + + @Override + public void buttonClick(ClickEvent event) { + if (row == null) { + row = grid.prependHeaderRow(); + if (grid.getColumn("firstName") != null) { + row.join("firstName", "lastName") + .setText("Full Name"); + } + row.join("streetAddress", "zipCode", "city") + .setText("Address"); + } else { + grid.removeHeaderRow(row); + row = null; + } + } + }); + join.setId("join"); + addComponent(new HorizontalLayout(showHide, selectionMode, join)); + } + + @Override + protected String getTestDescription() { + return "Grid for testing header re-rendering."; + } + + @Override + protected Integer getTicketNumber() { + return 17131; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderStyleNames.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderStyleNames.java new file mode 100644 index 0000000000..7e49bfd17f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderStyleNames.java @@ -0,0 +1,107 @@ +/* + * 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.AbstractTestUIWithLog; +import com.vaadin.tests.components.beanitemcontainer.BeanItemContainerGenerator; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.FooterCell; +import com.vaadin.v7.ui.Grid.FooterRow; +import com.vaadin.v7.ui.Grid.HeaderCell; +import com.vaadin.v7.ui.Grid.HeaderRow; +import com.vaadin.v7.ui.Grid.SelectionMode; + +@Theme("valo") +public class GridHeaderStyleNames extends AbstractTestUIWithLog { + + private HeaderCell ageHeaderCell; + private HeaderCell mergedCityCountryCell; + private FooterCell ageFooterCell; + private HeaderRow headerRow; + private FooterRow footerRow; + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.setContainerDataSource( + BeanItemContainerGenerator.createContainer(100)); + + ageHeaderCell = grid.getDefaultHeaderRow().getCell("age"); + grid.getDefaultHeaderRow().setStyleName("foo"); + headerRow = grid.prependHeaderRow(); + mergedCityCountryCell = headerRow.join("city", "country"); + mergedCityCountryCell.setText("Merged cell"); + addComponent(grid); + + footerRow = grid.appendFooterRow(); + ageFooterCell = footerRow.getCell("age"); + + getPage().getStyles().add( + ".age {background-image: linear-gradient(to bottom,green 2%, #efefef 98%) !important;}"); + getPage().getStyles().add( + ".valo .v-grid-header .v-grid-cell.city-country {background-image: linear-gradient(to bottom,yellow 2%, #efefef 98%) !important;}"); + getPage().getStyles().add( + ".valo .v-grid-footer .v-grid-cell.age-footer {background-image: linear-gradient(to bottom,blue 2%, #efefef 98%) !important;}"); + getPage().getStyles().add( + ".valo .v-grid .v-grid-row.custom-row > * {background-image: linear-gradient(to bottom,purple 2%, #efefef 98%);}"); + + setCellStyles(true); + setRowStyles(true); + + Button b = new Button("Toggle styles"); + b.addClickListener(new ClickListener() { + private boolean stylesOn = true; + + @Override + public void buttonClick(ClickEvent event) { + setCellStyles(!stylesOn); + setRowStyles(!stylesOn); + stylesOn = !stylesOn; + } + }); + addComponent(b); + } + + protected void setCellStyles(boolean set) { + if (set) { + ageHeaderCell.setStyleName("age"); + ageFooterCell.setStyleName("age-footer"); + mergedCityCountryCell.setStyleName("city-country"); + } else { + ageHeaderCell.setStyleName(null); + ageFooterCell.setStyleName(null); + mergedCityCountryCell.setStyleName(null); + } + + } + + protected void setRowStyles(boolean set) { + if (set) { + headerRow.setStyleName("custom-row"); + footerRow.setStyleName("custom-row"); + } else { + headerRow.setStyleName(null); + footerRow.setStyleName(null); + } + + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeight.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeight.java new file mode 100644 index 0000000000..b91324bf0c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeight.java @@ -0,0 +1,189 @@ +/* + * 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.Arrays; +import java.util.HashMap; +import java.util.Map; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.event.ItemClickEvent; +import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; +import com.vaadin.v7.shared.ui.grid.HeightMode; +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.OptionGroup; + +/** + * Tests that Grid gets correct height based on height mode, and resizes + * properly with details row if height is undefined. + * + * @author Vaadin Ltd + */ +public class GridHeight extends AbstractTestUI { + + static final String FULL = "Full"; + static final String UNDEFINED = "Undefined"; + static final String PX100 = "100px"; + static final Integer ROW3 = 3; + + static final Object[] gridHeights = { FULL, UNDEFINED, ROW3 }; + static final String[] gridWidths = { FULL, UNDEFINED }; + static final String[] detailsRowHeights = { FULL, UNDEFINED, PX100 }; + + private Grid grid; + private Map detailsLayouts = new HashMap(); + private OptionGroup detailsHeightSelector; + + @Override + protected void setup(VaadinRequest request) { + + grid = new Grid(); + grid.addColumn("name", String.class); + grid.addColumn("born", Integer.class); + + grid.addRow("Nicolaus Copernicus", 1543); + grid.addRow("Galileo Galilei", 1564); + for (int i = 0; i < 1; ++i) { + grid.addRow("Johannes Kepler", 1571); + } + + grid.setDetailsGenerator(new DetailsGenerator() { + @Override + public Component getDetails(final RowReference rowReference) { + if (!detailsLayouts.containsKey(rowReference.getItemId())) { + createDetailsLayout(rowReference.getItemId()); + } + return detailsLayouts.get(rowReference.getItemId()); + } + }); + + grid.addItemClickListener(new ItemClickListener() { + @Override + public void itemClick(final ItemClickEvent event) { + final Object itemId = event.getItemId(); + grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); + } + }); + + addComponent(createOptionLayout()); + addComponent(grid); + } + + private void createDetailsLayout(Object itemId) { + VerticalLayout detailsLayout = new VerticalLayout(); + setDetailsHeight(detailsLayout, detailsHeightSelector.getValue()); + detailsLayout.setWidth("100%"); + + Label lbl1 = new Label("details row"); + lbl1.setId("lbl1"); + lbl1.setSizeUndefined(); + detailsLayout.addComponent(lbl1); + detailsLayout.setComponentAlignment(lbl1, Alignment.MIDDLE_CENTER); + + detailsLayouts.put(itemId, detailsLayout); + } + + private Component createOptionLayout() { + HorizontalLayout optionLayout = new HorizontalLayout(); + OptionGroup gridHeightSelector = new OptionGroup("Grid height", + Arrays. asList(gridHeights)); + gridHeightSelector.setId("gridHeightSelector"); + gridHeightSelector.setItemCaption(ROW3, ROW3 + " rows"); + gridHeightSelector.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + Object value = event.getProperty().getValue(); + if (UNDEFINED.equals(value)) { + grid.setHeightUndefined(); + grid.setHeightMode(HeightMode.UNDEFINED); + } else if (FULL.equals(value)) { + grid.setHeight("100%"); + grid.setHeightMode(HeightMode.CSS); + } else if (ROW3.equals(value)) { + grid.setHeightByRows(ROW3); + grid.setHeightMode(HeightMode.ROW); + } + } + }); + gridHeightSelector.setValue(UNDEFINED); + optionLayout.addComponent(gridHeightSelector); + + OptionGroup gridWidthSelector = new OptionGroup("Grid width", + Arrays.asList(gridWidths)); + gridWidthSelector.setId("gridWidthSelector"); + gridWidthSelector.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + Object value = event.getProperty().getValue(); + if (UNDEFINED.equals(value)) { + grid.setWidthUndefined(); + } else if (FULL.equals(value)) { + grid.setWidth("100%"); + } + } + }); + gridWidthSelector.setValue(UNDEFINED); + optionLayout.addComponent(gridWidthSelector); + + detailsHeightSelector = new OptionGroup("Details row height", + Arrays.asList(detailsRowHeights)); + detailsHeightSelector.setId("detailsHeightSelector"); + detailsHeightSelector.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + Object value = event.getProperty().getValue(); + for (VerticalLayout detailsLayout : detailsLayouts.values()) { + setDetailsHeight(detailsLayout, value); + } + } + }); + detailsHeightSelector.setValue(PX100); + optionLayout.addComponent(detailsHeightSelector); + return optionLayout; + } + + private void setDetailsHeight(VerticalLayout detailsLayout, Object value) { + if (UNDEFINED.equals(value)) { + detailsLayout.setHeightUndefined(); + } else if (FULL.equals(value)) { + detailsLayout.setHeight("100%"); + } else if (PX100.equals(value)) { + detailsLayout.setHeight(PX100); + } + } + + @Override + protected String getTestDescription() { + return "Grid with undefined height should display all rows and resize when details row is opened." + + "
Grid with full height is always 400px high regardless or details row." + + "
Grid with row height should always be the height of those rows regardless of details row."; + } + + @Override + protected Integer getTicketNumber() { + return 19690; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInGridLayout.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInGridLayout.java new file mode 100644 index 0000000000..c272ef045d --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInGridLayout.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.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.ui.Grid; + +public class GridInGridLayout extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout layout = new VerticalLayout(); + final CssLayout cssLayout = new CssLayout(); + cssLayout.setWidth("100%"); + layout.setHeight("320px"); + layout.setMargin(true); + addComponent(cssLayout); + cssLayout.addComponent(layout); + + final Grid grid = new Grid(); + grid.setSizeFull(); + for (int i = 0; i < 20; i++) { + Grid.Column column = grid.addColumn("" + i); + column.setHidable(true); + column.setEditable(true); + } + grid.setEditorEnabled(true); + grid.setColumnReorderingAllowed(true); + for (int i = 0; i < 300; i++) { + grid.addRow("Foo", "Bar", "far", "bar", "bar", "Foo", "Bar", "Bar", + "bar", "bar", "Foo", "Bar", "Bar", "bar", "bar", "Foo", + "Bar", "Bar", "bar", "bar"); + + } + layout.addComponent(grid); + grid.setHeight("300px"); + grid.setWidth("400px"); + } + + @Override + protected Integer getTicketNumber() { + return 18698; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInTabSheet.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInTabSheet.java new file mode 100644 index 0000000000..ba17c82ed8 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInTabSheet.java @@ -0,0 +1,94 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.CellReference; +import com.vaadin.v7.ui.Grid.CellStyleGenerator; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridInTabSheet extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TabSheet sheet = new TabSheet(); + final Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.addColumn("count", Integer.class); + for (Integer i = 0; i < 3; ++i) { + grid.addRow(i); + } + + sheet.addTab(grid, "Grid"); + sheet.addTab(new Label("Hidden"), "Label"); + + addComponent(sheet); + addComponent(new Button("Add row to Grid", new Button.ClickListener() { + + private Integer k = 0; + + @Override + public void buttonClick(ClickEvent event) { + grid.addRow(100 + (k++)); + } + })); + addComponent( + new Button("Remove row from Grid", new Button.ClickListener() { + + private Integer k = 0; + + @Override + public void buttonClick(ClickEvent event) { + Object firstItemId = grid.getContainerDataSource() + .firstItemId(); + if (firstItemId != null) { + grid.getContainerDataSource() + .removeItem(firstItemId); + } + } + })); + addComponent(new Button("Add CellStyleGenerator", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.setCellStyleGenerator(new CellStyleGenerator() { + @Override + public String getStyle( + CellReference cellReference) { + int rowIndex = ((Integer) cellReference + .getItemId()).intValue(); + Object propertyId = cellReference + .getPropertyId(); + if (rowIndex % 4 == 1) { + return null; + } else if (rowIndex % 4 == 3 + && "Column 1".equals(propertyId)) { + return null; + } + return propertyId.toString().replace(' ', '_'); + } + }); + } + })); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInWindowResize.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInWindowResize.java new file mode 100644 index 0000000000..9d4775a4b7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInWindowResize.java @@ -0,0 +1,72 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +@Theme("valo") +public class GridInWindowResize extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid g = new Grid(); + IndexedContainer cont = new IndexedContainer(); + for (int j = 0; j < 3; j++) { + cont.addContainerProperty("" + j, String.class, ""); + } + + for (int k = 0; k < 100; k++) { + Item addItem = cont.addItem(k); + for (int j = 0; j < 3; j++) { + addItem.getItemProperty("" + j).setValue(1 + ""); + } + } + g.setContainerDataSource(cont); + g.setSizeFull(); + + VerticalLayout vl = new VerticalLayout(g); + vl.setSizeFull(); + Button resize = new Button("resize"); + VerticalLayout vl2 = new VerticalLayout(vl, resize); + vl2.setSizeFull(); + + final Window w = new Window(null, vl2); + addWindow(w); + + w.center(); + w.setModal(true); + w.setWidth("600px"); + w.setHeight("400px"); + + resize.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + w.setWidth("400px"); + } + }); + + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumns.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumns.java new file mode 100644 index 0000000000..6901dbd1d8 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumns.java @@ -0,0 +1,36 @@ +/* + * 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.AbstractTestUIWithLog; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.v7.ui.Grid; + +public class GridInitiallyHiddenColumns extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setContainerDataSource(ComplexPerson.createContainer(100)); + grid.setColumns("firstName", "lastName", "age"); + grid.getColumn("firstName").setHidden(true).setHidable(true); + grid.getColumn("lastName").setHidable(true); + grid.getColumn("age").setHidden(true).setHidable(true); + + addComponent(grid); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridItemSetChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridItemSetChange.java new file mode 100644 index 0000000000..bb84156a55 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridItemSetChange.java @@ -0,0 +1,69 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.tests.util.Person; +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 GridItemSetChange extends AbstractTestUI { + + public static class SneakyBeanContainer extends BeanItemContainer { + + private Person p = new Person("Foo", "Bar", "", "", "", 0, ""); + + public SneakyBeanContainer() throws IllegalArgumentException { + super(Person.class); + addItem(p); + } + + public void reset() { + internalRemoveAllItems(); + p.setLastName("Baz"); + internalAddItemAtEnd(p, createBeanItem(p), false); + fireItemSetChange(); + } + } + + @Override + protected void setup(VaadinRequest request) { + final SneakyBeanContainer c = new SneakyBeanContainer(); + Grid g = new Grid(c); + g.setColumns("firstName", "lastName"); + addComponent(g); + addComponent(new Button("Reset", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + c.reset(); + } + })); + addComponent(new Button("Modify", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + c.getItem(c.firstItemId()).getItemProperty("lastName") + .setValue("Spam"); + } + })); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRow.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRow.java new file mode 100644 index 0000000000..ec7e465ed0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRow.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.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Component; +import com.vaadin.ui.GridLayout; +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 that details row displays GridLayout contents properly. + * + * @author Vaadin Ltd + */ +public class GridLayoutDetailsRow extends AbstractTestUI { + + @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 GridLayout detailsLayout = new GridLayout(); + detailsLayout.setSizeFull(); + detailsLayout.setHeightUndefined(); + + final Label lbl1 = new Label("test1"); + lbl1.setId("lbl1"); + lbl1.setWidth("200px"); + detailsLayout.addComponent(lbl1); + + final Label lbl2 = new Label("test2"); + lbl2.setId("lbl2"); + detailsLayout.addComponent(lbl2); + + final Label lbl3 = new Label("test3"); + lbl3.setId("lbl3"); + detailsLayout.addComponent(lbl3); + + final Label lbl4 = new Label("test4"); + lbl4.setId("lbl4"); + detailsLayout.addComponent(lbl4); + + 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 String getTestDescription() { + return "GridLayout as part of Grid detail row should be correctly computed/displayed."; + } + + @Override + protected Integer getTicketNumber() { + return 18619; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionOnInit.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionOnInit.java new file mode 100644 index 0000000000..5aaf963c54 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionOnInit.java @@ -0,0 +1,46 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.MultiSelectionModel; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridMultiSelectionOnInit extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.addColumn("foo", String.class); + grid.addRow("Foo 1"); + grid.addRow("Foo 2"); + grid.setSelectionMode(SelectionMode.MULTI); + addComponent(grid); + + addComponent(new Button("Select rows", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + ((MultiSelectionModel) grid.getSelectionModel()).setSelected( + grid.getContainerDataSource().getItemIds()); + } + })); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionScrollBar.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionScrollBar.java new file mode 100644 index 0000000000..fa78d8f9aa --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionScrollBar.java @@ -0,0 +1,34 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.v7.ui.Grid; + +public class GridMultiSelectionScrollBar extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.addColumn("X").setWidth(39.25d); + grid.addColumn("Hello"); + grid.addColumn("World"); + grid.setFrozenColumnCount(1); + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRendererChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRendererChange.java new file mode 100644 index 0000000000..18626e4106 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRendererChange.java @@ -0,0 +1,68 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.renderers.ButtonRenderer; +import com.vaadin.v7.ui.renderers.HtmlRenderer; +import com.vaadin.v7.ui.renderers.TextRenderer; + +public class GridRendererChange extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final Grid grid = new Grid(); + grid.setColumns("num", "foo"); + grid.getColumn("num").setRenderer(new ButtonRenderer()); + + for (int i = 0; i < 1000; i++) { + grid.addRow(String.format("line %d", i), "" + i); + } + + Button button = new Button("Set ButtonRenderer", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.getColumn("num").setRenderer(new ButtonRenderer()); + } + }); + + Button buttonHtml = new Button("Set HTMLRenderer", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.getColumn("num").setRenderer(new HtmlRenderer()); + } + }); + + Button buttonText = new Button("Set TextRenderer", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.getColumn("num").setRenderer(new TextRenderer()); + } + }); + + addComponent(new HorizontalLayout(button, buttonHtml, buttonText)); + addComponent(grid); + } +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReplaceContainer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReplaceContainer.java new file mode 100644 index 0000000000..07a71f53e0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridReplaceContainer.java @@ -0,0 +1,94 @@ +/* + * 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.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.v7.data.Container.Indexed; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridReplaceContainer extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setContainerDataSource(createContainer()); + grid.addSelectionListener(new SelectionListener() { + + @Override + public void select(SelectionEvent event) { + Bean selected = (Bean) grid.getSelectedRow(); + if (selected != null) { + log("Now selected: " + selected.getData()); + } else { + log("Now selected: null"); + } + + } + }); + addComponent(grid); + Button b = new Button("Re-set data source", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.setContainerDataSource(createContainer()); + } + }); + addComponent(b); + } + + public static class Bean { + private int id; + private String data; + + public Bean(int id, String data) { + this.id = id; + this.data = data; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + } + + private Indexed createContainer() { + BeanItemContainer bic = new BeanItemContainer(Bean.class); + bic.addBean(new Bean(1, "First item")); + bic.addBean(new Bean(2, "Second item")); + bic.addBean(new Bean(3, "Third item")); + return bic; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeAndScroll.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeAndScroll.java new file mode 100644 index 0000000000..5364644721 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeAndScroll.java @@ -0,0 +1,68 @@ +/* + * 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.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.VerticalLayout; +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.SelectionMode; + +public class GridResizeAndScroll extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout content = new VerticalLayout(); + addComponent(content); + + final Grid g = new Grid(); + content.setHeight("500px"); + content.addComponent(g); + + IndexedContainer cont = new IndexedContainer(); + for (int j = 0; j < 3; j++) { + cont.addContainerProperty("" + j, String.class, ""); + } + + for (int k = 0; k < 50; k++) { + Item addItem = cont.addItem(k); + for (int j = 0; j < 3; j++) { + addItem.getItemProperty("" + j).setValue("cell " + k + " " + j); + } + } + g.setContainerDataSource(cont); + g.setSizeFull(); + + g.setSelectionMode(SelectionMode.MULTI); + + g.addSelectionListener(new SelectionListener() { + + @Override + public void select(SelectionEvent event) { + if (g.getSelectedRows().isEmpty()) { + g.setHeight("100%"); + } else { + g.setHeight("50%"); + } + } + }); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeHiddenColumn.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeHiddenColumn.java new file mode 100644 index 0000000000..ca94035edc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeHiddenColumn.java @@ -0,0 +1,64 @@ +/* + * 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.AbstractTestUIWithLog; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.ColumnResizeEvent; +import com.vaadin.v7.ui.Grid.ColumnResizeListener; + +@SuppressWarnings("serial") +public class GridResizeHiddenColumn extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setContainerDataSource(ComplexPerson.createContainer(100)); + grid.setColumns("firstName", "lastName", "gender", "birthDate"); + grid.getColumn("firstName").setHidable(true); + grid.getColumn("lastName").setHidable(true).setHidden(true); + grid.getColumn("gender").setHidable(true).setHidden(true); + grid.getColumn("birthDate").setHidable(true); + + addComponent(grid); + + grid.addColumnResizeListener(new ColumnResizeListener() { + @Override + public void columnResize(ColumnResizeEvent event) { + log(String.format("Column resized: id=%s, width=%s", + event.getColumn().getPropertyId(), + event.getColumn().getWidth())); + } + }); + } + + @Override + protected String getTestDescription() { + return "Resize columns and then make hidden column visible. The originally hidden column should have an extended width."; + } + + @Override + protected Integer getTicketNumber() { + return 19826; + } + + @Override + public String getDescription() { + return "Tests resize when columns with undefined width (-1) are hidden"; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeTerror.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeTerror.java new file mode 100644 index 0000000000..41a1081113 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridResizeTerror.java @@ -0,0 +1,46 @@ +/* + * 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.util.ResizeTerrorizer; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.ui.UI; +import com.vaadin.v7.ui.Grid; + +@Widgetset(TestingWidgetSet.NAME) +public class GridResizeTerror extends UI { + @Override + protected void init(VaadinRequest request) { + Grid grid = new Grid(); + + int cols = 10; + Object[] data = new Object[cols]; + + for (int i = 0; i < cols; i++) { + grid.addColumn("Col " + i); + data[i] = "Data " + i; + } + + for (int i = 0; i < 500; i++) { + grid.addRow(data); + } + + ResizeTerrorizer terrorizer = new ResizeTerrorizer(grid); + setContent(terrorizer); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRowHeightChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRowHeightChange.java new file mode 100644 index 0000000000..402b6357af --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridRowHeightChange.java @@ -0,0 +1,73 @@ +package com.vaadin.v7.tests.components.grid; + +import java.util.Arrays; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.data.Property; +import com.vaadin.v7.shared.ui.grid.HeightMode; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.NativeSelect; + +public class GridRowHeightChange extends AbstractTestUI { + + private final List themes = Arrays.asList("valo", "reindeer", + "runo", "chameleon", "base"); + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + + // create column and fill rows + grid.addColumn("Header"); + for (int i = 1; i <= 10; i++) { + grid.addRow("row_" + i); + } + + // set height mode and height + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(10); + + // create a tabsheet with one tab and place grid inside + VerticalLayout tab = new VerticalLayout(); + TabSheet tabSheet = new TabSheet(); + tabSheet.setWidthUndefined(); + tabSheet.addTab(tab, "Tab"); + tab.addComponent(grid); + + // Theme selector + NativeSelect themeSelector = new NativeSelect("Theme selector", themes); + themeSelector.select("reindeer"); + themeSelector.setNullSelectionAllowed(false); + themeSelector + .addValueChangeListener(new Property.ValueChangeListener() { + @Override + public void valueChange(Property.ValueChangeEvent event) { + setTheme((String) event.getProperty().getValue()); + } + }); + + VerticalLayout layout = new VerticalLayout(); + layout.setSpacing(true); + layout.setSizeUndefined(); + + layout.addComponent(themeSelector); + layout.addComponent(tabSheet); + + addComponent(layout); + } + + @Override + protected String getTestDescription() { + return "Test if Grid's height is adjusted when HeightMode.ROW and row height is recalculated.
" + + "When loading is complete, all 10 rows should be visible with all themes."; + } + + @Override + protected Integer getTicketNumber() { + return 20104; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridScrollToLineWhileResizing.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridScrollToLineWhileResizing.java new file mode 100644 index 0000000000..2c955bb840 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridScrollToLineWhileResizing.java @@ -0,0 +1,73 @@ +/* + * 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.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.VerticalSplitPanel; +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.SelectionMode; + +public class GridScrollToLineWhileResizing extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + final VerticalSplitPanel vsp = new VerticalSplitPanel(); + vsp.setWidth(500, Unit.PIXELS); + vsp.setHeight(500, Unit.PIXELS); + vsp.setSplitPosition(100, Unit.PERCENTAGE); + addComponent(vsp); + + IndexedContainer indexedContainer = new IndexedContainer(); + indexedContainer.addContainerProperty("column1", String.class, ""); + + for (int i = 0; i < 100; i++) { + Item addItem = indexedContainer.addItem(i); + addItem.getItemProperty("column1").setValue("cell" + i); + } + + final Grid grid = new Grid(indexedContainer); + grid.setSizeFull(); + + grid.setSelectionMode(SelectionMode.SINGLE); + grid.addSelectionListener(new SelectionListener() { + + @Override + public void select(SelectionEvent event) { + vsp.setSplitPosition(50, Unit.PERCENTAGE); + grid.scrollTo(event.getSelected().iterator().next()); + } + }); + + vsp.setFirstComponent(grid); + } + + @Override + protected String getTestDescription() { + return "Tests scrollToLine while moving SplitPanel split position to resize the Grid on the same round-trip."; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridScrolling.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridScrolling.java new file mode 100644 index 0000000000..dadf881ad2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridScrolling.java @@ -0,0 +1,112 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.shared.ui.grid.ScrollDestination; +import com.vaadin.v7.ui.Grid; + +@SuppressWarnings("serial") +public class GridScrolling extends AbstractTestUI { + + private Grid grid; + + private IndexedContainer ds; + + @Override + @SuppressWarnings("unchecked") + protected void setup(VaadinRequest request) { + // Build data source + ds = new IndexedContainer(); + + for (int col = 0; col < 5; col++) { + ds.addContainerProperty("col" + col, String.class, ""); + } + + for (int row = 0; row < 65536; row++) { + Item item = ds.addItem(Integer.valueOf(row)); + for (int col = 0; col < 5; col++) { + item.getItemProperty("col" + col) + .setValue("(" + row + ", " + col + ")"); + } + } + + grid = new Grid(ds); + + HorizontalLayout hl = new HorizontalLayout(); + hl.addComponent(grid); + hl.setMargin(true); + hl.setSpacing(true); + + VerticalLayout vl = new VerticalLayout(); + vl.setSpacing(true); + + // Add scroll buttons + Button scrollUpButton = new Button("Top", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.scrollToStart(); + } + }); + scrollUpButton.setSizeFull(); + vl.addComponent(scrollUpButton); + + for (int i = 1; i < 7; ++i) { + final int row = (ds.size() / 7) * i; + Button scrollButton = new Button("Scroll to row " + row, + new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.scrollTo(Integer.valueOf(row), + ScrollDestination.MIDDLE); + } + }); + scrollButton.setSizeFull(); + vl.addComponent(scrollButton); + } + + Button scrollDownButton = new Button("Bottom", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.scrollToEnd(); + } + }); + scrollDownButton.setSizeFull(); + vl.addComponent(scrollDownButton); + + hl.addComponent(vl); + addComponent(hl); + } + + @Override + protected String getTestDescription() { + return "Test Grid programmatic scrolling features"; + } + + @Override + protected Integer getTicketNumber() { + return 13327; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSelectAllCell.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSelectAllCell.java new file mode 100644 index 0000000000..19b8622802 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSelectAllCell.java @@ -0,0 +1,21 @@ +package com.vaadin.v7.tests.components.grid; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Grid; + +@Theme("valo") +public class GridSelectAllCell extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + + grid.addColumn("foo", String.class); + grid.addRow("bar"); + + grid.setSelectionMode(Grid.SelectionMode.MULTI); + + addComponent(grid); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSidebarPosition.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSidebarPosition.java new file mode 100644 index 0000000000..6c7fc95175 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSidebarPosition.java @@ -0,0 +1,70 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.ui.Alignment; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.v7.ui.Grid; + +@Theme("valo") +public class GridSidebarPosition extends AbstractTestUI { + + static final String POPUP_ABOVE = "above"; + static final String POPUP_WINDOW_MOVED_UP = "movedup"; + static final String POPUP_WINDOW_HEIGHT = "windowheight"; + + @Override + protected void setup(VaadinRequest request) { + HorizontalLayout hl = new HorizontalLayout(); + hl.setSpacing(true); + hl.setHeight("100%"); + setContent(hl); + Grid grid = new Grid("Popup window height"); + grid.setId(POPUP_WINDOW_HEIGHT); + grid.setWidth("100px"); + for (int i = 0; i < 30; i++) { + grid.addColumn( + "This is a really really really really long column name " + + i) + .setHidable(true); + } + hl.addComponent(grid); + + grid = new Grid("Popup moved up"); + grid.setId(POPUP_WINDOW_MOVED_UP); + grid.setWidth("100px"); + grid.setHeight("400px"); + for (int i = 0; i < 15; i++) { + grid.addColumn("Column " + i).setHidable(true); + } + hl.addComponent(grid); + hl.setComponentAlignment(grid, Alignment.BOTTOM_LEFT); + + grid = new Grid("Popup above"); + grid.setId(POPUP_ABOVE); + grid.setWidth("100px"); + grid.setHeight("200px"); + for (int i = 0; i < 10; i++) { + grid.addColumn("Column " + i).setHidable(true); + } + hl.addComponent(grid); + hl.setComponentAlignment(grid, Alignment.BOTTOM_LEFT); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSingleColumn.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSingleColumn.java new file mode 100644 index 0000000000..e6258159fc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSingleColumn.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.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +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.Column; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridSingleColumn extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + IndexedContainer indexedContainer = new IndexedContainer(); + indexedContainer.addContainerProperty("column1", String.class, ""); + + for (int i = 0; i < 100; i++) { + Item addItem = indexedContainer.addItem(i); + addItem.getItemProperty("column1").setValue("cell"); + } + + Grid grid = new Grid(indexedContainer); + grid.setSelectionMode(SelectionMode.NONE); + + Column column = grid.getColumn("column1"); + + column.setHeaderCaption("Header"); + + addComponent(grid); + grid.scrollTo(grid.getContainerDataSource().getIdByIndex(50)); + } + + @Override + protected String getTestDescription() { + return "Tests a single column grid"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSortIndicator.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSortIndicator.java new file mode 100644 index 0000000000..bf17dc553e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSortIndicator.java @@ -0,0 +1,96 @@ +/* + * 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 com.vaadin.data.sort.SortOrder; +import com.vaadin.event.SortEvent; +import com.vaadin.event.SortEvent.SortListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Grid; + +/* + * Test UI for checking that sort indicators of a Grid are updated when the sort order is changed by a + * SortListener. + */ +public class GridSortIndicator extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Grid g = getGrid(); + addComponent(g); + g.addSortListener(new SortListener() { + private SortDirection oldSortDirection = null; + + @Override + public void sort(SortEvent event) { + List currentSortOrder = new ArrayList( + event.getSortOrder()); + if (currentSortOrder.size() == 1) { + // If the name column was clicked, set a new sort order for + // both columns. Otherwise, revert to oldSortDirection if it + // is not null. + List newSortOrder = new ArrayList(); + SortDirection newSortDirection = oldSortDirection; + if (currentSortOrder.get(0).getPropertyId() + .equals("Name")) { + newSortDirection = SortDirection.ASCENDING.equals( + oldSortDirection) ? SortDirection.DESCENDING + : SortDirection.ASCENDING; + } + if (newSortDirection != null) { + newSortOrder + .add(new SortOrder("Name", newSortDirection)); + newSortOrder + .add(new SortOrder("Value", newSortDirection)); + g.setSortOrder(newSortOrder); + } + oldSortDirection = newSortDirection; + } + } + }); + } + + private final Grid getGrid() { + Grid g = new Grid(); + g.addColumn("Name"); + g.addColumn("Value", Integer.class); + g.addRow(new Object[] { "a", 4 }); + g.addRow(new Object[] { "b", 5 }); + g.addRow(new Object[] { "c", 3 }); + g.addRow(new Object[] { "a", 6 }); + g.addRow(new Object[] { "a", 2 }); + g.addRow(new Object[] { "c", 7 }); + g.addRow(new Object[] { "b", 1 }); + return g; + } + + @Override + public String getTestDescription() { + return "When the first column is the primary sort column, both columns should have " + + "a sort indicator with the same sort direction. Clicking on the right column " + + "in that state should have no effect."; + } + + @Override + public Integer getTicketNumber() { + return 17440; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSubPixelProblemWrapping.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSubPixelProblemWrapping.java new file mode 100644 index 0000000000..c37ffa86a4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSubPixelProblemWrapping.java @@ -0,0 +1,96 @@ +/* + * 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.Random; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +@Theme("valo") +public class GridSubPixelProblemWrapping extends AbstractTestUI { + + Random r = new Random(); + + public static class DataObject { + String foo; + String Bar; + + public DataObject(Random r) { + foo = r.nextInt() + ""; + Bar = r.nextInt() + ""; + } + + public DataObject(String foo, String bar) { + this.foo = foo; + Bar = bar; + } + + public String getFoo() { + return foo; + } + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getBar() { + return Bar; + } + + public void setBar(String bar) { + Bar = bar; + } + + } + + Button button = new Button("Click", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + addDAO(); + } + }); + + private BeanItemContainer container; + private int counter = 0; + + @Override + protected void setup(VaadinRequest request) { + addComponent(button); + container = new BeanItemContainer(DataObject.class); + container.addBean(new DataObject("Foo", "Bar")); + Grid grid = new Grid(container); + grid.getColumn("foo").setWidth(248.525); + grid.setSelectionMode(SelectionMode.SINGLE); + grid.setEditorEnabled(true); + grid.setWidth("500px"); + + addComponent(grid); + } + + private void addDAO() { + counter++; + container.addBean(new DataObject("Foo" + counter, "Bar" + counter)); + + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSwitchRenderers.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSwitchRenderers.java new file mode 100644 index 0000000000..b8738abf6f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridSwitchRenderers.java @@ -0,0 +1,98 @@ +package com.vaadin.v7.tests.components.grid; + +import java.util.List; +import java.util.Random; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.CheckBox; +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.Column; +import com.vaadin.v7.ui.Grid.SelectionMode; +import com.vaadin.v7.ui.renderers.HtmlRenderer; +import com.vaadin.v7.ui.renderers.TextRenderer; + +@SuppressWarnings("serial") +@Theme("valo") +public class GridSwitchRenderers extends AbstractTestUIWithLog { + private static final int MANUALLY_FORMATTED_COLUMNS = 1; + private static final int COLUMNS = 3; + private static final int ROWS = 1000; + private static final String EXPANSION_COLUMN_ID = "Column 0"; + + private IndexedContainer ds; + + @Override + protected void setup(VaadinRequest request) { + ds = new IndexedContainer() { + @Override + public List getItemIds(int startIndex, int numberOfIds) { + log("Requested items " + startIndex + " - " + + (startIndex + numberOfIds)); + return super.getItemIds(startIndex, numberOfIds); + } + }; + + { + ds.addContainerProperty(EXPANSION_COLUMN_ID, String.class, ""); + + int col = MANUALLY_FORMATTED_COLUMNS; + for (; col < COLUMNS; col++) { + ds.addContainerProperty(getColumnProperty(col), String.class, + ""); + } + } + + Random rand = new Random(); + rand.setSeed(13334); + for (int row = 0; row < ROWS; row++) { + Item item = ds.addItem(Integer.valueOf(row)); + fillRow("" + row, item); + item.getItemProperty(getColumnProperty(1)).setReadOnly(true); + } + + final Grid grid = new Grid(ds); + grid.setWidth("100%"); + + grid.getColumn(EXPANSION_COLUMN_ID).setWidth(50); + for (int col = MANUALLY_FORMATTED_COLUMNS; col < COLUMNS; col++) { + grid.getColumn(getColumnProperty(col)).setWidth(300); + grid.getColumn(getColumnProperty(col)) + .setRenderer(new TextRenderer()); + } + + grid.setSelectionMode(SelectionMode.NONE); + addComponent(grid); + + final CheckBox changeRenderer = new CheckBox( + "SetHtmlRenderer for Column 2", false); + changeRenderer.addValueChangeListener(event -> { + Column column = grid.getColumn(getColumnProperty(1)); + if (changeRenderer.getValue()) { + column.setRenderer(new HtmlRenderer()); + } else { + column.setRenderer(new TextRenderer()); + } + grid.markAsDirty(); + }); + addComponent(changeRenderer); + } + + @SuppressWarnings("unchecked") + private void fillRow(String content, Item item) { + int col = MANUALLY_FORMATTED_COLUMNS; + + for (; col < COLUMNS; col++) { + item.getItemProperty(getColumnProperty(col)) + .setValue("(" + content + ", " + col + ")"); + } + } + + private static String getColumnProperty(int c) { + return "Column " + c; + } + +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridThemeChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridThemeChange.java new file mode 100644 index 0000000000..e826603edd --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridThemeChange.java @@ -0,0 +1,59 @@ +/* + * 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.Arrays; +import java.util.List; + +import com.vaadin.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class GridThemeChange extends AbstractTestUI { + private final List themes = Arrays.asList("valo", "reindeer", + "runo", "chameleon", "base"); + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.SINGLE); + + grid.addColumn("Theme"); + for (String theme : themes) { + Object itemId = grid.addRow(theme); + if (theme.equals(getTheme())) { + grid.select(itemId); + } + } + + grid.addSelectionListener(new SelectionListener() { + @Override + public void select(SelectionEvent event) { + Object selectedItemId = grid.getSelectedRow(); + Object theme = grid.getContainerDataSource() + .getItem(selectedItemId).getItemProperty("Theme") + .getValue(); + setTheme(String.valueOf(theme)); + } + }); + + addComponent(grid); + + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridThemeUI.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridThemeUI.java new file mode 100644 index 0000000000..5c0df81c9c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridThemeUI.java @@ -0,0 +1,148 @@ +/* + * 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.text.DateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.fieldgroup.ComplexPerson; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.data.validator.IntegerRangeValidator; +import com.vaadin.v7.ui.ComboBox; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.NativeSelect; +import com.vaadin.v7.ui.renderers.DateRenderer; + +@Theme("valo") +public class GridThemeUI extends AbstractTestUIWithLog { + + private Grid grid; + + protected static String[] columns = new String[] { "firstName", "lastName", + "gender", "birthDate", "age", "alive", "address.streetAddress", + "address.postalCode", "address.city", "address.country" }; + + protected BeanItemContainer container = ComplexPerson + .createContainer(100);; + { + container.addNestedContainerBean("address"); + } + protected ComboBox formType; + + private Component active = null; + + @Override + protected void setup(VaadinRequest request) { + setLocale(new Locale("en", "US")); + + final NativeSelect pageSelect = new NativeSelect("Page"); + pageSelect.setImmediate(true); + pageSelect.setId("page"); + addComponent(pageSelect); + + pageSelect.addItem(new Editor()); + pageSelect.addItem(new HeaderFooter()); + + pageSelect.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + if (active != null) { + removeComponent(active); + } + active = (Component) pageSelect.getValue(); + addComponent(active); + } + }); + pageSelect.setNullSelectionAllowed(false); + pageSelect.setValue(pageSelect.getItemIds().iterator().next()); + + } + + public class Editor extends Grid { + @Override + public String toString() { + return "Editor"; + }; + + public Editor() { + setContainerDataSource(container); + setColumnOrder((Object[]) columns); + removeColumn("salary"); + setEditorEnabled(true); + getColumn("lastName").setEditable(false); + setSizeFull(); + getColumn("age").getEditorField().addValidator( + new IntegerRangeValidator("Must be between 0 and 100", 0, + 100)); + getColumn("birthDate").setRenderer(new DateRenderer( + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US))); + } + } + + public class HeaderFooter extends Grid { + @Override + public String toString() { + return getClass().getSimpleName(); + }; + + public HeaderFooter() { + setContainerDataSource(container); + setColumnOrder((Object[]) columns); + HeaderRow row = addHeaderRowAt(0); + row.join("firstName", "lastName").setHtml("Name"); + Button b = new Button("The address, yo"); + b.addClickListener(new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + HeaderRow row = addHeaderRowAt(0); + List pids = new ArrayList(); + for (Column c : getColumns()) { + pids.add(c.getPropertyId()); + } + row.join(pids.toArray()).setText("The big header"); + } + }); + b.setSizeFull(); + row.join("address.streetAddress", "address.postalCode", + "address.city", "address.country").setComponent(b); + // TODO: revert back to 25 when #16597 is fixed.. + getColumn("age").setWidth(42); + removeColumn("salary"); + setEditorEnabled(true); + setSizeFull(); + getColumn("age").getEditorField().addValidator( + new IntegerRangeValidator("Must be between 0 and 100", 0, + 100)); + getColumn("birthDate").setRenderer(new DateRenderer( + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US))); + + addFooterRowAt(0); + } + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWidgetRendererChange.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWidgetRendererChange.java new file mode 100644 index 0000000000..02f7ffde82 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWidgetRendererChange.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.v7.tests.components.grid; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridRendererChangeWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Widgetset(TestingWidgetSet.NAME) +public class GridWidgetRendererChange extends UI { + + @Override + protected void init(VaadinRequest request) { + setContent(new TestWidgetComponent(GridRendererChangeWidget.class)); + } + +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWidthIncrease.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWidthIncrease.java new file mode 100644 index 0000000000..6c51523742 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWidthIncrease.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.v7.tests.components.grid; + +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.ui.Grid; + +public class GridWidthIncrease extends AbstractTestUI { + + public static int COLUMN_COUNT = 5; + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + Object[] rowData = new String[COLUMN_COUNT]; + for (int i = 0; i < COLUMN_COUNT; ++i) { + grid.addColumn("Column " + i, String.class); + rowData[i] = "Foo (0, " + i + ")"; + } + grid.addRow(rowData); + grid.setWidth(400 + "px"); + addComponent(grid); + addComponent( + new Button("Increase Grid Width", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.setWidth((grid.getWidth() + 50) + "px"); + } + })); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithBrokenRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithBrokenRenderer.java new file mode 100644 index 0000000000..b12f5a10fa --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithBrokenRenderer.java @@ -0,0 +1,43 @@ +/* + * 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.ClassResource; +import com.vaadin.server.Resource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.integration.FlagSeResource; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.renderers.ImageRenderer; + +public class GridWithBrokenRenderer extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.addColumn("short", String.class); + grid.addColumn("icon", Resource.class); + grid.addColumn("country", String.class); + + grid.getColumn("icon").setRenderer(new ImageRenderer()); + addComponent(grid); + + grid.addRow("FI", new ClassResource("fi.gif"), "Finland"); + grid.addRow("SE", new FlagSeResource(), "Sweden"); + + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithLabelEditor.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithLabelEditor.java new file mode 100644 index 0000000000..87ad5d7a2c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithLabelEditor.java @@ -0,0 +1,154 @@ +/* + * 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.Collection; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.data.Validator; +import com.vaadin.v7.data.Validator.InvalidValueException; +import com.vaadin.v7.ui.Field; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Label; + +public class GridWithLabelEditor extends AbstractTestUI { + + public class LabelEditor extends Label implements Field { + + @Override + public void focus() { + super.focus(); + } + + @Override + public boolean isInvalidCommitted() { + return false; + } + + @Override + public void setInvalidCommitted(boolean isCommitted) { + } + + @Override + public void commit() throws SourceException, InvalidValueException { + } + + @Override + public void discard() throws SourceException { + } + + @Override + public void setBuffered(boolean buffered) { + } + + @Override + public boolean isBuffered() { + return false; + } + + @Override + public boolean isModified() { + return false; + } + + @Override + public void addValidator(Validator validator) { + } + + @Override + public void removeValidator(Validator validator) { + } + + @Override + public void removeAllValidators() { + } + + @Override + public Collection getValidators() { + return null; + } + + @Override + public boolean isValid() { + return true; + } + + @Override + public void validate() throws InvalidValueException { + } + + @Override + public boolean isInvalidAllowed() { + return false; + } + + @Override + public void setInvalidAllowed(boolean invalidValueAllowed) + throws UnsupportedOperationException { + } + + @Override + public int getTabIndex() { + return -1; + } + + @Override + public void setTabIndex(int tabIndex) { + } + + @Override + public boolean isRequired() { + return false; + } + + @Override + public void setRequired(boolean required) { + } + + @Override + public void setRequiredError(String requiredMessage) { + } + + @Override + public String getRequiredError() { + return null; + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public void clear() { + } + + } + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + addComponent(grid); + + grid.setEditorEnabled(true); + grid.addColumn("Foo", String.class).setEditorField(new LabelEditor()); + grid.addRow("FooFoo"); + + grid.editItem(grid.getContainerDataSource().firstItemId()); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithoutRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithoutRenderer.java new file mode 100644 index 0000000000..96d8d503a0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridWithoutRenderer.java @@ -0,0 +1,34 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.tests.util.PersonContainer; +import com.vaadin.v7.ui.Grid; + +@Theme("valo") +public class GridWithoutRenderer extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setContainerDataSource(PersonContainer.createWithTestData()); + 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 new file mode 100644 index 0000000000..0c7e6161fc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumns.java @@ -0,0 +1,41 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class InitialFrozenColumns extends AbstractTestUI { + + @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/main/java/com/vaadin/v7/tests/components/grid/IntArrayRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/IntArrayRenderer.java new file mode 100644 index 0000000000..a50d7dd251 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/IntArrayRenderer.java @@ -0,0 +1,24 @@ +/* + * 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.v7.ui.Grid.AbstractRenderer; + +public class IntArrayRenderer extends AbstractRenderer { + public IntArrayRenderer() { + super(int[].class, ""); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/JavaScriptRenderers.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/JavaScriptRenderers.java new file mode 100644 index 0000000000..4df254c94e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/JavaScriptRenderers.java @@ -0,0 +1,79 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +public class JavaScriptRenderers extends AbstractTestUI { + + public static class MyBean { + private int integer; + private String string; + + public MyBean(int integer, String string) { + super(); + this.integer = integer; + this.string = string; + } + + public int getInteger() { + return integer; + } + + public void setInteger(int integer) { + this.integer = integer; + } + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } + } + + @Override + protected void setup(VaadinRequest request) { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty("id", Integer.class, Integer.valueOf(0)); + container.addContainerProperty("bean", MyBean.class, null); + container.addContainerProperty("string", String.class, ""); + + for (int i = 0; i < 1000; i++) { + Integer itemId = Integer.valueOf(i); + Item item = container.addItem(itemId); + item.getItemProperty("id").setValue(itemId); + item.getItemProperty("bean") + .setValue(new MyBean(i + 1, Integer.toString(i - 1))); + item.getItemProperty("string").setValue("string" + i); + } + + Grid grid = new Grid(container); + + grid.getColumn("bean").setRenderer(new MyBeanJSRenderer()); + grid.getColumn("bean").setWidth(250); + + grid.getColumn("string").setRenderer(new JavaScriptStringRenderer()); + + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/JavaScriptStringRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/JavaScriptStringRenderer.java new file mode 100644 index 0000000000..193c698be4 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/JavaScriptStringRenderer.java @@ -0,0 +1,29 @@ +/* + * 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.JavaScript; +import com.vaadin.v7.ui.renderers.AbstractJavaScriptRenderer; + +@JavaScript("JavaScriptStringRenderer.js") +public class JavaScriptStringRenderer + extends AbstractJavaScriptRenderer { + + protected JavaScriptStringRenderer() { + super(String.class); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/MyBeanJSRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/MyBeanJSRenderer.java new file mode 100644 index 0000000000..a00ca0ec0e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/MyBeanJSRenderer.java @@ -0,0 +1,34 @@ +/* + * 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.JavaScript; +import com.vaadin.v7.tests.components.grid.JavaScriptRenderers.MyBean; +import com.vaadin.v7.ui.renderers.AbstractJavaScriptRenderer; + +/** + * + * @since + * @author Vaadin Ltd + */ +@JavaScript("myBeanJsRenderer.js") +public class MyBeanJSRenderer extends AbstractJavaScriptRenderer { + + public MyBeanJSRenderer() { + super(MyBean.class, ""); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/NullHeaders.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/NullHeaders.java new file mode 100644 index 0000000000..844c4643da --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/NullHeaders.java @@ -0,0 +1,40 @@ +/* + * 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.AbstractTestUIWithLog; +import com.vaadin.v7.ui.Grid; + +public class NullHeaders extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.addColumn("country", String.class); + grid.addColumn("foo", String.class); + grid.addColumn("bar", Integer.class); + + grid.getColumn("country").setHeaderCaption(null); + grid.getColumn("foo").setHeaderCaption(""); + grid.getColumn("bar").setHeaderCaption(null); + grid.addRow("Finland", "foo", 1); + grid.addRow("Swaziland", "bar", 2); + grid.addRow("Japan", "baz", 3); + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/NullRenderers.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/NullRenderers.java new file mode 100644 index 0000000000..215e6f7d04 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/NullRenderers.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.v7.tests.components.grid; + +import java.util.Date; +import java.util.Locale; + +import com.vaadin.server.Resource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; +import com.vaadin.v7.ui.renderers.ButtonRenderer; +import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickEvent; +import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickListener; +import com.vaadin.v7.ui.renderers.DateRenderer; +import com.vaadin.v7.ui.renderers.HtmlRenderer; +import com.vaadin.v7.ui.renderers.ImageRenderer; +import com.vaadin.v7.ui.renderers.NumberRenderer; +import com.vaadin.v7.ui.renderers.ProgressBarRenderer; +import com.vaadin.v7.ui.renderers.TextRenderer; + +@SuppressWarnings("all") +public class NullRenderers extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + IndexedContainer container = new IndexedContainer(); + + container.addContainerProperty(TextRenderer.class, String.class, null); + container.addContainerProperty(HtmlRenderer.class, String.class, null); + container.addContainerProperty(DateRenderer.class, Date.class, null); + container.addContainerProperty(NumberRenderer.class, Number.class, + null); + + container.addContainerProperty(ProgressBarRenderer.class, Double.class, + null); + container.addContainerProperty(ButtonRenderer.class, String.class, + null); + container.addContainerProperty(ImageRenderer.class, Resource.class, + null); + + container.addItem(); + + final Grid gridDefaults = new Grid(container); + + gridDefaults.setId("test-grid-defaults"); + gridDefaults.setSelectionMode(SelectionMode.NONE); + gridDefaults.setWidth("100%"); + + gridDefaults.getColumn(TextRenderer.class) + .setRenderer(new TextRenderer("-- No Text --")); + gridDefaults.getColumn(HtmlRenderer.class) + .setRenderer(new HtmlRenderer("-- No Jokes --")); + gridDefaults.getColumn(DateRenderer.class).setRenderer( + new DateRenderer("%s", Locale.getDefault(), "-- Never --")); + gridDefaults.getColumn(NumberRenderer.class).setRenderer( + new NumberRenderer("%s", Locale.getDefault(), "-- Nothing --")); + + gridDefaults.getColumn(ProgressBarRenderer.class) + .setRenderer(new ProgressBarRenderer()); + + gridDefaults.getColumn(ButtonRenderer.class) + .setRenderer(new ButtonRenderer(new RendererClickListener() { + @Override + public void click(RendererClickEvent event) { + } + }, "-- No Control --")); + + gridDefaults.getColumn(ImageRenderer.class) + .setRenderer(new ImageRenderer(new RendererClickListener() { + + @Override + public void click(RendererClickEvent event) { + } + })); + + addComponent(gridDefaults); + + final Grid gridNoDefaults = new Grid(container); + + gridNoDefaults.setId("test-grid"); + gridNoDefaults.setSelectionMode(SelectionMode.NONE); + gridNoDefaults.setWidth("100%"); + + gridNoDefaults.getColumn(TextRenderer.class) + .setRenderer(new TextRenderer()); + gridNoDefaults.getColumn(HtmlRenderer.class) + .setRenderer(new HtmlRenderer()); + gridNoDefaults.getColumn(DateRenderer.class) + .setRenderer(new DateRenderer()); + gridNoDefaults.getColumn(NumberRenderer.class) + .setRenderer(new NumberRenderer()); + + gridNoDefaults.getColumn(ProgressBarRenderer.class) + .setRenderer(new ProgressBarRenderer()); + + gridNoDefaults.getColumn(ButtonRenderer.class) + .setRenderer(new ButtonRenderer(new RendererClickListener() { + @Override + public void click(RendererClickEvent event) { + } + })); + + gridNoDefaults.getColumn(ImageRenderer.class) + .setRenderer(new ImageRenderer(new RendererClickListener() { + + @Override + public void click(RendererClickEvent event) { + } + })); + + addComponent(gridNoDefaults); + } + + @Override + protected String getTestDescription() { + return "Tests the functionality of widget-based renderers"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(13334); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/PersonTestGrid.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/PersonTestGrid.java new file mode 100644 index 0000000000..d32c28efaa --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/PersonTestGrid.java @@ -0,0 +1,30 @@ +/* + * 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.tests.fieldgroup.ComplexPerson; +import com.vaadin.v7.data.util.BeanItemContainer; +import com.vaadin.v7.ui.Grid; + +public class PersonTestGrid extends Grid { + + public PersonTestGrid(int size) { + BeanItemContainer container = ComplexPerson + .createContainer(size); + container.addNestedContainerBean("address"); + setContainerDataSource(container); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/ProgrammaticEditorControl.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/ProgrammaticEditorControl.java new file mode 100644 index 0000000000..6fbcc2ea9d --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/ProgrammaticEditorControl.java @@ -0,0 +1,46 @@ +package com.vaadin.v7.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +@SuppressWarnings("serial") +// @Push +public class ProgrammaticEditorControl extends AbstractTestUIWithLog { + + private Grid grid; + private IndexedContainer container = new IndexedContainer(); + + @Override + protected void setup(VaadinRequest request) { + container.addContainerProperty("name", String.class, null); + container.addItem("test").getItemProperty("name").setValue("test"); + grid = new Grid(); + grid.setContainerDataSource(container); + grid.setEditorEnabled(true); + addComponent(grid); + + Button button = new Button("Edit", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.editItem("test"); + } + }); + addComponent(button); + Button button2 = new Button("Cancel", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.cancelEditor(); + } + }); + addComponent(button2); + + } + +} \ No newline at end of file diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/RowAwareRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/RowAwareRenderer.java new file mode 100644 index 0000000000..288116b630 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/RowAwareRenderer.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.v7.tests.components.grid; + +import com.vaadin.tests.widgetset.client.v7.grid.RowAwareRendererConnector.RowAwareRendererRpc; +import com.vaadin.ui.Label; +import com.vaadin.v7.ui.Grid.AbstractRenderer; + +public class RowAwareRenderer extends AbstractRenderer { + public RowAwareRenderer(final Label debugLabel) { + super(Void.class, ""); + registerRpc(new RowAwareRendererRpc() { + @Override + public void clicky(String key) { + Object itemId = getItemId(key); + debugLabel.setValue("key: " + key + ", itemId: " + itemId); + } + }); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/SelectDuringInit.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/SelectDuringInit.java new file mode 100644 index 0000000000..6ef9b7f387 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/SelectDuringInit.java @@ -0,0 +1,40 @@ +/* + * 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.AbstractTestUI; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.SelectionMode; + +public class SelectDuringInit extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid(); + grid.setSelectionMode(SelectionMode.MULTI); + + grid.addColumn("value"); + grid.addRow("row 1"); + grid.addRow("row 2"); + grid.addRow("row 3"); + + grid.select(Integer.valueOf(2)); + + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/SortableHeaderStyles.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/SortableHeaderStyles.java new file mode 100644 index 0000000000..0d58367856 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/SortableHeaderStyles.java @@ -0,0 +1,66 @@ +/* + * 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.Collection; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.PersonContainer; +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.Column; +import com.vaadin.v7.ui.OptionGroup; + +@Theme("valo") +public class SortableHeaderStyles extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + getPage().getStyles().add( + ".valo .v-grid-header th.v-grid-cell.sortable { font-weight: bold;}"); + + PersonContainer container = PersonContainer.createWithTestData(); + + Collection sortableContainerPropertyIds = container + .getSortableContainerPropertyIds(); + + final OptionGroup sortableSelector = new OptionGroup("Sortable columns", + sortableContainerPropertyIds); + sortableSelector.setMultiSelect(true); + sortableSelector.setValue(sortableContainerPropertyIds); + + final Grid grid = new Grid(container); + + sortableSelector.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + Collection sortableCols = (Collection) sortableSelector + .getValue(); + for (Column column : grid.getColumns()) { + column.setSortable( + sortableCols.contains(column.getPropertyId())); + } + } + }); + + addComponent(sortableSelector); + addComponent(grid); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/WidgetRenderers.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/WidgetRenderers.java new file mode 100644 index 0000000000..390b78b875 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/WidgetRenderers.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.v7.tests.components.grid; + +import com.vaadin.server.Resource; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.NativeButton; +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.SelectionMode; +import com.vaadin.v7.ui.renderers.ButtonRenderer; +import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickEvent; +import com.vaadin.v7.ui.renderers.ClickableRenderer.RendererClickListener; +import com.vaadin.v7.ui.renderers.ImageRenderer; +import com.vaadin.v7.ui.renderers.ProgressBarRenderer; + +@SuppressWarnings("all") +public class WidgetRenderers extends AbstractTestUI { + + static final String PROPERTY_ID = "property id"; + + @Override + protected void setup(VaadinRequest request) { + IndexedContainer container = new IndexedContainer(); + + container.addContainerProperty(ProgressBarRenderer.class, Double.class, + null); + container.addContainerProperty(ButtonRenderer.class, String.class, + null); + container.addContainerProperty(ImageRenderer.class, Resource.class, + null); + container.addContainerProperty(PROPERTY_ID, String.class, null); + + final Item item = container.getItem(container.addItem()); + + item.getItemProperty(ProgressBarRenderer.class).setValue(0.3); + item.getItemProperty(ButtonRenderer.class).setValue("Click"); + item.getItemProperty(ImageRenderer.class) + .setValue(new ThemeResource("window/img/close.png")); + item.getItemProperty(PROPERTY_ID).setValue("Click"); + + final Grid grid = new Grid(container); + + grid.setId("test-grid"); + grid.setSelectionMode(SelectionMode.NONE); + + grid.getColumn(ProgressBarRenderer.class) + .setRenderer(new ProgressBarRenderer()); + + grid.getColumn(ButtonRenderer.class) + .setRenderer(new ButtonRenderer(new RendererClickListener() { + @Override + public void click(RendererClickEvent event) { + item.getItemProperty(ButtonRenderer.class) + .setValue("Clicked!"); + } + })); + + grid.getColumn(ImageRenderer.class) + .setRenderer(new ImageRenderer(new RendererClickListener() { + + @Override + public void click(RendererClickEvent event) { + item.getItemProperty(ImageRenderer.class).setValue( + new ThemeResource("window/img/maximize.png")); + } + })); + + grid.getColumn(PROPERTY_ID) + .setRenderer(new ButtonRenderer(new RendererClickListener() { + @Override + public void click(RendererClickEvent event) { + item.getItemProperty(PROPERTY_ID) + .setValue(event.getPropertyId()); + } + })); + + addComponent(grid); + + addComponent(new NativeButton("Change column order", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.setColumnOrder(ImageRenderer.class, + ProgressBarRenderer.class, + ButtonRenderer.class); + } + })); + } + + @Override + protected String getTestDescription() { + return "Tests the functionality of widget-based renderers"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(13334); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorBasicClientFeatures.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorBasicClientFeatures.java new file mode 100644 index 0000000000..8456f20e54 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorBasicClientFeatures.java @@ -0,0 +1,36 @@ +/* + * 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.basicfeatures; + +import com.vaadin.annotations.Title; +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.EscalatorBasicClientFeaturesWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Widgetset(TestingWidgetSet.NAME) +@Title("Escalator basic client features") +public class EscalatorBasicClientFeatures extends UI { + + @Override + public void init(VaadinRequest request) { + setContent(new TestWidgetComponent( + EscalatorBasicClientFeaturesWidget.class)); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorUpdaterUi.java new file mode 100644 index 0000000000..4023134f02 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorUpdaterUi.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.v7.tests.components.grid.basicfeatures; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.EscalatorBasicClientFeaturesWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Widgetset(TestingWidgetSet.NAME) +public class EscalatorUpdaterUi extends UI { + + @Override + protected void init(VaadinRequest request) { + setContent(new TestWidgetComponent( + EscalatorBasicClientFeaturesWidget.UpdaterLifetimeWidget.class)); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicClientFeatures.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicClientFeatures.java new file mode 100644 index 0000000000..cf56306b56 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicClientFeatures.java @@ -0,0 +1,40 @@ +/* + * 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.basicfeatures; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridBasicClientFeaturesWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +/** + * Initializer shell for GridClientBasicFeatures test application + * + * @since + * @author Vaadin Ltd + */ +@Widgetset(TestingWidgetSet.NAME) +public class GridBasicClientFeatures extends UI { + + @Override + protected void init(VaadinRequest request) { + setContent( + new TestWidgetComponent(GridBasicClientFeaturesWidget.class)); + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java new file mode 100644 index 0000000000..1e2fd09f2e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -0,0 +1,1630 @@ +/* + * 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.basicfeatures; + +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Random; + +import com.vaadin.data.sort.Sort; +import com.vaadin.data.sort.SortOrder; +import com.vaadin.event.SelectionEvent; +import com.vaadin.event.SelectionEvent.SelectionListener; +import com.vaadin.event.SortEvent; +import com.vaadin.event.SortEvent.SortListener; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.tests.components.AbstractComponentTest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Panel; +import com.vaadin.v7.data.Container.Filter; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.Property; +import com.vaadin.v7.data.Property.ValueChangeEvent; +import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.event.ItemClickEvent; +import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; +import com.vaadin.v7.shared.ui.grid.GridStaticCellType; +import com.vaadin.v7.shared.ui.grid.HeightMode; +import com.vaadin.v7.ui.Field; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.Grid.CellDescriptionGenerator; +import com.vaadin.v7.ui.Grid.CellReference; +import com.vaadin.v7.ui.Grid.CellStyleGenerator; +import com.vaadin.v7.ui.Grid.Column; +import com.vaadin.v7.ui.Grid.ColumnReorderEvent; +import com.vaadin.v7.ui.Grid.ColumnReorderListener; +import com.vaadin.v7.ui.Grid.ColumnResizeEvent; +import com.vaadin.v7.ui.Grid.ColumnResizeListener; +import com.vaadin.v7.ui.Grid.ColumnVisibilityChangeEvent; +import com.vaadin.v7.ui.Grid.ColumnVisibilityChangeListener; +import com.vaadin.v7.ui.Grid.DetailsGenerator; +import com.vaadin.v7.ui.Grid.FooterCell; +import com.vaadin.v7.ui.Grid.HeaderCell; +import com.vaadin.v7.ui.Grid.HeaderRow; +import com.vaadin.v7.ui.Grid.MultiSelectionModel; +import com.vaadin.v7.ui.Grid.RowDescriptionGenerator; +import com.vaadin.v7.ui.Grid.RowReference; +import com.vaadin.v7.ui.Grid.RowStyleGenerator; +import com.vaadin.v7.ui.Grid.SelectionMode; +import com.vaadin.v7.ui.Grid.SelectionModel; +import com.vaadin.v7.ui.renderers.DateRenderer; +import com.vaadin.v7.ui.renderers.HtmlRenderer; +import com.vaadin.v7.ui.renderers.NumberRenderer; + +/** + * Tests the basic features like columns, footers and headers + * + * @since + * @author Vaadin Ltd + */ +public class GridBasicFeatures extends AbstractComponentTest { + + public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4"; + public static final String ROW_STYLE_GENERATOR_NONE = "None"; + public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS = "Row numbers"; + public static final String ROW_STYLE_GENERATOR_EMPTY = "Empty string"; + public static final String ROW_STYLE_GENERATOR_NULL = "Null"; + public static final String CELL_STYLE_GENERATOR_NONE = "None"; + public static final String CELL_STYLE_GENERATOR_PROPERTY_TO_STRING = "Property to string"; + public static final String CELL_STYLE_GENERATOR_SPECIAL = "Special for 1/4 Column 1"; + public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string"; + public static final String CELL_STYLE_GENERATOR_NULL = "Null"; + private static final int MANUALLY_FORMATTED_COLUMNS = 5; + public static final int COLUMNS = 12; + public static final int EDITABLE_COLUMNS = COLUMNS - 1; + public static final int ROWS = 1000; + + private int containerDelay = 0; + + private boolean singleSelectAllowDeselect = true; + + private IndexedContainer ds; + private Grid grid; + private SelectionListener selectionListener = new SelectionListener() { + + @Override + public void select(SelectionEvent event) { + Iterator iter = event.getAdded().iterator(); + Object addedRow = (iter.hasNext() ? iter.next() : "none"); + iter = event.getRemoved().iterator(); + Object removedRow = (iter.hasNext() ? iter.next() : "none"); + log("SelectionEvent: Added " + addedRow + ", Removed " + + removedRow); + } + }; + + private ItemClickListener itemClickListener = new ItemClickListener() { + + @Override + public void itemClick(ItemClickEvent event) { + log("Item " + (event.isDoubleClick() ? "double " : "") + "click on " + + event.getPropertyId() + ", item " + event.getItemId()); + } + }; + + private RowDescriptionGenerator rowDescriptionGenerator = new RowDescriptionGenerator() { + + @Override + public String getDescription(RowReference row) { + return "Row tooltip for row " + row.getItemId(); + } + }; + + private CellDescriptionGenerator cellDescriptionGenerator = new CellDescriptionGenerator() { + + @Override + public String getDescription(CellReference cell) { + if ("Column 0".equals(cell.getPropertyId())) { + return "Cell tooltip for row " + cell.getItemId() + + ", column 0"; + } else { + return null; + } + } + }; + + private ItemClickListener editorOpeningItemClickListener = new ItemClickListener() { + + @Override + public void itemClick(ItemClickEvent event) { + grid.editItem(event.getItemId()); + } + }; + + private ValueChangeListener reactiveValueChanger = new ValueChangeListener() { + @Override + @SuppressWarnings("unchecked") + public void valueChange(ValueChangeEvent event) { + Object id = grid.getEditedItemId(); + grid.getContainerDataSource().getContainerProperty(id, "Column 2") + .setValue("Modified"); + } + }; + + private ColumnReorderListener columnReorderListener = new ColumnReorderListener() { + + @Override + public void columnReorder(ColumnReorderEvent event) { + log("Columns reordered, userOriginated: " + + event.isUserOriginated()); + } + }; + + private ColumnVisibilityChangeListener columnVisibilityListener = new ColumnVisibilityChangeListener() { + @Override + public void columnVisibilityChanged(ColumnVisibilityChangeEvent event) { + log("Visibility changed: "// + + "propertyId: " + event.getColumn().getPropertyId() // + + ", isHidden: " + event.getColumn().isHidden() // + + ", userOriginated: " + event.isUserOriginated()); + } + }; + + private final DetailsGenerator detailedDetailsGenerator = new DetailsGenerator() { + @Override + public Component getDetails(final RowReference rowReference) { + CssLayout cssLayout = new CssLayout(); + cssLayout.setHeight("200px"); + cssLayout.setWidth("100%"); + + Item item = rowReference.getItem(); + for (Object propertyId : item.getItemPropertyIds()) { + Property prop = item.getItemProperty(propertyId); + String string = prop.getValue().toString(); + cssLayout.addComponent(new Label(string)); + } + + final int rowIndex = grid.getContainerDataSource() + .indexOfId(rowReference.getItemId()); + ClickListener clickListener = new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Notification.show("You clicked on the " + + "button in the details for " + "row " + rowIndex); + } + }; + cssLayout.addComponent(new Button("Press me", clickListener)); + return cssLayout; + } + }; + + private final DetailsGenerator watchingDetailsGenerator = new DetailsGenerator() { + private int id = 0; + + @Override + public Component getDetails(RowReference rowReference) { + return new Label("You are watching item id " + + rowReference.getItemId() + " (" + (id++) + ")"); + } + }; + + private Map detailsMap = new HashMap(); + + private final DetailsGenerator persistingDetailsGenerator = new DetailsGenerator() { + + @Override + public Component getDetails(RowReference rowReference) { + Object itemId = rowReference.getItemId(); + if (!detailsMap.containsKey(itemId)) { + + Panel panel = new Panel(); + panel.setContent(new Label("One")); + detailsMap.put(itemId, panel); + } + return detailsMap.get(itemId); + } + }; + + @Override + @SuppressWarnings("unchecked") + protected Grid constructComponent() { + + // Build data source + ds = new IndexedContainer() { + @Override + public List getItemIds(int startIndex, int numberOfIds) { + log("Requested items " + startIndex + " - " + + (startIndex + numberOfIds)); + if (containerDelay > 0) { + try { + Thread.sleep(containerDelay); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + return super.getItemIds(startIndex, numberOfIds); + } + }; + + { + int col = 0; + for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; col++) { + ds.addContainerProperty(getColumnProperty(col), String.class, + ""); + } + + ds.addContainerProperty(getColumnProperty(col++), Integer.class, + Integer.valueOf(0)); + ds.addContainerProperty(getColumnProperty(col++), Date.class, + new Date()); + ds.addContainerProperty(getColumnProperty(col++), String.class, ""); + + // Random numbers + ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0); + ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0); + + } + + { + Random rand = new Random(); + rand.setSeed(13334); + long timestamp = 0; + for (int row = 0; row < ROWS; row++) { + Item item = ds.addItem(Integer.valueOf(row)); + int col = 0; + for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; col++) { + item.getItemProperty(getColumnProperty(col)) + .setValue("(" + row + ", " + col + ")"); + } + item.getItemProperty(getColumnProperty(1)).setReadOnly(true); + + item.getItemProperty(getColumnProperty(col++)) + .setValue(Integer.valueOf(row)); + item.getItemProperty(getColumnProperty(col++)) + .setValue(new Date(timestamp)); + timestamp += 91250000; // a bit over a day, just to get + // variation + item.getItemProperty(getColumnProperty(col++)) + .setValue("" + row + ""); + + // Random numbers + item.getItemProperty(getColumnProperty(col++)) + .setValue(rand.nextInt()); + // Random between 0 - 5 to test multisorting + item.getItemProperty(getColumnProperty(col++)) + .setValue(rand.nextInt(5)); + } + } + + // Create grid + Grid grid = new Grid(ds); + + { + int col = grid.getContainerDataSource().getContainerPropertyIds() + .size() - MANUALLY_FORMATTED_COLUMNS; + grid.getColumn(getColumnProperty(col++)) + .setRenderer(new NumberRenderer( + new DecimalFormat("0,000.00", DecimalFormatSymbols + .getInstance(new Locale("fi", "FI"))))); + + grid.getColumn(getColumnProperty(col++)).setRenderer( + new DateRenderer(new SimpleDateFormat("dd.MM.yy HH:mm"))); + grid.getColumn(getColumnProperty(col++)) + .setRenderer(new HtmlRenderer()); + grid.getColumn(getColumnProperty(col++)) + .setRenderer(new NumberRenderer()); + grid.getColumn(getColumnProperty(col++)) + .setRenderer(new NumberRenderer()); + } + + // Create footer + grid.appendFooterRow(); + grid.setFooterVisible(false); + + // Add footer values (header values are automatically created) + for (int col = 0; col < COLUMNS; col++) { + grid.getFooterRow(0).getCell(getColumnProperty(col)) + .setText("Footer " + col); + } + + // Set varying column widths + for (int col = 0; col < COLUMNS; col++) { + Column column = grid.getColumn(getColumnProperty(col)); + column.setWidth(100 + col * 50); + column.setHidable(isColumnHidableByDefault(col)); + } + + grid.addSortListener(new SortListener() { + @Override + public void sort(SortEvent event) { + log("SortEvent: isUserOriginated? " + event.isUserOriginated()); + } + }); + + grid.addColumnResizeListener(new ColumnResizeListener() { + @Override + public void columnResize(ColumnResizeEvent event) { + log("ColumnResizeEvent: isUserOriginated? " + + event.isUserOriginated()); + } + }); + + grid.setSelectionMode(SelectionMode.NONE); + + grid.getColumn(getColumnProperty(2)).getEditorField().setReadOnly(true); + grid.getColumn(getColumnProperty(3)).setEditable(false); + + createGridActions(); + + createColumnActions(); + + createPropertyActions(); + + createHeaderActions(); + + createFooterActions(); + + createRowActions(); + + createEditorActions(); + + addHeightActions(); + + addFilterActions(); + + addInternalActions(); + + createDetailsActions(); + + this.grid = grid; + return grid; + } + + protected boolean isColumnHidableByDefault(int col) { + return false; + } + + protected boolean isColumnHiddenByDefault(int col) { + return false; + } + + private void addInternalActions() { + createClickAction("Update column order without updating client", + "Internals", new Command() { + @Override + public void execute(Grid grid, Void value, Object data) { + List columns = grid.getColumns(); + grid.setColumnOrder(columns.get(1).getPropertyId(), + columns.get(0).getPropertyId()); + grid.getUI().getConnectorTracker().markClean(grid); + } + }, null); + } + + private void addFilterActions() { + createBooleanAction("Column 1 starts with \"(23\"", "Filter", false, + new Command() { + Filter filter = new Filter() { + @Override + public boolean passesFilter(Object itemId, Item item) { + return item.getItemProperty("Column 1").getValue() + .toString().startsWith("(23"); + } + + @Override + public boolean appliesToProperty(Object propertyId) { + return propertyId.equals("Column 1"); + } + }; + + @Override + public void execute(Grid grid, Boolean value, Object data) { + if (value) { + ds.addContainerFilter(filter); + } else { + ds.removeContainerFilter(filter); + } + } + }); + + createBooleanAction("Impassable filter", "Filter", false, + new Command() { + Filter filter = new Filter() { + @Override + public boolean passesFilter(Object itemId, Item item) { + return false; + } + + @Override + public boolean appliesToProperty(Object propertyId) { + return true; + } + }; + + @Override + public void execute(Grid c, Boolean value, Object data) { + if (value) { + ds.addContainerFilter(filter); + } else { + ds.removeContainerFilter(filter); + } + } + }); + } + + protected void createGridActions() { + + LinkedHashMap primaryStyleNames = new LinkedHashMap(); + primaryStyleNames.put("v-grid", "v-grid"); + primaryStyleNames.put("v-escalator", "v-escalator"); + primaryStyleNames.put("my-grid", "my-grid"); + + createMultiClickAction("Primary style name", "State", primaryStyleNames, + new Command() { + + @Override + public void execute(Grid grid, String value, Object data) { + grid.setPrimaryStyleName(value); + + } + }, primaryStyleNames.get("v-grid")); + + LinkedHashMap selectionModes = new LinkedHashMap(); + selectionModes.put("single", SelectionMode.SINGLE); + selectionModes.put("multi", SelectionMode.MULTI); + selectionModes.put("none", SelectionMode.NONE); + createSelectAction("Selection mode", "State", selectionModes, "none", + new Command() { + @Override + public void execute(Grid grid, SelectionMode selectionMode, + Object data) { + grid.setSelectionMode(selectionMode); + if (selectionMode == SelectionMode.SINGLE) { + grid.addSelectionListener(selectionListener); + + ((SelectionModel.Single) grid.getSelectionModel()) + .setDeselectAllowed( + singleSelectAllowDeselect); + } else { + grid.removeSelectionListener(selectionListener); + } + } + }); + + LinkedHashMap selectionLimits = new LinkedHashMap(); + selectionLimits.put("2", Integer.valueOf(2)); + selectionLimits.put("1000", Integer.valueOf(1000)); + selectionLimits.put("Integer.MAX_VALUE", + Integer.valueOf(Integer.MAX_VALUE)); + createSelectAction("Selection limit", "State", selectionLimits, "1000", + new Command() { + @Override + public void execute(Grid grid, Integer limit, Object data) { + if (!(grid + .getSelectionModel() instanceof MultiSelectionModel)) { + grid.setSelectionMode(SelectionMode.MULTI); + } + + ((MultiSelectionModel) grid.getSelectionModel()) + .setSelectionLimit(limit.intValue()); + } + }); + + LinkedHashMap> sortableProperties = new LinkedHashMap>(); + for (Object propertyId : ds.getSortableContainerPropertyIds()) { + sortableProperties.put(propertyId + ", ASC", + Sort.by(propertyId).build()); + sortableProperties.put(propertyId + ", DESC", + Sort.by(propertyId, SortDirection.DESCENDING).build()); + } + createSelectAction("Sort by column", "State", sortableProperties, + "Column 9, ascending", new Command>() { + @Override + public void execute(Grid grid, List sortOrder, + Object data) { + grid.setSortOrder(sortOrder); + } + }); + + createBooleanAction("Reverse Grid Columns", "State", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + List ids = new ArrayList(); + ids.addAll(ds.getContainerPropertyIds()); + if (!value) { + c.setColumnOrder(ids.toArray()); + } else { + Object[] idsArray = new Object[ids.size()]; + for (int i = 0; i < ids.size(); ++i) { + idsArray[i] = ids.get((ids.size() - 1) - i); + } + c.setColumnOrder(idsArray); + } + } + }); + + LinkedHashMap cellStyleGenerators = new LinkedHashMap(); + LinkedHashMap rowStyleGenerators = new LinkedHashMap(); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_NONE, null); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_ROW_NUMBERS, + new RowStyleGenerator() { + @Override + public String getStyle(RowReference rowReference) { + return "row" + rowReference.getItemId(); + } + }); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4, + new RowStyleGenerator() { + @Override + public String getStyle(RowReference rowReference) { + int rowIndex = ((Integer) rowReference.getItemId()) + .intValue(); + + if (rowIndex % 4 == 0) { + return null; + } else { + return "row" + rowReference.getItemId(); + } + } + }); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_EMPTY, + new RowStyleGenerator() { + + @Override + public String getStyle(RowReference rowReference) { + return ""; + } + }); + rowStyleGenerators.put(ROW_STYLE_GENERATOR_NULL, + new RowStyleGenerator() { + + @Override + public String getStyle(RowReference rowReference) { + return null; + } + }); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_NONE, null); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_PROPERTY_TO_STRING, + new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + return cellReference.getPropertyId().toString() + .replace(' ', '-'); + } + }); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_SPECIAL, + new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + int rowIndex = ((Integer) cellReference.getItemId()) + .intValue(); + Object propertyId = cellReference.getPropertyId(); + if (rowIndex % 4 == 1) { + return null; + } else if (rowIndex % 4 == 3 + && "Column 1".equals(propertyId)) { + return null; + } + return propertyId.toString().replace(' ', '_'); + } + }); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_EMPTY, + new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + return ""; + } + }); + cellStyleGenerators.put(CELL_STYLE_GENERATOR_NULL, + new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + return null; + } + }); + + createSelectAction("Row style generator", "State", rowStyleGenerators, + CELL_STYLE_GENERATOR_NONE, + new Command() { + @Override + public void execute(Grid grid, RowStyleGenerator generator, + Object data) { + grid.setRowStyleGenerator(generator); + } + }); + + createSelectAction("Cell style generator", "State", cellStyleGenerators, + CELL_STYLE_GENERATOR_NONE, + new Command() { + @Override + public void execute(Grid grid, CellStyleGenerator generator, + Object data) { + grid.setCellStyleGenerator(generator); + } + }); + + createBooleanAction("Row description generator", "State", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + c.setRowDescriptionGenerator( + value ? rowDescriptionGenerator : null); + } + }); + + createBooleanAction("Cell description generator", "State", false, + new Command() { + @Override + public void execute(Grid c, Boolean value, Object data) { + c.setCellDescriptionGenerator( + value ? cellDescriptionGenerator : null); + } + }); + + LinkedHashMap frozenOptions = new LinkedHashMap(); + for (int i = -1; i <= COLUMNS; i++) { + frozenOptions.put(String.valueOf(i), Integer.valueOf(i)); + } + /* + * This line below is a workaround for a FF24 bug regarding submenu + * handling - it makes the sub menu wider. + */ + frozenOptions.put("-1 for unfreezing selection column", -1); + createSelectAction("Frozen column count", "State", frozenOptions, "0", + new Command() { + @Override + public void execute(Grid c, Integer value, Object data) { + c.setFrozenColumnCount(value.intValue()); + } + }); + + LinkedHashMap containerDelayValues = new LinkedHashMap(); + for (int delay : new int[] { 0, 500, 2000, 10000 }) { + containerDelayValues.put(String.valueOf(delay), + Integer.valueOf(delay)); + } + + createSelectAction("Container delay", "State", containerDelayValues, + "0", new Command() { + @Override + public void execute(Grid grid, Integer delay, Object data) { + containerDelay = delay.intValue(); + } + }); + + createBooleanAction("ItemClickListener", "State", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + if (!value) { + c.removeItemClickListener(itemClickListener); + } else { + c.addItemClickListener(itemClickListener); + } + } + + }); + + createBooleanAction("EditorOpeningItemClickListener", "State", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + if (!value) { + c.removeItemClickListener( + editorOpeningItemClickListener); + } else { + c.addItemClickListener( + editorOpeningItemClickListener); + } + } + + }); + createBooleanAction("ReactiveValueChanger", "State", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + Field targetField = grid.getEditorFieldGroup() + .getField("Column 0"); + if (targetField != null) { + if (!value) { + targetField.removeValueChangeListener( + reactiveValueChanger); + } else { + targetField.addValueChangeListener( + reactiveValueChanger); + } + } + } + + }); + createBooleanAction("ColumnReorderListener", "State", false, + new Command() { + + @Override + public void execute(Grid grid, Boolean value, Object data) { + if (value) { + grid.addColumnReorderListener( + columnReorderListener); + } else { + grid.removeColumnReorderListener( + columnReorderListener); + } + } + }); + createBooleanAction("ColumnVisibilityChangeListener", "State", false, + new Command() { + @Override + public void execute(Grid grid, Boolean value, Object data) { + if (value) { + grid.addColumnVisibilityChangeListener( + columnVisibilityListener); + } else { + grid.removeColumnVisibilityChangeListener( + columnVisibilityListener); + } + } + }); + createBooleanAction("Single select allow deselect", "State", + singleSelectAllowDeselect, new Command() { + @Override + public void execute(Grid c, Boolean value, Object data) { + singleSelectAllowDeselect = value.booleanValue(); + + SelectionModel model = c.getSelectionModel(); + if (model instanceof SelectionModel.Single) { + ((SelectionModel.Single) model).setDeselectAllowed( + singleSelectAllowDeselect); + } + } + }); + createBooleanAction("Column Reordering Allowed", "State", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + c.setColumnReorderingAllowed(value); + } + }); + + createClickAction("Select all", "State", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + SelectionModel selectionModel = c.getSelectionModel(); + if (selectionModel instanceof SelectionModel.Multi) { + ((SelectionModel.Multi) selectionModel).selectAll(); + } + } + }, null); + + createClickAction("Select none", "State", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + SelectionModel selectionModel = c.getSelectionModel(); + if (selectionModel instanceof SelectionModel.Multi) { + ((SelectionModel.Multi) selectionModel).deselectAll(); + } + } + }, null); + } + + protected void createHeaderActions() { + createCategory("Header", null); + + createBooleanAction("Visible", "Header", true, + new Command() { + + @Override + public void execute(Grid grid, Boolean value, Object data) { + grid.setHeaderVisible(value); + } + }); + + LinkedHashMap defaultRows = new LinkedHashMap(); + defaultRows.put("Top", "Top"); + defaultRows.put("Bottom", "Bottom"); + defaultRows.put("Unset", "Unset"); + + createMultiClickAction("Default row", "Header", defaultRows, + new Command() { + + @Override + public void execute(Grid grid, String value, Object data) { + HeaderRow defaultRow = null; + if (value.equals("Top")) { + defaultRow = grid.getHeaderRow(0); + } else if (value.equals("Bottom")) { + defaultRow = grid + .getHeaderRow(grid.getHeaderRowCount() - 1); + } + grid.setDefaultHeaderRow(defaultRow); + } + + }, defaultRows.get("Top")); + + createClickAction("Prepend row", "Header", new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.prependHeaderRow(); + } + + }, null); + createClickAction("Append row", "Header", new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.appendHeaderRow(); + } + + }, null); + + createClickAction("Remove top row", "Header", + new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.removeHeaderRow(0); + } + + }, null); + createClickAction("Remove bottom row", "Header", + new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.removeHeaderRow(grid.getHeaderRowCount() - 1); + } + + }, null); + } + + protected void createFooterActions() { + createCategory("Footer", null); + + createBooleanAction("Visible", "Footer", false, + new Command() { + + @Override + public void execute(Grid grid, Boolean value, Object data) { + grid.setFooterVisible(value); + } + }); + + createClickAction("Prepend row", "Footer", new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.prependFooterRow(); + } + + }, null); + createClickAction("Append row", "Footer", new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.appendFooterRow(); + } + + }, null); + + createClickAction("Remove top row", "Footer", + new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.removeFooterRow(0); + } + + }, null); + createClickAction("Remove bottom row", "Footer", + new Command() { + + @Override + public void execute(Grid grid, Object value, Object data) { + grid.removeFooterRow(grid.getFooterRowCount() - 1); + } + + }, null); + } + + @SuppressWarnings("boxing") + protected void createColumnActions() { + createCategory("Columns", null); + for (int c = 0; c < COLUMNS; c++) { + final int index = c; + createCategory(getColumnProperty(c), "Columns"); + + createClickAction("Add / Remove", getColumnProperty(c), + new Command() { + + boolean wasHidable; + boolean wasHidden; + String wasColumnHidingToggleCaption; + + @Override + public void execute(Grid grid, String value, + Object data) { + String columnProperty = getColumnProperty( + (Integer) data); + Column column = grid.getColumn(columnProperty); + if (column == null) { + column = grid.addColumn(columnProperty); + column.setHidable(wasHidable); + column.setHidden(wasHidden); + column.setHidingToggleCaption( + wasColumnHidingToggleCaption); + } else { + wasHidable = column.isHidable(); + wasHidden = column.isHidden(); + wasColumnHidingToggleCaption = column + .getHidingToggleCaption(); + grid.removeColumn(columnProperty); + } + } + }, null, c); + createClickAction("Move left", getColumnProperty(c), + new Command() { + + @Override + public void execute(Grid grid, String value, + Object data) { + final String columnProperty = getColumnProperty( + (Integer) data); + List cols = grid.getColumns(); + List reordered = new ArrayList(); + boolean addAsLast = false; + for (int i = 0; i < cols.size(); i++) { + Column col = cols.get(i); + if (col.getPropertyId() + .equals(columnProperty)) { + if (i == 0) { + addAsLast = true; + } else { + reordered.add(i - 1, columnProperty); + } + } else { + reordered.add(col.getPropertyId()); + } + } + if (addAsLast) { + reordered.add(columnProperty); + } + grid.setColumnOrder(reordered.toArray()); + } + }, null, c); + + createBooleanAction("Sortable", getColumnProperty(c), true, + new Command() { + + @Override + public void execute(Grid grid, Boolean value, + Object columnIndex) { + Object propertyId = getColumnProperty( + (Integer) columnIndex); + Column column = grid.getColumn(propertyId); + column.setSortable(value); + } + }, c); + + createBooleanAction("Resizable", getColumnProperty(c), true, + new Command() { + + @Override + public void execute(Grid grid, Boolean value, + Object columnIndex) { + Object propertyId = getColumnProperty( + (Integer) columnIndex); + Column column = grid.getColumn(propertyId); + column.setResizable(value); + } + }, c); + + createBooleanAction("Hidable", getColumnProperty(c), + isColumnHidableByDefault(c), new Command() { + @Override + public void execute(Grid c, Boolean hidable, + Object propertyId) { + grid.getColumn(propertyId).setHidable(hidable); + } + }, getColumnProperty(c)); + + createBooleanAction("Hidden", getColumnProperty(c), + isColumnHiddenByDefault(c), new Command() { + @Override + public void execute(Grid c, Boolean hidden, + Object propertyId) { + grid.getColumn(propertyId).setHidden(hidden); + } + }, getColumnProperty(c)); + createClickAction("Change hiding toggle caption", + getColumnProperty(c), new Command() { + int count = 0; + + @Override + public void execute(Grid grid, String value, + Object data) { + final String columnProperty = getColumnProperty( + (Integer) data); + grid.getColumn(columnProperty) + .setHidingToggleCaption(columnProperty + + " caption " + count++); + } + }, null, c); + + createClickAction("Change header caption", getColumnProperty(c), + new Command() { + int count = 0; + + @Override + public void execute(Grid grid, String value, + Object data) { + final String columnProperty = getColumnProperty( + (Integer) data); + grid.getColumn(columnProperty).setHeaderCaption( + columnProperty + " header " + count++); + } + }, null, c); + + createCategory("Column " + c + " Width", getColumnProperty(c)); + + createClickAction("Auto", "Column " + c + " Width", + new Command() { + + @Override + public void execute(Grid grid, Integer value, + Object columnIndex) { + Object propertyId = getColumnProperty( + (Integer) columnIndex); + Column column = grid.getColumn(propertyId); + column.setWidthUndefined(); + } + }, -1, c); + + createClickAction("25.5px", "Column " + c + " Width", + new Command() { + @Override + public void execute(Grid grid, Void value, + Object columnIndex) { + grid.getColumns().get((Integer) columnIndex) + .setWidth(25.5); + } + }, null, c); + + for (int w = 50; w < 300; w += 50) { + createClickAction(w + "px", "Column " + c + " Width", + new Command() { + + @Override + public void execute(Grid grid, Integer value, + Object columnIndex) { + Object propertyId = getColumnProperty( + (Integer) columnIndex); + Column column = grid.getColumn(propertyId); + column.setWidth(value); + } + }, w, c); + } + + LinkedHashMap defaultRows = new LinkedHashMap(); + defaultRows.put("Text Header", GridStaticCellType.TEXT); + defaultRows.put("Html Header ", GridStaticCellType.HTML); + defaultRows.put("Widget Header", GridStaticCellType.WIDGET); + + createMultiClickAction("Header Type", getColumnProperty(c), + defaultRows, new Command() { + + @Override + public void execute(Grid grid, GridStaticCellType value, + Object columnIndex) { + final Object propertyId = getColumnProperty( + (Integer) columnIndex); + final HeaderCell cell = grid.getDefaultHeaderRow() + .getCell(propertyId); + switch (value) { + case TEXT: + cell.setText("Text Header"); + break; + case HTML: + cell.setHtml("HTML Header"); + break; + case WIDGET: + cell.setComponent(new Button("Button Header", + new ClickListener() { + + @Override + public void buttonClick( + ClickEvent event) { + log("Button clicked!"); + } + })); + default: + break; + } + } + + }, c); + + defaultRows = new LinkedHashMap(); + defaultRows.put("Text Footer", GridStaticCellType.TEXT); + defaultRows.put("Html Footer", GridStaticCellType.HTML); + defaultRows.put("Widget Footer", GridStaticCellType.WIDGET); + + createMultiClickAction("Footer Type", getColumnProperty(c), + defaultRows, new Command() { + + @Override + public void execute(Grid grid, GridStaticCellType value, + Object columnIndex) { + final Object propertyId = getColumnProperty( + (Integer) columnIndex); + final FooterCell cell = grid.getFooterRow(0) + .getCell(propertyId); + switch (value) { + case TEXT: + cell.setText("Text Footer"); + break; + case HTML: + cell.setHtml("HTML Footer"); + break; + case WIDGET: + cell.setComponent(new Button("Button Footer", + new ClickListener() { + + @Override + public void buttonClick( + ClickEvent event) { + log("Button clicked!"); + } + })); + default: + break; + } + } + + }, c); + } + + createClickAction("All columns auto width", "Columns", + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + for (Column col : grid.getColumns()) { + col.setWidthUndefined(); + } + + } + }, null); + + createBooleanAction("All columns hidable", "Columns", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + for (Column col : grid.getColumns()) { + col.setHidable(value); + } + + } + }); + createBooleanAction("All columns resizable", "Columns", false, + new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + for (Column col : grid.getColumns()) { + col.setResizable(value); + } + + } + }); + + createClickAction("All columns expanding, Col 0 has max width of 30px", + "Columns", new Command() { + + @Override + public void execute(Grid c, Boolean value, Object data) { + for (Column col : grid.getColumns()) { + col.setWidthUndefined(); + } + grid.getColumns().get(0).setMaximumWidth(30); + } + }, null); + } + + private static String getColumnProperty(int c) { + return "Column " + c; + } + + protected void createPropertyActions() { + createCategory("Properties", null); + + createBooleanAction("Prepend property", "Properties", false, + new Command() { + private final Object propertyId = new Object(); + + @Override + public void execute(Grid c, Boolean enable, Object data) { + if (enable.booleanValue()) { + ds.addContainerProperty(propertyId, String.class, + "property value"); + grid.getColumn(propertyId) + .setHeaderCaption("new property"); + grid.setColumnOrder(propertyId); + } else { + ds.removeContainerProperty(propertyId); + } + } + }, null); + } + + protected void createRowActions() { + createCategory("Body rows", null); + + class NewRowCommand implements Command { + private final int index; + + public NewRowCommand() { + this(0); + } + + public NewRowCommand(int index) { + this.index = index; + } + + @Override + public void execute(Grid c, String value, Object data) { + Item item = ds.addItemAt(index, new Object()); + for (int i = 0; i < COLUMNS; i++) { + Class type = ds.getType(getColumnProperty(i)); + if (String.class.isAssignableFrom(type)) { + Property itemProperty = getProperty(item, i); + itemProperty.setValue("newcell: " + i); + } else if (Integer.class.isAssignableFrom(type)) { + Property itemProperty = getProperty(item, i); + itemProperty.setValue(Integer.valueOf(i)); + } else { + // let the default value be taken implicitly. + } + } + } + + private Property getProperty(Item item, + int i) { + @SuppressWarnings("unchecked") + Property itemProperty = item + .getItemProperty(getColumnProperty(i)); + return itemProperty; + } + } + final NewRowCommand newRowCommand = new NewRowCommand(); + + createClickAction("Add 18 rows", "Body rows", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + for (int i = 0; i < 18; i++) { + newRowCommand.execute(c, value, data); + } + } + }, null); + + createClickAction("Add first row", "Body rows", newRowCommand, null); + + createClickAction("Add third row", "Body rows", new NewRowCommand(2), + null); + + createClickAction("Remove first row", "Body rows", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + Object firstItemId = ds.getIdByIndex(0); + ds.removeItem(firstItemId); + } + }, null); + + createClickAction("Remove 18 first rows", "Body rows", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + for (int i = 0; i < 18; i++) { + Object firstItemId = ds.getIdByIndex(0); + ds.removeItem(firstItemId); + } + } + }, null); + + createClickAction("Modify first row (getItemProperty)", "Body rows", + new Command() { + @SuppressWarnings("unchecked") + @Override + public void execute(Grid c, String value, Object data) { + Object firstItemId = ds.getIdByIndex(0); + Item item = ds.getItem(firstItemId); + for (int i = 0; i < COLUMNS; i++) { + Property property = item + .getItemProperty(getColumnProperty(i)); + if (property.getType().equals(String.class)) { + ((Property) property) + .setValue("modified: " + i); + } + } + } + }, null); + + createClickAction("Modify first row (getContainerProperty)", + "Body rows", new Command() { + @SuppressWarnings("unchecked") + @Override + public void execute(Grid c, String value, Object data) { + Object firstItemId = ds.getIdByIndex(0); + for (Object containerPropertyId : ds + .getContainerPropertyIds()) { + Property property = ds.getContainerProperty( + firstItemId, containerPropertyId); + if (property.getType().equals(String.class)) { + ((Property) property).setValue( + "modified: " + containerPropertyId); + } + } + } + }, null); + + createBooleanAction("Select first row", "Body rows", false, + new Command() { + @Override + public void execute(Grid grid, Boolean select, + Object data) { + final Object firstItemId = grid.getContainerDataSource() + .firstItemId(); + if (select.booleanValue()) { + grid.select(firstItemId); + } else { + grid.deselect(firstItemId); + } + } + }); + + createClickAction("Remove all rows", "Body rows", + new Command() { + @SuppressWarnings("unchecked") + @Override + public void execute(Grid c, String value, Object data) { + ds.removeAllItems(); + } + }, null); + + createClickAction("Remove selected rows", "Body rows", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + // Usually you'd deselect all the rows before removing + // them. It is done this way to test for #19152 + for (Object itemId : c.getSelectedRows()) { + ds.removeItem(itemId); + } + c.select(null); + } + }, null); + } + + protected void createEditorActions() { + createBooleanAction("Enabled", "Editor", false, + new Command() { + @Override + public void execute(Grid c, Boolean value, Object data) { + c.setEditorEnabled(value); + } + }); + + createBooleanAction("Buffered mode", "Editor", true, + new Command() { + @Override + public void execute(Grid c, Boolean value, Object data) { + c.setEditorBuffered(value); + } + }); + + createClickAction("Edit item 5", "Editor", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.editItem(5); + } + }, null); + + createClickAction("Edit item 100", "Editor", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.editItem(100); + } + }, null); + createClickAction("Save", "Editor", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + try { + c.saveEditor(); + } catch (CommitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }, null); + createClickAction("Cancel edit", "Editor", new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.cancelEditor(); + } + }, null); + + createClickAction("Change save caption", "Editor", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.setEditorSaveCaption("ǝʌɐS"); + } + }, null); + + createClickAction("Change cancel caption", "Editor", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.setEditorCancelCaption("ʃǝɔuɐↃ"); + } + }, null); + + } + + @SuppressWarnings("boxing") + protected void addHeightActions() { + createCategory("Height by Rows", "Size"); + + createBooleanAction("HeightMode Row", "Size", false, + new Command() { + @Override + public void execute(Grid c, Boolean heightModeByRows, + Object data) { + c.setHeightMode(heightModeByRows ? HeightMode.ROW + : HeightMode.CSS); + } + }, null); + + addActionForHeightByRows(1d / 3d); + addActionForHeightByRows(2d / 3d); + + for (double i = 1; i < 5; i++) { + addActionForHeightByRows(i); + addActionForHeightByRows(i + 1d / 3d); + addActionForHeightByRows(i + 2d / 3d); + } + + Command sizeCommand = new Command() { + @Override + public void execute(Grid grid, String height, Object data) { + grid.setHeight(height); + } + }; + + createCategory("Height", "Size"); + // header 20px + scrollbar 16px = 36px baseline + createClickAction("86px (no drag scroll select)", "Height", sizeCommand, + "86px"); + createClickAction("96px (drag scroll select limit)", "Height", + sizeCommand, "96px"); + createClickAction("106px (drag scroll select enabled)", "Height", + sizeCommand, "106px"); + } + + private void addActionForHeightByRows(final Double i) { + DecimalFormat df = new DecimalFormat("0.00"); + createClickAction(df.format(i) + " rows", "Height by Rows", + new Command() { + @Override + public void execute(Grid c, String value, Object data) { + c.setHeightByRows(i); + } + }, null); + } + + private void createDetailsActions() { + Command swapDetailsGenerator = new Command() { + @Override + public void execute(Grid c, DetailsGenerator generator, + Object data) { + grid.setDetailsGenerator(generator); + } + }; + + Command openOrCloseItemId = new Command() { + @Override + @SuppressWarnings("boxing") + public void execute(Grid g, Boolean visible, Object itemId) { + g.setDetailsVisible(itemId, visible); + } + }; + + createCategory("Generators", "Details"); + createClickAction("NULL", "Generators", swapDetailsGenerator, + DetailsGenerator.NULL); + createClickAction("\"Watching\"", "Generators", swapDetailsGenerator, + watchingDetailsGenerator); + createClickAction("Detailed", "Generators", swapDetailsGenerator, + detailedDetailsGenerator); + createClickAction("Persisting", "Generators", swapDetailsGenerator, + persistingDetailsGenerator); + + createClickAction("- Change Component", "Generators", + new Command() { + @Override + public void execute(Grid c, Void value, Object data) { + for (Object id : detailsMap.keySet()) { + Panel panel = detailsMap.get(id); + Label label = (Label) panel.getContent(); + if (label.getValue().equals("One")) { + panel.setContent(new Label("Two")); + } else { + panel.setContent(new Label("One")); + } + } + } + }, null); + + createClickAction("Toggle firstItemId", "Details", + new Command() { + @Override + public void execute(Grid g, Void value, Object data) { + Object firstItemId = g.getContainerDataSource() + .firstItemId(); + boolean toggle = g.isDetailsVisible(firstItemId); + g.setDetailsVisible(firstItemId, !toggle); + g.setDetailsVisible(firstItemId, toggle); + } + }, null); + + createBooleanAction("Open firstItemId", "Details", false, + openOrCloseItemId, ds.firstItemId()); + + createBooleanAction("Open 1", "Details", false, openOrCloseItemId, + ds.getIdByIndex(1)); + + createBooleanAction("Open 995", "Details", false, openOrCloseItemId, + ds.getIdByIndex(995)); + } + + @Override + protected Integer getTicketNumber() { + return 12829; + } + + @Override + protected Class getTestClass() { + return Grid.class; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeaturesValo.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeaturesValo.java new file mode 100644 index 0000000000..eb2599f951 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeaturesValo.java @@ -0,0 +1,28 @@ +/* + * 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.basicfeatures; + +import com.vaadin.annotations.Theme; +import com.vaadin.ui.themes.ValoTheme; + +@Theme(ValoTheme.THEME_NAME) +public class GridBasicFeaturesValo extends GridBasicFeatures { + @Override + @Deprecated + public String getTheme() { + return ValoTheme.THEME_NAME; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientDataSources.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientDataSources.java new file mode 100644 index 0000000000..b352982030 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientDataSources.java @@ -0,0 +1,32 @@ +/* + * 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.basicfeatures; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridClientDataSourcesWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Widgetset(TestingWidgetSet.NAME) +public class GridClientDataSources extends UI { + + @Override + protected void init(VaadinRequest request) { + setContent(new TestWidgetComponent(GridClientDataSourcesWidget.class)); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientHeightByRowOnInit.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientHeightByRowOnInit.java new file mode 100644 index 0000000000..20fdb5fcdc --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientHeightByRowOnInit.java @@ -0,0 +1,20 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures; + +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Title; +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridHeightByRowOnInitWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Theme("valo") +@Title("Client Grid height by row on init") +@Widgetset(TestingWidgetSet.NAME) +public class GridClientHeightByRowOnInit extends UI { + @Override + protected void init(VaadinRequest request) { + setContent(new TestWidgetComponent(GridHeightByRowOnInitWidget.class)); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDefaultTextRenderer.java new file mode 100644 index 0000000000..44e33caa56 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDefaultTextRenderer.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.v7.tests.components.grid.basicfeatures; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.v7.grid.GridDefaultTextRendererWidget; +import com.vaadin.tests.widgetset.server.TestWidgetComponent; +import com.vaadin.ui.UI; + +@Widgetset(TestingWidgetSet.NAME) +public class GridDefaultTextRenderer extends UI { + + @Override + protected void init(VaadinRequest request) { + setContent( + new TestWidgetComponent(GridDefaultTextRendererWidget.class)); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridHeightByRowOnInit.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridHeightByRowOnInit.java new file mode 100644 index 0000000000..26584823d7 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridHeightByRowOnInit.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.v7.tests.components.grid.basicfeatures; + +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Title; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.UI; +import com.vaadin.ui.themes.ValoTheme; +import com.vaadin.v7.data.Container; +import com.vaadin.v7.shared.ui.grid.HeightMode; +import com.vaadin.v7.ui.Grid; + +@Title("Server Grid height by row on init") +@Theme(ValoTheme.THEME_NAME) +public class GridHeightByRowOnInit extends UI { + + private static final String PROPERTY = "Property"; + + @Override + protected void init(VaadinRequest request) { + final Grid grid = new Grid(); + Container.Indexed container = grid.getContainerDataSource(); + container.addContainerProperty(PROPERTY, String.class, ""); + + container.addItem("A").getItemProperty(PROPERTY).setValue("A"); + container.addItem("B").getItemProperty(PROPERTY).setValue("B"); + container.addItem("C").getItemProperty(PROPERTY).setValue("C"); + container.addItem("D").getItemProperty(PROPERTY).setValue("D"); + container.addItem("E").getItemProperty(PROPERTY).setValue("E"); + + grid.setHeightMode(HeightMode.ROW); + grid.setHeightByRows(5); + + setContent(grid); + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSidebarFeatures.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSidebarFeatures.java new file mode 100644 index 0000000000..6540accbf1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSidebarFeatures.java @@ -0,0 +1,24 @@ +/* + * 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.basicfeatures; + +public class GridSidebarFeatures extends GridBasicFeatures { + + @Override + protected boolean isColumnHidableByDefault(int col) { + return true; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSortingIndicators.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSortingIndicators.java new file mode 100644 index 0000000000..3919e4c5a1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSortingIndicators.java @@ -0,0 +1,65 @@ +/* + * 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.basicfeatures; + +import com.vaadin.data.sort.Sort; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.v7.data.Container; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +public class GridSortingIndicators extends AbstractTestUI { + + private static int FOO_MIN = 4; + private static int BAR_MULTIPLIER = 3; + private static int BAZ_MAX = 132; + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(createContainer()); + addComponent(grid); + grid.sort(Sort.by("foo").then("bar", SortDirection.DESCENDING) + .then("baz")); + + addComponent(new Button("Reverse sorting", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.sort(Sort.by("baz", SortDirection.DESCENDING).then("bar") + .then("foo", SortDirection.DESCENDING)); + } + })); + } + + private Container.Indexed createContainer() { + IndexedContainer container = new IndexedContainer(); + container.addContainerProperty("foo", Integer.class, 0); + container.addContainerProperty("bar", Integer.class, 0); + container.addContainerProperty("baz", Integer.class, 0); + for (int i = 0; i < 10; ++i) { + Item item = container.getItem(container.addItem()); + item.getItemProperty("foo").setValue(FOO_MIN + i); + item.getItemProperty("baz").setValue(BAZ_MAX - i); + item.getItemProperty("bar").setValue(BAR_MULTIPLIER * i); + } + return container; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridClearContainer.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridClearContainer.java new file mode 100644 index 0000000000..7025a72d06 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridClearContainer.java @@ -0,0 +1,72 @@ +/* + * 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.basicfeatures.server; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.Grid; + +/** + * Tests that removing and adding rows doesn't cause an infinite loop in the + * browser. + * + * @author Vaadin Ltd + */ +@Theme("valo") +public class GridClearContainer extends AbstractTestUIWithLog { + + private IndexedContainer ic; + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + ic = new IndexedContainer(); + ic.addContainerProperty("Col 1", String.class, "default"); + ic.addItem("Row 1"); + ic.addItem("Row 2"); + grid.setContainerDataSource(ic); + + Button b = new Button("Clear and re-add", new ClickListener() { + + @SuppressWarnings("unchecked") + @Override + public void buttonClick(ClickEvent event) { + ic.removeAllItems(); + ic.addItem("Row 3").getItemProperty("Col 1") + .setValue("Updated value 1"); + ic.addItem("Row 4").getItemProperty("Col 1") + .setValue("Updated value 2"); + } + }); + addComponent(b); + addComponent(grid); + } + + @Override + protected String getTestDescription() { + return "Tests that removing and adding rows doesn't cause an infinite loop in the browser."; + } + + @Override + protected Integer getTicketNumber() { + return 16747; + } +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridDeclarativeBasicFeatures.java new file mode 100644 index 0000000000..32f1650364 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridDeclarativeBasicFeatures.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.v7.tests.components.grid.declarative; + +import com.vaadin.annotations.Theme; +import com.vaadin.tests.components.DeclarativeTestUI; +import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; + +@SuppressWarnings("serial") +@Theme("valo") +@DeclarativeUI("GridBasicFeatures.html") +public class GridDeclarativeBasicFeatures extends DeclarativeTestUI { + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridDeclarativeMultiSelect.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridDeclarativeMultiSelect.java new file mode 100644 index 0000000000..9c5965537a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridDeclarativeMultiSelect.java @@ -0,0 +1,26 @@ +/* + * 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.declarative; + +import com.vaadin.annotations.Theme; +import com.vaadin.tests.components.DeclarativeTestUI; +import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; + +@Theme("valo") +@SuppressWarnings("serial") +@DeclarativeUI("GridMultiSelect.html") +public class GridDeclarativeMultiSelect extends DeclarativeTestUI { +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridItemEditor.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridItemEditor.java new file mode 100644 index 0000000000..e4ee205078 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/declarative/GridItemEditor.java @@ -0,0 +1,23 @@ +/* + * 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.declarative; + +import com.vaadin.tests.components.DeclarativeTestUI; +import com.vaadin.tests.components.DeclarativeTestUI.DeclarativeUI; + +@DeclarativeUI("GridItemEditor.html") +public class GridItemEditor extends DeclarativeTestUI { +} 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 deleted file mode 100644 index ef34475518..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/AbstractGridColumnAutoWidthTest.java +++ /dev/null @@ -1,110 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -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 { - compareScreen("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/CustomRendererTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/CustomRendererTest.java deleted file mode 100644 index d03ca79205..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/CustomRendererTest.java +++ /dev/null @@ -1,70 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Test; - -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class CustomRendererTest extends MultiBrowserTest { - @Test - public void testIntArrayIsRendered() throws Exception { - openTestURL(); - - GridElement grid = findGrid(); - assertEquals("1 :: 1 :: 2 :: 3 :: 5 :: 8 :: 13", - grid.getCell(0, 0).getText()); - } - - @Test - public void testRowAwareRenderer() throws Exception { - openTestURL(); - - GridElement grid = findGrid(); - assertEquals("Click me!", grid.getCell(0, 1).getText()); - assertEquals(CustomRenderer.INIT_DEBUG_LABEL_CAPTION, - findDebugLabel().getText()); - - grid.getCell(0, 1).click(); - assertEquals("row: 0, key: 1", grid.getCell(0, 1).getText()); - assertEquals("key: 1, itemId: " + CustomRenderer.ITEM_ID, - findDebugLabel().getText()); - } - - @Test - public void testBeanRenderer() throws Exception { - openTestURL(); - - assertEquals("SimpleTestBean(42)", findGrid().getCell(0, 2).getText()); - } - - private GridElement findGrid() { - List elements = $(GridElement.class).all(); - return elements.get(0); - } - - private LabelElement findDebugLabel() { - return $(LabelElement.class).id(CustomRenderer.DEBUG_LABEL_ID); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.java deleted file mode 100644 index c2399ce9cb..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddAndRemoveDataOnInitTest.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.tests.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridAddAndRemoveDataOnInitTest extends MultiBrowserTest { - - @Test - public void verifyGridSizes() { - openTestURL(); - - GridElement gridAdd = $(GridElement.class).first(); - if (!gridAdd.isElementPresent(By.vaadin("#cell[9][0]")) - || gridAdd.isElementPresent(By.vaadin("#cell[10][0]"))) { - Assert.fail("Grid with added data contained incorrect rows"); - } - - GridElement gridRemove = $(GridElement.class).get(1); - if (!gridRemove.isElementPresent(By.vaadin("#cell[4][0]")) - || gridRemove.isElementPresent(By.vaadin("#cell[5][0]"))) { - Assert.fail("Grid with removed data contained incorrect rows"); - } - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddRowTest.java deleted file mode 100644 index 5e0793dbd2..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridAddRowTest.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.tests.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridAddRowTest extends MultiBrowserTest { - @Test - public void testAddRow() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - Assert.assertEquals("Lorem", grid.getCell(0, 1).getText()); - Assert.assertEquals("2", grid.getCell(1, 2).getText()); - - addRow(); - - Assert.assertEquals("Dolor", grid.getCell(2, 1).getText()); - - addRow(); - - Assert.assertEquals("Dolor", grid.getCell(3, 1).getText()); - } - - private void addRow() { - $(ButtonElement.class).caption("Add new row").first().click(); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSizeTest.java deleted file mode 100644 index 509261ddc8..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSizeTest.java +++ /dev/null @@ -1,59 +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.components.grid; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elementsbase.ServerClass; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridCellFocusOnResetSizeTest extends MultiBrowserTest { - - @ServerClass("com.vaadin.tests.widgetset.server.TestWidgetComponent") - public static class MyGridElement extends GridElement { - } - - @Test - public void testCellFocusOnSizeReset() throws IOException { - openTestURL(); - - GridElement grid = $(MyGridElement.class).first(); - int rowIndex = 9; - grid.getCell(rowIndex, 0).click(); - assertTrue("Row was not focused after click.", - grid.getRow(rowIndex).isFocused()); - - // Clicking the button decreases size until it is down to 5 rows. - while (rowIndex > 4) { - findElement(By.tagName("button")).click(); - assertTrue("Row focus was not moved when size decreased", - grid.getRow(--rowIndex).isFocused()); - } - - // Next click increases size back to 10, this should not move focus. - findElement(By.tagName("button")).click(); - assertTrue("Row focus should not have moved when size increased", - grid.getRow(4).isFocused()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridCheckBoxDisplayTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridCheckBoxDisplayTest.java deleted file mode 100644 index 76282e074e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridCheckBoxDisplayTest.java +++ /dev/null @@ -1,72 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.CheckBoxElement; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridCheckBoxDisplayTest extends SingleBrowserTest { - @Test - public void testAddRow() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - Assert.assertEquals("First item had wrong value", "true", - grid.getCell(0, 0).getText()); - Assert.assertEquals("Second item had wrong value", "false", - grid.getCell(1, 0).getText()); - - // First edit false item and see that the CheckBox is unchecked - grid.getCell(1, 0).doubleClick(); - - CheckBoxElement checkbox = $(CheckBoxElement.class).first(); - Assert.assertEquals("CheckBox was checked", "unchecked", - checkbox.getValue()); - - closeEditor(); - - // Edit true item and see that the CheckBox is checked - grid.getCell(0, 0).doubleClick(); - - checkbox = $(CheckBoxElement.class).first(); - Assert.assertEquals("CheckBox was not checked.", "checked", - checkbox.getValue()); - - closeEditor(); - - // Edit false item and confirm that the CheckBox is unchecked again - grid.getCell(1, 0).doubleClick(); - - checkbox = $(CheckBoxElement.class).first(); - Assert.assertEquals("CheckBox was checked", "unchecked", - checkbox.getValue()); - } - - /** - * Closes the grids editor using the cancel button - */ - private void closeEditor() { - findElement(By.className("v-grid-editor-cancel")).click(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java deleted file mode 100644 index d0d8868b72..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridClientDataChangeHandlerTest.java +++ /dev/null @@ -1,40 +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.components.grid; - -import static org.junit.Assert.assertFalse; - -import org.junit.Test; - -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; - -@TestCategory("grid") -public class GridClientDataChangeHandlerTest extends SingleBrowserTest { - - @Test - public void testNoErrorsOnGridInit() throws InterruptedException { - setDebug(true); - openTestURL(); - - // Wait for delayed functionality. - sleep(1000); - - assertFalse("Unexpected exception is visible.", - $(NotificationElement.class).exists()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridClientRenderers.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridClientRenderers.java deleted file mode 100644 index a0b4b51eeb..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridClientRenderers.java +++ /dev/null @@ -1,282 +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.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.elements.NativeButtonElement; -import com.vaadin.testbench.elementsbase.ServerClass; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.tests.widgetset.client.grid.GridClientColumnRendererConnector.Renderers; -import com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.NativeSelectElement; - -/** - * Tests Grid client side renderers - * - * @since - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridClientRenderers extends MultiBrowserTest { - - private static final double SLEEP_MULTIPLIER = 1.2; - private int latency = 0; - - @Override - protected Class getUIClass() { - return GridClientColumnRenderers.class; - } - - @Override - protected String getDeploymentPath(Class uiClass) { - String path = super.getDeploymentPath(uiClass); - if (latency > 0) { - path += (path.contains("?") ? "&" : "?") + "latency=" + latency; - } - return path; - } - - @ServerClass("com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers.GridController") - public static class MyClientGridElement extends GridElement { - } - - @Override - public void setup() throws Exception { - latency = 0; // reset - super.setup(); - } - - @Test - public void addWidgetRenderer() throws Exception { - openTestURL(); - - // Add widget renderer column - $(NativeSelectElement.class).first() - .selectByText(Renderers.WIDGET_RENDERER.toString()); - $(NativeButtonElement.class).caption("Add").first().click(); - - // Click the button in cell 1,1 - TestBenchElement cell = getGrid().getCell(1, 2); - WebElement gwtButton = cell.findElement(By.tagName("button")); - gwtButton.click(); - - // Should be an alert visible - assertEquals("Button did not contain text \"Clicked\"", "Clicked", - gwtButton.getText()); - } - - @Test - public void detachAndAttachGrid() { - openTestURL(); - - // Add widget renderer column - $(NativeSelectElement.class).first() - .selectByText(Renderers.WIDGET_RENDERER.toString()); - $(NativeButtonElement.class).caption("Add").first().click(); - - // Detach and re-attach the Grid - $(NativeButtonElement.class).caption("DetachAttach").first().click(); - - // Click the button in cell 1,1 - TestBenchElement cell = getGrid().getCell(1, 2); - WebElement gwtButton = cell.findElement(By.tagName("button")); - gwtButton.click(); - - // Should be an alert visible - assertEquals("Button did not contain text \"Clicked\"", - gwtButton.getText(), "Clicked"); - } - - @Test - public void rowsWithDataHasStyleName() throws Exception { - - testBench().disableWaitForVaadin(); - - // Simulate network latency with 2000ms - latency = 2000; - - openTestURL(); - - sleep((int) (latency * SLEEP_MULTIPLIER)); - - TestBenchElement row = getGrid().getRow(51); - String className = row.getAttribute("class"); - assertFalse("Row should not yet contain style name v-grid-row-has-data", - className.contains("v-grid-row-has-data")); - - // Wait for data to arrive - sleep((int) (latency * SLEEP_MULTIPLIER)); - - row = getGrid().getRow(51); - className = row.getAttribute("class"); - assertTrue("Row should now contain style name v-grid-row-has-data", - className.contains("v-grid-row-has-data")); - } - - @Test - public void complexRendererSetVisibleContent() throws Exception { - - DesiredCapabilities desiredCapabilities = getDesiredCapabilities(); - - // Simulate network latency with 2000ms - latency = 2000; - - // Chrome uses RGB instead of RGBA - String colorRed = "rgba(255, 0, 0, 1)"; - String colorWhite = "rgba(255, 255, 255, 1)"; - String colorDark = "rgba(239, 240, 241, 1)"; - - openTestURL(); - - getGrid(); - - testBench().disableWaitForVaadin(); - - // Test initial renderering with contentVisible = False - TestBenchElement cell = getGrid().getCell(51, 1); - String backgroundColor = cell.getCssValue("backgroundColor"); - assertEquals("Background color was not red.", colorRed, - backgroundColor); - - // data arrives... - sleep((int) (latency * SLEEP_MULTIPLIER)); - - // Content becomes visible - cell = getGrid().getCell(51, 1); - backgroundColor = cell.getCssValue("backgroundColor"); - assertNotEquals("Background color was red.", colorRed, backgroundColor); - - // scroll down, new cells becomes contentVisible = False - getGrid().scrollToRow(60); - - // Cell should be red (setContentVisible set cell red) - cell = getGrid().getCell(55, 1); - backgroundColor = cell.getCssValue("backgroundColor"); - assertEquals("Background color was not red.", colorRed, - backgroundColor); - - // data arrives... - sleep((int) (latency * SLEEP_MULTIPLIER)); - - // Cell should no longer be red - backgroundColor = cell.getCssValue("backgroundColor"); - assertTrue("Background color was not reset", - backgroundColor.equals(colorWhite) - || backgroundColor.equals(colorDark)); - } - - @Test - public void testSortingEvent() throws Exception { - openTestURL(); - - $(NativeButtonElement.class).caption("Trigger sorting event").first() - .click(); - - String consoleText = $(LabelElement.class).id("testDebugConsole") - .getText(); - - assertTrue("Console text as expected", - consoleText.contains("Columns: 1, order: Column 1: ASCENDING")); - - } - - @Test - public void testListSorter() throws Exception { - openTestURL(); - - $(NativeButtonElement.class).caption("Shuffle").first().click(); - - GridElement gridElem = $(MyClientGridElement.class).first(); - - // XXX: DANGER! We'll need to know how many rows the Grid has! - // XXX: Currently, this is impossible; hence the hardcoded value of 70. - - boolean shuffled = false; - for (int i = 1, l = 70; i < l; ++i) { - - String str_a = gridElem.getCell(i - 1, 0).getAttribute("innerHTML"); - String str_b = gridElem.getCell(i, 0).getAttribute("innerHTML"); - - int value_a = Integer.parseInt(str_a); - int value_b = Integer.parseInt(str_b); - - if (value_a > value_b) { - shuffled = true; - break; - } - } - assertTrue("Grid shuffled", shuffled); - - $(NativeButtonElement.class).caption("Test sorting").first().click(); - - for (int i = 1, l = 70; i < l; ++i) { - - String str_a = gridElem.getCell(i - 1, 0).getAttribute("innerHTML"); - String str_b = gridElem.getCell(i, 0).getAttribute("innerHTML"); - - int value_a = Integer.parseInt(str_a); - int value_b = Integer.parseInt(str_b); - - if (value_a > value_b) { - assertTrue("Grid sorted", false); - } - } - } - - @Test - public void testComplexRendererOnActivate() { - openTestURL(); - - GridCellElement cell = getGrid().getCell(3, 1); - cell.click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - assertEquals("onActivate was not called on KeyDown Enter.", - "Activated!", cell.getText()); - - cell = getGrid().getCell(4, 1); - cell.click(); - new Actions(getDriver()).moveToElement(cell).doubleClick().perform(); - assertEquals("onActivate was not called on double click.", "Activated!", - cell.getText()); - } - - private GridElement getGrid() { - return $(MyClientGridElement.class).first(); - } - - private void addColumn(Renderers renderer) { - // Add widget renderer column - $(NativeSelectElement.class).first().selectByText(renderer.toString()); - $(NativeButtonElement.class).caption("Add").first().click(); - } -} 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 deleted file mode 100644 index c2c740a5f9..0000000000 --- a/uitest/src/test/java/com/vaadin/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.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.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@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/tests/components/grid/GridColumnAutoExpandTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoExpandTest.java deleted file mode 100644 index 6f4c0da27f..0000000000 --- a/uitest/src/test/java/com/vaadin/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.tests.components.grid; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -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/tests/components/grid/GridColumnAutoWidthClientTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnAutoWidthClientTest.java deleted file mode 100644 index b74d16eda1..0000000000 --- a/uitest/src/test/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.testbench.parallel.TestCategory; - -@TestCategory("grid") -public class GridColumnAutoWidthClientTest - extends AbstractGridColumnAutoWidthTest { - @Override - protected Class getUIClass() { - return GridColumnAutoWidthClient.class; - } -} \ No newline at end of file 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 deleted file mode 100644 index f57607cdda..0000000000 --- a/uitest/src/test/java/com/vaadin/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.tests.components.grid; - -import com.vaadin.testbench.parallel.TestCategory; - -@TestCategory("grid") -public class GridColumnAutoWidthServerTest - extends AbstractGridColumnAutoWidthTest { - @Override - protected Class getUIClass() { - return GridColumnAutoWidth.class; - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthRecalculationTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthRecalculationTest.java deleted file mode 100644 index 12f98979fa..0000000000 --- a/uitest/src/test/java/com/vaadin/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.tests.components.grid; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.Dimension; - -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; -import com.vaadin.v7.testbench.customelements.GridElement; - -@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/tests/components/grid/GridColumnWidthsWithoutDataTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridColumnWidthsWithoutDataTest.java deleted file mode 100644 index e9a8892628..0000000000 --- a/uitest/src/test/java/com/vaadin/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.tests.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.NativeSelectElement; - -@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/GridCustomSelectionModelTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridCustomSelectionModelTest.java deleted file mode 100644 index 0a14c57fa0..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridCustomSelectionModelTest.java +++ /dev/null @@ -1,58 +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.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridCustomSelectionModelTest extends MultiBrowserTest { - - @Test - public void testCustomSelectionModel() { - setDebug(true); - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - GridCellElement cell = grid.getCell(0, 0); - assertTrue("First column of Grid should not have an input element", - cell.findElements(By.className("input")).isEmpty()); - - assertFalse("Row should not be selected initially", - grid.getRow(0).isSelected()); - - cell.click(5, 5); - assertTrue("Click should select row", grid.getRow(0).isSelected()); - cell.click(5, 5); - assertFalse("Click should deselect row", grid.getRow(0).isSelected()); - - grid.sendKeys(Keys.SPACE); - assertTrue("Space should select row", grid.getRow(0).isSelected()); - grid.sendKeys(Keys.SPACE); - assertFalse("Space should deselect row", grid.getRow(0).isSelected()); - - assertNoErrorNotifications(); - } -} 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 deleted file mode 100644 index 0ba591076c..0000000000 --- a/uitest/src/test/java/com/vaadin/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.tests.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -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/GridDefaultSelectionModeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDefaultSelectionModeTest.java deleted file mode 100644 index ddd0bcb7aa..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDefaultSelectionModeTest.java +++ /dev/null @@ -1,84 +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.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridDefaultSelectionModeTest extends MultiBrowserTest { - - @Test - public void testSelectionFromServer() { - setDebug(true); - openTestURL(); - - $(ButtonElement.class).caption("Select on server").first().click(); - - assertTrue("Row should be selected.", - $(GridElement.class).first().getRow(0).isSelected()); - - $(ButtonElement.class).caption("Deselect on server").first().click(); - - assertFalse("Row should not be selected.", - $(GridElement.class).first().getRow(0).isSelected()); - - assertNoErrorNotifications(); - } - - @Test - public void testSelectionWithSort() { - setDebug(true); - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - grid.getCell(0, 0).click(); - - GridCellElement header = grid.getHeaderCell(0, 1); - header.click(); - header.click(); - - assertTrue("Row should be selected.", grid.getRow(1).isSelected()); - - assertNoErrorNotifications(); - } - - @Test - public void testReselectDeselectedRow() { - setDebug(true); - openTestURL(); - - $(ButtonElement.class).caption("Select on server").first().click(); - - GridElement grid = $(GridElement.class).first(); - assertTrue("Row should be selected.", grid.getRow(0).isSelected()); - - $(ButtonElement.class).caption("Deselect on server").first().click(); - - assertFalse("Row should not be selected.", grid.getRow(0).isSelected()); - - grid.getCell(0, 0).click(); - assertTrue("Row should be selected.", grid.getRow(0).isSelected()); - - assertNoErrorNotifications(); - } -} 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 deleted file mode 100644 index 5382897784..0000000000 --- a/uitest/src/test/java/com/vaadin/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.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.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@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/tests/components/grid/GridDetailsLayoutExpandTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLayoutExpandTest.java deleted file mode 100644 index 897566500a..0000000000 --- a/uitest/src/test/java/com/vaadin/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.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.elements.LabelElement; -import com.vaadin.testbench.parallel.Browser; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -/** - * 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/GridDetailsLocationTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLocationTest.java deleted file mode 100644 index 4293c61de7..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsLocationTest.java +++ /dev/null @@ -1,319 +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.components.grid; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.StaleElementReferenceException; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.CheckBoxElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridDetailsLocationTest extends MultiBrowserTest { - - private static final int detailsDefaultHeight = 51; - private static final int detailsDefinedHeight = 33; - - private static class Param { - private final int rowIndex; - private final boolean useGenerator; - private final boolean scrollFirstToBottom; - - public Param(int rowIndex, boolean useGenerator, - boolean scrollFirstToBottom) { - this.rowIndex = rowIndex; - this.useGenerator = useGenerator; - this.scrollFirstToBottom = scrollFirstToBottom; - } - - public int getRowIndex() { - return rowIndex; - } - - public boolean useGenerator() { - return useGenerator; - } - - public boolean scrollFirstToBottom() { - return scrollFirstToBottom; - } - - @Override - public String toString() { - return "Param [rowIndex=" + getRowIndex() + ", useGenerator=" - + useGenerator() + ", scrollFirstToBottom=" - + scrollFirstToBottom() + "]"; - } - - } - - public static Collection parameters() { - List data = new ArrayList(); - - int[] params = new int[] { 0, 500, 999 }; - - for (int rowIndex : params) { - - data.add(new Param(rowIndex, true, false)); - data.add(new Param(rowIndex, true, true)); - } - - return data; - } - - @Before - public void setUp() { - setDebug(true); - } - - @Test - public void toggleAndScroll() throws Throwable { - for (Param param : parameters()) { - try { - openTestURL(); - useGenerator(param.useGenerator()); - scrollToBottom(param.scrollFirstToBottom()); - - // the tested method - toggleAndScroll(param.getRowIndex()); - - verifyLocation(param); - } catch (Throwable t) { - throw new Throwable("" + param, t); - } - } - } - - @Test - public void scrollAndToggle() throws Throwable { - for (Param param : parameters()) { - try { - openTestURL(); - useGenerator(param.useGenerator()); - scrollToBottom(param.scrollFirstToBottom()); - - // the tested method - scrollAndToggle(param.getRowIndex()); - - verifyLocation(param); - - } catch (Throwable t) { - throw new Throwable("" + param, t); - } - } - } - - @Test - public void testDetailsHeightWithGenerator() { - openTestURL(); - useGenerator(true); - toggleAndScroll(5); - - verifyDetailsRowHeight(5, detailsDefinedHeight, 0); - verifyDetailsDecoratorLocation(5, 0, 0); - - toggleAndScroll(0); - - verifyDetailsRowHeight(0, detailsDefinedHeight, 0); - // decorator elements are in DOM in the order they have been added - verifyDetailsDecoratorLocation(0, 0, 1); - - verifyDetailsRowHeight(5, detailsDefinedHeight, 1); - verifyDetailsDecoratorLocation(5, 1, 0); - } - - private void verifyDetailsRowHeight(int rowIndex, int expectedHeight, - int visibleIndexOfSpacer) { - waitForDetailsVisible(); - WebElement details = getDetailsElement(visibleIndexOfSpacer); - Assert.assertEquals("Wrong details row height", expectedHeight, - details.getSize().getHeight()); - } - - private void verifyDetailsDecoratorLocation(int row, - int visibleIndexOfSpacer, int visibleIndexOfDeco) { - WebElement detailsElement = getDetailsElement(visibleIndexOfSpacer); - WebElement detailsDecoElement = getDetailsDecoElement( - visibleIndexOfDeco); - GridRowElement rowElement = getGrid().getRow(row); - - Assert.assertEquals( - "Details deco top position does not match row top pos", - rowElement.getLocation().getY(), - detailsDecoElement.getLocation().getY()); - Assert.assertEquals( - "Details deco bottom position does not match details bottom pos", - detailsElement.getLocation().getY() - + detailsElement.getSize().getHeight(), - detailsDecoElement.getLocation().getY() - + detailsDecoElement.getSize().getHeight()); - } - - private void verifyLocation(Param param) { - Assert.assertFalse("Notification was present", - isElementPresent(By.className("v-Notification"))); - - TestBenchElement headerRow = getGrid().getHeaderRow(0); - final int topBoundary = headerRow.getLocation().getX() - + headerRow.getSize().height; - final int bottomBoundary = getGrid().getLocation().getX() - + getGrid().getSize().getHeight() - - getHorizontalScrollbar().getSize().height; - - GridRowElement row = getGrid().getRow(param.getRowIndex()); - final int rowTop = row.getLocation().getX(); - - waitForDetailsVisible(); - WebElement details = getDetailsElement(); - final int detailsBottom = details.getLocation().getX() - + details.getSize().getHeight(); - - assertGreaterOrEqual("Row top should be inside grid, gridTop:" - + topBoundary + " rowTop" + rowTop, topBoundary, rowTop); - assertLessThanOrEqual( - "Decorator bottom should be inside grid, gridBottom:" - + bottomBoundary + " decoratorBotton:" + detailsBottom, - detailsBottom, bottomBoundary); - - verifyDetailsRowHeight(param.getRowIndex(), param.useGenerator() - ? detailsDefinedHeight : detailsDefaultHeight, 0); - verifyDetailsDecoratorLocation(param.getRowIndex(), 0, 0); - - Assert.assertFalse("Notification was present", - isElementPresent(By.className("v-Notification"))); - } - - private final By locator = By.className("v-grid-spacer"); - - private WebElement getDetailsElement() { - return getDetailsElement(0); - } - - private WebElement getDetailsElement(int index) { - return findElements(locator).get(index); - } - - private WebElement getDetailsDecoElement(int index) { - return findElements(By.className("v-grid-spacer-deco")).get(index); - } - - private void waitForDetailsVisible() { - waitUntil(new ExpectedCondition() { - - @Override - public WebElement apply(WebDriver driver) { - try { - WebElement detailsElement = getDetailsElement(); - return detailsElement.isDisplayed() - && detailsElement.getSize().getHeight() > 3 - ? detailsElement : null; - } catch (StaleElementReferenceException e) { - return null; - } - } - - @Override - public String toString() { - return "visibility of element located by " + locator; - } - - }, 5); - waitForElementVisible(By.className("v-grid-spacer")); - } - - private void scrollToBottom(boolean scrollFirstToBottom) { - if (scrollFirstToBottom) { - executeScript("arguments[0].scrollTop = 9999999", - getVerticalScrollbar()); - } - } - - private void useGenerator(boolean use) { - CheckBoxElement checkBox = $(CheckBoxElement.class).first(); - boolean isChecked = isCheckedValo(checkBox); - if (use != isChecked) { - clickValo(checkBox); - } - } - - @SuppressWarnings("boxing") - private boolean isCheckedValo(CheckBoxElement checkBoxElement) { - WebElement checkbox = checkBoxElement.findElement(By.tagName("input")); - Object value = executeScript("return arguments[0].checked;", checkbox); - return (Boolean) value; - } - - private void clickValo(CheckBoxElement checkBoxElement) { - checkBoxElement.click(5, 5); - } - - private void scrollAndToggle(int row) { - setRow(row); - getScrollAndToggle().click(); - } - - private void toggleAndScroll(int row) { - setRow(row); - getToggleAndScroll().click(); - } - - private ButtonElement getScrollAndToggle() { - return $(ButtonElement.class).caption("Scroll and toggle").first(); - } - - private ButtonElement getToggleAndScroll() { - return $(ButtonElement.class).caption("Toggle and scroll").first(); - } - - private void setRow(int row) { - $(TextFieldElement.class).first().clear(); - $(TextFieldElement.class).first().sendKeys(String.valueOf(row), - Keys.ENTER, Keys.TAB); - } - - private GridElement getGrid() { - return $(GridElement.class).first(); - } - - private WebElement getVerticalScrollbar() { - WebElement scrollBar = getGrid() - .findElement(By.className("v-grid-scroller-vertical")); - return scrollBar; - } - - private WebElement getHorizontalScrollbar() { - WebElement scrollBar = getGrid() - .findElement(By.className("v-grid-scroller-horizontal")); - return scrollBar; - } -} \ No newline at end of file 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 deleted file mode 100644 index d2e078db8c..0000000000 --- a/uitest/src/test/java/com/vaadin/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.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.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@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()); - - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDisabledMultiselectTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDisabledMultiselectTest.java deleted file mode 100644 index d3383cbf44..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDisabledMultiselectTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.vaadin.tests.components.grid; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class GridDisabledMultiselectTest extends MultiBrowserTest { - - @Override - public void setup() throws Exception { - super.setup(); - - openTestURL(); - } - - private void disable() { - $(ButtonElement.class).caption("Disable").first().click(); - } - - private void setMultiselect() { - $(ButtonElement.class).caption("Multi").first().click(); - } - - private WebElement getSelectAllCheckBox() { - return findCheckBoxes().get(0); - } - - private List findCheckBoxes() { - return findElements(By.cssSelector("span input")); - } - - private WebElement getFirstSelectCheckBox() { - return findCheckBoxes().get(1); - } - - @Test - public void checkBoxesAreDisabledAfterModeChange() { - disable(); - - setMultiselect(); - - assertThat(getSelectAllCheckBox().isEnabled(), is(false)); - assertThat(getFirstSelectCheckBox().isEnabled(), is(false)); - } - - @Test - public void checkBoxesAreDisabledAfterDisabled() { - setMultiselect(); - - assertThat(getSelectAllCheckBox().isEnabled(), is(true)); - assertThat(getFirstSelectCheckBox().isEnabled(), is(true)); - - disable(); - - assertThat(getSelectAllCheckBox().isEnabled(), is(false)); - assertThat(getFirstSelectCheckBox().isEnabled(), is(false)); - } - - @Test - public void parentSpanCannotBeClickedWhenDisabled() { - setMultiselect(); - disable(); - - WebElement firstCheckBoxSpan = findElements(By.cssSelector("span")) - .get(1); - new Actions(driver).moveToElement(firstCheckBoxSpan, 1, 1).click() - .perform(); - - assertThat(getFirstSelectCheckBox().isSelected(), is(false)); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java deleted file mode 100644 index 5ecd1d4d88..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDisabledSideBarTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.vaadin.tests.components.grid; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.By; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -public class GridDisabledSideBarTest extends GridBasicClientFeaturesTest { - - @Override - public void setup() throws Exception { - super.setup(); - - openTestURL(); - } - - private void makeColumnHidable() { - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - } - - private void toggleSideBarMenuAndDisable() { - selectMenuPath("Component", "Sidebar", "Open sidebar and disable grid"); - waitUntil(new ExpectedCondition() { - - @Override - public Boolean apply(WebDriver input) { - return !findElement(By.className("v-grid-sidebar-button")) - .isEnabled(); - } - }); - } - - private void clickSideBarButton() { - findElement(By.cssSelector(".v-grid-sidebar-button")).click(); - } - - private void toggleEnabled() { - selectMenuPath("Component", "State", "Enabled"); - } - - private void assertSideBarContainsClass(String cssClass) { - assertThat(findElement(By.cssSelector(".v-grid-sidebar")) - .getAttribute("class"), containsString(cssClass)); - } - - @Test - public void sidebarButtonIsDisabledOnCreation() { - selectMenuPath("Component", "State", "Enabled"); - makeColumnHidable(); - - clickSideBarButton(); - - assertSideBarContainsClass("closed"); - } - - @Test - public void sidebarButtonCanBeEnabled() { - makeColumnHidable(); - - clickSideBarButton(); - - assertSideBarContainsClass("open"); - } - - @Test - public void sidebarButtonCanBeDisabled() { - makeColumnHidable(); - toggleEnabled(); - - clickSideBarButton(); - - assertSideBarContainsClass("closed"); - } - - @Test - public void sidebarIsClosedOnDisable() { - makeColumnHidable(); - - toggleSideBarMenuAndDisable(); - - assertSideBarContainsClass("closed"); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java deleted file mode 100644 index e747fe034e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDragSelectionWhileScrolledTest.java +++ /dev/null @@ -1,61 +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.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridDragSelectionWhileScrolledTest extends MultiBrowserTest { - - @Override - protected boolean requireWindowFocusForIE() { - return true; - } - - @Test - public void testDragSelect() throws IOException { - openTestURL(); - - // Scroll grid to view - GridElement grid = $(GridElement.class).first(); - ((JavascriptExecutor) getDriver()) - .executeScript("arguments[0].scrollIntoView(true);", grid); - - // Drag select 2 rows - new Actions(getDriver()).moveToElement(grid.getCell(3, 0), 5, 5) - .clickAndHold().moveToElement(grid.getCell(2, 0), 5, 5) - .release().perform(); - - // Assert only those are selected. - assertTrue("Row 3 should be selected", grid.getRow(3).isSelected()); - assertTrue("Row 2 should be selected", grid.getRow(2).isSelected()); - assertFalse("Row 4 should not be selected", - grid.getRow(4).isSelected()); - assertFalse("Row 1 should not be selected", - grid.getRow(1).isSelected()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java deleted file mode 100644 index 37cb978ffc..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java +++ /dev/null @@ -1,38 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridEditingWithNoScrollBarsTest extends MultiBrowserTest { - - @Test - public void testEditorWideEnough() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - grid.getCell(1, 1).doubleClick(); - assertEquals(grid.getEditor().getSize().width, - grid.getTableWrapper().getSize().width); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorConverterNotFoundTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorConverterNotFoundTest.java deleted file mode 100644 index abe96c61b9..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorConverterNotFoundTest.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.tests.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridEditorConverterNotFoundTest extends GridBasicFeaturesTest { - - @Override - protected Class getUIClass() { - // Use the correct UI with helpers from GridBasicFeatures - return GridEditorConverterNotFound.class; - } - - @Test - public void testConverterNotFound() { - openTestURL(); - - $(GridElement.class).first().getCell(0, 0).doubleClick(); - - assertEquals("1. com.vaadin.v7.data.Buffered$SourceException", - getLogRow(0)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java deleted file mode 100644 index de6156bd42..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.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.tests.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.ComboBoxElement; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridEditorCustomFieldTest extends MultiBrowserTest { - - @Test - public void testCustomFieldWorksInEditorRow() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - Assert.assertEquals("Stockholm", grid.getCell(0, 2).getText()); - grid.getCell(0, 1).doubleClick(); - GridEditorElement editor = grid.getEditor(); - TestBenchElement customField = editor.getField(2); - - ComboBoxElement comboBox = customField.$(ComboBoxElement.class).first(); - comboBox.selectByText("Oslo"); - editor.save(); - Assert.assertEquals("Oslo", grid.getCell(0, 2).getText()); - - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java deleted file mode 100644 index 21dad915eb..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java +++ /dev/null @@ -1,77 +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.components.grid; - -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridEditorFrozenColumnsUITest extends MultiBrowserTest { - - @Test - public void testEditorWithFrozenColumns() throws IOException { - openTestURL(); - - openEditor(10); - - compareScreen("noscroll"); - - scrollGridHorizontallyTo(100); - - compareScreen("scrolled"); - } - - private void openEditor(int rowIndex) { - GridElement grid = $(GridElement.class).first(); - - GridCellElement cell = grid.getCell(rowIndex, 1); - - new Actions(driver).moveToElement(cell).doubleClick().build().perform(); - } - - private void scrollGridHorizontallyTo(double px) { - executeScript("arguments[0].scrollLeft = " + px, - getGridHorizontalScrollbar()); - } - - private Object executeScript(String script, WebElement element) { - final WebDriver driver = getDriver(); - if (driver instanceof JavascriptExecutor) { - final JavascriptExecutor je = (JavascriptExecutor) driver; - return je.executeScript(script, element); - } else { - throw new IllegalStateException("current driver " - + getDriver().getClass().getName() + " is not a " - + JavascriptExecutor.class.getSimpleName()); - } - } - - private WebElement getGridHorizontalScrollbar() { - return getDriver().findElement(By.xpath( - "//div[contains(@class, \"v-grid-scroller-horizontal\")]")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorMultiselectTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorMultiselectTest.java deleted file mode 100644 index a66cf2fb9c..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorMultiselectTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.vaadin.tests.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridEditorMultiselectTest extends MultiBrowserTest { - - @Test - public void testSelectCheckboxesDisabled() { - openTestURL(); - GridElement grid = openEditor(); - assertCheckboxesEnabled(grid, false); - } - - @Test - public void testSelectCheckboxesEnabledBackOnSave() { - openTestURL(); - GridElement grid = openEditor(); - grid.getEditor().save(); - assertCheckboxesEnabled(grid, true); - } - - @Test - public void testSelectCheckboxesEnabledBackOnCancel() { - openTestURL(); - GridElement grid = openEditor(); - grid.getEditor().cancel(); - assertCheckboxesEnabled(grid, true); - } - - private GridElement openEditor() { - GridElement grid = $(GridElement.class).first(); - grid.getRow(0).doubleClick(); - Assert.assertTrue("Grid editor should be displayed.", - grid.getEditor().isDisplayed()); - return grid; - } - - private void assertCheckboxesEnabled(GridElement grid, boolean isEnabled) { - List checkboxes = grid - .findElements(By.xpath("//input[@type='checkbox']")); - for (WebElement checkbox : checkboxes) { - Assert.assertEquals( - "Select checkboxes should be " - + (isEnabled ? "enabled" : "disabled"), - isEnabled, checkbox.isEnabled()); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorUITest.java deleted file mode 100644 index de80c5fcc5..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorUITest.java +++ /dev/null @@ -1,96 +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.components.grid; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.PasswordFieldElement; - -@TestCategory("grid") -public class GridEditorUITest extends MultiBrowserTest { - - @Override - public void setup() throws Exception { - super.setup(); - - setDebug(true); - openTestURL(); - } - - private void openEditor(int rowIndex) { - GridElement grid = $(GridElement.class).first(); - - GridCellElement cell = grid.getCell(rowIndex, 1); - - new Actions(driver).moveToElement(cell).doubleClick().build().perform(); - } - - private void saveEditor() { - findElement(By.cssSelector(".v-grid-editor-save")).click(); - } - - private GridCellElement getHeaderCell(int rowIndex, int colIndex) { - GridElement grid = $(GridElement.class).first(); - - GridCellElement headerCell = grid.getHeaderCell(rowIndex, colIndex); - - return headerCell; - } - - @Test - public void testEditor() { - assertFalse("Sanity check", - isElementPresent(PasswordFieldElement.class)); - - openEditor(5); - new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); - - openEditor(10); - - assertTrue("Editor should be opened with a password field", - isElementPresent(PasswordFieldElement.class)); - - assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - } - - @Test - public void savingResetsSortingIndicator() { - GridCellElement headerCell = getHeaderCell(0, 0); - headerCell.click(); - - openEditor(1); - - saveEditor(); - - assertThat(headerCell.getAttribute("class"), - not(containsString("sort-"))); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridExtensionCommunicationTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridExtensionCommunicationTest.java deleted file mode 100644 index fed6083b25..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridExtensionCommunicationTest.java +++ /dev/null @@ -1,47 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridExtensionCommunicationTest extends SingleBrowserTest { - - @Test - public void testMouseClickIsSentToExtension() { - openTestURL(); - - GridCellElement cell = $(GridElement.class).first().getCell(0, 4); - cell.click(5, 5); - - int expectedX = cell.getLocation().getX() + 5; - int expectedY = cell.getLocation().getY() + 5; - - assertEquals( - "1. Click on Person Nina Brown on column Column[propertyId:gender]", - getLogRow(1)); - assertEquals("2. MouseEventDetails: left (" + expectedX + ", " - + expectedY + ")", getLogRow(0)); - - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridGeneratedPropertiesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridGeneratedPropertiesTest.java deleted file mode 100644 index 6298153999..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridGeneratedPropertiesTest.java +++ /dev/null @@ -1,90 +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.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridGeneratedPropertiesTest extends MultiBrowserTest { - - @Test - public void testMilesColumnExists() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - assertEquals("Miles header wasn't present.", "miles", - grid.getHeaderCell(0, 2).getText().toLowerCase()); - } - - @Test - public void testUnsortableGeneratedProperty() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Overwritten foo property should not be sortable - GridCellElement fooHeader = grid.getHeaderCell(0, 0); - fooHeader.click(); - assertFalse("Column foo was unexpectedly sorted.", - fooHeader.getAttribute("class").contains("sort")); - - // Generated property miles is not sortable - GridCellElement milesHeader = grid.getHeaderCell(0, 2); - milesHeader.click(); - assertFalse("Column miles was unexpectedly sorted.", - milesHeader.getAttribute("class").contains("sort")); - } - - @Test - public void testSortableGeneratedProperty() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Generated property baz is sortable - GridCellElement bazHeader = grid.getHeaderCell(0, 3); - bazHeader.click(); - assertTrue("Column baz was not sorted ascending", - bazHeader.getAttribute("class").contains("sort-asc")); - bazHeader.click(); - assertTrue("Column baz was not sorted descending", - bazHeader.getAttribute("class").contains("sort-desc")); - } - - @Test - public void testInitialSorting() { - // Grid is sorted in this case by one visible and one nonexistent - // column. There should be no sort indicator. - setDebug(true); - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - GridCellElement kmHeader = grid.getHeaderCell(0, 1); - assertFalse("Column km was unexpectedly sorted", - kmHeader.getAttribute("class").contains("sort-asc") || kmHeader - .getAttribute("class").contains("sort-desc")); - assertFalse("Unexpected client-side exception was visible", - isElementPresent(NotificationElement.class)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java deleted file mode 100644 index 3b5c33c956..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java +++ /dev/null @@ -1,138 +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.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridHeaderFooterComponentsTest extends SingleBrowserTest { - - @Before - public void setUp() { - setDebug(true); - - openTestURL(); - } - - @Test - public void hideAndShowComponentsInHeader() { - GridElement grid = $(GridElement.class).first(); - - int filterRow = 2; - Assert.assertNull(getHeaderElement(grid, filterRow, 1)); - Assert.assertNotNull(getHeaderElement(grid, filterRow, 2)); - Assert.assertNotNull(getHeaderElement(grid, filterRow, 3)); - - // Show (1,2) - grid.getHeaderCell(1, 1).$(ButtonElement.class).first().click(); - - TextFieldElement textfield = getHeaderElement(grid, filterRow, 1); - Assert.assertNotNull(textfield); - Assert.assertEquals("Filter: string", textfield.getValue()); - - textfield.setValue("foo"); - Assert.assertEquals("1. value change for field in string to foo", - getLogRow(0)); - - assertNoErrorNotifications(); - } - - private TextFieldElement getHeaderElement(GridElement grid, int row, - int col) { - GridCellElement cell = grid.getHeaderCell(row, col); - List all = cell.$(TextFieldElement.class).all(); - if (all.size() == 0) { - return null; - } else if (all.size() == 1) { - return all.get(0); - } else { - throw new RuntimeException( - "Multiple elements found in the header cell at " + row + "," - + col); - } - } - - @Test - public void hideAndShowComponentsInFooter() { - GridElement grid = $(GridElement.class).first(); - - int filterRow = 0; - Assert.assertNull(getFooterElement(grid, filterRow, 1)); - Assert.assertNotNull(getFooterElement(grid, filterRow, 2)); - Assert.assertNotNull(getFooterElement(grid, filterRow, 3)); - - // Show (1,2) - grid.getFooterCell(1, 1).$(ButtonElement.class).first().click(); - - TextFieldElement textfield = getFooterElement(grid, filterRow, 1); - Assert.assertNotNull(textfield); - Assert.assertEquals("Filter: string", textfield.getValue()); - - textfield.setValue("foo"); - Assert.assertEquals("1. value change for field in string to foo", - getLogRow(0)); - - assertNoErrorNotifications(); - } - - private TextFieldElement getFooterElement(GridElement grid, int row, - int col) { - GridCellElement cell = grid.getFooterCell(row, col); - List all = cell.$(TextFieldElement.class).all(); - if (all.size() == 0) { - return null; - } else if (all.size() == 1) { - return all.get(0); - } else { - throw new RuntimeException( - "Multiple elements found in the footer cell at " + row + "," - + col); - } - } - - @Test - public void testRemoveAllHeadersAndFooters() { - openTestURL(); - - for (int i = 2; i >= 0; --i) { - // Remove Header - $(GridElement.class).first().getHeaderCell(i, 0) - .$(ButtonElement.class).first().click(); - Assert.assertFalse("Header " + i + " should not be present.", - $(GridElement.class).first() - .isElementPresent(By.vaadin("#header[" + i + "]"))); - - // Remove Footer - $(GridElement.class).first().getFooterCell(i, 0) - .$(ButtonElement.class).first().click(); - Assert.assertFalse("Footer " + i + " should not be present.", - $(GridElement.class).first() - .isElementPresent(By.vaadin("#footer[" + i + "]"))); - } - - assertNoErrorNotifications(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java deleted file mode 100644 index 59d53c5a26..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java +++ /dev/null @@ -1,151 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridHeaderFormatChangeTest extends MultiBrowserTest { - - @Test - public void testHeaderRetainsSelectAllForColumnRemoval() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Assert that we do not have the select all checkbox - Assert.assertTrue( - "Found input in header even though none should exist.", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // Set grid into multiselection mode - toggleSelectionMode(); - - // Assert that we now have a select all checkbox in the header - Assert.assertFalse("Expected one input field in header", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // Hide the firstName column from the grid. - toggleFirstName(); - - // Assert that we still have the select all checkbox in the header. - Assert.assertFalse("Header was missing checkbox after hiding column", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // Show the firstName column. - toggleFirstName(); - - // Assert that we still have the select all checkbox in the header. - Assert.assertFalse( - "Header was missing checkbox after bringing back column", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - } - - @Test - public void testHeaderRetainsSelectAllForJoinColumnAdd() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Assert that we do not have the select all checkbox - Assert.assertTrue( - "Found input in header even though none should exist.", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // Set grid into multiselection mode - toggleSelectionMode(); - - // Assert that we now have a select all checkbox in the header - Assert.assertFalse("Expected one input field in header", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // Add Join columns header - toggleJoin(); - - // Assert that we still have the select all checkbox in the header. - Assert.assertFalse("Header was missing checkbox after hiding column", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // remove Join Columns header - toggleJoin(); - - // Assert that we still have the select all checkbox in the header. - Assert.assertFalse( - "Header was missing checkbox after bringing back column", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - } - - @Test - public void selectAllShouldKeepState() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - - // Assert that we do not have the select all checkbox - Assert.assertTrue( - "Found input in header even though none should exist.", - grid.getHeader().findElements(By.tagName("input")).isEmpty()); - - // Set grid into multiselection mode - toggleSelectionMode(); - - // Assert that we now have a select all checkbox in the header - Assert.assertFalse("Should not be selected after adding", - grid.getHeader().findElement(By.tagName("input")).isSelected()); - - grid.getHeader().findElement(By.tagName("input")).click(); - - // Assert that checkbox is checked - assertSelectAllChecked( - "Not selected even though we just clicked selection", grid); - - // Hide the firstName column from the grid. - toggleFirstName(); - - // Assert that checkbox is still checked - assertSelectAllChecked("Selection disappeared after removing column", - grid); - - // Show the firstName column. - toggleFirstName(); - - // Assert that checkbox is still checked - assertSelectAllChecked("Selection disappeared after adding column", - grid); - - } - - private void assertSelectAllChecked(String message, GridElement grid) { - Assert.assertTrue(message, - grid.getHeader().findElement(By.tagName("input")).isSelected()); - } - - private void toggleSelectionMode() { - $(ButtonElement.class).id("selection_mode").click(); - } - - private void toggleFirstName() { - $(ButtonElement.class).id("show_hide").click(); - } - - private void toggleJoin() { - $(ButtonElement.class).id("join").click(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java deleted file mode 100644 index be9cfc1356..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderStyleNamesTest.java +++ /dev/null @@ -1,174 +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.components.grid; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridHeaderStyleNamesTest extends SingleBrowserTest { - - private GridElement grid; - - @Before - public void findGridCells() { - openTestURL(); - grid = $(GridElement.class).first(); - } - - private GridCellElement getMergedHeaderCell() { - return grid.getHeaderCell(0, 3); - } - - private WebElement getMergedHeaderCellContent() { - return getMergedHeaderCell().findElement( - By.cssSelector("div.v-grid-column-header-content")); - } - - private GridCellElement getAgeFooterCell() { - return grid.getFooterCell(0, 2); - } - - private WebElement getAgeFooterCellContent() { - return getAgeFooterCell().findElement( - By.cssSelector("div.v-grid-column-footer-content")); - } - - @Test - public void cellStyleNamesCanBeAddedAndRemoved() { - ButtonElement toggleStyles = $(ButtonElement.class) - .caption("Toggle styles").first(); - - assertStylesSet(true); - toggleStyles.click(); - assertStylesSet(false); - toggleStyles.click(); - assertStylesSet(true); - } - - @Test - public void rowStyleNamesCanBeAddedAndRemoved() { - ButtonElement toggleStyles = $(ButtonElement.class) - .caption("Toggle styles").first(); - - assertRowStylesSet(true); - toggleStyles.click(); - assertRowStylesSet(false); - toggleStyles.click(); - assertRowStylesSet(true); - - } - - private void assertStylesSet(boolean set) { - if (set) { - assertHasStyleName( - "Footer cell should have the assigned 'age-footer' class name", - getAgeFooterCell(), "age-footer"); - assertHasStyleName( - "Header cell should have the assigned 'age' class name", - getAgeHeaderCell(), "age"); - assertHasStyleName( - "The merged header cell should have the assigned 'city-country' class name", - getMergedHeaderCell(), "city-country"); - } else { - assertHasNotStyleName( - "Footer cell should not have the removed 'age-footer' class name", - getAgeFooterCell(), "age-footer"); - assertHasNotStyleName( - "Header cell should not have the removed 'age' class name", - getAgeHeaderCell(), "age"); - assertHasNotStyleName( - "Ther merged header cell should not have the removed 'city-country' class name", - getMergedHeaderCell(), "city-country"); - } - assertHasStyleName( - "The default v-grid-cell style name should not be removed from the header cell", - getAgeHeaderCell(), "v-grid-cell"); - assertHasStyleName( - "The default v-grid-cell style name should not be removed from the footer cell", - getAgeFooterCell(), "v-grid-cell"); - assertHasStyleName( - "The default v-grid-cell style name should not be removed from the merged header cell", - getMergedHeaderCell(), "v-grid-cell"); - - } - - private void assertRowStylesSet(boolean set) { - if (set) { - assertHasStyleName( - "Footer row should have the assigned 'custom-row' class name", - getFooterRow(), "custom-row"); - assertHasStyleName( - "Header row should have the assigned 'custom-row' class name", - getHeaderRow(), "custom-row"); - } else { - assertHasNotStyleName( - "Footer row should not have the removed 'custom-row' class name", - getFooterRow(), "custom-row"); - assertHasNotStyleName( - "Header row should not have the removed 'custom-row' class name", - getHeaderRow(), "custom-row"); - } - assertHasStyleName( - "The default v-grid-row style name should not be removed from the header row", - getHeaderRow(), "v-grid-row"); - assertHasStyleName( - "The default v-grid-row style name should not be removed from the footer row", - getFooterRow(), "v-grid-row"); - - } - - private WebElement getAgeHeaderCell() { - return grid.getHeaderCell(1, 2); - } - - private WebElement getAgeHeaderCellContent() { - return getAgeHeaderCell().findElement( - By.cssSelector("div.v-grid-column-header-content")); - } - - private WebElement getFooterRow() { - return grid.getFooterRow(0); - } - - private WebElement getHeaderRow() { - return grid.getHeaderRow(0); - } - - private void assertHasStyleName(String message, WebElement element, - String stylename) { - if (!hasCssClass(element, stylename)) { - Assert.fail(message); - } - } - - private void assertHasNotStyleName(String message, WebElement element, - String stylename) { - if (hasCssClass(element, stylename)) { - Assert.fail(message); - } - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeightTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeightTest.java deleted file mode 100644 index ad293fe385..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridHeightTest.java +++ /dev/null @@ -1,176 +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.components.grid; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.number.IsCloseTo.closeTo; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.OptionGroupElement; - -/** - * Tests that Grid gets correct height based on height mode, and resizes - * properly with details row if height is undefined. - * - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridHeightTest extends MultiBrowserTest { - - @Override - public void setup() throws Exception { - super.setup(); - openTestURL(); - waitForElementPresent(By.className("v-grid")); - } - - @Test - public void testGridHeightAndResizingUndefined() - throws InterruptedException { - assertNoErrors(testGridHeightAndResizing(GridHeight.UNDEFINED)); - } - - @Test - public void testGridHeightAndResizingRow() throws InterruptedException { - assertNoErrors(testGridHeightAndResizing(GridHeight.ROW3)); - } - - @Test - public void testGridHeightAndResizingFull() throws InterruptedException { - assertNoErrors(testGridHeightAndResizing(GridHeight.FULL)); - } - - private Map testGridHeightAndResizing( - Object gridHeight) throws InterruptedException { - Map errors = new HashMap(); - String caption; - if (GridHeight.ROW3.equals(gridHeight)) { - caption = gridHeight + " rows"; - } else { - caption = (String) gridHeight; - } - $(OptionGroupElement.class).id("gridHeightSelector") - .selectByText(caption); - for (String gridWidth : GridHeight.gridWidths) { - $(OptionGroupElement.class).id("gridWidthSelector") - .selectByText(gridWidth); - for (String detailsRowHeight : GridHeight.detailsRowHeights) { - $(OptionGroupElement.class).id("detailsHeightSelector") - .selectByText(detailsRowHeight); - sleep(500); - - GridElement grid = $(GridElement.class).first(); - int initialHeight = grid.getSize().getHeight(); - try { - // check default height - assertGridHeight(getExpectedInitialHeight(gridHeight), - initialHeight); - } catch (AssertionError e) { - errors.put(e, new Object[] { gridHeight, gridWidth, - detailsRowHeight, "initial" }); - } - - grid.getRow(2).click(5, 5); - waitForElementPresent(By.id("lbl1")); - - int openHeight = grid.getSize().getHeight(); - try { - // check height with details row opened - assertGridHeight(getExpectedOpenedHeight(gridHeight, - detailsRowHeight), openHeight); - } catch (AssertionError e) { - errors.put(e, new Object[] { gridHeight, gridWidth, - detailsRowHeight, "opened" }); - } - - grid.getRow(2).click(5, 5); - waitForElementNotPresent(By.id("lbl1")); - - int afterHeight = grid.getSize().getHeight(); - try { - // check height with details row closed again - assertThat("Unexpected Grid Height", afterHeight, - is(initialHeight)); - } catch (AssertionError e) { - errors.put(e, new Object[] { gridHeight, gridWidth, - detailsRowHeight, "closed" }); - } - } - } - return errors; - } - - private void assertNoErrors(Map errors) { - if (!errors.isEmpty()) { - StringBuilder sb = new StringBuilder("Exceptions: "); - for (Entry entry : errors.entrySet()) { - sb.append("\n"); - for (Object value : entry.getValue()) { - sb.append(value); - sb.append(" - "); - } - sb.append(entry.getKey().getMessage()); - } - Assert.fail(sb.toString()); - } - } - - private int getExpectedInitialHeight(Object gridHeight) { - int result = 0; - if (GridHeight.UNDEFINED.equals(gridHeight) - || GridHeight.ROW3.equals(gridHeight)) { - result = 81; - } else if (GridHeight.FULL.equals(gridHeight)) { - // pre-existing issue - result = 400; - } - return result; - } - - private int getExpectedOpenedHeight(Object gridHeight, - Object detailsRowHeight) { - int result = 0; - if (GridHeight.UNDEFINED.equals(gridHeight)) { - if (GridHeight.PX100.equals(detailsRowHeight)) { - result = 182; - } else if (GridHeight.FULL.equals(detailsRowHeight)) { - result = 131; - } else if (GridHeight.UNDEFINED.equals(detailsRowHeight)) { - result = 100; - } - } else if (GridHeight.ROW3.equals(gridHeight) - || GridHeight.FULL.equals(gridHeight)) { - result = getExpectedInitialHeight(gridHeight); - } - return result; - } - - private void assertGridHeight(int expected, int actual) { - assertThat("Unexpected Grid Height", (double) actual, - closeTo(expected, 1)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.java deleted file mode 100644 index 9aba286c5a..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInTabSheetTest.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.tests.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.elements.TabSheetElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridInTabSheetTest extends MultiBrowserTest { - - @Test - public void testRemoveAllRowsAndAddThreeNewOnes() { - setDebug(true); - openTestURL(); - - for (int i = 0; i < 3; ++i) { - removeGridRow(); - } - - for (int i = 0; i < 3; ++i) { - addGridRow(); - assertEquals("" + (100 + i), - getGridElement().getCell(i, 1).getText()); - } - - assertNoNotification(); - } - - private void assertNoNotification() { - assertFalse("There was an unexpected error notification", - isElementPresent(NotificationElement.class)); - } - - @Test - public void testAddManyRowsWhenGridIsHidden() { - setDebug(true); - openTestURL(); - - TabSheetElement tabsheet = $(TabSheetElement.class).first(); - tabsheet.openTab("Label"); - for (int i = 0; i < 50; ++i) { - addGridRow(); - } - - tabsheet.openTab("Grid"); - - assertNoNotification(); - } - - @Test - public void testAddCellStyleGeneratorWhenGridIsHidden() { - setDebug(true); - openTestURL(); - - TabSheetElement tabsheet = $(TabSheetElement.class).first(); - tabsheet.openTab("Label"); - addCellStyleGenerator(); - - tabsheet.openTab("Grid"); - - assertNoNotification(); - } - - private void removeGridRow() { - $(ButtonElement.class).caption("Remove row from Grid").first().click(); - } - - private void addGridRow() { - $(ButtonElement.class).caption("Add row to Grid").first().click(); - } - - private void addCellStyleGenerator() { - $(ButtonElement.class).caption("Add CellStyleGenerator").first() - .click(); - } - - private GridElement getGridElement() { - return $(GridElement.class).first(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInWindowResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridInWindowResizeTest.java deleted file mode 100644 index 570ca4a5a7..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInWindowResizeTest.java +++ /dev/null @@ -1,48 +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.components.grid; - -import java.util.Collections; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.Browser; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridInWindowResizeTest extends MultiBrowserTest { - @Override - public List getBrowsersToTest() { - // Must test on a browser with animations - return Collections - .singletonList(Browser.CHROME.getDesiredCapabilities()); - } - - @Test - public void resizeWindow() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - int col1WidthBefore = grid.getCell(0, 0).getSize().getWidth(); - $(ButtonElement.class).caption("resize").first().click(); - int col1WidthAfter = grid.getCell(0, 0).getSize().getWidth(); - - Assert.assertTrue(col1WidthAfter < col1WidthBefore); - } -} 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 deleted file mode 100644 index 1e370b7e8c..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridInitiallyHiddenColumnsTest.java +++ /dev/null @@ -1,84 +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.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.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest { - - @Test - public void ensureCorrectlyRendered() { - openTestURL("debug"); - GridElement grid = $(GridElement.class).first(); - Assert.assertEquals("Rowling", grid.getCell(0, 0).getText()); - Assert.assertEquals("Scott", grid.getCell(1, 0).getText()); - - getSidebarOpenButton(grid).click(); - getColumnHidingToggle(grid, "First 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("25", grid.getCell(0, 2).getText()); - Assert.assertEquals("Dan", grid.getCell(1, 0).getText()); - Assert.assertEquals("Scott", grid.getCell(1, 1).getText()); - Assert.assertEquals("54", grid.getCell(1, 2).getText()); - - } - - // TODO: as to the getX methods reuse ones from GridBasicFeaturesTest? - - protected WebElement getSidebarOpenButton(GridElement grid) { - List elements = grid - .findElements(By.className("v-grid-sidebar-button")); - return elements.isEmpty() ? null : elements.get(0); - } - - /** - * Returns the toggle inside the sidebar for hiding the column at the given - * index, or null if not found. - */ - protected WebElement getColumnHidingToggle(GridElement grid, - String caption) { - WebElement sidebar = getSidebar(grid); - List elements = sidebar - .findElements(By.className("column-hiding-toggle")); - for (WebElement e : elements) { - if (caption.equalsIgnoreCase(e.getText())) { - return e; - } - } - return null; - } - - protected WebElement getSidebar(GridElement grid) { - List elements = findElements( - By.className("v-grid-sidebar-popup")); - return elements.isEmpty() ? null : elements.get(0); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridItemSetChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridItemSetChangeTest.java deleted file mode 100644 index 4eafd5f13d..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridItemSetChangeTest.java +++ /dev/null @@ -1,48 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridItemSetChangeTest extends SingleBrowserTest { - - @Test - public void testValueChangeListenersWorkAfterItemSetChange() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - assertEquals("Last name initially wrong", "Bar", - grid.getCell(0, 1).getText()); - - $(ButtonElement.class).caption("Modify").first().click(); - assertEquals("Last name was not updated", "Spam", - grid.getCell(0, 1).getText()); - - $(ButtonElement.class).caption("Reset").first().click(); - assertEquals("Last name was not updated on reset", "Baz", - grid.getCell(0, 1).getText()); - - $(ButtonElement.class).caption("Modify").first().click(); - assertEquals("Last name was not updated after reset modification", - "Spam", grid.getCell(0, 1).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.java deleted file mode 100644 index 575ae8e95f..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridLayoutDetailsRowTest.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.tests.components.grid; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.number.IsCloseTo.closeTo; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elements.GridLayoutElement; -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -/** - * Tests that details row displays GridLayout contents properly. - * - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridLayoutDetailsRowTest extends MultiBrowserTest { - - @Test - public void testLabelHeights() { - openTestURL(); - waitForElementPresent(By.className("v-grid")); - - GridElement grid = $(GridElement.class).first(); - - grid.getRow(2).click(5, 5); - waitForElementPresent(By.id("lbl2")); - - GridLayoutElement gridLayout = $(GridLayoutElement.class).first(); - int gridLayoutHeight = gridLayout.getSize().height; - - // height should be divided equally - double expectedHeight = gridLayoutHeight / 4; - assertLabelHeight("lbl1", expectedHeight); - assertLabelHeight("lbl2", expectedHeight); - assertLabelHeight("lbl3", expectedHeight); - assertLabelHeight("lbl4", expectedHeight); - } - - private void assertLabelHeight(String id, double expectedHeight) { - // 1px leeway for calculations - assertThat("Unexpected label height.", - (double) $(LabelElement.class).id(id).getSize().height, - closeTo(expectedHeight, 1d)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionOnInitTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionOnInitTest.java deleted file mode 100644 index 797ac8a680..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionOnInitTest.java +++ /dev/null @@ -1,49 +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.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridMultiSelectionOnInitTest extends MultiBrowserTest { - - @Test - public void testSelectAllCheckBoxExists() { - openTestURL(); - assertTrue("The select all checkbox was missing.", - $(GridElement.class).first().getHeaderCell(0, 0) - .isElementPresent(By.tagName("input"))); - } - - @Test - public void testSetSelectedUpdatesClient() { - openTestURL(); - assertFalse("Rows should not be selected initially.", - $(GridElement.class).first().getRow(0).isSelected()); - $(ButtonElement.class).first().click(); - assertTrue("Rows should be selected after button click.", - $(GridElement.class).first().getRow(0).isSelected()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionScrollBarTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionScrollBarTest.java deleted file mode 100644 index b1322949a8..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionScrollBarTest.java +++ /dev/null @@ -1,43 +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.components.grid; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Test; - -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridMultiSelectionScrollBarTest extends MultiBrowserTest { - - @Test - public void testNoVisibleScrollBar() throws IOException { - setDebug(true); - openTestURL(); - - assertTrue("Horizontal scrollbar should not be visible.", - $(GridElement.class).first().getHorizontalScroller() - .getAttribute("style").toLowerCase() - .contains("display: none;")); - - // Just to make sure nothing odd happened. - assertNoErrorNotifications(); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererChangeTest.java deleted file mode 100644 index 6bf16d6fe6..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRendererChangeTest.java +++ /dev/null @@ -1,59 +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.components.grid; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridRendererChangeTest extends MultiBrowserTest { - - @Test - public void testChangeRenderer() { - setDebug(true); - openTestURL(); - - GridCellElement cell = $(GridElement.class).first().getCell(0, 0); - assertTrue("No button in the first cell.", - cell.isElementPresent(By.tagName("button"))); - int width = cell.getSize().getWidth(); - - List buttons = $(ButtonElement.class).all(); - Collections.reverse(buttons); - - // Order: TextRenderer, HTMLRenderer, ButtonRenderer - for (ButtonElement button : buttons) { - button.click(); - assertNoErrorNotifications(); - cell = $(GridElement.class).first().getCell(0, 0); - assertEquals("Cell size changed", width, cell.getSize().getWidth()); - } - - assertTrue("No button in the first cell.", - cell.isElementPresent(By.tagName("button"))); - } - -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridReplaceContainerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridReplaceContainerTest.java deleted file mode 100644 index 7f52ba3be4..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridReplaceContainerTest.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.tests.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridReplaceContainerTest extends SingleBrowserTest { - - @Test - public void selectAfterContainerChange() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - grid.getCell(0, 0).click(); - Assert.assertTrue(grid.getRow(0).isSelected()); - - $(ButtonElement.class).first().click(); - Assert.assertFalse(grid.getRow(0).isSelected()); - grid.getCell(0, 0).click(); - Assert.assertTrue(grid.getRow(0).isSelected()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridResizeAndScrollTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridResizeAndScrollTest.java deleted file mode 100644 index 63af9e6dce..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridResizeAndScrollTest.java +++ /dev/null @@ -1,45 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridResizeAndScrollTest extends MultiBrowserTest { - - @Test - public void scrollAndClick() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - grid.scrollToRow(49); - // select a row (click on checkbox) - grid.getCell(49, 0).click(); - - // verify rows are what they should be - GridCellElement cell = grid.getCell(33, 1); - String textBefore = cell.getText(); - cell.click(); - - Assert.assertEquals("String contents changed on click", textBefore, - cell.getText()); - - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridResizeHiddenColumnTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridResizeHiddenColumnTest.java deleted file mode 100644 index ccf54a5f47..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridResizeHiddenColumnTest.java +++ /dev/null @@ -1,116 +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.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridResizeHiddenColumnTest extends MultiBrowserTest { - - @Before - public void before() { - openTestURL(); - } - - @Test - public void testDragResizeHiddenColumnSize() { - GridElement grid = $(GridElement.class).first(); - Actions action = new Actions(getDriver()); - - // Check if column 'Gender' hidden - List headerCells = grid.getHeaderCells(0); - Assert.assertEquals("There should be two visible columns", 2, - headerCells.size()); - Assert.assertFalse("Gender column should be hidden", - containsText("Gender", headerCells)); - - // Resize first column - int dragOffset = -100; - int headerCellWidth = headerCells.get(0).getSize().getWidth(); - dragResizeColumn(headerCells.get(0), 1, dragOffset); - - // When dragging the resizer on IE8, the final offset will be smaller - // (might be an issue with the feature that doesn't start resizing until - // the cursor moved a few pixels) - double delta = BrowserUtil.isIE8(getDesiredCapabilities()) ? 5d : 0; - Assert.assertEquals( - "Column width should've changed by " + dragOffset + "px", - headerCellWidth + dragOffset, - headerCells.get(0).getSize().getWidth(), delta); - - // Make column 'Gender' visible - WebElement menuButton = grid.findElement(By.className("v-contextmenu")) - .findElement(By.tagName("button")); - action.click(menuButton).perform(); // Click on menu button - - WebElement sidebarPopup = findElement( - By.className("v-grid-sidebar-popup")); - WebElement visibilityToggle = findElementByText("Gender", - sidebarPopup.findElements(By.className("gwt-MenuItem"))); - action.click(visibilityToggle).perform(); // Click on 'Gender' menu item - - // Check if column 'Gender' is visible - headerCells = grid.getHeaderCells(0); - Assert.assertEquals("There should be three visible columns", 3, - headerCells.size()); - Assert.assertTrue("Gender column should be visible", - containsText("Gender", headerCells)); - - // Check if column 'Gender' has expanded width - int widthSum = 0; - for (GridCellElement e : headerCells) { - widthSum += e.getSize().getWidth(); - } - Assert.assertEquals("Gender column should take up the remaining space", - grid.getHeader().getSize().getWidth(), widthSum, 1d); - } - - private WebElement findElementByText(String text, - List elements) { - for (WebElement e : elements) { - if (text.equalsIgnoreCase(e.getText())) { - return e; - } - } - return null; - } - - private boolean containsText(String text, - List elements) { - return !(findElementByText(text, elements) == null); - } - - private void dragResizeColumn(GridCellElement headerCell, int posX, - int offset) { - Dimension size = headerCell.getSize(); - new Actions(getDriver()) - .moveToElement(headerCell, size.getWidth() + posX, - size.getHeight() / 2) - .clickAndHold().moveByOffset(offset, 0).release().perform(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRowHeightChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridRowHeightChangeTest.java deleted file mode 100644 index 766b14adcc..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridRowHeightChangeTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.vaadin.tests.components.grid; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; - -import com.vaadin.testbench.By; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.NativeSelectElement; - -public class GridRowHeightChangeTest extends MultiBrowserTest { - - private final List themes = Arrays.asList("valo", "reindeer", - "runo", "chameleon", "base"); - - @Override - public void setup() throws Exception { - super.setup(); - openTestURL(); - } - - @Test - public void changeThemeAndMeasureGridHeight() { - for (String theme : themes) { - // select theme - $(NativeSelectElement.class).first().selectByText(theme); - - GridElement grid = $(GridElement.class).first(); - - int gridHeight = grid.getSize().getHeight(); - int tabsheetHeight = findElements( - By.className("v-tabsheet-content")).get(0).getSize() - .getHeight(); - - assertEquals("Grid's visible height should be equal to Grid height", - gridHeight, tabsheetHeight, 1); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrollToLineWhileResizingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrollToLineWhileResizingTest.java deleted file mode 100644 index 2687716fcd..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridScrollToLineWhileResizingTest.java +++ /dev/null @@ -1,49 +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.components.grid; - -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridScrollToLineWhileResizingTest extends MultiBrowserTest { - - @Test - public void testScrollToLineWorksWhileMovingSplitProgrammatically() { - openTestURL(); - - $(GridElement.class).first().getCell(21, 0).click(); - - List cells = findElements(By.className("v-grid-cell")); - boolean foundCell21 = false; - for (WebElement cell : cells) { - if ("cell21".equals(cell.getText())) { - foundCell21 = true; - } - } - - assertTrue(foundCell21); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllCellTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllCellTest.java deleted file mode 100644 index db2a558637..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllCellTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.vaadin.tests.components.grid; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridSelectAllCellTest extends MultiBrowserTest { - - @Override - public void setup() throws Exception { - super.setup(); - - openTestURL(); - } - - @Test - public void selectAllCellCanBeClicked() throws IOException { - GridElement.GridCellElement selectAllCell = $(GridElement.class).first() - .getHeaderCell(0, 0); - - new Actions(getDriver()).moveToElement(selectAllCell, 2, 2).click() - .perform(); - - WebElement selectAllCheckbox = selectAllCell - .findElement(By.cssSelector("input")); - assertThat(selectAllCheckbox.isSelected(), is(true)); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.java deleted file mode 100644 index 23dd6f6ff5..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSidebarPositionTest.java +++ /dev/null @@ -1,87 +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.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Dimension; -import org.openqa.selenium.Point; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridSidebarPositionTest extends MultiBrowserTest { - - @Test - public void heightRestrictedToBrowserWindow() { - openTestURL(); - GridElement gridWithVeryManyColumns = $(GridElement.class) - .id(GridSidebarPosition.POPUP_WINDOW_HEIGHT); - getSidebarOpenButton(gridWithVeryManyColumns).click(); - Dimension popupSize = getSidebarPopup().getSize(); - Dimension browserWindowSize = getDriver().manage().window().getSize(); - - Assert.assertTrue( - popupSize.getHeight() <= browserWindowSize.getHeight()); - } - - @Test - public void popupNotBelowBrowserWindow() { - openTestURL(); - GridElement gridAtBottom = $(GridElement.class) - .id(GridSidebarPosition.POPUP_WINDOW_MOVED_UP); - getSidebarOpenButton(gridAtBottom).click(); - WebElement sidebarPopup = getSidebarPopup(); - Dimension popupSize = sidebarPopup.getSize(); - Point popupLocation = sidebarPopup.getLocation(); - int popupBottom = popupLocation.getY() + popupSize.getHeight(); - Dimension browserWindowSize = getDriver().manage().window().getSize(); - - Assert.assertTrue(popupBottom <= browserWindowSize.getHeight()); - } - - @Test - public void popupAbove() { - openTestURL(); - GridElement gridPopupAbove = $(GridElement.class) - .id(GridSidebarPosition.POPUP_ABOVE); - WebElement sidebarOpenButton = getSidebarOpenButton(gridPopupAbove); - sidebarOpenButton.click(); - WebElement sidebarPopup = getSidebarPopup(); - Dimension popupSize = sidebarPopup.getSize(); - Point popupLocation = sidebarPopup.getLocation(); - int popupBottom = popupLocation.getY() + popupSize.getHeight(); - int sideBarButtonTop = sidebarOpenButton.getLocation().getY(); - Assert.assertTrue(popupBottom <= sideBarButtonTop); - } - - protected WebElement getSidebarOpenButton(GridElement grid) { - List elements = grid - .findElements(By.className("v-grid-sidebar-button")); - return elements.isEmpty() ? null : elements.get(0); - } - - protected WebElement getSidebarPopup() { - List elements = findElements( - By.className("v-grid-sidebar-popup")); - return elements.isEmpty() ? null : elements.get(0); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSingleColumnTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSingleColumnTest.java deleted file mode 100644 index 7c6fe714ea..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSingleColumnTest.java +++ /dev/null @@ -1,47 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridSingleColumnTest extends MultiBrowserTest { - - @Test - public void testHeaderIsVisible() { - openTestURL(); - - GridCellElement cell = $(GridElement.class).first().getHeaderCell(0, 0); - Assert.assertTrue("No header available", - cell.getText().equalsIgnoreCase("header")); - } - - @Test - public void testScrollDidNotThrow() { - setDebug(true); - openTestURL(); - - Assert.assertFalse("Exception when scrolling on init", - isElementPresent(NotificationElement.class)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java deleted file mode 100644 index 82b1b74617..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSortIndicatorTest.java +++ /dev/null @@ -1,53 +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.components.grid; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridSortIndicatorTest extends MultiBrowserTest { - - @Test - public void testIndicators() throws InterruptedException { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - // Clicking the left header cell should set ascending sort order for - // both columns. - grid.getHeaderCell(0, 0).click(); - assertTrue(grid.getHeaderCell(0, 0).getAttribute("class") - .contains("sort-asc")); - assertTrue(grid.getHeaderCell(0, 1).getAttribute("class") - .contains("sort-asc")); - // Click the left column to change the sort direction. - grid.getHeaderCell(0, 0).click(); - assertTrue(grid.getHeaderCell(0, 0).getAttribute("class") - .contains("sort-desc")); - assertTrue(grid.getHeaderCell(0, 1).getAttribute("class") - .contains("sort-desc")); - // Clicking on the right column should have no effect. - grid.getHeaderCell(0, 1).click(); - assertTrue(grid.getHeaderCell(0, 0).getAttribute("class") - .contains("sort-desc")); - assertTrue(grid.getHeaderCell(0, 1).getAttribute("class") - .contains("sort-desc")); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSpacerDecoClipTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSpacerDecoClipTest.java deleted file mode 100644 index fc716621e3..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSpacerDecoClipTest.java +++ /dev/null @@ -1,98 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.SearchContext; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.minitutorials.v7_5.ShowingExtraDataForRows; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -/** - * Test for "Grid detail row outline overflows" (#17826) - * - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridSpacerDecoClipTest extends MultiBrowserTest { - - private static final String SPACER_CSS_CLASS_DECO = "v-grid-spacer-deco"; - - @Override - protected Class getUIClass() { - return ShowingExtraDataForRows.class; - } - - @Test - public void testNewSpacerClip() { - openTestURL(); - - GridElement gridElement = $(GridElement.class).first(); - gridElement.scrollToRow(999); - GridElement.GridRowElement nextToLastRow = gridElement.getRow(998); - nextToLastRow.doubleClick(); - - TestBenchElement deco = getSpacerDeco(0); - System.out.println("Lower deco.clip = " + deco.getCssValue("clip")); - GridElement.GridRowElement nearToBottomRow = gridElement.getRow(993); - nearToBottomRow.doubleClick(); - deco = getSpacerDeco(0); - System.out.println("Lower deco.clip = " + deco.getCssValue("clip")); - Assert.assertNotEquals( - "Spacer deco clipping is not updated after opening another spacer", - "auto", deco.getCssValue("clip")); - } - - @Test - public void testRemovedSpacerClip() throws InterruptedException { - openTestURL(); - - GridElement gridElement = $(GridElement.class).first(); - gridElement.scrollToRow(999); - GridElement.GridRowElement lastRow = gridElement.getRow(999); - lastRow.doubleClick(); // Open lowest Row Details - - TestBenchElement deco = getSpacerDeco(0); - System.out.println("deco.rect = " + deco.getCssValue("clip")); - - GridElement.GridRowElement nearToBottomRow = gridElement.getRow(993); - - nearToBottomRow.doubleClick(); // Open upper Row Details, lower Row - // Details goes out of visible range - Thread.sleep(500); - nearToBottomRow.doubleClick(); // Close upper Row Details, lower Row - // Details goes back to visible range - - deco = getSpacerDeco(0); - String clip = deco.getCssValue("clip"); - System.out.println("deco.rect = " + clip); - - Assert.assertTrue( - "Part of lower Row Details is visible, its deco clip height should be positive, but it is negative", - clip.indexOf('-') < 0); - } - - private TestBenchElement getSpacerDeco(int index) { - SearchContext context = getContext(); - return (TestBenchElement) context - .findElements(By.className(SPACER_CSS_CLASS_DECO)).get(index); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java deleted file mode 100644 index 0349335e0b..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java +++ /dev/null @@ -1,57 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridSubPixelProblemWrappingTest extends MultiBrowserTest { - - @Test - public void addedRowShouldNotWrap() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - // Cells in first row should be at the same y coordinate as the row - assertRowAndCellTops(grid, 0); - - // Add a row - $(ButtonElement.class).first().click(); - - // Cells in the first row should be at the same y coordinate as the row - assertRowAndCellTops(grid, 0); - // Cells in the second row should be at the same y coordinate as the row - assertRowAndCellTops(grid, 1); - } - - private void assertRowAndCellTops(GridElement grid, int rowIndex) { - GridRowElement row = grid.getRow(rowIndex); - int rowTop = row.getLocation().y; - - int cell0Top = grid.getCell(rowIndex, 0).getLocation().y; - int cell1Top = grid.getCell(rowIndex, 1).getLocation().y; - Assert.assertEquals(rowTop, cell0Top); - Assert.assertEquals(rowTop, cell1Top); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java deleted file mode 100644 index b596c35d41..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSwitchRenderersTest.java +++ /dev/null @@ -1,86 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.CheckBoxElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridSwitchRenderersTest extends MultiBrowserTest { - - @Test - public void testRendererSwitch() { - - // The UI should start with TEXT rendering in the second column - // Clicking the checkbox will toggle rendering to HTML mode - // Clicking it again should return TEXT rendering mode. - - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - Assert.assertTrue( - "Initial rendering of column 1 is not unformatted text", - cellTextIsUnformatted(grid.getCell(0, 1).getText())); - - // NOTE: must click at 5,5 because of Valo and rendering in Chrome - // This is a TestBench bug that may be fixed sometime in the future - CheckBoxElement cb = $(CheckBoxElement.class).first(); - cb.click(5, 5); - - Assert.assertTrue( - "Column 1 data has not been rendered with HTMLRenderer after renderer swap", - cellTextIsHTMLFormatted(grid.getCell(0, 1).getText())); - cb.click(5, 5); - - Assert.assertTrue( - "Column 1 data has not been re-rendered as text after renderer swap", - cellTextIsUnformatted(grid.getCell(0, 1).getText())); - } - - /** - * Attempts to match a string to a string like {@code (4, 1)}. - * - * @param cellText - * input string - * @return true if input string is formatted like a raw HTML string - */ - private boolean cellTextIsUnformatted(String cellText) { - String regex = "\\(\\d+, \\d+\\)"; - return cellText.matches(regex); - } - - /** - * Attempts to match a string to a string like {@code (4, 1)}, i.e. the HTML - * formatted version of the above (the bold tags should be consumed by the - * renderer). - * - * @param cellText - * input string - * @return true if input string is formatted like plain text (i.e. HTML bits - * have been consumed by renderer) - */ - private boolean cellTextIsHTMLFormatted(String cellText) { - String regex = "\\(\\d+, \\d+\\)"; - return cellText.matches(regex); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeChangeTest.java deleted file mode 100644 index b855b74a75..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeChangeTest.java +++ /dev/null @@ -1,54 +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.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridThemeChangeTest extends MultiBrowserTest { - @Override - public List getBrowsersToTest() { - // Seems like stylesheet onload is not fired on PhantomJS - // https://github.com/ariya/phantomjs/issues/12332 - return super.getBrowsersExcludingPhantomJS(); - } - - @Test - public void testThemeChange() { - openTestURL("debug"); - - GridElement grid = $(GridElement.class).first(); - - int reindeerHeight = grid.getRow(0).getSize().getHeight(); - - grid.getCell(0, 0).click(); - - grid = $(GridElement.class).first(); - int valoHeight = grid.getRow(0).getSize().getHeight(); - - Assert.assertTrue( - "Row height should increase when changing from Reindeer to Valo", - valoHeight > reindeerHeight); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java deleted file mode 100644 index 0762533074..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridThemeUITest.java +++ /dev/null @@ -1,109 +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.components.grid; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserThemeTest; -import com.vaadin.v7.testbench.customelements.DateFieldElement; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.NativeSelectElement; -import com.vaadin.v7.testbench.customelements.TextFieldElement; - -@TestCategory("grid") -public class GridThemeUITest extends MultiBrowserThemeTest { - - private GridElement grid; - - @Test - public void grid() throws Exception { - openTestURL(); - selectPage("Editor"); - compareScreen("basic"); - } - - @Test - public void headerAndFooter() throws Exception { - openTestURL(); - selectPage("HeaderFooter"); - compareScreen("basic"); - grid.getHeaderCell(0, 6).$(ButtonElement.class).first().click(); - compareScreen("additional-header"); - grid.getHeaderCell(2, 1).click(); - compareScreen("sorted-last-name"); - grid.getHeaderCell(2, 4).click(); - compareScreen("sorted-age"); - } - - @Test - public void editor() throws Exception { - openTestURL(); - selectPage("Editor"); - GridCellElement ritaBirthdate = grid.getCell(2, 3); - // Open editor row - openEditor(ritaBirthdate); - - compareScreen("initial"); - - GridEditorElement editor = grid.getEditor(); - - DateFieldElement dateField = editor.$(DateFieldElement.class).first(); - WebElement input = dateField.findElement(By.xpath("input")); - input.sendKeys("Invalid", Keys.TAB); - editor.save(); - compareScreen("one-invalid"); - - TextFieldElement age = editor.$(TextFieldElement.class).caption("Age") - .first(); - age.sendKeys("abc", Keys.TAB); - editor.save(); - - compareScreen("two-invalid"); - } - - private void openEditor(GridCellElement targetCell) { - new Actions(getDriver()).doubleClick(targetCell).perform(); - try { - if (grid.getEditor().isDisplayed()) { - return; - } - } catch (Exception e) { - - } - - // Try again if IE happen to fail.. - new Actions(getDriver()).doubleClick(targetCell).perform(); - } - - /** - * @since - * @param string - */ - private void selectPage(String string) { - $(NativeSelectElement.class).id("page").selectByText(string); - grid = $(GridElement.class).first(); - - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWidgetRendererChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridWidgetRendererChangeTest.java deleted file mode 100644 index 8589f4d0ba..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWidgetRendererChangeTest.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.tests.components.grid; - -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.tests.tb3.SingleBrowserTest; - -public class GridWidgetRendererChangeTest extends SingleBrowserTest { - - @Test - public void testChangeWidgetRenderer() { - setDebug(true); - openTestURL(); - - selectMenuPath("Component", "Change first renderer"); - - assertNoErrorNotifications(); - - selectMenuPath("Component", "Change first renderer"); - - assertNoErrorNotifications(); - - // First renderer OK - - selectMenuPath("Component", "Change second renderer"); - - assertNoErrorNotifications(); - - selectMenuPath("Component", "Change second renderer"); - - assertNoErrorNotifications(); - - } - - @Override - protected void selectMenu(String menuCaption) { - // GWT menu does not need to be clicked. - selectMenu(menuCaption, false); - } - - @Override - protected WebElement getMenuElement(String menuCaption) { - return getDriver() - .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWidthIncreaseTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridWidthIncreaseTest.java deleted file mode 100644 index f016f7ce70..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWidthIncreaseTest.java +++ /dev/null @@ -1,70 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridWidthIncreaseTest extends MultiBrowserTest { - - private static int INCREASE_COUNT = 3; - - @Test - public void testColumnsExpandWithGrid() throws IOException { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - double accuracy = 1.0d; - DesiredCapabilities cap = getDesiredCapabilities(); - if (BrowserUtil.isIE(cap, 8) || BrowserUtil.isIE(cap, 9) - || BrowserUtil.isPhantomJS(cap)) { - accuracy = 2.0d; - } - - for (int i = 0; i < INCREASE_COUNT; ++i) { - $(ButtonElement.class).first().click(); - int prevWidth = 0; - for (int c = 0; c < GridWidthIncrease.COLUMN_COUNT; ++c) { - int width = grid.getCell(0, c).getSize().getWidth(); - if (c > 0) { - // check that columns are roughly the same width. - assertEquals("Difference in column widths", prevWidth, - width, accuracy); - } - prevWidth = width; - } - /* - * Column widths should be the same as table wrapper size. Since - * Selenium doesn't support subpixels correctly, we use a rough - * estimation. - */ - assertEquals(grid.getRow(0).getSize().getWidth(), - grid.getTableWrapper().getSize().getWidth(), accuracy); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithBrokenRendererTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithBrokenRendererTest.java deleted file mode 100644 index b8ed9d4ce2..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithBrokenRendererTest.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.tests.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridWithBrokenRendererTest extends SingleBrowserTest { - - @Test - public void ensureRendered() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - assertRow(grid, 0, "FI", "", "Finland"); - assertRow(grid, 1, "SE", "", "Sweden"); - } - - private void assertRow(GridElement grid, int row, String... texts) { - for (int column = 0; column < texts.length; column++) { - Assert.assertEquals("Cell " + row + "," + column, texts[column], - grid.getCell(row, column).getText()); - } - - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithLabelEditorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithLabelEditorTest.java deleted file mode 100644 index b152e46428..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithLabelEditorTest.java +++ /dev/null @@ -1,37 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridWithLabelEditorTest extends SingleBrowserTest { - - @Test - public void testNoExceptionOnEdit() { - setDebug(true); - openTestURL(); - - assertNoErrorNotifications(); - - assertEquals("LabelEditor content not correct.", "FooFoo", - $(GridElement.class).first().getEditor().getField(0).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithoutRendererTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithoutRendererTest.java deleted file mode 100644 index 1a62adce43..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/GridWithoutRendererTest.java +++ /dev/null @@ -1,43 +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.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.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; - -@TestCategory("grid") -public class GridWithoutRendererTest extends SingleBrowserTest { - - @Test - public void ensureNoError() { - openTestURL(); - // WebElement errorIndicator = findElement(By - // .cssSelector("v-error-indicator")); - // System.out.println(errorIndicator); - List errorIndicator = findElements( - By.xpath("//span[@class='v-errorindicator']")); - Assert.assertTrue("There should not be an error indicator", - errorIndicator.isEmpty()); - } - -} 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 deleted file mode 100644 index a84f119e1d..0000000000 --- a/uitest/src/test/java/com/vaadin/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.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.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@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")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java deleted file mode 100644 index 3bf1301a6e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/JavaScriptRenderersTest.java +++ /dev/null @@ -1,52 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class JavaScriptRenderersTest extends MultiBrowserTest { - - @Test - public void testJavaScriptRenderer() { - setDebug(true); - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - GridCellElement cell_1_1 = grid.getCell(1, 1); - - GridCellElement cell_2_2 = grid.getCell(2, 2); - - // Verify render functionality - Assert.assertEquals("Bean(2, 0)", cell_1_1.getText()); - - Assert.assertEquals("string2", cell_2_2.getText()); - - // Verify init functionality - Assert.assertEquals("1", cell_1_1.getAttribute("column")); - - // Verify onbrowserevent - cell_1_1.click(); - Assert.assertTrue( - cell_1_1.getText().startsWith("Clicked 1 with key 2 at")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/NullHeadersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/NullHeadersTest.java deleted file mode 100644 index a8b4b1ca98..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/NullHeadersTest.java +++ /dev/null @@ -1,49 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class NullHeadersTest extends SingleBrowserTest { - - @Test - public void gridWithNullHeadersShouldBeRendered() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - Assert.assertEquals(1, grid.getHeaderCount()); - Assert.assertEquals(3, grid.getHeaderCells(0).size()); - for (int i = 0; i < 3; i++) { - Assert.assertEquals("", grid.getHeaderCell(0, 0).getText()); - } - assertRow(grid, 0, "Finland", "foo", "1"); - assertRow(grid, 1, "Swaziland", "bar", "2"); - assertRow(grid, 2, "Japan", "baz", "3"); - } - - private void assertRow(GridElement grid, int row, String... contents) { - for (int col = 0; col < contents.length; col++) { - Assert.assertEquals(contents[col], - grid.getCell(row, col).getText()); - } - - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/NullRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/NullRenderersTest.java deleted file mode 100644 index 1e5b03b16e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/NullRenderersTest.java +++ /dev/null @@ -1,64 +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.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.elements.LabelElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class NullRenderersTest extends MultiBrowserTest { - @Test - public void testDefaults() throws Exception { - openTestURL(); - - GridElement grid = findGridWithDefaults(); - assertEquals("-- No Text --", grid.getCell(0, 0).getText()); - assertEquals("-- No Jokes --", grid.getCell(0, 1).getText()); - assertEquals("-- Never --", grid.getCell(0, 2).getText()); - assertEquals("-- Nothing --", grid.getCell(0, 3).getText()); - assertEquals("-- No Control --", grid.getCell(0, 5).getText()); - } - - @Test - public void testNoDefaults() throws Exception { - openTestURL(); - - GridElement grid = findGridNoDefaults(); - assertEquals("", grid.getCell(0, 0).getText()); - assertEquals("", grid.getCell(0, 1).getText()); - assertEquals("", grid.getCell(0, 2).getText()); - assertEquals("", grid.getCell(0, 3).getText()); - assertEquals("", grid.getCell(0, 5).getText()); - } - - private GridElement findGridWithDefaults() { - return $(GridElement.class).id("test-grid-defaults"); - } - - private GridElement findGridNoDefaults() { - return $(GridElement.class).id("test-grid"); - } - - private LabelElement findDebugLabel() { - return $(LabelElement.class).id(CustomRenderer.DEBUG_LABEL_ID); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/ProgrammaticEditorControlTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/ProgrammaticEditorControlTest.java deleted file mode 100644 index 001c4d2322..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/ProgrammaticEditorControlTest.java +++ /dev/null @@ -1,64 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.TextFieldElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class ProgrammaticEditorControlTest extends SingleBrowserTest { - - @Test - public void multipleOpenFromServerSide() { - openTestURL(); - GridElement grid = $(GridElement.class).first(); - ButtonElement editButton = $(ButtonElement.class).caption("Edit") - .first(); - ButtonElement cancelButton = $(ButtonElement.class).caption("Cancel") - .first(); - - editButton.click(); - assertEditorFieldContents(grid, "test"); - cancelButton.click(); - - assertEditorNotPresent(grid); - - editButton.click(); - assertEditorFieldContents(grid, "test"); - } - - private void assertEditorFieldContents(GridElement grid, String text) { - TextFieldElement editorField = wrap(TextFieldElement.class, - grid.getEditor().getField(0)); - Assert.assertEquals(text, editorField.getValue()); - } - - private void assertEditorNotPresent(GridElement grid) { - try { - grid.getEditor(); - Assert.fail("Editor should not be present"); - } catch (Exception e) { - - } - } - -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/SelectDuringInitTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/SelectDuringInitTest.java deleted file mode 100644 index f8b7705143..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/SelectDuringInitTest.java +++ /dev/null @@ -1,37 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class SelectDuringInitTest extends SingleBrowserTest { - - @Test - public void testSelectDuringInit() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - - Assert.assertTrue(grid.getRow(1).isSelected()); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/SortableHeaderStylesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/SortableHeaderStylesTest.java deleted file mode 100644 index fce9878276..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/SortableHeaderStylesTest.java +++ /dev/null @@ -1,51 +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.components.grid; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; -import com.vaadin.v7.testbench.customelements.OptionGroupElement; - -public class SortableHeaderStylesTest extends SingleBrowserTest { - @Test - public void testSortableHeaderStyles() { - openTestURL(); - - Assert.assertFalse(hasSortableStyle(0)); - for (int i = 1; i < 8; i++) { - Assert.assertTrue(hasSortableStyle(i)); - } - - OptionGroupElement sortableSelector = $(OptionGroupElement.class) - .first(); - - // Toggle sortability - sortableSelector.selectByText("lastName"); - Assert.assertFalse(hasSortableStyle(3)); - - // Toggle back - sortableSelector.selectByText("lastName"); - Assert.assertTrue(hasSortableStyle(3)); - } - - private boolean hasSortableStyle(int column) { - return $(GridElement.class).first().getHeaderCell(0, column) - .getAttribute("class").contains("sortable"); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/WidgetRenderersTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/WidgetRenderersTest.java deleted file mode 100644 index 0b2d216ade..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/WidgetRenderersTest.java +++ /dev/null @@ -1,167 +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.components.grid; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -/** - * TB tests for the various builtin widget-based renderers. - * - * @since - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class WidgetRenderersTest extends MultiBrowserTest { - - @Override - public void setup() throws Exception { - super.setup(); - - openTestURL(); - } - - @Test - public void testProgressBarRenderer() { - assertTrue(getGridCell(0, 0) - .isElementPresent(By.className("v-progressbar"))); - } - - @Test - public void testButtonRenderer() { - WebElement button = getGridCell(0, 1) - .findElement(By.className("v-nativebutton")); - - button.click(); - - waitUntilTextUpdated(button, "Clicked!"); - } - - @Test - public void testButtonRendererAfterCellBeingFocused() { - GridCellElement buttonCell = getGridCell(0, 1); - assertFalse("cell should not be focused before focusing", - buttonCell.isFocused()); - - // avoid clicking on the button - buttonCell.click(buttonCell.getSize().getWidth() - 10, 5); - assertTrue("cell should be focused after focusing", - buttonCell.isFocused()); - - WebElement button = buttonCell - .findElement(By.className("v-nativebutton")); - assertNotEquals("Button should not be clicked before click", "Clicked!", - button.getText()); - - new Actions(getDriver()).moveToElement(button).click().perform(); - - waitUntilTextUpdated(button, "Clicked!"); - } - - @Test - public void testImageRenderer() { - final WebElement image = getGridCell(0, 2) - .findElement(By.className("gwt-Image")); - - waitUntilmageSrcEndsWith(image, "window/img/close.png"); - - image.click(); - - waitUntilmageSrcEndsWith(image, "window/img/maximize.png"); - } - - private void waitUntilmageSrcEndsWith(final WebElement image, - final String expectedText) { - waitUntil(new ExpectedCondition() { - - @Override - public Boolean apply(WebDriver input) { - return image.getAttribute("src").endsWith(expectedText); - } - - @Override - public String toString() { - // Timed out after 10 seconds waiting for ... - return String.format( - "image source to update. Supposed to end with '%s' (was: '%s').", - expectedText, image.getAttribute("src")); - } - }); - } - - @Test - public void testColumnReorder() { - $(ButtonElement.class).caption("Change column order").first().click(); - - assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - - assertTrue( - getGridCell(0, 0).isElementPresent(By.className("gwt-Image"))); - assertTrue(getGridCell(0, 1) - .isElementPresent(By.className("v-progressbar"))); - assertTrue(getGridCell(0, 2) - .isElementPresent(By.className("v-nativebutton"))); - } - - @Test - public void testPropertyIdInEvent() { - WebElement button = getGridCell(0, 3) - .findElement(By.className("v-nativebutton")); - - button.click(); - - waitUntilTextUpdated(button, WidgetRenderers.PROPERTY_ID); - } - - GridCellElement getGridCell(int row, int col) { - return $(GridElement.class).first().getCell(row, col); - } - - private void waitUntilTextUpdated(final WebElement button, - final String expectedText) { - waitUntil(new ExpectedCondition() { - - @Override - public Boolean apply(WebDriver input) { - return button.getText().equals(expectedText); - } - - @Override - public String toString() { - // Timed out after 10 seconds waiting for ... - return String.format("button's text to become '%s' (was: '').", - expectedText, button.getText()); - } - - }); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java deleted file mode 100644 index 603c9c2d79..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java +++ /dev/null @@ -1,316 +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.components.grid.basicfeatures; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public abstract class EscalatorBasicClientFeaturesTest - extends MultiBrowserTest { - - private static final String LOGICAL_ROW_ATTRIBUTE_NAME = "vLogicalRow"; - private static final String SPACER_CSS_CLASS = "v-escalator-spacer"; - - protected static final String COLUMNS_AND_ROWS = "Columns and Rows"; - - protected static final String COLUMNS = "Columns"; - protected static final String ADD_ONE_COLUMN_TO_BEGINNING = "Add one column to beginning"; - protected static final String ADD_ONE_ROW_TO_BEGINNING = "Add one row to beginning"; - protected static final String ADD_ONE_ROW_TO_END = "Add one row to end"; - protected static final String REMOVE_ONE_COLUMN_FROM_BEGINNING = "Remove one column from beginning"; - protected static final String REMOVE_ONE_ROW_FROM_BEGINNING = "Remove one row from beginning"; - protected static final String REMOVE_ALL_ROWS = "Remove all rows"; - protected static final String REMOVE_50_ROWS_FROM_BOTTOM = "Remove 50 rows from bottom"; - protected static final String REMOVE_50_ROWS_FROM_ALMOST_BOTTOM = "Remove 50 rows from almost bottom"; - protected static final String ADD_ONE_OF_EACH_ROW = "Add one of each row"; - protected static final String RESIZE_FIRST_COLUMN_TO_MAX_WIDTH = "Resize first column to max width"; - protected static final String RESIZE_FIRST_COLUMN_TO_100PX = "Resize first column to 100 px"; - - protected static final String HEADER_ROWS = "Header Rows"; - protected static final String BODY_ROWS = "Body Rows"; - protected static final String FOOTER_ROWS = "Footer Rows"; - - protected static final String SCROLL_TO = "Scroll to..."; - - protected static final String REMOVE_ALL_INSERT_SCROLL = "Remove all, insert 30 and scroll 40px"; - - protected static final String GENERAL = "General"; - protected static final String DETACH_ESCALATOR = "Detach Escalator"; - protected static final String ATTACH_ESCALATOR = "Attach Escalator"; - protected static final String POPULATE_COLUMN_ROW = "Populate Escalator (columns, then rows)"; - protected static final String POPULATE_ROW_COLUMN = "Populate Escalator (rows, then columns)"; - protected static final String CLEAR_COLUMN_ROW = "Clear (columns, then rows)"; - protected static final String CLEAR_ROW_COLUMN = "Clear (rows, then columns)"; - - protected static final String FEATURES = "Features"; - protected static final String FROZEN_COLUMNS = "Frozen columns"; - protected static final String FREEZE_1_COLUMN = "Freeze 1 column"; - protected static final String FREEZE_0_COLUMNS = "Freeze 0 columns"; - protected static final String COLUMN_SPANNING = "Column spanning"; - protected static final String COLSPAN_NORMAL = "Apply normal colspan"; - protected static final String COLSPAN_NONE = "Apply no colspan"; - protected static final String SET_100PX = "Set 100px"; - protected static final String SPACERS = "Spacers"; - protected static final String FOCUSABLE_UPDATER = "Focusable Updater"; - protected static final String SCROLL_HERE_ANY_0PADDING = "Scroll here (ANY, 0)"; - protected static final String SCROLL_HERE_SPACERBELOW_ANY_0PADDING = "Scroll here row+spacer below (ANY, 0)"; - protected static final String REMOVE = "Remove"; - - protected static final String ROW_MINUS1 = "Row -1"; - protected static final String ROW_0 = "Row 0"; - protected static final String ROW_1 = "Row 1"; - protected static final String ROW_25 = "Row 25"; - protected static final String ROW_50 = "Row 50"; - protected static final String ROW_75 = "Row 75"; - protected static final String ROW_99 = "Row 99"; - - @Override - public void setup() throws Exception { - super.setup(); - - setDebug(true); - } - - @Override - protected Class getUIClass() { - return EscalatorBasicClientFeatures.class; - } - - protected TestBenchElement getEscalator() { - By className = By.className("v-escalator"); - if (isElementPresent(className)) { - return (TestBenchElement) findElement(className); - } - return null; - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - protected TestBenchElement getHeaderRow(int row) { - return getRow("thead", row); - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - protected TestBenchElement getBodyRow(int row) { - return getRow("tbody", row); - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - protected TestBenchElement getFooterRow(int row) { - return getRow("tfoot", row); - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - protected TestBenchElement getHeaderCell(int row, int col) { - return getCell("thead", row, col); - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - protected TestBenchElement getBodyCell(int row, int col) { - return getCell("tbody", row, col); - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - protected TestBenchElement getFooterCell(int row, int col) { - return getCell("tfoot", row, col); - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - private TestBenchElement getCell(String sectionTag, int row, int col) { - TestBenchElement rowElement = getRow(sectionTag, row); - By xpath = By.xpath("*[" + (col + 1) + "]"); - if (rowElement != null && rowElement.isElementPresent(xpath)) { - return (TestBenchElement) rowElement.findElement(xpath); - } - return null; - } - - /** - * @param row - * the index of the row element in the section. If negative, the - * calculation starts from the end (-1 is the last, -2 is the - * second-to-last etc) - */ - private TestBenchElement getRow(String sectionTag, int row) { - TestBenchElement escalator = getEscalator(); - WebElement tableSection = escalator.findElement(By.tagName(sectionTag)); - - String xpathExpression = "tr[not(@class='" + SPACER_CSS_CLASS + "')]"; - if (row >= 0) { - int fromFirst = row + 1; - xpathExpression += "[" + fromFirst + "]"; - } else { - int fromLast = Math.abs(row + 1); - xpathExpression += "[last() - " + fromLast + "]"; - } - By xpath = By.xpath(xpathExpression); - if (tableSection != null - && ((TestBenchElement) tableSection).isElementPresent(xpath)) { - return (TestBenchElement) tableSection.findElement(xpath); - } - return null; - } - - @Override - protected void selectMenu(String menuCaption) { - // GWT menu does not need to be clicked. - selectMenu(menuCaption, false); - } - - @Override - protected WebElement getMenuElement(String menuCaption) { - return getDriver() - .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); - } - - protected void assertLogContains(String substring) { - assertTrue("log should've contained, but didn't: " + substring, - getLogText().contains(substring)); - } - - protected void assertLogDoesNotContain(String substring) { - assertFalse("log shouldn't have contained, but did: " + substring, - getLogText().contains(substring)); - } - - private String getLogText() { - WebElement log = findElement(By.cssSelector("#log")); - return log.getText(); - } - - protected void assertLogContainsInOrder(String... substrings) { - String log = getLogText(); - int cursor = 0; - for (String substring : substrings) { - String remainingLog = log.substring(cursor, log.length()); - int substringIndex = remainingLog.indexOf(substring); - if (substringIndex == -1) { - fail("substring \"" + substring - + "\" was not found in order from log."); - } - - cursor += substringIndex + substring.length(); - } - } - - protected void scrollVerticallyTo(int px) { - getVerticalScrollbar().scroll(px); - } - - protected long getScrollTop() { - return ((Long) executeScript("return arguments[0].scrollTop;", - getVerticalScrollbar())).longValue(); - } - - private TestBenchElement getVerticalScrollbar() { - return (TestBenchElement) getEscalator() - .findElement(By.className("v-escalator-scroller-vertical")); - } - - protected void scrollHorizontallyTo(int px) { - getHorizontalScrollbar().scrollLeft(px); - } - - protected long getScrollLeft() { - return ((Long) executeScript("return arguments[0].scrollLeft;", - getHorizontalScrollbar())).longValue(); - } - - protected TestBenchElement getHorizontalScrollbar() { - return (TestBenchElement) getEscalator() - .findElement(By.className("v-escalator-scroller-horizontal")); - } - - @Override - protected Object executeScript(String script, Object... args) { - return ((JavascriptExecutor) getDriver()).executeScript(script, args); - } - - protected void populate() { - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - } - - private List getSpacers() { - return getEscalator().findElements(By.className(SPACER_CSS_CLASS)); - } - - protected boolean spacersAreFoundInDom() { - List spacers = getSpacers(); - return spacers != null && !spacers.isEmpty(); - } - - @SuppressWarnings("boxing") - protected WebElement getSpacer(int logicalRowIndex) { - List spacers = getSpacers(); - System.out.println("size: " + spacers.size()); - for (WebElement spacer : spacers) { - System.out.println(spacer + ", " + logicalRowIndex); - Boolean isInDom = (Boolean) executeScript("return arguments[0]['" - + LOGICAL_ROW_ATTRIBUTE_NAME + "'] === arguments[1]", - spacer, logicalRowIndex); - if (isInDom) { - return spacer; - } - } - return null; - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java deleted file mode 100644 index b55e3ec026..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java +++ /dev/null @@ -1,115 +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.components.grid.basicfeatures; - -import java.util.List; - -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.v7.testbench.customelements.GridElement; - -/** - * GridBasicClientFeatures. - * - * @since - * @author Vaadin Ltd - */ -public abstract class GridBasicClientFeaturesTest - extends GridBasicFeaturesTest { - - private boolean composite = false; - - @Override - protected Class getUIClass() { - return GridBasicClientFeatures.class; - } - - @Override - protected String getDeploymentPath() { - String path = super.getDeploymentPath(); - if (composite) { - path += (path.contains("?") ? "&" : "?") + "composite"; - } - return path; - } - - protected void setUseComposite(boolean useComposite) { - composite = useComposite; - } - - @Override - protected void selectMenu(String menuCaption) { - // GWT menu does not need to be clicked. - selectMenu(menuCaption, false); - } - - @Override - protected WebElement getMenuElement(String menuCaption) { - return getDriver() - .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); - } - - @Override - protected GridElement getGridElement() { - if (composite) { - // Composite requires the basic client features widget for subparts - return ((TestBenchElement) findElement( - By.vaadin("//TestWidgetComponent"))) - .wrap(GridElement.class); - } else { - return super.getGridElement(); - } - } - - @Override - protected void assertColumnHeaderOrder(int... indices) { - List headers = getGridHeaderRowCells(); - for (int i = 0; i < indices.length; i++) { - assertColumnHeader("HEADER (0," + indices[i] + ")", headers.get(i)); - } - } - - protected void toggleColumnReorder() { - selectMenuPath("Component", "State", "Column Reordering"); - } - - protected boolean isRowSelected(int index) { - boolean selected = getGridElement().getRow(index).isSelected(); - return selected; - } - - protected void setSelectionModelMulti() { - setSelectionModel("multi"); - } - - protected void setSelectionModelSingle(boolean deselectAllowed) { - String mode = "single"; - if (!deselectAllowed) { - mode += " (no deselect)"; - } - setSelectionModel(mode); - } - - protected void setSelectionModelNone() { - setSelectionModel("none"); - } - - protected void setSelectionModel(String model) { - selectMenuPath("Component", "State", "Selection mode", model); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java deleted file mode 100644 index bd229cfc76..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java +++ /dev/null @@ -1,254 +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.components.grid.basicfeatures; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public abstract class GridBasicFeaturesTest extends MultiBrowserTest { - - public enum CellSide { - LEFT, RIGHT; - } - - @Override - protected boolean requireWindowFocusForIE() { - return true; - } - - @Override - protected Class getUIClass() { - return GridBasicFeatures.class; - } - - protected GridElement getGridElement() { - return ((TestBenchElement) findElement(By.id("testComponent"))) - .wrap(GridElement.class); - } - - protected void scrollGridVerticallyTo(double px) { - executeScript("arguments[0].scrollTop = " + px, - getGridVerticalScrollbar()); - } - - protected void scrollGridHorizontallyTo(double px) { - executeScript("arguments[0].scrollLeft = " + px, - getGridHorizontalScrollbar()); - } - - protected int getGridVerticalScrollPos() { - return ((Number) executeScript("return arguments[0].scrollTop", - getGridVerticalScrollbar())).intValue(); - } - - protected List getGridHeaderRowCells() { - List headerCells = new ArrayList(); - for (int i = 0; i < getGridElement().getHeaderCount(); ++i) { - headerCells.addAll(getGridElement().getHeaderCells(i)); - } - return headerCells; - } - - protected List getGridFooterRowCells() { - List footerCells = new ArrayList(); - for (int i = 0; i < getGridElement().getFooterCount(); ++i) { - footerCells.addAll(getGridElement().getFooterCells(i)); - } - return footerCells; - } - - protected WebElement getEditor() { - List elems = getGridElement() - .findElements(By.className("v-grid-editor")); - - assertLessThanOrEqual("number of editors", elems.size(), 1); - - return elems.isEmpty() ? null : elems.get(0); - } - - private Object executeScript(String script, WebElement element) { - final WebDriver driver = getDriver(); - if (driver instanceof JavascriptExecutor) { - final JavascriptExecutor je = (JavascriptExecutor) driver; - return je.executeScript(script, element); - } else { - throw new IllegalStateException("current driver " - + getDriver().getClass().getName() + " is not a " - + JavascriptExecutor.class.getSimpleName()); - } - } - - protected WebElement getGridVerticalScrollbar() { - return getDriver().findElement(By.xpath( - "//div[contains(@class, \"v-grid-scroller-vertical\")]")); - } - - protected WebElement getGridHorizontalScrollbar() { - return getDriver().findElement(By.xpath( - "//div[contains(@class, \"v-grid-scroller-horizontal\")]")); - } - - /** - * Reloads the page without restartApplication. This occasionally breaks - * stuff. - */ - protected void reopenTestURL() { - String testUrl = getTestUrl(); - testUrl = testUrl.replace("?restartApplication", "?"); - testUrl = testUrl.replace("?&", "?"); - driver.get(testUrl); - } - - protected void focusCell(int row, int column) { - getGridElement().getCell(row, column).click(); - } - - protected void setFrozenColumns(int numberOfFrozenColumns) { - selectMenuPath("Component", "State", "Frozen column count", - Integer.toString(numberOfFrozenColumns)); - } - - protected void assertColumnHeaderOrder(int... indices) { - List headers = getGridHeaderRowCells(); - for (int i = 0; i < indices.length; i++) { - assertColumnHeader("Column " + indices[i], headers.get(i)); - } - } - - protected void assertColumnHeader(String expectedHeaderCaption, - TestBenchElement testBenchElement) { - assertEquals(expectedHeaderCaption.toLowerCase(), - testBenchElement.getText().toLowerCase()); - } - - protected GridCellElement getDefaultColumnHeader(int index) { - List headerRowCells = getGridElement() - .getHeaderCells(0); - return headerRowCells.get(index); - } - - protected void dragAndDropDefaultColumnHeader(int draggedColumnHeaderIndex, - int onTopOfColumnHeaderIndex, CellSide cellSide) { - GridCellElement columnHeader = getDefaultColumnHeader( - onTopOfColumnHeaderIndex); - new Actions(getDriver()) - .clickAndHold(getDefaultColumnHeader(draggedColumnHeaderIndex)) - .moveToElement(columnHeader, getHorizontalOffsetForDragAndDrop( - columnHeader, cellSide), 0) - .release().perform(); - } - - private int getHorizontalOffsetForDragAndDrop(GridCellElement columnHeader, - CellSide cellSide) { - if (cellSide == CellSide.LEFT) { - return 5; - } else { - int half = columnHeader.getSize().getWidth() / 2; - return half + (half / 2); - } - } - - protected void dragAndDropColumnHeader(int headerRow, - int draggedColumnHeaderIndex, int onTopOfColumnHeaderIndex, - CellSide cellSide) { - GridCellElement headerCell = getGridElement().getHeaderCell(headerRow, - onTopOfColumnHeaderIndex); - new Actions(getDriver()) - .clickAndHold(getGridElement().getHeaderCell(headerRow, - draggedColumnHeaderIndex)) - .moveToElement(headerCell, - getHorizontalOffsetForDragAndDrop(headerCell, cellSide), - 0) - .release().perform(); - } - - protected void dragAndDropColumnHeader(int headerRow, - int draggedColumnHeaderIndex, int onTopOfColumnHeaderIndex, - int horizontalOffset) { - GridCellElement headerCell = getGridElement().getHeaderCell(headerRow, - onTopOfColumnHeaderIndex); - new Actions(getDriver()) - .clickAndHold(getGridElement().getHeaderCell(headerRow, - draggedColumnHeaderIndex)) - .moveToElement(headerCell, horizontalOffset, 0).release() - .perform(); - } - - protected void assertColumnIsSorted(int index) { - WebElement columnHeader = getDefaultColumnHeader(index); - assertTrue(columnHeader.getAttribute("class").contains("sort")); - } - - protected void assertFocusedCell(int row, int column) { - assertTrue(getGridElement().getCell(row, column).getAttribute("class") - .contains("focused")); - } - - protected WebElement getSidebarPopup() { - List elements = findElements( - By.className("v-grid-sidebar-popup")); - if (elements.isEmpty()) { - getSidebarOpenButton().click(); - elements = findElements(By.className("v-grid-sidebar-popup")); - } - return elements.isEmpty() ? null : elements.get(0); - } - - protected WebElement getSidebarPopupIfPresent() { - List elements = findElements( - By.className("v-grid-sidebar-popup")); - return elements.isEmpty() ? null : elements.get(0); - } - - protected WebElement getSidebarOpenButton() { - List elements = findElements( - By.className("v-grid-sidebar-button")); - return elements.isEmpty() ? null : elements.get(0); - } - - /** - * Returns the toggle inside the sidebar for hiding the column at the given - * index, or null if not found. - */ - protected WebElement getColumnHidingToggle(int columnIndex) { - WebElement sidebar = getSidebarPopup(); - List elements = sidebar - .findElements(By.className("column-hiding-toggle")); - for (WebElement e : elements) { - if ((e.getText().toLowerCase()) - .startsWith("column " + columnIndex)) { - return e; - } - } - return null; - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java deleted file mode 100644 index 1d824ae31e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java +++ /dev/null @@ -1,166 +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.components.grid.basicfeatures; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridClientDataSourcesTest extends MultiBrowserTest { - - @Before - public void before() { - openTestURL(); - } - - @Test - public void normalRestishDatasource() throws Exception { - selectMenuPath("DataSources", "RESTish", "Use"); - assertCellPresent("cell 0 #0"); - - scrollToBottom(); - assertCellPresent("cell 199 #0"); - assertCellNotPresent("cell 200 #0"); - } - - @Test - public void growOnRequestRestishDatasource() throws Exception { - selectMenuPath("DataSources", "RESTish", "Use"); - selectMenuPath("DataSources", "RESTish", "Next request +10"); - - scrollToBottom(); - /* second scroll needed because of scrollsize change after scrolling */ - scrollToBottom(); - - assertCellPresent("cell 209 #1"); - assertCellNotPresent("cell 210 #1"); - } - - @Test - public void shrinkOnRequestRestishDatasource() throws Exception { - selectMenuPath("DataSources", "RESTish", "Use"); - scrollToBottom(); - - selectMenuPath("DataSources", "RESTish", "Next request -10"); - scrollToTop(); - - assertCellPresent("cell 0 #1"); - } - - @Test - public void pushChangeRestishDatasource() throws Exception { - selectMenuPath("DataSources", "RESTish", "Use"); - selectMenuPath("DataSources", "RESTish", "Push data change"); - assertCellPresent("cell 0 #1"); - assertCellNotPresent("cell 0 #0"); - } - - @Test - public void growOnPushRestishDatasource() throws Exception { - selectMenuPath("DataSources", "RESTish", "Use"); - selectMenuPath("DataSources", "RESTish", "Push data change +10"); - assertCellPresent("cell 0 #1"); - assertCellNotPresent("cell 0 #0"); - scrollToBottom(); - assertCellPresent("cell 209 #1"); - } - - @Test - public void shrinkOnPushRestishDatasource() throws Exception { - selectMenuPath("DataSources", "RESTish", "Use"); - scrollToBottom(); - - selectMenuPath("DataSources", "RESTish", "Push data change -10"); - assertCellPresent("cell 189 #1"); - assertCellNotPresent("cell 189 #0"); - assertCellNotPresent("cell 199 #1"); - assertCellNotPresent("cell 199 #0"); - } - - private void assertCellPresent(String content) { - assertNotNull( - "A cell with content \"" + content + "\" should've been found", - findByXPath("//td[text()='" + content + "']")); - } - - private void assertCellNotPresent(String content) { - assertNull( - "A cell with content \"" + content - + "\" should've not been found", - findByXPath("//td[text()='" + content + "']")); - } - - private void scrollToTop() { - scrollVerticallyTo(0); - } - - private void scrollToBottom() { - scrollVerticallyTo(9999); - } - - private WebElement findByXPath(String string) { - if (isElementPresent(By.xpath(string))) { - return findElement(By.xpath(string)); - } else { - return null; - } - } - - private void scrollVerticallyTo(int px) { - executeScript("arguments[0].scrollTop = " + px, - findVerticalScrollbar()); - } - - private Object executeScript(String script, Object args) { - final WebDriver driver = getDriver(); - if (driver instanceof JavascriptExecutor) { - final JavascriptExecutor je = (JavascriptExecutor) driver; - return je.executeScript(script, args); - } else { - throw new IllegalStateException("current driver " - + getDriver().getClass().getName() + " is not a " - + JavascriptExecutor.class.getSimpleName()); - } - } - - private WebElement findVerticalScrollbar() { - return getDriver().findElement(By.xpath( - "//div[contains(@class, " + "\"v-grid-scroller-vertical\")]")); - } - - @Override - protected void selectMenu(String menuCaption) { - // GWT menu does not need to be clicked. - selectMenu(menuCaption, false); - } - - @Override - protected WebElement getMenuElement(String menuCaption) { - return getDriver() - .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridClientHeightByRowOnInitTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridClientHeightByRowOnInitTest.java deleted file mode 100644 index 7aec919080..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridClientHeightByRowOnInitTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@SuppressWarnings("all") -@TestCategory("grid") -public class GridClientHeightByRowOnInitTest extends MultiBrowserTest { - @Test - public void gridHeightIsMoreThanACoupleOfRows() { - openTestURL(); - int height = findElement(By.className("v-grid")).getSize().getHeight(); - assertGreater( - "Grid should be much taller than 150px (was " + height + "px)", - height, 150); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java deleted file mode 100644 index c22a670207..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnHidingTest.java +++ /dev/null @@ -1,1096 +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.components.grid.basicfeatures; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; - -@TestCategory("grid") -public class GridColumnHidingTest extends GridBasicClientFeaturesTest { - - private static final String CAPTION_0_1 = "Join column cells 0, 1"; - private static final String CAPTION_1_2 = "Join columns 1, 2"; - private static final String CAPTION_3_4_5 = "Join columns 3, 4, 5"; - private static final String CAPTION_ALL = "Join all columns"; - - @Before - public void before() { - openTestURL(); - } - - @Test - public void testColumnHiding_hidingColumnsFromAPI_works() { - selectMenuPath("Component", "State", "Width", "1000px"); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(1); - toggleHideColumnAPI(2); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(4, 5, 6, 7, 8); - } - - @Test - public void testColumnHiding_unhidingColumnsFromAPI_works() { - selectMenuPath("Component", "State", "Width", "1000px"); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(1); - toggleHideColumnAPI(2); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 4, 5, 6, 7, 8); - - toggleHideColumnAPI(1); - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 2, 4, 5, 6); - } - - @Test - public void testColumnHiding_hidingUnhidingFromAPI_works() { - selectMenuPath("Component", "State", "Width", "1000px"); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 3, 4, 5, 6); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 3, 4, 5, 6); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); - } - - @Test - public void testColumnHiding_changeVisibilityAPI_triggersClientSideEvent() { - assertColumnHeaderOrder(0, 1, 2, 3, 4); - selectMenuPath("Component", "Internals", "Listeners", - "Add Column Visibility Change listener"); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 3, 4); - - WebElement webElement = findElement(By.id("columnvisibility")); - int counter = Integer.parseInt(webElement.getAttribute("counter")); - int columnIndex = Integer - .parseInt(webElement.getAttribute("columnindex")); - boolean userOriginated = Boolean - .parseBoolean(webElement.getAttribute("useroriginated")); - boolean hidden = Boolean - .parseBoolean(webElement.getAttribute("ishidden")); - - assertNotNull("no event fired", webElement); - assertEquals(1, counter); - assertEquals(2, columnIndex); - assertEquals(false, userOriginated); - assertEquals(true, hidden); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - webElement = findElement(By.id("columnvisibility")); - counter = Integer.parseInt(webElement.getAttribute("counter")); - columnIndex = Integer.parseInt(webElement.getAttribute("columnIndex")); - userOriginated = Boolean - .parseBoolean(webElement.getAttribute("userOriginated")); - hidden = Boolean.parseBoolean(webElement.getAttribute("ishidden")); - - assertNotNull("no event fired", webElement); - assertEquals(2, counter); - assertEquals(2, columnIndex); - assertEquals(false, userOriginated); - assertEquals(false, hidden); - } - - @Test - public void testColumnHiding_changeVisibilityToggle_triggersClientSideEvent() { - assertColumnHeaderOrder(0, 1, 2, 3, 4); - selectMenuPath("Component", "Internals", "Listeners", - "Add Column Visibility Change listener"); - - toggleHidableColumnAPI(2); - clickSidebarOpenButton(); - getColumnHidingToggle(2).click(); - assertColumnHeaderOrder(0, 1, 3, 4); - - WebElement webElement = findElement(By.id("columnvisibility")); - int counter = Integer.parseInt(webElement.getAttribute("counter")); - int columnIndex = Integer - .parseInt(webElement.getAttribute("columnindex")); - boolean userOriginated = Boolean - .parseBoolean(webElement.getAttribute("useroriginated")); - boolean hidden = Boolean - .parseBoolean(webElement.getAttribute("ishidden")); - - assertNotNull("no event fired", webElement); - assertEquals(1, counter); - assertEquals(2, columnIndex); - assertEquals(true, userOriginated); - assertEquals(true, hidden); - - getColumnHidingToggle(2).click(); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - webElement = findElement(By.id("columnvisibility")); - counter = Integer.parseInt(webElement.getAttribute("counter")); - columnIndex = Integer.parseInt(webElement.getAttribute("columnIndex")); - userOriginated = Boolean - .parseBoolean(webElement.getAttribute("userOriginated")); - hidden = Boolean.parseBoolean(webElement.getAttribute("ishidden")); - - assertNotNull("no event fired", webElement); - assertEquals(2, counter); - assertEquals(2, columnIndex); - assertEquals(true, userOriginated); - assertEquals(false, hidden); - } - - @Test - public void testColumnHidability_onTriggerColumnHidability_showsSidebarButton() { - WebElement sidebar = getSidebarOpenButton(); - assertNull(sidebar); - - toggleHidableColumnAPI(0); - - sidebar = getSidebarOpenButton(); - assertNotNull(sidebar); - } - - @Test - public void testColumnHidability_triggeringColumnHidabilityWithSeveralColumns_showsAndHidesSiderbarButton() { - verifySidebarNotVisible(); - - toggleHidableColumnAPI(3); - toggleHidableColumnAPI(4); - - verifySidebarVisible(); - - toggleHidableColumnAPI(3); - - verifySidebarVisible(); - - toggleHidableColumnAPI(4); - - verifySidebarNotVisible(); - } - - @Test - public void testColumnHidability_clickingSidebarButton_opensClosesSidebar() { - toggleHidableColumnAPI(0); - verifySidebarClosed(); - - clickSidebarOpenButton(); - - verifySidebarOpened(); - - clickSidebarOpenButton(); - - verifySidebarClosed(); - } - - @Test - public void testColumnHidability_settingColumnHidable_showsToggleInSidebar() { - toggleHidableColumnAPI(0); - verifySidebarClosed(); - clickSidebarOpenButton(); - verifySidebarOpened(); - - verifyColumnHidingOption(0, false); - } - - @Test - public void testColumnHiding_hidingColumnWithToggle_works() { - assertColumnHeaderOrder(0, 1, 2, 3, 4); - toggleHidableColumnAPI(0); - verifySidebarClosed(); - clickSidebarOpenButton(); - verifySidebarOpened(); - verifyColumnHidingOption(0, false); - - getColumnHidingToggle(0).click(); - verifyColumnHidingOption(0, true); - assertColumnHeaderOrder(1, 2, 3, 4); - - getColumnHidingToggle(0).click(); - verifyColumnHidingOption(0, false); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - } - - @Test - public void testColumnHiding_updatingHiddenWhileSidebarClosed_updatesToggleValue() { - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(3); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 1, 2, 4); - verifySidebarClosed(); - - clickSidebarOpenButton(); - verifySidebarOpened(); - verifyColumnHidingOption(0, false); - verifyColumnHidingOption(3, true); - - clickSidebarOpenButton(); - verifySidebarClosed(); - - toggleHideColumnAPI(0); - toggleHideColumnAPI(3); - - clickSidebarOpenButton(); - verifySidebarOpened(); - verifyColumnHidingOption(0, true); - verifyColumnHidingOption(3, false); - - } - - @Test - public void testColumnHiding_hidingMultipleColumnsWithToggle_hidesColumns() { - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - toggleHideColumnAPI(1); - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(1); - toggleHidableColumnAPI(2); - toggleHidableColumnAPI(3); - toggleHidableColumnAPI(4); - verifySidebarClosed(); - assertColumnHeaderOrder(0, 2, 3, 4); - - clickSidebarOpenButton(); - verifySidebarOpened(); - verifyColumnHidingOption(0, false); - verifyColumnHidingOption(1, true); - verifyColumnHidingOption(2, false); - verifyColumnHidingOption(3, false); - verifyColumnHidingOption(4, false); - - // must be done in a funny order so that the header indexes won't break - // (because of data source uses counter) - getColumnHidingToggle(1).click(); - getColumnHidingToggle(2).click(); - getColumnHidingToggle(3).click(); - getColumnHidingToggle(4).click(); - getColumnHidingToggle(0).click(); - verifyColumnHidingOption(0, true); - verifyColumnHidingOption(1, false); - verifyColumnHidingOption(2, true); - verifyColumnHidingOption(3, true); - verifyColumnHidingOption(4, true); - - assertColumnHeaderOrder(1, 5, 6, 7); - - getColumnHidingToggle(0).click(); - getColumnHidingToggle(2).click(); - getColumnHidingToggle(1).click(); - verifyColumnHidingOption(0, false); - verifyColumnHidingOption(1, true); - verifyColumnHidingOption(2, false); - assertColumnHeaderOrder(0, 2, 5, 6); - } - - @Test - public void testColumnHidability_changingHidabilityWhenSidebarClosed_addsRemovesToggles() { - toggleHideColumnAPI(0); - toggleHideColumnAPI(4); - assertColumnHeaderOrder(1, 2, 3, 5); - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(3); - toggleHidableColumnAPI(4); - verifySidebarClosed(); - - clickSidebarOpenButton(); - verifySidebarOpened(); - verifyColumnHidingOption(0, true); - verifyColumnHidingOption(3, false); - verifyColumnHidingOption(4, true); - - clickSidebarOpenButton(); - verifySidebarClosed(); - - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(3); - - verifySidebarClosed(); - clickSidebarOpenButton(); - verifySidebarOpened(); - verifyColumnHidingOption(4, true); - - assertNull(getColumnHidingToggle(0)); - assertNull(getColumnHidingToggle(3)); - } - - @Test - public void testColumnHidability_togglingHidability_placesTogglesInRightOrder() { - toggleHidableColumnAPI(3); - toggleHidableColumnAPI(2); - clickSidebarOpenButton(); - - verifyColumnHidingTogglesOrder(2, 3); - - toggleHidableColumnAPI(1); - toggleHidableColumnAPI(2); - toggleHidableColumnAPI(6); - toggleHidableColumnAPI(0); - - // Selecting from the menu closes the sidebar - clickSidebarOpenButton(); - - verifyColumnHidingTogglesOrder(0, 1, 3, 6); - - toggleHidableColumnAPI(2); - toggleHidableColumnAPI(4); - toggleHidableColumnAPI(7); - - clickSidebarOpenButton(); - - verifyColumnHidingTogglesOrder(0, 1, 2, 3, 4, 6, 7); - } - - @Test - public void testColumnHidability_reorderingColumns_updatesColumnToggleOrder() { - selectMenuPath("Component", "State", "Width", "1000px"); - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(1); - toggleHidableColumnAPI(3); - toggleHidableColumnAPI(4); - clickSidebarOpenButton(); - verifyColumnHidingTogglesOrder(0, 1, 3, 4); - clickSidebarOpenButton(); - - toggleColumnReorder(); - dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); - - assertColumnHeaderOrder(3, 0, 1, 2, 4); - clickSidebarOpenButton(); - verifyColumnHidingTogglesOrder(3, 0, 1, 4); - - clickSidebarOpenButton(); - dragAndDropColumnHeader(0, 1, 3, CellSide.RIGHT); - dragAndDropColumnHeader(0, 4, 0, CellSide.LEFT); - dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); - - assertColumnHeaderOrder(2, 4, 3, 1, 0); - clickSidebarOpenButton(); - verifyColumnHidingTogglesOrder(4, 3, 1, 0); - } - - @Test - public void testColumnHidingAndReorder_reorderingOverHiddenColumn_orderIsKept() { - selectMenuPath("Component", "State", "Width", "1000px"); - toggleColumnReorder(); - toggleHideColumnAPI(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - - dragAndDropColumnHeader(0, 1, 0, CellSide.LEFT); - assertColumnHeaderOrder(2, 1, 3, 4, 5); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(0, 2, 1, 3, 4, 5); - - toggleHideColumnAPI(1); - assertColumnHeaderOrder(0, 2, 3, 4, 5); - - // right side of hidden column - dragAndDropColumnHeader(0, 0, 2, CellSide.LEFT); - assertColumnHeaderOrder(2, 0, 3, 4, 5); - - toggleHideColumnAPI(1); - assertColumnHeaderOrder(2, 1, 0, 3, 4, 5); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(2, 1, 3, 4, 5); - - // left side of hidden column - dragAndDropColumnHeader(0, 0, 1, CellSide.RIGHT); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(1, 0, 2, 3, 4, 5); - } - - @Test - public void testColumnHidingAndReorder_reorderingWithMultipleHiddenColumns_works() { - selectMenuPath("Component", "State", "Width", "1000px"); - toggleColumnReorder(); - toggleHideColumnAPI(2); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 1, 4, 5, 6); - - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - assertColumnHeaderOrder(1, 0, 4, 5, 6); - - toggleHideColumnAPI(3); - assertColumnHeaderOrder(1, 3, 0, 4, 5, 6); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(1, 2, 3, 0, 4, 5, 6); - - toggleHideColumnAPI(0); - toggleHideColumnAPI(4); - assertColumnHeaderOrder(1, 2, 3, 5, 6); - - dragAndDropDefaultColumnHeader(4, 3, CellSide.LEFT); - assertColumnHeaderOrder(1, 2, 3, 6, 5); - - dragAndDropDefaultColumnHeader(4, 2, CellSide.RIGHT); - assertColumnHeaderOrder(1, 2, 3, 5, 6); - - toggleHideColumnAPI(0); - assertColumnHeaderOrder(1, 2, 3, 0, 5, 6); - - toggleHideColumnAPI(4); - assertColumnHeaderOrder(1, 2, 3, 0, 4, 5, 6); - } - - @Test - public void testReorderingHiddenColumns_movingHiddenColumn_indexIsUpdated() { - selectMenuPath("Component", "State", "Width", "1000px"); - toggleHideColumnAPI(2); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 1, 4, 5, 6); - - moveColumnLeft(3); - assertColumnHeaderOrder(0, 1, 4, 5, 6); - - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 1, 3, 4, 5, 6); - toggleHideColumnAPI(2); - assertColumnHeaderOrder(0, 1, 3, 2, 4, 5, 6); - - toggleHideColumnAPI(2); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 1, 4, 5, 6); - - moveColumnLeft(2); - moveColumnLeft(2); - moveColumnLeft(2); - assertColumnHeaderOrder(0, 1, 4, 5, 6); - - toggleHideColumnAPI(2); - assertColumnHeaderOrder(2, 0, 1, 4, 5, 6); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(2, 0, 1, 3, 4, 5, 6); - } - - // keyboard actions not working in client side test case? - @Test - @Ignore - public void testNavigationWithHiddenColumns_navigatingOverHiddenColumn_goesToNextVisibleColumn() { - selectMenuPath("Component", "State", "Width", "1000px"); - toggleHideColumnAPI(2); - toggleHideColumnAPI(3); - assertColumnHeaderOrder(0, 1, 4, 5, 6); - - getGridElement().getCell(2, 4).click(); - GridCellElement cell = getGridElement().getCell(2, 4); - assertTrue(cell.isFocused()); - - new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT); - cell = getGridElement().getCell(2, 1); - assertTrue(cell.isFocused()); - - new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT); - cell = getGridElement().getCell(2, 4); - assertTrue(cell.isFocused()); - } - - @Test - public void testNavigationWithHiddenColumns_hiddenFirstAndLastColumn_keepsNavigation() { - selectMenuPath("Component", "State", "Width", "1000px"); - toggleHideColumnAPI(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5, 6); - - getGridElement().getCell(2, 1).click(); - assertTrue(getGridElement().getCell(2, 1).isFocused()); - - new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT); - GridCellElement cell = getGridElement().getCell(2, 1); - assertTrue(cell.isFocused()); - - scrollGridHorizontallyTo(10000); - - // - getGridElement().getHeaderCell(0, 9).click(); - cell = getGridElement().getHeaderCell(0, 9); - assertTrue(cell.isFocused()); - toggleHideColumnAPI(10); - toggleHideColumnAPI(11); - - new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT); - new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT); - toggleHideColumnAPI(10); - toggleHideColumnAPI(11); - cell = getGridElement().getHeaderCell(0, 9); - assertTrue(cell.isFocused()); - } - - @Test - public void testFrozenColumnHiding_lastFrozenColumnHidden_isFrozenWhenMadeVisible() { - toggleFrozenColumns(2); - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(1); - getSidebarOpenButton().click(); - verifyColumnIsFrozen(0); - verifyColumnIsFrozen(1); - verifyColumnIsNotFrozen(2); - assertColumnHeaderOrder(0, 1, 2, 3); - - getColumnHidingToggle(1).click(); - verifyColumnIsFrozen(0); - // the grid element indexing doesn't take hidden columns into account! - verifyColumnIsNotFrozen(1); - assertColumnHeaderOrder(0, 2, 3); - - getColumnHidingToggle(0).click(); - verifyColumnIsNotFrozen(0); - assertColumnHeaderOrder(2, 3, 4); - - getColumnHidingToggle(0).click(); - assertColumnHeaderOrder(0, 2, 3); - verifyColumnIsFrozen(0); - verifyColumnIsNotFrozen(1); - - getColumnHidingToggle(1).click(); - assertColumnHeaderOrder(0, 1, 2, 3); - verifyColumnIsFrozen(0); - verifyColumnIsFrozen(1); - verifyColumnIsNotFrozen(2); - } - - @Test - public void testFrozenColumnHiding_columnHiddenFrozenCountChanged_columnIsFrozenWhenVisible() { - toggleHidableColumnAPI(1); - toggleHidableColumnAPI(2); - getSidebarOpenButton().click(); - getColumnHidingToggle(1).click(); - getColumnHidingToggle(2).click(); - assertColumnHeaderOrder(0, 3, 4); - - toggleFrozenColumns(3); - verifyColumnIsFrozen(0); - // the grid element indexing doesn't take hidden columns into account! - verifyColumnIsNotFrozen(1); - verifyColumnIsNotFrozen(2); - - getSidebarOpenButton().click(); - getColumnHidingToggle(2).click(); - verifyColumnIsFrozen(0); - verifyColumnIsFrozen(1); - verifyColumnIsNotFrozen(2); - verifyColumnIsNotFrozen(3); - - getColumnHidingToggle(1).click(); - verifyColumnIsFrozen(0); - verifyColumnIsFrozen(1); - verifyColumnIsFrozen(2); - verifyColumnIsNotFrozen(3); - verifyColumnIsNotFrozen(4); - } - - @Test - public void testSpannedCells_hidingColumnInBeginning_rendersSpannedCellCorrectly() { - loadSpannedCellsFixture(); - verifySpannedCellsFixtureStart(); - - toggleHideColumnAPI(0); - - verifyNumberOfCellsInHeader(0, 7); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 6); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 2, CAPTION_3_4_5); - verifyHeaderCellContent(2, 0, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 1); - verifyHeaderCellColspan(1, 2, 3); - verifyHeaderCellColspan(2, 1, 2); - - toggleHideColumnAPI(0); - - verifySpannedCellsFixtureStart(); - - toggleHideColumnAPI(1); - - verifyNumberOfCellsInHeader(0, 7); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 7); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 2, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 1); - verifyHeaderCellColspan(1, 2, 3); - verifyHeaderCellColspan(2, 1, 1); - - toggleHideColumnAPI(3); - - verifyNumberOfCellsInHeader(0, 6); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 6); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 2, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 1); - verifyHeaderCellColspan(1, 2, 2); - verifyHeaderCellColspan(2, 1, 1); - - toggleHideColumnAPI(1); - - verifyNumberOfCellsInHeader(0, 7); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 6); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 3, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 2); - verifyHeaderCellColspan(1, 3, 2); - verifyHeaderCellColspan(2, 1, 2); - - toggleHideColumnAPI(3); - - verifySpannedCellsFixtureStart(); - } - - @Test - public void testSpannedCells_hidingColumnInMiddle_rendersSpannedCellCorrectly() { - loadSpannedCellsFixture(); - verifySpannedCellsFixtureStart(); - - toggleHideColumnAPI(4); - - verifyNumberOfCellsInHeader(0, 7); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 6); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 3, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 2); - verifyHeaderCellColspan(1, 3, 2); - verifyHeaderCellColspan(2, 1, 2); - - toggleHideColumnAPI(4); - - verifySpannedCellsFixtureStart(); - } - - @Test - public void testSpannedCells_hidingColumnInEnd_rendersSpannedCellCorrectly() { - loadSpannedCellsFixture(); - verifySpannedCellsFixtureStart(); - - toggleHideColumnAPI(1); - - verifyNumberOfCellsInHeader(0, 7); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 7); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 2, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 1, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 1); - verifyHeaderCellColspan(1, 2, 3); - verifyHeaderCellColspan(2, 1, 1); - - toggleHideColumnAPI(1); - - verifySpannedCellsFixtureStart(); - - toggleHideColumnAPI(2); - - verifyNumberOfCellsInHeader(0, 7); - verifyNumberOfCellsInHeader(1, 4); - verifyNumberOfCellsInHeader(2, 7); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 3, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 2); - verifyHeaderCellColspan(1, 3, 3); - verifyHeaderCellColspan(2, 1, 1); - - toggleHideColumnAPI(5); - - verifyNumberOfCellsInHeader(0, 6); - verifyNumberOfCellsInHeader(1, 4); - verifyNumberOfCellsInHeader(2, 6); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 3, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 2); - verifyHeaderCellColspan(1, 3, 2); - verifyHeaderCellColspan(2, 1, 1); - - toggleHideColumnAPI(5); - toggleHideColumnAPI(2); - - verifySpannedCellsFixtureStart(); - } - - @Test - public void testSpannedCells_spanningCellOverHiddenColumn_rendersSpannedCellCorrectly() { - selectMenuPath("Component", "State", "Width", "1000px"); - appendHeaderRow(); - toggleHideColumnAPI(4); - toggleHideColumnAPI(8); - toggleHideColumnAPI(9); - toggleHideColumnAPI(10); - toggleHideColumnAPI(11); - assertColumnHeaderOrder(0, 1, 2, 3, 5, 6, 7); - verifyNumberOfCellsInHeader(1, 7); - - mergeHeaderCellsTwoThreeFour(2); - - verifyNumberOfCellsInHeader(1, 6); - verifyHeaderCellContent(1, 3, CAPTION_3_4_5); - verifyHeaderCellColspan(1, 3, 2); - } - - @Test - public void testSpannedCells_spanningCellAllHiddenColumns_rendersSpannedCellCorrectly() { - selectMenuPath("Component", "State", "Width", "1000px"); - appendHeaderRow(); - toggleHideColumnAPI(3); - toggleHideColumnAPI(4); - toggleHideColumnAPI(5); - toggleHideColumnAPI(8); - toggleHideColumnAPI(9); - toggleHideColumnAPI(10); - toggleHideColumnAPI(11); - assertColumnHeaderOrder(0, 1, 2, 6, 7); - verifyNumberOfCellsInHeader(1, 5); - - mergeHeaderCellsTwoThreeFour(2); - - verifyNumberOfCellsInHeader(1, 5); - verifyHeaderCellColspan(1, 0, 1); - verifyHeaderCellColspan(1, 1, 1); - verifyHeaderCellColspan(1, 2, 1); - verifyHeaderCellColspan(1, 3, 1); - verifyHeaderCellColspan(1, 4, 1); - } - - @Test - public void testColumnHiding_detailsRowIsOpen_renderedCorrectly() { - selectMenuPath("Component", "Row details", "Set generator"); - selectMenuPath("Component", "Row details", "Toggle details for...", - "Row 1"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - Assert.assertNotNull("Details not found", - getGridElement().getDetails(1)); - - toggleHideColumnAPI(0); - - assertColumnHeaderOrder(1, 2, 3, 4); - Assert.assertNotNull("Details not found", - getGridElement().getDetails(1)); - - toggleHideColumnAPI(0); - - assertColumnHeaderOrder(0, 1, 2, 3, 4); - Assert.assertNotNull("Details not found", - getGridElement().getDetails(1)); - } - - @Test - public void testHideShowAllColumns() { - selectMenuPath("Component", "State", "Width", "1000px"); - int colCount = 12; - for (int i = 0; i < colCount; i++) { - toggleHidableColumnAPI(i); - } - clickSidebarOpenButton(); - for (int i = 0; i < colCount; i++) { - getColumnHidingToggle(i).click(); - } - - clickSidebarOpenButton(); - // All columns hidden - assertEquals(0, getGridHeaderRowCells().size()); - clickSidebarOpenButton(); - for (int i = 0; i < colCount; i++) { - getColumnHidingToggle(i).click(); - } - - assertEquals(colCount, getGridHeaderRowCells().size()); - } - - @Test - public void testColumnHidingPopupClosedWhenClickingOutside() { - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - getSidebarOpenButton().click(); - verifySidebarOpened(); - // Click somewhere far from Grid. - new Actions(getDriver()) - .moveToElement(findElement(By.className("v-app")), 600, 600) - .click().perform(); - verifySidebarClosed(); - } - - @Test - public void hideScrollAndShow() { - toggleHidableColumnAPI(1); - toggleHideColumnAPI(1); - - getGridElement().scrollToRow(500); - Assert.assertEquals("(500, 0)", - getGridElement().getCell(500, 0).getText()); - Assert.assertEquals("(500, 2)", - getGridElement().getCell(500, 1).getText()); - - toggleHideColumnAPI(1); - - Assert.assertEquals("(500, 0)", - getGridElement().getCell(500, 0).getText()); - Assert.assertEquals("(500, 1)", - getGridElement().getCell(500, 1).getText()); - } - - @Test - public void scrollHideAndShow() { - toggleHidableColumnAPI(0); - toggleHidableColumnAPI(1); - - Assert.assertEquals("(500, 0)", - getGridElement().getCell(500, 0).getText()); - Assert.assertEquals("(500, 1)", - getGridElement().getCell(500, 1).getText()); - - toggleHideColumnAPI(0); - toggleHideColumnAPI(1); - - Assert.assertEquals("(500, 2)", - getGridElement().getCell(500, 0).getText()); - Assert.assertEquals("(500, 3)", - getGridElement().getCell(500, 1).getText()); - - toggleHideColumnAPI(0); - toggleHideColumnAPI(1); - - Assert.assertEquals("(500, 0)", - getGridElement().getCell(500, 0).getText()); - Assert.assertEquals("(500, 1)", - getGridElement().getCell(500, 1).getText()); - } - - private void loadSpannedCellsFixture() { - selectMenuPath("Component", "State", "Width", "1000px"); - appendHeaderRow(); - appendHeaderRow(); - appendHeaderRow(); - mergeHeaderCellsTwoThreeFour(2); - mergeHeaderCellsZeroOne(2); - mergeHeaderCellsOneTwo(3); - mergeHeaderCellsAll(4); - toggleHideColumnAPI(8); - toggleHideColumnAPI(9); - toggleHideColumnAPI(10); - toggleHideColumnAPI(11); - } - - private void verifySpannedCellsFixtureStart() { - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6, 7); - verifyNumberOfCellsInHeader(0, 8); - verifyNumberOfCellsInHeader(1, 5); - verifyNumberOfCellsInHeader(2, 7); - verifyNumberOfCellsInHeader(3, 1); - verifyHeaderCellContent(1, 0, CAPTION_0_1); - verifyHeaderCellContent(1, 3, CAPTION_3_4_5); - verifyHeaderCellContent(2, 1, CAPTION_1_2); - verifyHeaderCellContent(3, 0, CAPTION_ALL); - verifyHeaderCellColspan(1, 0, 2); - verifyHeaderCellColspan(1, 3, 3); - verifyHeaderCellColspan(2, 1, 2); - } - - private void toggleFrozenColumns(int count) { - selectMenuPath("Component", "State", "Frozen column count", - count + " columns"); - } - - private void verifyHeaderCellColspan(int row, int column, int colspan) { - try { - assertEquals(Integer.valueOf(colspan), - Integer.valueOf(Integer.parseInt( - getGridElement().getHeaderCell(row, column) - .getAttribute("colspan")))); - } catch (NumberFormatException nfe) { - // IE8 has colSpan - assertEquals(Integer.valueOf(colspan), - Integer.valueOf(Integer.parseInt( - getGridElement().getHeaderCell(row, column) - .getAttribute("colSpan")))); - } - } - - private void verifyNumberOfCellsInHeader(int row, int numberOfCells) { - int size = 0; - for (TestBenchElement cell : getGridElement().getHeaderCells(row)) { - if (cell.isDisplayed()) { - size++; - } - } - assertEquals(numberOfCells, size); - } - - private void verifyHeaderCellContent(int row, int column, String content) { - GridCellElement headerCell = getGridElement().getHeaderCell(row, - column); - assertEquals(content.toLowerCase(), headerCell.getText().toLowerCase()); - assertTrue(headerCell.isDisplayed()); - } - - private void verifyColumnIsFrozen(int index) { - assertTrue(getGridElement().getHeaderCell(0, index).isFrozen()); - } - - private void verifyColumnIsNotFrozen(int index) { - assertFalse(getGridElement().getHeaderCell(0, index).isFrozen()); - } - - private void verifyColumnHidingTogglesOrder(int... indices) { - WebElement sidebar = getSidebarPopup(); - List elements = sidebar - .findElements(By.className("column-hiding-toggle")); - for (int i = 0; i < indices.length; i++) { - WebElement e = elements.get(i); - assertTrue(("Header (0," + indices[i] + ")") - .equalsIgnoreCase(e.getText())); - } - } - - private void verifyColumnHidingOption(int columnIndex, boolean hidden) { - WebElement columnHidingToggle = getColumnHidingToggle(columnIndex); - assertEquals(hidden, - columnHidingToggle.getAttribute("class").contains("hidden")); - } - - private void verifySidebarOpened() { - WebElement sidebar = getSidebarPopupIfPresent(); - assertNotNull(sidebar); - } - - private void verifySidebarClosed() { - WebElement sidebar = getSidebarPopupIfPresent(); - assertNull(sidebar); - } - - private void verifySidebarNotVisible() { - WebElement sidebar = getSidebarOpenButton(); - assertNull(sidebar); - } - - private void verifySidebarVisible() { - WebElement sidebar = getSidebarOpenButton(); - assertNotNull(sidebar); - } - - /** - * Returns the toggle inside the sidebar for hiding the column at the given - * index, or null if not found. - */ - @Override - protected WebElement getColumnHidingToggle(int columnIndex) { - WebElement sidebar = getSidebarPopup(); - List elements = sidebar - .findElements(By.className("column-hiding-toggle")); - for (WebElement e : elements) { - if (("Header (0," + columnIndex + ")") - .equalsIgnoreCase(e.getText())) { - return e; - } - } - return null; - } - - private void clickSidebarOpenButton() { - getSidebarOpenButton().click(); - } - - private void moveColumnLeft(int index) { - selectMenuPath("Component", "Columns", "Column " + index, - "Move column left"); - } - - private void toggleHidableColumnAPI(int columnIndex) { - selectMenuPath("Component", "Columns", "Column " + columnIndex, - "Hidable"); - } - - private void toggleHideColumnAPI(int columnIndex) { - selectMenuPath("Component", "Columns", "Column " + columnIndex, - "Hidden"); - } - - private void appendHeaderRow() { - selectMenuPath("Component", "Header", "Append row"); - } - - private void mergeHeaderCellsZeroOne(int row) { - selectMenuPath("Component", "Header", "Row " + row, CAPTION_0_1); - } - - private void mergeHeaderCellsOneTwo(int row) { - selectMenuPath("Component", "Header", "Row " + row, CAPTION_1_2); - } - - private void mergeHeaderCellsTwoThreeFour(int row) { - selectMenuPath("Component", "Header", "Row " + row, CAPTION_3_4_5); - } - - private void mergeHeaderCellsAll(int row) { - selectMenuPath("Component", "Header", "Row " + row, CAPTION_ALL); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java deleted file mode 100644 index ddf81d73e2..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridColumnReorderTest.java +++ /dev/null @@ -1,653 +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.components.grid.basicfeatures; - -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 org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; - -/** - * - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridColumnReorderTest extends GridBasicClientFeaturesTest { - - @Before - public void before() { - openTestURL(); - } - - @Test - public void columnReorderEventTriggered() { - final int firstIndex = 3; - final int secondIndex = 4; - final String firstHeaderText = getGridElement() - .getHeaderCell(0, firstIndex).getText(); - final String secondHeaderText = getGridElement() - .getHeaderCell(0, secondIndex).getText(); - selectMenuPath("Component", "Internals", "Listeners", - "Add ColumnReorder listener"); - selectMenuPath("Component", "Columns", "Column " + secondIndex, - "Move column left"); - // columns 3 and 4 should have swapped to 4 and 3 - GridCellElement headerCell = getGridElement().getHeaderCell(0, - firstIndex); - assertEquals(secondHeaderText, headerCell.getText()); - headerCell = getGridElement().getHeaderCell(0, secondIndex); - assertEquals(firstHeaderText, headerCell.getText()); - - // the reorder event should have typed the order to this label - WebElement columnReorderElement = findElement(By.id("columnreorder")); - int eventIndex = Integer - .parseInt(columnReorderElement.getAttribute("columns")); - assertEquals(1, eventIndex); - - // trigger another event - selectMenuPath("Component", "Columns", "Column " + secondIndex, - "Move column left"); - columnReorderElement = findElement(By.id("columnreorder")); - eventIndex = Integer - .parseInt(columnReorderElement.getAttribute("columns")); - assertEquals(2, eventIndex); - } - - @Test - public void testColumnReorder_onReorder_columnReorderEventTriggered() { - final int firstIndex = 3; - final int secondIndex = 4; - final String firstHeaderText = getGridElement() - .getHeaderCell(0, firstIndex).getText(); - final String secondHeaderText = getGridElement() - .getHeaderCell(0, secondIndex).getText(); - selectMenuPath("Component", "Internals", "Listeners", - "Add ColumnReorder listener"); - selectMenuPath("Component", "Columns", "Column " + secondIndex, - "Move column left"); - // columns 3 and 4 should have swapped to 4 and 3 - GridCellElement headerCell = getGridElement().getHeaderCell(0, - firstIndex); - assertEquals(secondHeaderText, headerCell.getText()); - headerCell = getGridElement().getHeaderCell(0, secondIndex); - assertEquals(firstHeaderText, headerCell.getText()); - - // the reorder event should have typed the order to this label - WebElement columnReorderElement = findElement(By.id("columnreorder")); - int eventIndex = Integer - .parseInt(columnReorderElement.getAttribute("columns")); - assertEquals(1, eventIndex); - - // trigger another event - selectMenuPath("Component", "Columns", "Column " + secondIndex, - "Move column left"); - columnReorderElement = findElement(By.id("columnreorder")); - eventIndex = Integer - .parseInt(columnReorderElement.getAttribute("columns")); - assertEquals(2, eventIndex); - } - - @Test - public void testColumnReorder_draggingSortedColumn_sortIndicatorShownOnDraggedElement() { - // given - toggleColumnReorder(); - toggleSortableColumn(0); - sortColumn(0); - - // when - startDragButDontDropOnDefaultColumnHeader(0); - - // then - WebElement draggedElement = getDraggedHeaderElement(); - assertTrue(draggedElement.getAttribute("class").contains("sort")); - } - - @Test - public void testColumnReorder_draggingSortedColumn_sortStays() { - // given - toggleColumnReorder(); - toggleSortableColumn(0); - sortColumn(0); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - - // then - assertColumnIsSorted(1); - } - - @Test - public void testColumnReorder_draggingFocusedHeader_focusShownOnDraggedElement() { - // given - toggleColumnReorder(); - focusDefaultHeader(0); - - // when - startDragButDontDropOnDefaultColumnHeader(0); - - // then - WebElement draggedElement = getDraggedHeaderElement(); - assertTrue(draggedElement.getAttribute("class").contains("focused")); - } - - @Test - public void testColumnReorder_draggingFocusedHeader_focusIsKeptOnHeader() { - // given - toggleColumnReorder(); - focusDefaultHeader(0); - - // when - dragAndDropDefaultColumnHeader(0, 3, CellSide.LEFT); - - // then - WebElement defaultColumnHeader = getDefaultColumnHeader(2); - String attribute = defaultColumnHeader.getAttribute("class"); - assertTrue(attribute.contains("focused")); - } - - @Test - public void testColumnReorder_draggingFocusedCellColumn_focusIsKeptOnCell() { - // given - toggleColumnReorder(); - focusCell(2, 2); - - // when - dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); - - // then - assertFocusedCell(2, 0); - } - - @Test - public void testColumnReorderWithHiddenColumn_draggingFocusedCellColumnOverHiddenColumn_focusIsKeptOnCell() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Columns", "Column 1", "Hidden"); - focusCell(2, 2); - assertFocusedCell(2, 2); - - // when - dragAndDropDefaultColumnHeader(1, 0, CellSide.LEFT); - - // then - assertFocusedCell(2, 2); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - - // then - assertFocusedCell(2, 2); - } - - @Test - public void testColumnReorder_dragColumnFromRightToLeftOfFocusedCellColumn_focusIsKept() { - // given - toggleColumnReorder(); - focusCell(1, 3); - - // when - dragAndDropDefaultColumnHeader(4, 1, CellSide.LEFT); - - // then - assertFocusedCell(1, 4); - } - - @Test - public void testColumnReorder_dragColumnFromLeftToRightOfFocusedCellColumn_focusIsKept() { - // given - toggleColumnReorder(); - focusCell(4, 2); - - // when - dragAndDropDefaultColumnHeader(0, 4, CellSide.LEFT); - - // then - assertFocusedCell(4, 1); - } - - @Test - public void testColumnReorder_draggingHeaderRowThatHasColumnHeadersSpanned_cantDropInsideSpannedHeaderFromOutside() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - int horizontalOffset = (getGridElement().getHeaderCell(1, 1).getSize() - .getWidth() / 2) - 10; - dragAndDropColumnHeader(1, 3, 1, horizontalOffset); - - // then - assertColumnHeaderOrder(0, 3, 1, 2, 4); - } - - @Test - public void testColumnReorder_anotherRowHasColumnHeadersSpanned_cantDropInsideSpannedHeaderFromOutside() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - int horizontalOffset = (getGridElement().getHeaderCell(1, 1).getSize() - .getWidth() / 2) + 10; - dragAndDropColumnHeader(0, 0, 2, horizontalOffset); - - // then - assertColumnHeaderOrder(1, 2, 0, 3, 4); - } - - @Test - public void testColumnReorder_cellInsideSpannedHeader_cantBeDroppedOutsideSpannedArea() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(0, 2, 1, 3, 4); - } - - @Test - public void testColumnReorder_cellInsideTwoCrossingSpanningHeaders_cantTouchThis() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", - "Join column cells 0, 1"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); - assertColumnHeaderOrder(3, 0, 1, 2, 4); - - // when - dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(3, 0, 1, 2, 4); - } - - @Test - public void testColumnReorder_cellsInsideSpannedHeaderAndBlockedByOtherSpannedCells_cantTouchThose() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", - "Join column cells 0, 1"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); - assertColumnHeaderOrder(3, 0, 1, 2, 4); - - // when then - dragAndDropColumnHeader(0, 1, 3, CellSide.LEFT); - assertColumnHeaderOrder(3, 0, 1, 2, 4); - - dragAndDropColumnHeader(1, 2, 1, CellSide.LEFT); - assertColumnHeaderOrder(3, 0, 1, 2, 4); - - dragAndDropColumnHeader(2, 1, 2, CellSide.RIGHT); - assertColumnHeaderOrder(3, 0, 1, 2, 4); - } - - @Test - public void testColumnReorder_cellsInsideSpannedHeaderAndBlockedByOtherSpannedCells_reorderingLimited() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - dragAndDropColumnHeader(0, 0, 4, CellSide.RIGHT); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - - // when then - dragAndDropColumnHeader(0, 1, 4, CellSide.LEFT); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - - dragAndDropColumnHeader(0, 2, 4, CellSide.LEFT); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - - dragAndDropColumnHeader(0, 3, 4, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 5, 4); - - dragAndDropColumnHeader(0, 4, 2, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - - dragAndDropColumnHeader(2, 3, 4, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 5, 4); - - dragAndDropColumnHeader(2, 4, 2, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - assertColumnHeaderOrder(1, 2, 3, 4, 5); - } - - @Test - public void testColumnReorder_cellsInsideTwoAdjacentSpannedHeaders_reorderingLimited() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - dragAndDropColumnHeader(0, 0, 4, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - dragAndDropColumnHeader(0, 1, 4, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - assertColumnHeaderOrder(1, 3, 4, 5, 2); - - // when then - dragAndDropColumnHeader(0, 1, 4, CellSide.LEFT); - assertColumnHeaderOrder(1, 4, 3, 5, 2); - - dragAndDropColumnHeader(0, 2, 4, CellSide.LEFT); - assertColumnHeaderOrder(1, 4, 3, 5, 2); - - dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); - assertColumnHeaderOrder(1, 3, 4, 5, 2); - } - - @Test - public void testColumnReorder_footerHasSpannedCells_cantDropInside() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Footer", "Append row"); - selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(0, 3, 1, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(0, 3, 1, 2, 4); - } - - @Test - public void testColumnReorder_cellInsideASpannedFooter_cantBeDroppedOutsideSpannedArea() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Footer", "Append row"); - selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(0, 2, 1, 3, 4); - } - - @Test - public void testColumnReorder_cellInsideTwoCrossingSpanningFooters_cantTouchThis() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Footer", "Append row"); - selectMenuPath("Component", "Footer", "Append row"); - selectMenuPath("Component", "Footer", "Row 1", - "Join column cells 0, 1"); - selectMenuPath("Component", "Footer", "Row 2", "Join columns 1, 2"); - dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); - assertColumnHeaderOrder(3, 0, 1, 2, 4); - - // when - dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(3, 0, 1, 2, 4); - } - - @Test - public void testColumnReorder_cellsInsideTwoAdjacentSpannedHeaderAndFooter_reorderingLimited() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Footer", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - dragAndDropColumnHeader(0, 0, 5, CellSide.LEFT); - scrollGridHorizontallyTo(0); - dragAndDropColumnHeader(0, 1, 5, CellSide.LEFT); - scrollGridHorizontallyTo(0); - selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); - assertColumnHeaderOrder(1, 3, 4, 5, 2); - - // when then - dragAndDropColumnHeader(0, 1, 3, CellSide.RIGHT); - assertColumnHeaderOrder(1, 4, 3, 5, 2); - - dragAndDropColumnHeader(0, 2, 4, CellSide.RIGHT); - assertColumnHeaderOrder(1, 4, 3, 5, 2); - - dragAndDropColumnHeader(0, 2, 0, CellSide.RIGHT); - assertColumnHeaderOrder(1, 3, 4, 5, 2); - } - - @Test - public void testColumnReorder_draggingASpannedCell_dragWorksNormally() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(1, 1, 4, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 3, 1, 2, 4); - } - - @Test - public void testColumnReorder_twoEqualSpannedCells_bothCanBeDragged() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(1, 1, 4, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 3, 1, 2, 4); - - // when - dragAndDropColumnHeader(2, 3, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(1, 2, 0, 3, 4); - } - - @Test - public void testColumReorder_twoCrossingSpanningHeaders_neitherCanBeDragged() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 3", - "Join column cells 0, 1"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(1, 1, 4, CellSide.LEFT); - - // then - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(2, 0, 3, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(0, 1, 2, 3, 4); - } - - @Test - public void testColumnReorder_spannedCellHasAnotherSpannedCellInside_canBeDraggedNormally() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - dragAndDropColumnHeader(1, 3, 1, CellSide.LEFT); - scrollGridHorizontallyTo(0); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 3, 4, 5, 1); - - // when - dragAndDropColumnHeader(1, 1, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(3, 4, 5, 0, 1); - } - - @Test - public void testColumnReorder_spannedCellInsideAnotherSpanned_canBeDraggedWithBoundaries() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - dragAndDropColumnHeader(1, 3, 1, CellSide.LEFT); - scrollGridHorizontallyTo(0); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 3, 4, 5, 1); - - // when - dragAndDropColumnHeader(2, 1, 3, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 5, 3, 4, 1); - - // when - dragAndDropColumnHeader(2, 2, 0, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 3, 4, 5, 1); - } - - @Test - public void testColumnReorder_cellInsideAndNextToSpannedCells_canBeDraggedWithBoundaries() { - // given - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - dragAndDropColumnHeader(1, 3, 1, CellSide.LEFT); - scrollGridHorizontallyTo(0); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 3, 4, 5, 1); - - // when - dragAndDropColumnHeader(2, 3, 0, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 5, 3, 4, 1); - - // when - dragAndDropColumnHeader(2, 1, 4, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 3, 4, 5, 1); - } - - @Test - public void testColumnReorder_multipleSpannedCells_dragWorksNormally() { - toggleColumnReorder(); - selectMenuPath("Component", "State", "Width", "750px"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(1, 3, 1, CellSide.RIGHT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 3, 4, 5, 1); - - // when - scrollGridHorizontallyTo(100); - dragAndDropColumnHeader(2, 4, 2, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(0, 1, 2, 3, 4); - - // when - dragAndDropColumnHeader(0, 0, 3, CellSide.LEFT); - scrollGridHorizontallyTo(0); - - // then - assertColumnHeaderOrder(1, 2, 0, 3, 4); - } - - private void toggleSortableColumn(int index) { - selectMenuPath("Component", "Columns", "Column " + index, "Sortable"); - } - - private void startDragButDontDropOnDefaultColumnHeader(int index) { - new Actions(getDriver()) - .clickAndHold(getGridHeaderRowCells().get(index)) - .moveByOffset(100, 0).perform(); - } - - private void sortColumn(int index) { - getGridHeaderRowCells().get(index).click(); - } - - private void focusDefaultHeader(int index) { - getGridHeaderRowCells().get(index).click(); - } - - private WebElement getDraggedHeaderElement() { - return findElement(By.className("dragged-column-header")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java deleted file mode 100644 index 358d310190..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.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.tests.components.grid.basicfeatures; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.components.grid.GridCellFocusOnResetSizeTest.MyGridElement; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@TestCategory("grid") -public class GridDefaultTextRendererTest extends MultiBrowserTest { - - private GridElement grid; - - @Before - public void init() { - setDebug(true); - openTestURL(); - grid = $(MyGridElement.class).first(); - assertFalse("There was an unexpected notification during init", - $(NotificationElement.class).exists()); - } - - @Test - public void testNullIsRenderedAsEmptyStringByDefaultTextRenderer() { - assertTrue("First cell should've been empty", - grid.getCell(0, 0).getText().isEmpty()); - } - - @Test - public void testStringIsRenderedAsStringByDefaultTextRenderer() { - assertEquals("Second cell should've been populated ", "string", - grid.getCell(1, 0).getText()); - } - - @Test - public void testWarningShouldNotBeInDebugLog() { - assertFalse("Warning visible with string content.", isElementPresent( - By.xpath("//span[contains(.,'attached:#1')]"))); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java deleted file mode 100644 index a73de13b15..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java +++ /dev/null @@ -1,83 +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.components.grid.basicfeatures; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.remote.DesiredCapabilities; - -public class GridDescriptionGeneratorTest extends GridBasicFeaturesTest { - - @Test - public void testCellDescription() { - openTestURL(); - selectMenuPath("Component", "State", "Cell description generator"); - - getGridElement().getCell(1, 0).showTooltip(); - String tooltipText = findElement(By.className("v-tooltip-text")) - .getText(); - assertEquals("Tooltip text", "Cell tooltip for row 1, column 0", - tooltipText); - - getGridElement().getCell(1, 1).showTooltip(); - assertTrue("Tooltip should not be present in cell (1, 1) ", - findElement(By.className("v-tooltip-text")).getText() - .isEmpty()); - } - - @Test - public void testRowDescription() { - openTestURL(); - selectMenuPath("Component", "State", "Row description generator"); - - getGridElement().getCell(5, 3).showTooltip(); - String tooltipText = findElement(By.className("v-tooltip-text")) - .getText(); - assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText); - - getGridElement().getCell(15, 3).showTooltip(); - tooltipText = findElement(By.className("v-tooltip-text")).getText(); - assertEquals("Tooltip text", "Row tooltip for row 15", tooltipText); - } - - @Test - public void testRowAndCellDescription() { - openTestURL(); - selectMenuPath("Component", "State", "Row description generator"); - selectMenuPath("Component", "State", "Cell description generator"); - - getGridElement().getCell(5, 0).showTooltip(); - String tooltipText = findElement(By.className("v-tooltip-text")) - .getText(); - assertEquals("Tooltip text", "Cell tooltip for row 5, column 0", - tooltipText); - - getGridElement().getCell(5, 3).showTooltip(); - tooltipText = findElement(By.className("v-tooltip-text")).getText(); - assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText); - } - - @Override - public List getBrowsersToTest() { - return getBrowsersExcludingFirefox(); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridHeightByRowOnInitTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridHeightByRowOnInitTest.java deleted file mode 100644 index 2767f71578..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridHeightByRowOnInitTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures; - -import org.junit.Test; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -@SuppressWarnings("all") -@TestCategory("grid") -public class GridHeightByRowOnInitTest extends MultiBrowserTest { - - @Test - public void gridHeightIsMoreThanACoupleOfRows() { - openTestURL(); - int height = $(GridElement.class).first().getSize().getHeight(); - assertGreater( - "Grid should be much taller than 150px (was " + height + "px)", - height, 150); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java deleted file mode 100644 index e152493150..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java +++ /dev/null @@ -1,47 +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.components.grid.basicfeatures; - -import java.io.IOException; -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridSortingIndicatorsTest extends MultiBrowserTest { - - @Override - public List getBrowsersToTest() { - List browsers = getBrowsersExcludingPhantomJS(); - browsers.add(PHANTOMJS2()); - return browsers; - } - - @Test - public void testSortingIndicators() throws IOException { - openTestURL(); - compareScreen("initialSort"); - - $(ButtonElement.class).first().click(); - - compareScreen("reversedSort"); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java deleted file mode 100644 index 802d55eb50..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java +++ /dev/null @@ -1,59 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -public class DisabledGridClientTest extends GridBasicClientFeaturesTest { - - @Before - public void setUp() { - openTestURL(); - selectMenuPath("Component", "State", "Enabled"); - } - - @Test - public void testSelection() { - selectMenuPath("Component", "State", "Selection mode", "single"); - - GridRowElement row = getGridElement().getRow(0); - GridCellElement cell = getGridElement().getCell(0, 0); - cell.click(); - assertFalse("disabled row should not be selected", row.isSelected()); - } - - @Test - public void testEditorOpening() { - selectMenuPath("Component", "Editor", "Enabled"); - GridRowElement row = getGridElement().getRow(0); - GridCellElement cell = getGridElement().getCell(0, 0); - cell.click(); - assertNull("Editor should not open", getEditor()); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertNull("Editor should not open", getEditor()); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridCellStyleGeneratorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridCellStyleGeneratorTest.java deleted file mode 100644 index dcb4740eda..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridCellStyleGeneratorTest.java +++ /dev/null @@ -1,145 +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.components.grid.basicfeatures.client; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget; - -public class GridCellStyleGeneratorTest extends GridBasicClientFeaturesTest { - - @Test - public void testStyleNameGeneratorScrolling() throws Exception { - openTestURL(); - - selectCellStyleNameGenerator( - GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); - selectRowStyleNameGenerator( - GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); - - GridRowElement row2 = getGridElement().getRow(2); - GridCellElement cell4_2 = getGridElement().getCell(4, 2); - - Assert.assertTrue(hasCssClass(row2, "2")); - Assert.assertTrue(hasCssClass(cell4_2, "4_2")); - - // Scroll down and verify that the old elements don't have the - // stylename any more - - getGridElement().getRow(350); - - Assert.assertFalse(hasCssClass(row2, "2")); - Assert.assertFalse(hasCssClass(cell4_2, "4_2")); - } - - @Test - public void testDisableStyleNameGenerator() throws Exception { - openTestURL(); - - selectCellStyleNameGenerator( - GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); - selectRowStyleNameGenerator( - GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); - - // Just verify that change was effective - GridRowElement row2 = getGridElement().getRow(2); - GridCellElement cell4_2 = getGridElement().getCell(4, 2); - - Assert.assertTrue(hasCssClass(row2, "2")); - Assert.assertTrue(hasCssClass(cell4_2, "4_2")); - - // Disable the generator and check again - selectCellStyleNameGenerator( - GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_NONE); - selectRowStyleNameGenerator( - GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE); - - Assert.assertFalse(hasCssClass(row2, "2")); - Assert.assertFalse(hasCssClass(cell4_2, "4_2")); - } - - @Test - public void testChangeStyleNameGenerator() throws Exception { - openTestURL(); - - selectCellStyleNameGenerator( - GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); - selectRowStyleNameGenerator( - GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); - - // Just verify that change was effective - GridRowElement row2 = getGridElement().getRow(2); - GridCellElement cell4_2 = getGridElement().getCell(4, 2); - - Assert.assertTrue(hasCssClass(row2, "2")); - Assert.assertTrue(hasCssClass(cell4_2, "4_2")); - - // Change the generator and check again - selectRowStyleNameGenerator( - GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE); - selectCellStyleNameGenerator( - GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_SIMPLE); - - // Old styles removed? - Assert.assertFalse(hasCssClass(row2, "2")); - Assert.assertFalse(hasCssClass(cell4_2, "4_2")); - - // New style present? - Assert.assertTrue(hasCssClass(cell4_2, "two")); - } - - @Test - public void testStyleNameGeneratorChangePrimary() throws Exception { - openTestURL(); - - selectCellStyleNameGenerator( - GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); - selectRowStyleNameGenerator( - GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); - - // Just verify that change was effective - GridRowElement row2 = getGridElement().getRow(2); - GridCellElement cell4_2 = getGridElement().getCell(4, 2); - - Assert.assertTrue(hasCssClass(row2, "2")); - Assert.assertTrue(hasCssClass(cell4_2, "4_2")); - - // Change primary stylename - selectMenuPath("Component", "State", "Primary Stylename", - "v-escalator"); - - // Styles still present - Assert.assertTrue(hasCssClass(row2, "2")); - Assert.assertTrue(hasCssClass(cell4_2, "4_2")); - - // New styles present? - Assert.assertFalse(hasCssClass(row2, "v-escalator-row-2")); - Assert.assertFalse( - hasCssClass(cell4_2, "v-escalator-cell-content-4_2")); - } - - private void selectCellStyleNameGenerator(String name) { - selectMenuPath("Component", "State", "Cell style generator", name); - } - - private void selectRowStyleNameGenerator(String name) { - selectMenuPath("Component", "State", "Row style generator", name); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java deleted file mode 100644 index 4ffa26a22d..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java +++ /dev/null @@ -1,183 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridClientColumnPropertiesTest - extends GridBasicClientFeaturesTest { - - @Test - public void initialColumnWidths() { - openTestURL(); - - for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) { - int width = getGridElement().getCell(0, col).getSize().getWidth(); - if (col <= 6) { - // Growing column widths - int expectedWidth = 50 + col * 25; - assertEquals("column " + col + " has incorrect width", - expectedWidth, width); - } - } - } - - @Test - public void testChangingColumnWidth() { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Width", "50px"); - int width = getGridElement().getCell(0, 0).getSize().getWidth(); - assertEquals(50, width); - - selectMenuPath("Component", "Columns", "Column 0", "Width", "200px"); - width = getGridElement().getCell(0, 0).getSize().getWidth(); - assertEquals(200, width); - - selectMenuPath("Component", "Columns", "Column 0", "Width", "auto"); - int autoWidth = getGridElement().getCell(0, 0).getSize().getWidth(); - assertLessThan("Automatic sizing should've shrunk the column", - autoWidth, width); - } - - @Test - public void testFrozenColumns() { - openTestURL(); - - assertFalse(cellIsFrozen(0, 0)); - assertFalse(cellIsFrozen(0, 1)); - - selectMenuPath("Component", "State", "Frozen column count", - "1 columns"); - - assertTrue(cellIsFrozen(1, 0)); - assertFalse(cellIsFrozen(1, 1)); - - selectMenuPath("Component", "State", "Selection mode", "multi"); - - assertTrue(cellIsFrozen(1, 1)); - assertFalse(cellIsFrozen(1, 2)); - - selectMenuPath("Component", "State", "Frozen column count", - "0 columns"); - - assertTrue(cellIsFrozen(1, 0)); - assertFalse(cellIsFrozen(1, 1)); - - selectMenuPath("Component", "State", "Frozen column count", - "-1 columns"); - - assertFalse(cellIsFrozen(1, 0)); - } - - @Test - public void testFrozenColumns_columnsReordered_frozenColumnsKept() { - openTestURL(); - - selectMenuPath("Component", "State", "Frozen column count", - "2 columns"); - - assertTrue(cellIsFrozen(1, 0)); - assertTrue(cellIsFrozen(1, 1)); - assertFalse(cellIsFrozen(1, 2)); - - selectMenuPath("Component", "State", "Reverse grid columns"); - - assertTrue(cellIsFrozen(1, 0)); - assertTrue(cellIsFrozen(1, 1)); - assertFalse(cellIsFrozen(1, 2)); - } - - @Test - public void testBrokenRenderer() { - setDebug(true); - openTestURL(); - - GridElement gridElement = getGridElement(); - - // Scroll first row out of view - gridElement.getRow(50); - - // Enable broken renderer for the first row - selectMenuPath("Component", "Columns", "Column 0", "Broken renderer"); - - // Shouldn't have an error notification yet - assertFalse("Notification was present", - isElementPresent(NotificationElement.class)); - - // Scroll broken row into view and enjoy the chaos - gridElement.getRow(0); - - assertTrue("Notification was not present", - isElementPresent(NotificationElement.class)); - - assertFalse("Text in broken cell should have old value", - "(0, 0)".equals(gridElement.getCell(0, 0).getText())); - - assertEquals("Neighbour cell should be updated", "(0, 1)", - gridElement.getCell(0, 1).getText()); - - assertEquals("Neighbour cell should be updated", "(1, 0)", - gridElement.getCell(1, 0).getText()); - } - - @Test - public void testColumnWidths_onColumnReorder_columnWidthsKeptTheSame() { - // given - openTestURL(); - GridElement gridElement = getGridElement(); - List headerCells = gridElement.getHeaderCells(0); - - final List columnWidths = new ArrayList(); - for (GridCellElement cell : headerCells) { - columnWidths.add(cell.getSize().getWidth()); - } - - // when - selectMenuPath("Component", "State", "Reverse grid columns"); - - // then - gridElement = getGridElement(); - headerCells = gridElement.getHeaderCells(0); - final int size = headerCells.size(); - for (int i = 0; i < size; i++) { - // Avoid issues with inaccuracies regarding subpixels. - assertEquals( - "Column widths don't match after reset, index after flip " - + i, - columnWidths.get(i), - headerCells.get(size - 1 - i).getSize().getWidth(), 1.0d); - } - - } - - private boolean cellIsFrozen(int row, int col) { - return getGridElement().getCell(row, col).isFrozen(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java deleted file mode 100644 index 29e6fed68c..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures.client; - -import org.junit.Before; - -public class GridClientCompositeEditorTest extends GridEditorClientTest { - - @Override - @Before - public void setUp() { - setUseComposite(true); - super.setUp(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeFooterTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeFooterTest.java deleted file mode 100644 index 26ae7320b0..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeFooterTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures.client; - -import org.junit.Before; - -public class GridClientCompositeFooterTest extends GridFooterTest { - - @Before - public void setUp() { - setUseComposite(true); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeHeaderTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeHeaderTest.java deleted file mode 100644 index c0ed833ab2..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeHeaderTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures.client; - -import org.junit.Before; - -public class GridClientCompositeHeaderTest extends GridHeaderTest { - - @Before - public void setUp() { - setUseComposite(true); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeKeyEventsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeKeyEventsTest.java deleted file mode 100644 index fada87b15d..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeKeyEventsTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures.client; - -import org.junit.Before; - -public class GridClientCompositeKeyEventsTest extends GridClientKeyEventsTest { - - @Before - public void setUp() { - setUseComposite(true); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeSelectionTest.java deleted file mode 100644 index 7a79a114b8..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientCompositeSelectionTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.vaadin.tests.components.grid.basicfeatures.client; - -import org.junit.Before; - -public class GridClientCompositeSelectionTest extends GridClientSelectionTest { - - @Before - public void setUp() { - setUseComposite(true); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java deleted file mode 100644 index 1734aeef51..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java +++ /dev/null @@ -1,64 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -public class GridClientContextMenuEventTest - extends GridBasicClientFeaturesTest { - - @Override - public List getBrowsersToTest() { - // PhantomJS doesn't support context click.. - return getBrowsersExcludingPhantomJS(); - } - - @Test - public void testContextMenuEventIsHandledCorrectly() { - setDebug(true); - openTestURL(); - - selectMenuPath("Component", "Internals", "Listeners", - "Add context menu listener"); - - openDebugLogTab(); - clearDebugMessages(); - - new Actions(getDriver()) - .moveToElement(getGridElement().getCell(0, 0), 5, 5) - .contextClick().perform(); - - assertTrue("Debug log was not visible", isElementPresent(By.xpath( - "//span[text() = 'Prevented opening a context menu in grid body']"))); - - new Actions(getDriver()) - .moveToElement(getGridElement().getHeaderCell(0, 0), 5, 5) - .contextClick().perform(); - - assertTrue("Debug log was not visible", isElementPresent(By.xpath( - "//span[text() = 'Prevented opening a context menu in grid header']"))); - - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java deleted file mode 100644 index 5b4e9abbe9..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java +++ /dev/null @@ -1,167 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest { - - private List eventOrder = Arrays.asList("Down", "Up", "Press"); - - @Test - public void testBodyKeyEvents() throws IOException { - openTestURL(); - - getGridElement().getCell(2, 2).click(); - - new Actions(getDriver()).sendKeys("a").perform(); - - for (int i = 0; i < 3; ++i) { - assertEquals("Body key event handler was not called.", - "(2, 2) event: GridKey" + eventOrder.get(i) + "Event:[" - + (eventOrder.get(i).equals("Press") ? "a" : 65) - + "]", - findElements(By.className("v-label")).get(i * 3).getText()); - - assertTrue("Header key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3 + 1) - .getText().isEmpty()); - assertTrue("Footer key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3 + 2) - .getText().isEmpty()); - } - - } - - @Test - public void testHeaderKeyEvents() throws IOException { - openTestURL(); - - getGridElement().getHeaderCell(0, 2).click(); - - new Actions(getDriver()).sendKeys("a").perform(); - - for (int i = 0; i < 3; ++i) { - assertEquals("Header key event handler was not called.", - "(0, 2) event: GridKey" + eventOrder.get(i) + "Event:[" - + (eventOrder.get(i).equals("Press") ? "a" : 65) - + "]", - findElements(By.className("v-label")).get(i * 3 + 1) - .getText()); - - assertTrue("Body key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3).getText() - .isEmpty()); - assertTrue("Footer key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3 + 2) - .getText().isEmpty()); - } - } - - @Test - public void selectAllUsingKeyboard() { - openTestURL(); - - selectMenuPath("Component", "Header", "Prepend row"); - selectMenuPath("Component", "Header", "Append row"); - selectMenuPath("Component", "State", "Selection mode", "multi"); - - // IE8 does not handle 1k rows well with assertions enabled. Less rows! - selectMenuPath("Component", "DataSource", - "Reset with 100 rows of Data"); - - // Focus cell above select all checkbox - getGridElement().getHeaderCell(0, 0).click(); - Assert.assertFalse(isRowSelected(1)); - new Actions(getDriver()).sendKeys(" ").perform(); - Assert.assertFalse(isRowSelected(1)); - - // Move down to select all checkbox cell - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - Assert.assertFalse(isRowSelected(1)); - new Actions(getDriver()).sendKeys(" ").perform(); // select all - Assert.assertTrue(isRowSelected(1)); - new Actions(getDriver()).sendKeys(" ").perform(); // deselect all - Assert.assertFalse(isRowSelected(1)); - - // Move down to header below select all checkbox cell - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - Assert.assertFalse(isRowSelected(1)); - new Actions(getDriver()).sendKeys(" ").perform(); // deselect all - Assert.assertFalse(isRowSelected(1)); - - } - - @Test - public void testFooterKeyEvents() throws IOException { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - getGridElement().getFooterCell(0, 2).click(); - - new Actions(getDriver()).sendKeys("a").perform(); - - for (int i = 0; i < 3; ++i) { - assertEquals("Footer key event handler was not called.", - "(0, 2) event: GridKey" + eventOrder.get(i) + "Event:[" - + (eventOrder.get(i).equals("Press") ? "a" : 65) - + "]", - findElements(By.className("v-label")).get(i * 3 + 2) - .getText()); - - assertTrue("Body key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3).getText() - .isEmpty()); - assertTrue("Header key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3 + 1) - .getText().isEmpty()); - - } - } - - @Test - public void testNoKeyEventsFromWidget() { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 2", "Header Type", - "Widget Header"); - GridCellElement header = getGridElement().getHeaderCell(0, 2); - header.findElement(By.tagName("button")).click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - for (int i = 0; i < 3; ++i) { - assertTrue("Header key event handler got called unexpectedly.", - findElements(By.className("v-label")).get(i * 3 + 1) - .getText().isEmpty()); - - } - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java deleted file mode 100644 index 1e10f7abdf..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java +++ /dev/null @@ -1,212 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -public class GridClientSelectionTest extends GridBasicClientFeaturesTest { - - @Test - public void testChangeSelectionMode() { - openTestURL(); - - setSelectionModelNone(); - assertTrue("First column was selection column", - getGridElement().getCell(0, 0).getText().equals("(0, 0)")); - setSelectionModelMulti(); - assertTrue("First column was not selection column", - getGridElement().getCell(0, 1).getText().equals("(0, 0)")); - } - - @Test - public void testSelectAllCheckbox() { - openTestURL(); - - setSelectionModelMulti(); - selectMenuPath("Component", "DataSource", - "Reset with 100 rows of Data"); - GridCellElement header = getGridElement().getHeaderCell(0, 0); - - assertTrue("No checkbox", header.isElementPresent(By.tagName("input"))); - header.findElement(By.tagName("input")).click(); - - for (int i = 0; i < 100; i += 10) { - assertTrue("Row " + i + " was not selected.", - getGridElement().getRow(i).isSelected()); - } - - header.findElement(By.tagName("input")).click(); - assertFalse("Row 52 was still selected", - getGridElement().getRow(52).isSelected()); - } - - @Test - public void testSelectAllCheckboxWhenChangingModels() { - openTestURL(); - - GridCellElement header; - header = getGridElement().getHeaderCell(0, 0); - assertFalse( - "Check box shouldn't have been in header for None Selection Model", - header.isElementPresent(By.tagName("input"))); - - setSelectionModelMulti(); - header = getGridElement().getHeaderCell(0, 0); - assertTrue("Multi Selection Model should have select all checkbox", - header.isElementPresent(By.tagName("input"))); - - setSelectionModelSingle(true); - header = getGridElement().getHeaderCell(0, 0); - assertFalse( - "Check box shouldn't have been in header for Single Selection Model", - header.isElementPresent(By.tagName("input"))); - - setSelectionModelNone(); - header = getGridElement().getHeaderCell(0, 0); - assertFalse( - "Check box shouldn't have been in header for None Selection Model", - header.isElementPresent(By.tagName("input"))); - - } - - @Test - public void testDeselectAllowedMouseInput() { - openTestURL(); - - setSelectionModelSingle(true); - - getGridElement().getCell(5, 1).click(); - - assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); - - getGridElement().getCell(7, 1).click(); - - assertFalse("Row 5 should be deselected after clicking another row", - isRowSelected(5)); - assertTrue("Row 7 should be selected after clicking", isRowSelected(7)); - - getGridElement().getCell(7, 1).click(); - - assertFalse("Row should be deselected after clicking again", - isRowSelected(7)); - } - - @Test - public void testDeselectAllowedKeyboardInput() { - openTestURL(); - - setSelectionModelSingle(true); - - getGridElement().getHeaderCell(0, 0).click(); - - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Row 0 should be selected after pressing space", - isRowSelected(0)); - - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertFalse( - "Row 0 should be deselected after pressing space another row", - isRowSelected(0)); - assertTrue("Row 1 should be selected after pressing space", - isRowSelected(1)); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertFalse("Row should be deselected after pressing space again", - isRowSelected(1)); - } - - @Test - public void testDeselectNotAllowedMouseInput() { - openTestURL(); - - setSelectionModelSingle(false); - - getGridElement().getCell(5, 1).click(); - - assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); - - getGridElement().getCell(7, 1).click(); - - assertFalse("Row 5 should be deselected after clicking another row", - isRowSelected(5)); - assertTrue("Row 7 should be selected after clicking", isRowSelected(7)); - - getGridElement().getCell(7, 1).click(); - - assertTrue("Row should remain selected after clicking again", - isRowSelected(7)); - } - - @Test - public void testDeselectNotAllowedKeyboardInput() { - openTestURL(); - - setSelectionModelSingle(false); - - getGridElement().getHeaderCell(0, 0).click(); - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Row 0 should be selected after pressing space", - isRowSelected(0)); - - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertFalse( - "Row 0 should be deselected after pressing space another row", - isRowSelected(0)); - assertTrue("Row 1 should be selected after pressing space", - isRowSelected(1)); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Row should remain selected after pressing space again", - isRowSelected(1)); - } - - @Test - public void testChangeSelectionModelUpdatesUI() { - openTestURL(); - - setSelectionModelSingle(true); - getGridElement().getCell(5, 1).click(); - assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); - setSelectionModelNone(); - assertFalse( - "Row 5 should not be selected after changing selection model", - isRowSelected(5)); - - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientStructureTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientStructureTest.java deleted file mode 100644 index 2bafd260ee..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridClientStructureTest.java +++ /dev/null @@ -1,37 +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.components.grid.basicfeatures.client; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -@SuppressWarnings("all") -public class GridClientStructureTest extends GridBasicClientFeaturesTest { - @Test - public void haederDecoSizeShouldBeRecalculated() { - // it's easier to notice with valo - openTestURL("theme=valo"); - - WebElement topDeco = getGridElement() - .findElement(By.className("v-grid-header-deco")); - assertGreater( - "The header deco in Valo hasn't been recalculated after initial rendering", - topDeco.getSize().getHeight(), 20); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java deleted file mode 100644 index 1b00d14050..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java +++ /dev/null @@ -1,252 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; - -import com.vaadin.shared.Range; -import com.vaadin.testbench.By; -import com.vaadin.testbench.ElementQuery; -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.customelements.FixedNotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.v7.shared.ui.grid.ScrollDestination; - -public class GridDetailsClientTest extends GridBasicClientFeaturesTest { - - private static final String[] SET_GENERATOR = new String[] { "Component", - "Row details", "Set generator" }; - private static final String[] SET_FAULTY_GENERATOR = new String[] { - "Component", "Row details", "Set faulty generator" }; - private static final String[] SET_EMPTY_GENERATOR = new String[] { - "Component", "Row details", "Set empty generator" }; - - @Before - public void setUp() { - setDebug(true); - openTestURL(); - } - - @Test(expected = NoSuchElementException.class) - public void noDetailsByDefault() { - assertNull("details for row 1 should not exist at the start", - getGridElement().getDetails(1)); - } - - @Test(expected = NoSuchElementException.class) - public void nullRendererDoesNotShowDetailsPlaceholder() { - toggleDetailsFor(1); - getGridElement().getDetails(1); - } - - @Test - public void applyRendererThenOpenDetails() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - - TestBenchElement details = getGridElement().getDetails(1); - assertTrue("Unexpected details content", - details.getText().startsWith("Row: 1.")); - } - - @Test(expected = NoSuchElementException.class) - public void openDetailsThenAppyRendererShouldNotShowDetails() { - toggleDetailsFor(1); - selectMenuPath(SET_GENERATOR); - - getGridElement().getDetails(1); - } - - @Test - public void openHiddenDetailsThenScrollToIt() { - try { - getGridElement().getDetails(100); - fail("details row for 100 was apparently found, while it shouldn't have been."); - } catch (NoSuchElementException e) { - // expected - } - - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(100); - - // scroll a bit beyond so we see below. - getGridElement().scrollToRow(101); - - TestBenchElement details = getGridElement().getDetails(100); - assertTrue("Unexpected details content", - details.getText().startsWith("Row: 100.")); - } - - @Test - public void errorUpdaterShowsErrorNotification() { - assertFalse("No notifications should've been at the start", - $(FixedNotificationElement.class).exists()); - - selectMenuPath(SET_FAULTY_GENERATOR); - toggleDetailsFor(1); - - ElementQuery notification = $( - FixedNotificationElement.class); - assertTrue("Was expecting an error notification here", - notification.exists()); - notification.first().close(); - - assertEquals("The error details element should be empty", "", - getGridElement().getDetails(1).getText()); - } - - @Test(expected = NoSuchElementException.class) - public void detailsClosedWhenResettingGenerator() { - - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - - selectMenuPath(SET_FAULTY_GENERATOR); - getGridElement().getDetails(1); - } - - @Test - public void settingNewGeneratorStillWorksAfterError() { - selectMenuPath(SET_FAULTY_GENERATOR); - toggleDetailsFor(1); - $(FixedNotificationElement.class).first().close(); - toggleDetailsFor(1); - - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - - assertNotEquals("New details should've been generated even after error", - "", getGridElement().getDetails(1).getText()); - } - - @Test - public void updaterRendersExpectedWidgets() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - - TestBenchElement detailsElement = getGridElement().getDetails(1); - assertNotNull(detailsElement.findElement(By.className("gwt-Label"))); - assertNotNull(detailsElement.findElement(By.className("gwt-Button"))); - } - - @Test - public void widgetsInUpdaterWorkAsExpected() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - - TestBenchElement detailsElement = getGridElement().getDetails(1); - WebElement button = detailsElement - .findElement(By.className("gwt-Button")); - button.click(); - - WebElement label = detailsElement - .findElement(By.className("gwt-Label")); - assertEquals("clicked", label.getText()); - } - - @Test - public void emptyGenerator() { - selectMenuPath(SET_EMPTY_GENERATOR); - toggleDetailsFor(1); - - assertEquals("empty generator did not produce an empty details row", "", - getGridElement().getDetails(1).getText()); - } - - @Test(expected = NoSuchElementException.class) - public void removeDetailsRow() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - toggleDetailsFor(1); - - getGridElement().getDetails(1); - } - - @Test - public void rowElementClassNames() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(0); - toggleDetailsFor(1); - - List elements = getGridElement() - .findElements(By.className("v-grid-spacer")); - assertEquals("v-grid-spacer", elements.get(0).getAttribute("class")); - assertEquals("v-grid-spacer stripe", - elements.get(1).getAttribute("class")); - } - - @Test - public void scrollDownToRowWithDetails() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(100); - scrollToRow(100, ScrollDestination.ANY); - - Range validScrollRange = Range.between(1691, 1706); - assertTrue(validScrollRange.contains(getGridVerticalScrollPos())); - } - - @Test - public void scrollUpToRowWithDetails() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(100); - scrollGridVerticallyTo(999999); - scrollToRow(100, ScrollDestination.ANY); - - Range validScrollRange = Range.between(1981, 2001); - assertTrue(validScrollRange.contains(getGridVerticalScrollPos())); - } - - @Test - public void cannotScrollBeforeTop() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(1); - scrollToRow(0, ScrollDestination.END); - assertEquals(0, getGridVerticalScrollPos()); - } - - @Test - public void cannotScrollAfterBottom() { - selectMenuPath(SET_GENERATOR); - toggleDetailsFor(999); - scrollToRow(999, ScrollDestination.START); - - Range expectedRange = Range.withLength(19671, 20); - assertTrue(expectedRange.contains(getGridVerticalScrollPos())); - } - - private void scrollToRow(int rowIndex, ScrollDestination destination) { - selectMenuPath(new String[] { "Component", "State", "Scroll to...", - "Row " + rowIndex + "...", "Destination " + destination }); - } - - private void toggleDetailsFor(int rowIndex) { - selectMenuPath(new String[] { "Component", "Row details", - "Toggle details for...", "Row " + rowIndex }); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java deleted file mode 100644 index abbd954b9b..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridEditorClientTest.java +++ /dev/null @@ -1,301 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.v7.shared.ui.grid.GridConstants; - -public class GridEditorClientTest extends GridBasicClientFeaturesTest { - - private static final String[] EDIT_ROW_100 = new String[] { "Component", - "Editor", "Edit row 100" }; - private static final String[] EDIT_ROW_5 = new String[] { "Component", - "Editor", "Edit row 5" }; - - @Before - public void setUp() { - openTestURL(); - selectMenuPath("Component", "Editor", "Enabled"); - } - - @Test - public void testProgrammaticOpeningClosing() { - selectMenuPath(EDIT_ROW_5); - assertNotNull(getEditor()); - - selectMenuPath("Component", "Editor", "Cancel edit"); - assertNull(getEditor()); - assertEquals("Row 5 edit cancelled", - findElement(By.className("grid-editor-log")).getText()); - } - - @Test - public void testProgrammaticOpeningWithScroll() { - selectMenuPath(EDIT_ROW_100); - assertNotNull(getEditor()); - } - - @Test(expected = NoSuchElementException.class) - public void testVerticalScrollLocking() { - selectMenuPath(EDIT_ROW_5); - getGridElement().getCell(200, 0); - } - - @Test - public void testMouseOpeningClosing() { - - getGridElement().getCell(4, 0).doubleClick(); - assertNotNull(getEditor()); - - // Move focus to the third input field - getEditor().findElements(By.className("gwt-TextBox")).get(2).click(); - - // Press save button - getSaveButton().click(); - - // Make sure the editor went away - assertNull(getEditor()); - - // Check that focus has moved to cell 4,2 - the last one that was - // focused in Editor - assertTrue(getGridElement().getCell(4, 2).isFocused()); - - // Disable editor - selectMenuPath("Component", "Editor", "Enabled"); - - getGridElement().getCell(4, 0).doubleClick(); - assertNull(getEditor()); - } - - @Test - public void testKeyboardOpeningClosing() { - - getGridElement().getCell(4, 0).click(); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - assertNotNull(getEditor()); - - new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); - assertNull(getEditor()); - assertEquals("Row 4 edit cancelled", - findElement(By.className("grid-editor-log")).getText()); - - // Disable editor - selectMenuPath("Component", "Editor", "Enabled"); - - getGridElement().getCell(5, 0).click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertNull(getEditor()); - } - - @Test - public void testWidgetBinding() throws Exception { - selectMenuPath(EDIT_ROW_100); - WebElement editor = getEditor(); - - List widgets = editor - .findElements(By.className("gwt-TextBox")); - - assertEquals(GridBasicFeatures.EDITABLE_COLUMNS, widgets.size()); - - assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); - assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); - assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); - - assertEquals("100", widgets.get(6).getAttribute("value")); - assertEquals("100", widgets.get(8).getAttribute("value")); - } - - @Test - public void testWithSelectionColumn() throws Exception { - selectMenuPath("Component", "State", "Selection mode", "multi"); - selectMenuPath("Component", "State", "Frozen column count", - "-1 columns"); - selectMenuPath(EDIT_ROW_5); - - WebElement editorCells = findElements( - By.className("v-grid-editor-cells")).get(1); - List selectorDivs = editorCells - .findElements(By.cssSelector("div")); - - assertFalse("selector column cell should've had contents", - selectorDivs.get(0).getAttribute("innerHTML").isEmpty()); - assertFalse("normal column cell shoul've had contents", - selectorDivs.get(1).getAttribute("innerHTML").isEmpty()); - } - - @Test - public void testSave() { - selectMenuPath(EDIT_ROW_100); - - WebElement textField = getEditor() - .findElements(By.className("gwt-TextBox")).get(0); - - textField.clear(); - textField.sendKeys("Changed"); - - WebElement saveButton = getEditor() - .findElement(By.className("v-grid-editor-save")); - - saveButton.click(); - - assertEquals("Changed", getGridElement().getCell(100, 0).getText()); - } - - @Test - public void testProgrammaticSave() { - selectMenuPath(EDIT_ROW_100); - - WebElement textField = getEditor() - .findElements(By.className("gwt-TextBox")).get(0); - - textField.clear(); - textField.sendKeys("Changed"); - - selectMenuPath("Component", "Editor", "Save"); - - assertEquals("Changed", getGridElement().getCell(100, 0).getText()); - } - - @Test - public void testCaptionChange() { - selectMenuPath(EDIT_ROW_5); - assertEquals("Save button caption should've been \"" - + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with", - GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); - assertEquals("Cancel button caption should've been \"" - + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with", - GridConstants.DEFAULT_CANCEL_CAPTION, - getCancelButton().getText()); - - selectMenuPath("Component", "Editor", "Change Save Caption"); - assertNotEquals( - "Save button caption should've changed while editor is open", - GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); - - getCancelButton().click(); - - selectMenuPath("Component", "Editor", "Change Cancel Caption"); - selectMenuPath(EDIT_ROW_5); - assertNotEquals( - "Cancel button caption should've changed while editor is closed", - GridConstants.DEFAULT_CANCEL_CAPTION, - getCancelButton().getText()); - } - - @Test - public void testUneditableColumn() { - selectMenuPath("Component", "Editor", "Edit row 5"); - - assertFalse("Uneditable column should not have an editor widget", - getGridElement().getEditor().isEditable(3)); - } - - @Test - public void testErrorField() { - selectMenuPath(EDIT_ROW_5); - - GridEditorElement editor = getGridElement().getEditor(); - - assertTrue("No errors should be present", - editor.findElements(By.className("error")).isEmpty()); - assertEquals("No error message should be present", null, - editor.getErrorMessage()); - - selectMenuPath("Component", "Editor", "Toggle second editor error"); - getSaveButton().click(); - - assertEquals("Unexpected amount of error fields", 1, - editor.findElements(By.className("error")).size()); - assertEquals("Unexpedted error message", - "Syntethic fail of editor in column 2. " - + "This message is so long that it doesn't fit into its box", - editor.getErrorMessage()); - } - - @Test - public void testFocusOnMouseOpen() { - - GridCellElement cell = getGridElement().getCell(4, 2); - - cell.doubleClick(); - - WebElement focused = getFocusedElement(); - - assertEquals("", "input", focused.getTagName()); - assertEquals("", cell.getText(), focused.getAttribute("value")); - } - - @Test - public void testFocusOnKeyboardOpen() { - - GridCellElement cell = getGridElement().getCell(4, 2); - - cell.click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - WebElement focused = getFocusedElement(); - - assertEquals("", "input", focused.getTagName()); - assertEquals("", cell.getText(), focused.getAttribute("value")); - } - - @Test - public void testNoFocusOnProgrammaticOpen() { - - selectMenuPath(EDIT_ROW_5); - - WebElement focused = getFocusedElement(); - - if (BrowserUtil.isIE(getDesiredCapabilities())) { - assertEquals("Focus should be nowhere", null, focused); - } else { - // GWT menubar loses focus after clicking a menuitem - assertEquals("Focus should be in body", "body", - focused.getTagName()); - } - } - - protected WebElement getSaveButton() { - return getEditor().findElement(By.className("v-grid-editor-save")); - } - - protected WebElement getCancelButton() { - return getEditor().findElement(By.className("v-grid-editor-cancel")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridFooterTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridFooterTest.java deleted file mode 100644 index 0aef98acbc..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridFooterTest.java +++ /dev/null @@ -1,220 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; - -public class GridFooterTest extends GridStaticSectionTest { - - @Test - public void testDefaultFooter() { - openTestURL(); - - // Footer should have zero rows by default - assertFooterCount(0); - } - - @Test - public void testFooterVisibility() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Visible"); - - assertFooterCount(0); - - selectMenuPath("Component", "Footer", "Append row"); - - assertFooterCount(0); - - selectMenuPath("Component", "Footer", "Visible"); - - assertFooterCount(1); - } - - @Test - public void testAddRows() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - assertFooterCount(1); - assertFooterTexts(0, 0); - - selectMenuPath("Component", "Footer", "Prepend row"); - - assertFooterCount(2); - assertFooterTexts(1, 0); - assertFooterTexts(0, 1); - - selectMenuPath("Component", "Footer", "Append row"); - - assertFooterCount(3); - assertFooterTexts(1, 0); - assertFooterTexts(0, 1); - assertFooterTexts(2, 2); - } - - @Test - public void testRemoveRows() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Prepend row"); - selectMenuPath("Component", "Footer", "Append row"); - - selectMenuPath("Component", "Footer", "Remove top row"); - - assertFooterCount(1); - assertFooterTexts(1, 0); - - selectMenuPath("Component", "Footer", "Remove bottom row"); - assertFooterCount(0); - } - - @Test - public void joinColumnsByCells() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - selectMenuPath("Component", "Footer", "Row 1", - "Join column cells 0, 1"); - - GridCellElement spannedCell = getGridElement().getFooterCell(0, 0); - assertTrue(spannedCell.isDisplayed()); - assertEquals("2", spannedCell.getAttribute("colspan")); - - // TestBench returns the spanned cell for all columns - assertEquals(spannedCell.getText(), - getGridElement().getFooterCell(0, 1).getText()); - } - - @Test - public void joinColumnsByColumns() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); - - GridCellElement spannedCell = getGridElement().getFooterCell(0, 1); - assertTrue(spannedCell.isDisplayed()); - assertEquals("2", spannedCell.getAttribute("colspan")); - - // TestBench returns the spanned cell for all columns - assertEquals(spannedCell.getText(), - getGridElement().getFooterCell(0, 2).getText()); - } - - @Test - public void joinAllColumnsInRow() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - selectMenuPath("Component", "Footer", "Row 1", "Join all columns"); - - GridCellElement spannedCell = getGridElement().getFooterCell(0, 0); - assertTrue(spannedCell.isDisplayed()); - assertEquals("" + GridBasicFeatures.COLUMNS, - spannedCell.getAttribute("colspan")); - - for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) { - GridCellElement hiddenCell = getGridElement().getFooterCell(0, - columnIndex); - // TestBench returns the spanned cell for all columns - assertEquals(spannedCell.getText(), hiddenCell.getText()); - } - } - - @Test - public void testInitialCellTypes() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - GridCellElement textCell = getGridElement().getFooterCell(0, 0); - /* - * Reindeer has a CSS text transformation that changes the casing so - * that we can't rely on it being what we set - */ - assertEquals("footer (0,0)", textCell.getText().toLowerCase()); - - GridCellElement widgetCell = getGridElement().getFooterCell(0, 1); - assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML"))); - - GridCellElement htmlCell = getGridElement().getFooterCell(0, 2); - assertHTML("Footer (0,2)", htmlCell); - } - - @Test - public void testDynamicallyChangingCellType() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - selectMenuPath("Component", "Columns", "Column 0", "Footer Type", - "Widget Footer"); - GridCellElement widgetCell = getGridElement().getFooterCell(0, 0); - assertTrue(widgetCell.isElementPresent(By.className("gwt-Button"))); - - selectMenuPath("Component", "Columns", "Column 1", "Footer Type", - "HTML Footer"); - GridCellElement htmlCell = getGridElement().getFooterCell(0, 1); - assertHTML("HTML Footer", htmlCell); - - selectMenuPath("Component", "Columns", "Column 2", "Footer Type", - "Text Footer"); - GridCellElement textCell = getGridElement().getFooterCell(0, 2); - - /* - * Reindeer has a CSS text transformation that changes the casing so - * that we can't rely on it being what we set - */ - assertEquals("text footer", textCell.getText().toLowerCase()); - } - - @Test - public void testCellWidgetInteraction() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Append row"); - - selectMenuPath("Component", "Columns", "Column 0", "Footer Type", - "Widget Footer"); - GridCellElement widgetCell = getGridElement().getFooterCell(0, 0); - WebElement button = widgetCell.findElement(By.className("gwt-Button")); - - assertNotEquals("clicked", button.getText().toLowerCase()); - - new Actions(getDriver()).moveToElement(button, 5, 5).click().perform(); - - assertEquals("clicked", button.getText().toLowerCase()); - } - - private void assertFooterCount(int count) { - assertEquals("footer count", count, getGridElement().getFooterCount()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java deleted file mode 100644 index dd507555c0..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridHeaderTest.java +++ /dev/null @@ -1,282 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; - -public class GridHeaderTest extends GridStaticSectionTest { - - @Test - public void testDefaultHeader() throws Exception { - openTestURL(); - - assertHeaderCount(1); - assertHeaderTexts(0, 0); - } - - @Test - public void testHeaderVisibility() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Header", "Visible"); - - assertHeaderCount(0); - - selectMenuPath("Component", "Header", "Append row"); - - assertHeaderCount(0); - - selectMenuPath("Component", "Header", "Visible"); - - assertHeaderCount(2); - } - - @Test - public void testHeaderCaptions() throws Exception { - openTestURL(); - - assertHeaderTexts(0, 0); - } - - @Test - public void testAddRows() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Header", "Append row"); - - assertHeaderCount(2); - assertHeaderTexts(0, 0); - assertHeaderTexts(1, 1); - - selectMenuPath("Component", "Header", "Prepend row"); - - assertHeaderCount(3); - assertHeaderTexts(2, 0); - assertHeaderTexts(0, 1); - assertHeaderTexts(1, 2); - - selectMenuPath("Component", "Header", "Append row"); - - assertHeaderCount(4); - assertHeaderTexts(2, 0); - assertHeaderTexts(0, 1); - assertHeaderTexts(1, 2); - assertHeaderTexts(3, 3); - } - - @Test - public void testRemoveRows() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Header", "Prepend row"); - selectMenuPath("Component", "Header", "Append row"); - - selectMenuPath("Component", "Header", "Remove top row"); - - assertHeaderCount(2); - assertHeaderTexts(0, 0); - assertHeaderTexts(2, 1); - - selectMenuPath("Component", "Header", "Remove bottom row"); - assertHeaderCount(1); - assertHeaderTexts(0, 0); - } - - @Test - public void testDefaultRow() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Sortable"); - - GridCellElement headerCell = getGridElement().getHeaderCell(0, 0); - - headerCell.click(); - - assertTrue(hasClassName(headerCell, "sort-asc")); - - headerCell.click(); - - assertFalse(hasClassName(headerCell, "sort-asc")); - assertTrue(hasClassName(headerCell, "sort-desc")); - - selectMenuPath("Component", "Header", "Prepend row"); - selectMenuPath("Component", "Header", "Default row", "Top"); - - assertFalse(hasClassName(headerCell, "sort-desc")); - headerCell = getGridElement().getHeaderCell(0, 0); - assertTrue(hasClassName(headerCell, "sort-desc")); - - selectMenuPath("Component", "Header", "Default row", "Unset"); - - assertFalse(hasClassName(headerCell, "sort-desc")); - } - - @Test - public void joinHeaderColumnsByCells() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Header", "Append row"); - - selectMenuPath("Component", "Header", "Row 2", - "Join column cells 0, 1"); - - GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0); - assertTrue(spannedCell.isDisplayed()); - assertEquals("2", spannedCell.getAttribute("colspan")); - - // TestBench returns the spanned cell for all spanned columns - GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 1); - assertEquals(spannedCell.getText(), hiddenCell.getText()); - } - - @Test - public void joinHeaderColumnsByColumns() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Header", "Append row"); - - selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); - - GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1); - assertTrue(spannedCell.isDisplayed()); - assertEquals("2", spannedCell.getAttribute("colspan")); - - // TestBench returns the spanned cell for all spanned columns - GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 2); - assertEquals(spannedCell.getText(), hiddenCell.getText()); - } - - @Test - public void joinAllColumnsInHeaderRow() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Header", "Append row"); - - selectMenuPath("Component", "Header", "Row 2", "Join all columns"); - - GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0); - assertTrue(spannedCell.isDisplayed()); - assertEquals("" + GridBasicFeatures.COLUMNS, - spannedCell.getAttribute("colspan")); - - for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) { - // TestBench returns the spanned cell for all spanned columns - GridCellElement hiddenCell = getGridElement().getHeaderCell(1, - columnIndex); - assertEquals(spannedCell.getText(), hiddenCell.getText()); - } - } - - @Test - public void testInitialCellTypes() throws Exception { - openTestURL(); - - GridCellElement textCell = getGridElement().getHeaderCell(0, 0); - - /* - * Reindeer has a CSS text transformation that changes the casing so - * that we can't rely on it being what we set - */ - assertEquals("header (0,0)", textCell.getText().toLowerCase()); - - GridCellElement widgetCell = getGridElement().getHeaderCell(0, 1); - assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML"))); - - GridCellElement htmlCell = getGridElement().getHeaderCell(0, 2); - assertHTML("Header (0,2)", htmlCell); - } - - @Test - public void testDynamicallyChangingCellType() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Header Type", - "Widget Header"); - GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0); - assertTrue(widgetCell.isElementPresent(By.className("gwt-Button"))); - - selectMenuPath("Component", "Columns", "Column 1", "Header Type", - "HTML Header"); - GridCellElement htmlCell = getGridElement().getHeaderCell(0, 1); - assertHTML("HTML Header", htmlCell); - - selectMenuPath("Component", "Columns", "Column 2", "Header Type", - "Text Header"); - GridCellElement textCell = getGridElement().getHeaderCell(0, 2); - - /* - * Reindeer has a CSS text transformation that changes the casing so - * that we can't rely on it being what we set - */ - assertEquals("text header", textCell.getText().toLowerCase()); - } - - @Test - public void testCellWidgetInteraction() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Header Type", - "Widget Header"); - GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0); - WebElement button = widgetCell.findElement(By.className("gwt-Button")); - - new Actions(getDriver()).moveToElement(button, 5, 5).click().perform(); - - assertEquals("clicked", button.getText().toLowerCase()); - } - - @Test - public void widgetInSortableCellInteraction() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Header Type", - "Widget Header"); - - selectMenuPath("Component", "Columns", "Column 0", "Sortable"); - - GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0); - WebElement button = widgetCell.findElement(By.className("gwt-Button")); - - assertNotEquals("clicked", button.getText().toLowerCase()); - - new Actions(getDriver()).moveToElement(button, 5, 5).click().perform(); - - assertEquals("clicked", button.getText().toLowerCase()); - } - - private void assertHeaderCount(int count) { - assertEquals("header count", count, getGridElement().getHeaderCount()); - } - - private boolean hasClassName(TestBenchElement element, String name) { - return Arrays.asList(element.getAttribute("class").split(" ")) - .contains(name); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridRowHandleRefreshTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridRowHandleRefreshTest.java deleted file mode 100644 index 9b5c3695d5..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridRowHandleRefreshTest.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.tests.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; - -public class GridRowHandleRefreshTest extends GridBasicClientFeaturesTest { - - @Test - public void testRefreshingThroughRowHandle() { - openTestURL(); - - assertEquals("Unexpected initial state", "(0, 0)", - getGridElement().getCell(0, 0).getText()); - selectMenuPath("Component", "State", "Edit and refresh Row 0"); - assertEquals("Cell contents did not update correctly", "Foo", - getGridElement().getCell(0, 0).getText()); - } - - @Test - public void testDelayedRefreshingThroughRowHandle() - throws InterruptedException { - openTestURL(); - - assertEquals("Unexpected initial state", "(0, 0)", - getGridElement().getCell(0, 0).getText()); - selectMenuPath("Component", "State", "Delayed edit of Row 0"); - // Still the same data - assertEquals("Cell contents did not update correctly", "(0, 0)", - getGridElement().getCell(0, 0).getText()); - sleep(5000); - // Data should be updated - assertEquals("Cell contents did not update correctly", "Bar", - getGridElement().getCell(0, 0).getText()); - } - - @Test - public void testRefreshingWhenNotInViewThroughRowHandle() { - openTestURL(); - - assertEquals("Unexpected initial state", "(0, 0)", - getGridElement().getCell(0, 0).getText()); - getGridElement().scrollToRow(100); - selectMenuPath("Component", "State", "Edit and refresh Row 0"); - assertEquals("Cell contents did not update correctly", "Foo", - getGridElement().getCell(0, 0).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridSidebarContentTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridSidebarContentTest.java deleted file mode 100644 index 5f793e6620..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridSidebarContentTest.java +++ /dev/null @@ -1,147 +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.components.grid.basicfeatures.client; - -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.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridSidebarContentTest extends GridBasicClientFeaturesTest { - - @Test - public void testSidebarWithHidableColumn() { - openTestURL(); - - Assert.assertEquals("Sidebar should not be initially present", 0, - countBySelector(".v-grid-sidebar-button")); - - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - - getSidebarOpenButton().click(); - - WebElement toggle = getSidebarPopup() - .findElement(By.className("column-hiding-toggle")); - - Assert.assertEquals("Column 0 should be togglable", "Header (0,0)", - toggle.getText()); - - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - Assert.assertEquals("Sidebar should disappear without toggable column", - 0, countBySelector(".v-grid-sidebar-button")); - - } - - @Test - public void testAddingCustomSidebarItem() { - openTestURL(); - GridElement gridElement = getGridElement(); - - selectMenuPath("Component", "Sidebar", "Add item to end"); - - gridElement.findElement(By.className("v-grid-sidebar-button")).click(); - - WebElement sidebarItem = getSidebarPopup().findElement( - By.cssSelector(".v-grid-sidebar-content .gwt-MenuItem")); - - sidebarItem.click(); - - Assert.assertEquals("Sidebar should be closed after clicking item 0", 0, - countBySelector(".v-grid-sidebar-content")); - } - - @Test - public void testProgrammaticSidebarOpen() { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - - selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); - - Assert.assertEquals("Sidebar should be open", 1, - countBySelector(".v-grid-sidebar-content")); - } - - @Test - public void testBasicSidebarOrder() { - openTestURL(); - - // First add custom content - selectMenuPath("Component", "Sidebar", "Add separator to end"); - selectMenuPath("Component", "Sidebar", "Add item to end"); - - // Then make one column togglable - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - - selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); - - assertSidebarMenuItems("Header (0,0)", null, "Custom menu item 0"); - } - - @Test - public void testSidebarOrderAbuse() { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 0", "Hidable"); - selectMenuPath("Component", "Columns", "Column 1", "Hidable"); - - // Inserts a menu item between the two visibility toggles - selectMenuPath("Component", "Sidebar", "Add item before index 1"); - - selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); - - // Total order enforcement not implemented at this point. Test can be - // updated when it is. - assertSidebarMenuItems("Header (0,0)", "Custom menu item 0", - "Header (0,1)"); - - selectMenuPath("Component", "Columns", "Column 2", "Hidable"); - selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); - - // Adding a new togglable column should have restored the expected order - assertSidebarMenuItems("Header (0,0)", "Header (0,1)", "Header (0,2)", - "Custom menu item 0"); - } - - private void assertSidebarMenuItems(String... items) { - List menuItems = getSidebarPopup() - .findElements(By.cssSelector(".v-grid-sidebar-content td")); - - Assert.assertEquals("Expected " + items.length + " menu items", - items.length, menuItems.size()); - - for (int i = 0; i < items.length; i++) { - String expectedItem = items[i]; - if (expectedItem == null) { - Assert.assertEquals("Item " + i + " should be a separator", - "gwt-MenuItemSeparator", - menuItems.get(i).getAttribute("class")); - } else { - Assert.assertEquals("Unexpected content for item " + i, - expectedItem, menuItems.get(i).getText()); - } - } - } - - private int countBySelector(String cssSelector) { - return findElements(By.cssSelector(cssSelector)).size(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridStaticSectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridStaticSectionTest.java deleted file mode 100644 index b7b5b8a1e9..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridStaticSectionTest.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.tests.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; - -/** - * Abstract base class for header and footer tests. - * - * @since - * @author Vaadin Ltd - */ -public abstract class GridStaticSectionTest - extends GridBasicClientFeaturesTest { - - protected void assertHeaderTexts(int headerId, int rowIndex) { - int i = 0; - for (TestBenchElement cell : getGridElement() - .getHeaderCells(rowIndex)) { - WebElement content = cell.findElement(By.tagName("div")); - - if (i % 3 == 0) { - assertText(String.format("Header (%d,%d)", headerId, i), - content); - } else if (i % 2 == 0) { - assertHTML(String.format("Header (%d,%d)", headerId, i), - content); - } else { - assertHTML(String.format( - "
Header (%d,%d)
", - headerId, i), content); - } - - i++; - } - assertEquals("number of header columns", GridBasicFeatures.COLUMNS, i); - } - - protected void assertFooterTexts(int footerId, int rowIndex) { - int i = 0; - for (TestBenchElement cell : getGridElement() - .getFooterCells(rowIndex)) { - WebElement content = cell.findElement(By.tagName("div")); - - if (i % 3 == 0) { - assertText(String.format("Footer (%d,%d)", footerId, i), - content); - } else if (i % 2 == 0) { - assertHTML(String.format("Footer (%d,%d)", footerId, i), - content); - } else { - assertHTML(String.format( - "
Footer (%d,%d)
", - footerId, i), content); - } - i++; - } - assertEquals("number of footer columns", GridBasicFeatures.COLUMNS, i); - } - - protected static void assertText(String text, WebElement e) { - // TBE.getText returns "" if the element is scrolled out of view - assertEquals(text, e.getAttribute("innerHTML")); - } - - protected static void assertHTML(String text, WebElement e) { - String html = e.getAttribute("innerHTML"); - - // IE 8 returns tags as upper case while other browsers do not, make the - // comparison non-casesensive - html = html.toLowerCase(); - text = text.toLowerCase(); - - // IE 8 returns attributes without quotes, make the comparison without - // quotes - html = html.replaceAll("\"", ""); - text = html.replaceAll("\"", ""); - - assertEquals(text, html); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java deleted file mode 100644 index 5b91b2c819..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/client/GridStylingTest.java +++ /dev/null @@ -1,115 +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.components.grid.basicfeatures.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.By; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; - -public class GridStylingTest extends GridStaticSectionTest { - - @Test - public void testGridPrimaryStyle() throws Exception { - openTestURL(); - - validateStylenames("v-grid"); - } - - @Test - public void testChangingPrimaryStyleName() throws Exception { - openTestURL(); - - selectMenuPath("Component", "State", "Primary Stylename", - "v-custom-style"); - - validateStylenames("v-custom-style"); - } - - private void validateStylenames(String stylename) { - - String classNames = getGridElement().getAttribute("class"); - assertEquals(stylename, classNames); - - classNames = getGridElement().getVerticalScroller() - .getAttribute("class"); - assertTrue(classNames.contains(stylename + "-scroller")); - assertTrue(classNames.contains(stylename + "-scroller-vertical")); - - classNames = getGridElement().getHorizontalScroller() - .getAttribute("class"); - assertTrue(classNames.contains(stylename + "-scroller")); - assertTrue(classNames.contains(stylename + "-scroller-horizontal")); - - classNames = getGridElement().getTableWrapper().getAttribute("class"); - assertEquals(stylename + "-tablewrapper", classNames); - - classNames = getGridElement().getHeader().getAttribute("class"); - assertEquals(stylename + "-header", classNames); - - for (int row = 0; row < getGridElement().getHeaderCount(); row++) { - classNames = getGridElement().getHeaderRow(row) - .getAttribute("class"); - assertEquals(stylename + "-row", classNames); - - for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) { - classNames = getGridElement().getHeaderCell(row, col) - .getAttribute("class"); - assertTrue(classNames.contains(stylename + "-cell")); - } - } - - classNames = getGridElement().getBody().getAttribute("class"); - assertEquals(stylename + "-body", classNames); - - int rowsInBody = getGridElement().getBody() - .findElements(By.tagName("tr")).size(); - for (int row = 0; row < rowsInBody; row++) { - classNames = getGridElement().getRow(row).getAttribute("class"); - assertTrue(classNames.contains(stylename + "-row")); - assertTrue(classNames.contains(stylename + "-row-has-data")); - - for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) { - classNames = getGridElement().getCell(row, col) - .getAttribute("class"); - assertTrue(classNames.contains(stylename + "-cell")); - - if (row == 0 && col == 0) { - assertTrue( - classNames.contains(stylename + "-cell-focused")); - } - } - } - - classNames = getGridElement().getFooter().getAttribute("class"); - assertEquals(stylename + "-footer", classNames); - - for (int row = 0; row < getGridElement().getFooterCount(); row++) { - classNames = getGridElement().getFooterRow(row) - .getAttribute("class"); - assertEquals(stylename + "-row", classNames); - - for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) { - classNames = getGridElement().getFooterCell(row, col) - .getAttribute("class"); - assertTrue(classNames.contains(stylename + "-cell")); - } - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java deleted file mode 100644 index 7913c948f7..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java +++ /dev/null @@ -1,80 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -public class EscalatorBasicsTest extends EscalatorBasicClientFeaturesTest { - - @Before - public void setUp() { - setDebug(true); - openTestURL(); - } - - @Test - public void testDetachingAnEmptyEscalator() { - selectMenuPath(GENERAL, DETACH_ESCALATOR); - assertEscalatorIsRemovedCorrectly(); - } - - @Test - public void testDetachingASemiPopulatedEscalator() throws IOException { - selectMenuPath(COLUMNS_AND_ROWS, ADD_ONE_OF_EACH_ROW); - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - selectMenuPath(GENERAL, DETACH_ESCALATOR); - assertEscalatorIsRemovedCorrectly(); - } - - @Test - public void testDetachingAPopulatedEscalator() { - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - selectMenuPath(GENERAL, DETACH_ESCALATOR); - assertEscalatorIsRemovedCorrectly(); - } - - @Test - public void testDetachingAndReattachingAnEscalator() { - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - scrollVerticallyTo(50); - scrollHorizontallyTo(50); - - selectMenuPath(GENERAL, DETACH_ESCALATOR); - selectMenuPath(GENERAL, ATTACH_ESCALATOR); - - assertEquals("Vertical scroll position", 50, getScrollTop()); - assertEquals("Horizontal scroll position", 50, getScrollLeft()); - - assertEquals("First cell of first visible row", "Row 2: 0,2", - getBodyCell(0, 0).getText()); - } - - private void assertEscalatorIsRemovedCorrectly() { - assertFalse($(NotificationElement.class).exists()); - assertNull(getEscalator()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java deleted file mode 100644 index daef10a706..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java +++ /dev/null @@ -1,80 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -public class EscalatorColspanTest extends EscalatorBasicClientFeaturesTest { - private static final int NO_COLSPAN = 1; - - @Test - public void testNoColspan() { - openTestURL(); - populate(); - - assertEquals(NO_COLSPAN, getColSpan(getHeaderCell(0, 0))); - assertEquals(NO_COLSPAN, getColSpan(getBodyCell(0, 0))); - assertEquals(NO_COLSPAN, getColSpan(getFooterCell(0, 0))); - } - - @Test - public void testColspan() { - openTestURL(); - populate(); - - int firstCellWidth = getBodyCell(0, 0).getSize().getWidth(); - int secondCellWidth = getBodyCell(0, 1).getSize().getWidth(); - int doubleCellWidth = firstCellWidth + secondCellWidth; - - selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL); - - WebElement bodyCell = getBodyCell(0, 0); - assertEquals("Cell was not spanned correctly", 2, getColSpan(bodyCell)); - assertEquals( - "Spanned cell's width was not the sum of the previous cells (" - + firstCellWidth + " + " + secondCellWidth + ")", - doubleCellWidth, bodyCell.getSize().getWidth(), 1); - } - - @Test - public void testColspanToggle() { - openTestURL(); - populate(); - - int singleCellWidth = getBodyCell(0, 0).getSize().getWidth(); - - selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL); - selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NONE); - - WebElement bodyCell = getBodyCell(0, 0); - assertEquals(NO_COLSPAN, getColSpan(bodyCell)); - assertEquals(singleCellWidth, bodyCell.getSize().getWidth(), 1); - } - - private static int getColSpan(WebElement cell) { - String attribute = cell.getAttribute("colspan"); - if (attribute == null) { - return NO_COLSPAN; - } else { - return Integer.parseInt(attribute); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java deleted file mode 100644 index 452f61ee1b..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java +++ /dev/null @@ -1,111 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -public class EscalatorColumnFreezingTest - extends EscalatorBasicClientFeaturesTest { - - private final static Pattern TRANSFORM_PATTERN = Pattern.compile(// @formatter:off - // any start of the string - ".*" - - // non-capturing group for "webkitTransform: " or "transform: " - + "(?:webkitT|t)ransform: " - - // non-capturing group for "translate" or "translate3d" - + "translate(?:3d)?" - - // capturing the digits in e.g "(100px," - + "\\((\\d+)px," - - // any end of the string - + ".*", Pattern.CASE_INSENSITIVE); - - // @formatter:on - - private final static Pattern LEFT_PATTERN = Pattern - .compile(".*left: (\\d+)px.*", Pattern.CASE_INSENSITIVE); - - private static final int NO_FREEZE = -1; - - @Test - public void testNoFreeze() { - openTestURL(); - populate(); - - WebElement bodyCell = getBodyCell(0, 0); - assertFalse(isFrozen(bodyCell)); - assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell)); - } - - @Test - public void testOneFreeze() { - openTestURL(); - populate(); - - selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); - int scrollPx = 60; - scrollHorizontallyTo(scrollPx); - - WebElement bodyCell = getBodyCell(0, 0); - assertTrue(isFrozen(bodyCell)); - assertEquals(scrollPx, getFrozenScrollCompensation(bodyCell)); - } - - @Test - public void testFreezeToggle() { - openTestURL(); - populate(); - - selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); - scrollHorizontallyTo(100); - selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_0_COLUMNS); - - WebElement bodyCell = getBodyCell(0, 0); - assertFalse(isFrozen(bodyCell)); - assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell)); - } - - private static boolean isFrozen(WebElement cell) { - return cell.getAttribute("class").contains("frozen"); - } - - private static int getFrozenScrollCompensation(WebElement cell) { - String styleAttribute = cell.getAttribute("style"); - Matcher transformMatcher = TRANSFORM_PATTERN.matcher(styleAttribute); - Matcher leftMatcher = LEFT_PATTERN.matcher(styleAttribute); - - if (transformMatcher.find()) { - return Integer.parseInt(transformMatcher.group(1)); - } else if (leftMatcher.find()) { - return Integer.parseInt(leftMatcher.group(1)); - } else { - return NO_FREEZE; - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.java deleted file mode 100644 index 39854ab8bd..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.java +++ /dev/null @@ -1,49 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -/** - * Test class to test the escalator level issue for ticket #16832 - */ -public class EscalatorRemoveAndAddRowsTest - extends EscalatorBasicClientFeaturesTest { - - @Test - public void testRemoveAllRowsAndAddThirtyThenScroll() throws IOException { - openTestURL(); - - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - scrollVerticallyTo(99999); - assertTrue("Escalator is not scrolled to bottom.", - isElementPresent(By.xpath("//td[text() = 'Row 99: 0,99']"))); - - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_INSERT_SCROLL); - - scrollVerticallyTo(99999); - assertTrue("Escalator is not scrolled to bottom.", - isElementPresent(By.xpath("//td[text() = 'Row 29: 0,129']"))); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java deleted file mode 100644 index 7eefcfe2f9..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java +++ /dev/null @@ -1,316 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { - - /** - * The scroll position of the Escalator when scrolled all the way down, to - * reveal the 100:th row. - */ - private static final int BOTTOM_SCROLL_POSITION = 1857; - - @Test - public void testInit() { - openTestURL(); - assertNotNull(getEscalator()); - assertNull(getHeaderRow(0)); - assertNull(getBodyRow(0)); - assertNull(getFooterRow(0)); - - assertLogContains("Columns: 0"); - assertLogContains("Header rows: 0"); - assertLogContains("Body rows: 0"); - assertLogContains("Footer rows: 0"); - } - - @Test - public void testInsertAColumn() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - assertNull(getHeaderRow(0)); - assertNull(getBodyRow(0)); - assertNull(getFooterRow(0)); - assertLogContains("Columns: 1"); - } - - @Test - public void testInsertAHeaderRow() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Header rows: 1"); - } - - @Test - public void testInsertABodyRow() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Body rows: 1"); - } - - @Test - public void testInsertAFooterRow() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Footer rows: 1"); - } - - @Test - public void testInsertAColumnAndAHeaderRow() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING); - assertNotNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Columns: 1"); - assertLogContains("Header rows: 1"); - } - - @Test - public void testInsertAColumnAndABodyRow() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNotNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Columns: 1"); - assertLogContains("Body rows: 1"); - } - - @Test - public void testInsertAColumnAndAFooterRow() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNotNull(getFooterCell(0, 0)); - assertLogContains("Columns: 1"); - assertLogContains("Footer rows: 1"); - } - - @Test - public void testInsertAHeaderRowAndAColumn() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - assertNotNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Columns: 1"); - assertLogContains("Header rows: 1"); - } - - @Test - public void testInsertABodyRowAndAColumn() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNotNull(getBodyCell(0, 0)); - assertNull(getFooterCell(0, 0)); - assertLogContains("Columns: 1"); - assertLogContains("Body rows: 1"); - } - - @Test - public void testInsertAFooterRowAndAColumn() { - openTestURL(); - - selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); - assertNull(getHeaderCell(0, 0)); - assertNull(getBodyCell(0, 0)); - assertNotNull(getFooterCell(0, 0)); - assertLogContains("Columns: 1"); - assertLogContains("Footer rows: 1"); - } - - @Test - public void testFillColRow() { - openTestURL(); - - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - scrollVerticallyTo(2000); // more like 1857, but this should be enough. - - // if not found, an exception is thrown here - assertTrue("Wanted cell was not visible", - isElementPresent(By.xpath("//td[text()='Cell: 9,99']"))); - } - - @Test - public void testFillRowCol() { - openTestURL(); - - selectMenuPath(GENERAL, POPULATE_ROW_COLUMN); - scrollVerticallyTo(2000); // more like 1857, but this should be enough. - - // if not found, an exception is thrown here - assertTrue("Wanted cell was not visible", - isElementPresent(By.xpath("//td[text()='Cell: 9,99']"))); - } - - @Test - public void testClearColRow() { - openTestURL(); - - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - selectMenuPath(GENERAL, CLEAR_COLUMN_ROW); - - assertNull(getBodyCell(0, 0)); - } - - @Test - public void testClearRowCol() { - openTestURL(); - - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - selectMenuPath(GENERAL, CLEAR_ROW_COLUMN); - - assertNull(getBodyCell(0, 0)); - } - - @Test - public void testResizeColToFit() { - openTestURL(); - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, RESIZE_FIRST_COLUMN_TO_100PX); - int originalWidth = getBodyCell(0, 0).getSize().getWidth(); - - assertEquals(100, originalWidth); - - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, - RESIZE_FIRST_COLUMN_TO_MAX_WIDTH); - int newWidth = getBodyCell(0, 0).getSize().getWidth(); - assertNotEquals("Column width should've changed", originalWidth, - newWidth); - } - - @Test - public void testRemoveMoreThanPagefulAtBottomWhileScrolledToBottom() - throws Exception { - openTestURL(); - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - scrollVerticallyTo(BOTTOM_SCROLL_POSITION); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM); - assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText()); - - scrollVerticallyTo(0); - - // let the DOM organize itself - Thread.sleep(500); - - // if something goes wrong, it'll explode before this. - assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); - } - - @Test - public void testRemoveMoreThanPagefulAtBottomWhileScrolledAlmostToBottom() - throws Exception { - openTestURL(); - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - // bottom minus 15 rows. - scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM); - assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText()); - - scrollVerticallyTo(0); - - // let the DOM organize itself - Thread.sleep(500); - - // if something goes wrong, it'll explode before this. - assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); - } - - @Test - public void testRemoveMoreThanPagefulNearBottomWhileScrolledToBottom() - throws Exception { - openTestURL(); - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - scrollVerticallyTo(BOTTOM_SCROLL_POSITION); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, - REMOVE_50_ROWS_FROM_ALMOST_BOTTOM); - assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText()); - - scrollVerticallyTo(0); - - // let the DOM organize itself - Thread.sleep(500); - - // if something goes wrong, it'll explode before this. - assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); - } - - @Test - public void testRemoveMoreThanPagefulNearBottomWhileScrolledAlmostToBottom() - throws Exception { - openTestURL(); - selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); - - // bottom minus 15 rows. - scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, - REMOVE_50_ROWS_FROM_ALMOST_BOTTOM); - - // let the DOM organize itself - Thread.sleep(500); - assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText()); - - scrollVerticallyTo(0); - - // let the DOM organize itself - Thread.sleep(500); - - // if something goes wrong, it'll explode before this. - assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java deleted file mode 100644 index 5fcdb2dca0..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java +++ /dev/null @@ -1,95 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -@SuppressWarnings("all") -public class EscalatorScrollTest extends EscalatorBasicClientFeaturesTest { - - @Before - public void setUp() { - openTestURL(); - populate(); - } - - /** - * Before the fix, removing and adding rows and also scrolling would put the - * scroll state in an internally inconsistent state. The scrollbar would've - * been scrolled correctly, but the body wasn't. - * - * This was due to optimizations that didn't keep up with the promises, so - * to say. So the optimizations were removed. - */ - @Test - public void testScrollRaceCondition() { - scrollVerticallyTo(40); - String originalStyle = getTBodyStyle(); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_INSERT_SCROLL); - - // body should be scrolled to exactly the same spot. (not 0) - assertEquals(originalStyle, getTBodyStyle()); - } - - @Test - public void scrollToBottomAndRemoveHeader() throws Exception { - scrollVerticallyTo(999999); // to bottom - - /* - * apparently the scroll event isn't fired by the time the next assert - * would've been done. - */ - Thread.sleep(50); - - assertEquals("Unexpected last row cell before header removal", - "Row 99: 0,99", getBodyCell(-1, 0).getText()); - selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, - REMOVE_ONE_ROW_FROM_BEGINNING); - assertEquals("Unexpected last row cell after header removal", - "Row 99: 0,99", getBodyCell(-1, 0).getText()); - - } - - @Test - public void scrollToBottomAndRemoveFooter() throws Exception { - scrollVerticallyTo(999999); // to bottom - - /* - * apparently the scroll event isn't fired by the time the next assert - * would've been done. - */ - Thread.sleep(50); - - assertEquals("Unexpected last row cell before footer removal", - "Row 99: 0,99", getBodyCell(-1, 0).getText()); - selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, - REMOVE_ONE_ROW_FROM_BEGINNING); - assertEquals("Unexpected last row cell after footer removal", - "Row 99: 0,99", getBodyCell(-1, 0).getText()); - } - - private String getTBodyStyle() { - WebElement tbody = getEscalator().findElement(By.tagName("tbody")); - return tbody.getAttribute("style"); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java deleted file mode 100644 index 93931d50ec..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java +++ /dev/null @@ -1,592 +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.components.grid.basicfeatures.escalator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.junit.Before; -import org.junit.ComparisonFailure; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; - -import com.vaadin.client.WidgetUtil; -import com.vaadin.shared.Range; -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.parallel.BrowserUtil; -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; - -@SuppressWarnings("boxing") -public class EscalatorSpacerTest extends EscalatorBasicClientFeaturesTest { - - //@formatter:off - // separate strings made so that eclipse can show the concatenated string by hovering the mouse over the constant - - // translate3d(0px, 40px, 123px); - // translate3d(24px, 15.251px, 0); - // translate(0, 40px); - private final static String TRANSLATE_VALUE_REGEX = - "translate(?:3d|)" // "translate" or "translate3d" - + "\\(" // literal "(" - + "(" // start capturing the x argument - + "[0-9]+" // the integer part of the value - + "(?:" // start of the subpixel part of the value - + "\\.[0-9]" // if we have a period, there must be at least one number after it - + "[0-9]*" // any amount of accuracy afterwards is fine - + ")?" // the subpixel part is optional - + ")" - + "(?:px)?" // we don't care if the values are suffixed by "px" or not. - + ", " - + "(" // start capturing the y argument - + "[0-9]+" // the integer part of the value - + "(?:" // start of the subpixel part of the value - + "\\.[0-9]" // if we have a period, there must be at least one number after it - + "[0-9]*" // any amount of accuracy afterwards is fine - + ")?" // the subpixel part is optional - + ")" - + "(?:px)?" // we don't care if the values are suffixed by "px" or not. - + "(?:, .*?)?" // the possible z argument, uninteresting (translate doesn't have one, translate3d does) - + "\\)" // literal ")" - + ";?"; // optional ending semicolon - - // 40px; - // 12.34px - private final static String PIXEL_VALUE_REGEX = - "(" // capture the pixel value - + "[0-9]+" // the pixel argument - + "(?:" // start of the subpixel part of the value - + "\\.[0-9]" // if we have a period, there must be at least one number after it - + "[0-9]*" // any amount of accuracy afterwards is fine - + ")?" // the subpixel part is optional - + ")" - + "(?:px)?" // optional "px" string - + ";?"; // optional semicolon - //@formatter:on - - // also matches "-webkit-transform"; - private final static Pattern TRANSFORM_CSS_PATTERN = Pattern - .compile("transform: (.*?);"); - private final static Pattern TOP_CSS_PATTERN = Pattern.compile( - "top: ([0-9]+(?:\\.[0-9]+)?(?:px)?);?", Pattern.CASE_INSENSITIVE); - private final static Pattern LEFT_CSS_PATTERN = Pattern.compile( - "left: ([0-9]+(?:\\.[0-9]+)?(?:px)?);?", Pattern.CASE_INSENSITIVE); - - private final static Pattern TRANSLATE_VALUE_PATTERN = Pattern - .compile(TRANSLATE_VALUE_REGEX); - private final static Pattern PIXEL_VALUE_PATTERN = Pattern - .compile(PIXEL_VALUE_REGEX, Pattern.CASE_INSENSITIVE); - - @Before - public void before() { - setDebug(true); - openTestURL(); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, "Set 20px default height"); - populate(); - } - - @Test - public void openVisibleSpacer() { - assertFalse("No spacers should be shown at the start", - spacersAreFoundInDom()); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - assertNotNull("Spacer should be shown after setting it", getSpacer(1)); - } - - @Test - public void closeVisibleSpacer() { - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_1, REMOVE); - assertNull("Spacer should not exist after removing it", getSpacer(1)); - } - - @Test - public void spacerPushesVisibleRowsDown() { - double oldTop = getElementTop(getBodyRow(2)); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - double newTop = getElementTop(getBodyRow(2)); - - assertGreater("Row below a spacer was not pushed down", newTop, oldTop); - } - - @Test - public void addingRowAboveSpacerPushesItDown() { - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_ROWS); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - double oldTop = getElementTop(getSpacer(1)); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - double newTop = getElementTop(getSpacer(2)); - - assertGreater("Spacer should've been pushed down (oldTop: " + oldTop - + ", newTop: " + newTop + ")", newTop, oldTop); - } - - @Test - public void addingRowBelowSpacerDoesNotPushItDown() { - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_ROWS); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - double oldTop = getElementTop(getSpacer(1)); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_END); - double newTop = getElementTop(getSpacer(1)); - - assertEquals("Spacer should've not been pushed down", newTop, oldTop, - WidgetUtil.PIXEL_EPSILON); - } - - @Test - public void addingRowBelowSpacerIsActuallyRenderedBelowWhenEscalatorIsEmpty() { - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_ROWS); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); - - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - double spacerTop = getElementTop(getSpacer(1)); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_END); - double rowTop = getElementTop(getBodyRow(2)); - - assertEquals("Next row should've been rendered below the spacer", - spacerTop + 100, rowTop, WidgetUtil.PIXEL_EPSILON); - } - - @Test - public void addSpacerAtBottomThenScrollThere() { - selectMenuPath(FEATURES, SPACERS, ROW_99, SET_100PX); - scrollVerticallyTo(999999); - - assertFalse("Did not expect a notification", - $(NotificationElement.class).exists()); - } - - @Test - public void scrollToBottomThenAddSpacerThere() { - scrollVerticallyTo(999999); - long oldBottomScrollTop = getScrollTop(); - selectMenuPath(FEATURES, SPACERS, ROW_99, SET_100PX); - - assertEquals( - "Adding a spacer underneath the current viewport should " - + "not scroll anywhere", - oldBottomScrollTop, getScrollTop()); - assertFalse("Got an unexpected notification", - $(NotificationElement.class).exists()); - - scrollVerticallyTo(999999); - - assertFalse("Got an unexpected notification", - $(NotificationElement.class).exists()); - assertGreater("Adding a spacer should've made the scrollbar scroll " - + "further", getScrollTop(), oldBottomScrollTop); - } - - @Test - public void removingRowAboveSpacerMovesSpacerUp() { - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - WebElement spacer = getSpacer(1); - double originalElementTop = getElementTop(spacer); - - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, - REMOVE_ONE_ROW_FROM_BEGINNING); - assertLessThan("spacer should've moved up", getElementTop(spacer), - originalElementTop); - assertNull("No spacer for row 1 should be found after removing the " - + "top row", getSpacer(1)); - } - - @Test - public void removingSpacedRowRemovesSpacer() { - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - assertTrue("Spacer should've been found in the DOM", - spacersAreFoundInDom()); - - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, - REMOVE_ONE_ROW_FROM_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, - REMOVE_ONE_ROW_FROM_BEGINNING); - - assertFalse("No spacers should be in the DOM after removing " - + "associated spacer", spacersAreFoundInDom()); - - } - - @Test - public void spacersAreFixedInViewport_firstFreezeThenScroll() { - selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - assertEquals( - "Spacer's left position should've been 0 at the " + "beginning", - 0d, getElementLeft(getSpacer(1)), WidgetUtil.PIXEL_EPSILON); - - int scrollTo = 10; - scrollHorizontallyTo(scrollTo); - assertEquals( - "Spacer's left position should've been " + scrollTo - + " after scrolling " + scrollTo + "px", - scrollTo, getElementLeft(getSpacer(1)), - WidgetUtil.PIXEL_EPSILON); - } - - @Test - public void spacersAreFixedInViewport_firstScrollThenFreeze() { - selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); - int scrollTo = 10; - scrollHorizontallyTo(scrollTo); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - assertEquals( - "Spacer's left position should've been " + scrollTo - + " after scrolling " + scrollTo + "px", - scrollTo, getElementLeft(getSpacer(1)), - WidgetUtil.PIXEL_EPSILON); - } - - @Test - public void addingMinusOneSpacerDoesNotScrollWhenScrolledAtTop() { - scrollVerticallyTo(5); - selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, SET_100PX); - assertEquals( - "No scroll adjustment should've happened when adding the -1 spacer", - 5, getScrollTop()); - } - - @Test - public void removingMinusOneSpacerScrolls() { - scrollVerticallyTo(5); - selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, REMOVE); - assertEquals("Scroll adjustment should've happened when removing the " - + "-1 spacer", 0, getScrollTop()); - } - - @Test - public void scrollToRowWorksProperlyWithSpacers() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - - /* - * we check for row -2 instead of -1, because escalator has the one row - * buffered underneath the footer - */ - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_75); - Thread.sleep(500); - assertEquals("Row 75: 0,75", getBodyCell(-2, 0).getText()); - - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_25); - Thread.sleep(500); - - try { - assertEquals("Row 25: 0,25", getBodyCell(0, 0).getText()); - } catch (ComparisonFailure retryForIE10andIE11) { - /* - * This seems to be some kind of subpixel/off-by-one-pixel error. - * Everything's scrolled correctly, but Escalator still loads one - * row above to the DOM, underneath the header. It's there, but it's - * not visible. We'll allow for that one pixel error. - */ - assertEquals("Row 24: 0,24", getBodyCell(0, 0).getText()); - } - } - - @Test - public void scrollToSpacerFromAbove() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); - - // Browsers might vary with a few pixels. - Range allowableScrollRange = Range.between(765, 780); - int scrollTop = (int) getScrollTop(); - assertTrue("Scroll position was not " + allowableScrollRange + ", but " - + scrollTop, allowableScrollRange.contains(scrollTop)); - } - - @Test - public void scrollToSpacerFromBelow() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - scrollVerticallyTo(999999); - selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); - - // Browsers might vary with a few pixels. - Range allowableScrollRange = Range.between(1015, 1025); - int scrollTop = (int) getScrollTop(); - assertTrue("Scroll position was not " + allowableScrollRange + ", but " - + scrollTop, allowableScrollRange.contains(scrollTop)); - } - - @Test - public void scrollToSpacerAlreadyInViewport() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - scrollVerticallyTo(1000); - selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); - - assertEquals(getScrollTop(), 1000); - } - - @Test - public void scrollToRowAndSpacerFromAbove() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_50, - SCROLL_HERE_SPACERBELOW_ANY_0PADDING); - - // Browsers might vary with a few pixels. - Range allowableScrollRange = Range.between(765, 780); - int scrollTop = (int) getScrollTop(); - assertTrue("Scroll position was not " + allowableScrollRange + ", but " - + scrollTop, allowableScrollRange.contains(scrollTop)); - } - - @Test - public void scrollToRowAndSpacerFromBelow() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - scrollVerticallyTo(999999); - selectMenuPath(FEATURES, SPACERS, ROW_50, - SCROLL_HERE_SPACERBELOW_ANY_0PADDING); - - // Browsers might vary with a few pixels. - Range allowableScrollRange = Range.between(995, 1005); - int scrollTop = (int) getScrollTop(); - assertTrue("Scroll position was not " + allowableScrollRange + ", but " - + scrollTop, allowableScrollRange.contains(scrollTop)); - } - - @Test - public void scrollToRowAndSpacerAlreadyInViewport() throws Exception { - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - scrollVerticallyTo(950); - selectMenuPath(FEATURES, SPACERS, ROW_50, - SCROLL_HERE_SPACERBELOW_ANY_0PADDING); - - assertEquals(getScrollTop(), 950); - } - - @Test - public void domCanBeSortedWithFocusInSpacer() throws InterruptedException { - - // Firefox behaves badly with focus-related tests - skip it. - if (BrowserUtil.isFirefox(super.getDesiredCapabilities())) { - return; - } - - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - - WebElement inputElement = getEscalator() - .findElement(By.tagName("input")); - inputElement.click(); - scrollVerticallyTo(30); - - // Sleep needed because of all the JS we're doing, and to let - // the DOM reordering to take place. - Thread.sleep(500); - - assertFalse("Error message detected", - $(NotificationElement.class).exists()); - } - - @Test - public void spacersAreInsertedInCorrectDomPosition() { - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - - WebElement tbody = getEscalator().findElement(By.tagName("tbody")); - WebElement spacer = getChild(tbody, 2); - String cssClass = spacer.getAttribute("class"); - assertTrue( - "element index 2 was not a spacer (class=\"" + cssClass + "\")", - cssClass.contains("-spacer")); - } - - @Test - public void spacersAreInCorrectDomPositionAfterScroll() { - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - - scrollVerticallyTo(32); // roughly one row's worth - - WebElement tbody = getEscalator().findElement(By.tagName("tbody")); - WebElement spacer = getChild(tbody, 1); - String cssClass = spacer.getAttribute("class"); - assertTrue( - "element index 1 was not a spacer (class=\"" + cssClass + "\")", - cssClass.contains("-spacer")); - } - - @Test - public void spacerScrolledIntoViewGetsFocus() { - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); - - tryToTabIntoFocusUpdaterElement(); - assertEquals("input", getFocusedElement().getTagName()); - } - - @Test - public void spacerScrolledOutOfViewDoesNotGetFocus() { - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); - - tryToTabIntoFocusUpdaterElement(); - assertNotEquals("input", getFocusedElement().getTagName()); - } - - @Test - public void spacerOpenedInViewGetsFocus() { - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - tryToTabIntoFocusUpdaterElement(); - WebElement focusedElement = getFocusedElement(); - assertEquals("input", focusedElement.getTagName()); - } - - @Test - public void spacerOpenedOutOfViewDoesNotGetFocus() { - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - - tryToTabIntoFocusUpdaterElement(); - assertNotEquals("input", getFocusedElement().getTagName()); - } - - @Test - public void spacerOpenedInViewAndScrolledOutAndBackAgainGetsFocus() { - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_50); - selectMenuPath(FEATURES, SPACERS, ROW_1, SCROLL_HERE_ANY_0PADDING); - - tryToTabIntoFocusUpdaterElement(); - assertEquals("input", getFocusedElement().getTagName()); - } - - @Test - public void spacerOpenedOutOfViewAndScrolledInAndBackAgainDoesNotGetFocus() { - selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); - selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); - selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); - selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_0); - - tryToTabIntoFocusUpdaterElement(); - assertNotEquals("input", getFocusedElement().getTagName()); - } - - private void tryToTabIntoFocusUpdaterElement() { - ((TestBenchElement) findElement(By.className("gwt-MenuBar"))).focus(); - WebElement focusedElement = getFocusedElement(); - focusedElement.sendKeys(Keys.TAB); - } - - private WebElement getChild(WebElement parent, int childIndex) { - return (WebElement) executeScript( - "return arguments[0].children[" + childIndex + "];", parent); - } - - private static double[] getElementDimensions(WebElement element) { - /* - * we need to parse the style attribute, since using getCssValue gets a - * normalized value that is harder to parse. - */ - String style = element.getAttribute("style"); - - String transform = getTransformFromStyle(style); - if (transform != null) { - return getTranslateValues(transform); - } - - double[] result = new double[] { -1, -1 }; - String left = getLeftFromStyle(style); - if (left != null) { - result[0] = getPixelValue(left); - } - String top = getTopFromStyle(style); - if (top != null) { - result[1] = getPixelValue(top); - } - - if (result[0] != -1 && result[1] != -1) { - return result; - } else { - throw new IllegalArgumentException("Could not parse the position " - + "information from the CSS \"" + style + "\""); - } - } - - private static double getElementTop(WebElement element) { - return getElementDimensions(element)[1]; - } - - private static double getElementLeft(WebElement element) { - return getElementDimensions(element)[0]; - } - - private static String getTransformFromStyle(String style) { - return getFromStyle(TRANSFORM_CSS_PATTERN, style); - } - - private static String getTopFromStyle(String style) { - return getFromStyle(TOP_CSS_PATTERN, style); - } - - private static String getLeftFromStyle(String style) { - return getFromStyle(LEFT_CSS_PATTERN, style); - } - - private static String getFromStyle(Pattern pattern, String style) { - Matcher matcher = pattern.matcher(style); - if (matcher.find()) { - assertEquals("wrong amount of groups matched in " + style, 1, - matcher.groupCount()); - return matcher.group(1); - } else { - return null; - } - } - - /** - * @return {@code [0] == x}, {@code [1] == y} - */ - private static double[] getTranslateValues(String translate) { - Matcher matcher = TRANSLATE_VALUE_PATTERN.matcher(translate); - assertTrue("no matches for " + translate + " against " - + TRANSLATE_VALUE_PATTERN, matcher.find()); - assertEquals("wrong amout of groups matched in " + translate, 2, - matcher.groupCount()); - - return new double[] { Double.parseDouble(matcher.group(1)), - Double.parseDouble(matcher.group(2)) }; - } - - private static double getPixelValue(String top) { - Matcher matcher = PIXEL_VALUE_PATTERN.matcher(top); - assertTrue( - "no matches for \"" + top + "\" against " + PIXEL_VALUE_PATTERN, - matcher.find()); - assertEquals("wrong amount of groups matched in " + top, 1, - matcher.groupCount()); - return Double.parseDouble(matcher.group(1)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java deleted file mode 100644 index 033ec67c91..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java +++ /dev/null @@ -1,151 +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.components.grid.basicfeatures.escalator; - -import org.junit.Test; - -import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; -import com.vaadin.tests.components.grid.basicfeatures.EscalatorUpdaterUi; - -public class EscalatorUpdaterUiTest extends EscalatorBasicClientFeaturesTest { - @Override - protected Class getUIClass() { - return EscalatorUpdaterUi.class; - } - - @Test - public void testHeaderPaintOrderRowColRowCol() { - boolean addColumnFirst = false; - boolean removeColumnFirst = false; - testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testHeaderPaintOrderRowColColRow() { - boolean addColumnFirst = false; - boolean removeColumnFirst = true; - testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testHeaderPaintOrderColRowColRow() { - boolean addColumnFirst = true; - boolean removeColumnFirst = true; - testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testHeaderPaintOrderColRowRowCol() { - boolean addColumnFirst = true; - boolean removeColumnFirst = false; - testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testBodyPaintOrderRowColRowCol() { - boolean addColumnFirst = false; - boolean removeColumnFirst = false; - testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testBodyPaintOrderRowColColRow() { - boolean addColumnFirst = false; - boolean removeColumnFirst = true; - testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testBodyPaintOrderColRowColRow() { - boolean addColumnFirst = true; - boolean removeColumnFirst = true; - testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testBodyPaintOrderColRowRowCol() { - boolean addColumnFirst = true; - boolean removeColumnFirst = false; - testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testFooterPaintOrderRowColRowCol() { - boolean addColumnFirst = false; - boolean removeColumnFirst = false; - testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testFooterPaintOrderRowColColRow() { - boolean addColumnFirst = false; - boolean removeColumnFirst = true; - testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testFooterPaintOrderColRowColRow() { - boolean addColumnFirst = true; - boolean removeColumnFirst = true; - testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); - } - - @Test - public void testFooterPaintOrderColRowRowCol() { - boolean addColumnFirst = true; - boolean removeColumnFirst = false; - testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); - } - - private void testPaintOrder(String tableSection, boolean addColumnFirst, - boolean removeColumnFirst) { - openTestURL(); - - if (addColumnFirst) { - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, - ADD_ONE_COLUMN_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, tableSection, - ADD_ONE_ROW_TO_BEGINNING); - } else { - selectMenuPath(COLUMNS_AND_ROWS, tableSection, - ADD_ONE_ROW_TO_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, - ADD_ONE_COLUMN_TO_BEGINNING); - } - - assertLogContainsInOrder("preAttach: elementIsAttached == false", - "postAttach: elementIsAttached == true", - "update: elementIsAttached == true"); - assertLogDoesNotContain("preDetach"); - assertLogDoesNotContain("postDetach"); - - if (removeColumnFirst) { - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, - REMOVE_ONE_COLUMN_FROM_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, tableSection, - REMOVE_ONE_ROW_FROM_BEGINNING); - } else { - selectMenuPath(COLUMNS_AND_ROWS, tableSection, - REMOVE_ONE_ROW_FROM_BEGINNING); - selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, - REMOVE_ONE_COLUMN_FROM_BEGINNING); - } - - assertLogContainsInOrder("preDetach: elementIsAttached == true", - "postDetach: elementIsAttached == false"); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/DisabledGridTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/DisabledGridTest.java deleted file mode 100644 index fd87a261c6..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/DisabledGridTest.java +++ /dev/null @@ -1,61 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class DisabledGridTest extends GridBasicFeaturesTest { - - @Before - public void setUp() { - openTestURL(); - selectMenuPath("Component", "State", "Enabled"); - } - - @Test - public void testSelection() { - selectMenuPath("Component", "State", "Selection mode", "single"); - - GridRowElement row = getGridElement().getRow(0); - GridCellElement cell = getGridElement().getCell(0, 0); - cell.click(); - assertFalse("disabled row should not be selected", row.isSelected()); - - } - - @Test - public void testEditorOpening() { - selectMenuPath("Component", "Editor", "Enabled"); - - GridRowElement row = getGridElement().getRow(0); - GridCellElement cell = getGridElement().getCell(0, 0); - cell.click(); - assertNull("Editor should not open", getEditor()); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertNull("Editor should not open", getEditor()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java deleted file mode 100644 index d340e27c63..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java +++ /dev/null @@ -1,86 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridCellFocusAdjustmentTest extends GridBasicFeaturesTest { - - @Test - public void testCellFocusWithAddAndRemoveRows() { - openTestURL(); - GridElement grid = getGridElement(); - - grid.getCell(0, 0).click(); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Cell focus was not moved when adding a row", - grid.getCell(1, 0).isFocused()); - - selectMenuPath("Component", "Body rows", "Add 18 rows"); - assertTrue("Cell focus was not moved when adding multiple rows", - grid.getCell(19, 0).isFocused()); - - for (int i = 18; i <= 0; --i) { - selectMenuPath("Component", "Body rows", "Remove first row"); - assertTrue("Cell focus was not moved when removing a row", - grid.getCell(i, 0).isFocused()); - } - } - - @Test - public void testCellFocusOffsetWhileInDifferentSection() { - openTestURL(); - getGridElement().getCell(0, 0).click(); - new Actions(getDriver()).sendKeys(Keys.UP).perform(); - assertTrue("Header 0,0 should've become focused", - getGridElement().getHeaderCell(0, 0).isFocused()); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Header 0,0 should've remained focused", - getGridElement().getHeaderCell(0, 0).isFocused()); - } - - @Test - public void testCellFocusOffsetWhileInSameSectionAndInsertedAbove() { - openTestURL(); - assertTrue("Body 0,0 should've gotten focus", - getGridElement().getCell(0, 0).isFocused()); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Body 1,0 should've gotten focus", - getGridElement().getCell(1, 0).isFocused()); - } - - @Test - public void testCellFocusOffsetWhileInSameSectionAndInsertedBelow() { - openTestURL(); - assertTrue("Body 0,0 should've gotten focus", - getGridElement().getCell(0, 0).isFocused()); - - selectMenuPath("Component", "Body rows", "Add third row"); - assertTrue("Body 0,0 should've remained focused", - getGridElement().getCell(0, 0).isFocused()); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java deleted file mode 100644 index 09431b2f6f..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java +++ /dev/null @@ -1,155 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertFalse; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest { - @Test - public void testStyleNameGeneratorScrolling() throws Exception { - openTestURL(); - - selectRowStyleNameGenerator( - GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); - - GridRowElement row = getGridElement().getRow(2); - GridCellElement cell = getGridElement().getCell(3, 2); - - Assert.assertTrue(hasCssClass(row, "row2")); - Assert.assertTrue(hasCssClass(cell, "Column_2")); - - // Scroll down and verify that the old elements don't have the - // stylename any more - - // Carefully chosen offset to hit an index % 4 without cell style - row = getGridElement().getRow(352); - cell = getGridElement().getCell(353, 2); - - Assert.assertFalse(hasCssClass(row, "row352")); - Assert.assertFalse(hasCssClass(cell, "Column_2")); - } - - @Test - public void testDisableStyleNameGenerator() throws Exception { - openTestURL(); - - selectRowStyleNameGenerator( - GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); - - // Just verify that change was effective - GridRowElement row2 = getGridElement().getRow(2); - GridCellElement cell3_2 = getGridElement().getCell(3, 2); - - Assert.assertTrue(hasCssClass(row2, "row2")); - Assert.assertTrue(hasCssClass(cell3_2, "Column_2")); - - // Disable the generator and check again - selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_NONE); - - Assert.assertFalse(hasCssClass(row2, "row2")); - Assert.assertFalse(hasCssClass(cell3_2, "Column_2")); - } - - @Test - public void testChangeStyleNameGenerator() throws Exception { - openTestURL(); - - selectRowStyleNameGenerator( - GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); - - // Just verify that change was effective - GridRowElement row2 = getGridElement().getRow(2); - GridCellElement cell3_2 = getGridElement().getCell(3, 2); - - Assert.assertTrue(hasCssClass(row2, "row2")); - Assert.assertTrue(hasCssClass(cell3_2, "Column_2")); - - // Change the generator and check again - selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_PROPERTY_TO_STRING); - - // Old styles removed? - Assert.assertFalse(hasCssClass(row2, "row2")); - Assert.assertFalse(hasCssClass(cell3_2, "Column_2")); - - // New style present? - Assert.assertTrue(hasCssClass(cell3_2, "Column-2")); - } - - @Test - public void testCellStyleGeneratorWithSelectionColumn() { - setDebug(true); - openTestURL(); - selectMenuPath("Component", "State", "Selection mode", "multi"); - - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); - - assertFalse("Error notification was present", - isElementPresent(NotificationElement.class)); - } - - private void selectRowStyleNameGenerator(String name) { - selectMenuPath("Component", "State", "Row style generator", name); - } - - private void selectCellStyleNameGenerator(String name) { - selectMenuPath("Component", "State", "Cell style generator", name); - } - - @Test - public void testEmptyStringStyleGenerator() { - setDebug(true); - openTestURL(); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_EMPTY); - selectRowStyleNameGenerator( - GridBasicFeatures.ROW_STYLE_GENERATOR_EMPTY); - - assertFalse("Error notification was present", - isElementPresent(NotificationElement.class)); - } - - @Test - public void testNullStringStyleGenerator() { - setDebug(true); - openTestURL(); - selectCellStyleNameGenerator( - GridBasicFeatures.CELL_STYLE_GENERATOR_NULL); - selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NULL); - - assertFalse("Error notification was present", - isElementPresent(NotificationElement.class)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridClearContainerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridClearContainerTest.java deleted file mode 100644 index 922b43e4dc..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridClearContainerTest.java +++ /dev/null @@ -1,51 +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.components.grid.basicfeatures.server; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -/** - * Tests that removing and adding rows doesn't cause an infinite loop in the - * browser. - * - * @author Vaadin Ltd - */ -@TestCategory("grid") -public class GridClearContainerTest extends MultiBrowserTest { - - private final String ERRORNOTE = "Unexpected cell contents."; - - @Test - public void clearAndReadd() { - openTestURL(); - ButtonElement button = $(ButtonElement.class) - .caption("Clear and re-add").first(); - GridElement grid = $(GridElement.class).first(); - Assert.assertEquals(ERRORNOTE, "default", grid.getCell(0, 0).getText()); - Assert.assertEquals(ERRORNOTE, "default", grid.getCell(1, 0).getText()); - button.click(); - Assert.assertEquals(ERRORNOTE, "Updated value 1", - grid.getCell(0, 0).getText()); - Assert.assertEquals(ERRORNOTE, "Updated value 2", - grid.getCell(1, 0).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnMaxWidthTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnMaxWidthTest.java deleted file mode 100644 index adabad797f..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnMaxWidthTest.java +++ /dev/null @@ -1,37 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridColumnMaxWidthTest extends GridBasicFeaturesTest { - - @Test - public void testMaxWidthAffectsColumnWidth() { - setDebug(true); - openTestURL(); - - selectMenuPath("Component", "Columns", - "All columns expanding, Col 0 has max width of 30px"); - - assertEquals("Column 0 did not obey max width of 30px.", 30, - getGridElement().getCell(0, 0).getSize().getWidth()); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java deleted file mode 100644 index b4acb7f161..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java +++ /dev/null @@ -1,403 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -/** - * Tests that Grid columns can be reordered by user with drag and drop #16643. - * - * @author Vaadin Ltd - */ -public class GridColumnReorderTest extends GridBasicFeaturesTest { - - private static final String[] COLUMN_REORDERING_PATH = { "Component", - "State", "Column Reordering Allowed" }; - private static final String[] COLUMN_REORDER_LISTENER_PATH = { "Component", - "State", "ColumnReorderListener" }; - - @Before - public void setUp() { - setDebug(true); - } - - @Test - public void testColumnReordering_firstColumnDroppedOnThird_dropOnLeftSide() { - // given - openTestURL(); - assertColumnHeaderOrder(0, 1, 2); - toggleColumnReordering(); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - - // then - assertColumnHeaderOrder(1, 0, 2); - } - - @Test - public void testColumnReordering_firstColumnDroppedOnThird_dropOnRightSide() { - // given - openTestURL(); - assertColumnHeaderOrder(0, 1, 2); - toggleColumnReordering(); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(1, 2, 0); - } - - @Test - public void testColumnReordering_reorderingTwiceBackForth_reordered() { - // given - openTestURL(); - selectMenuPath("Component", "Size", "Width", "800px"); - assertColumnHeaderOrder(0, 1, 2, 3, 4); - toggleColumnReordering(); - - // when - dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(2, 0, 1, 3, 4); - - // when - dragAndDropDefaultColumnHeader(1, 3, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(2, 1, 3, 0); - } - - @Test - public void testColumnReordering_notEnabled_noReordering() { - // given - openTestURL(); - assertColumnHeaderOrder(0, 1, 2); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(0, 1, 2); - } - - @Test - public void testColumnReordering_userChangesRevertedByServer_columnsAreUpdated() { - // given - openTestURL(); - assertColumnHeaderOrder(0, 1, 2); - toggleColumnReordering(); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - assertColumnHeaderOrder(1, 0, 2); - moveColumnManuallyLeftByOne(0); - - // then - assertColumnHeaderOrder(0, 1, 2); - } - - @Test - public void testColumnReordering_concurrentUpdatesFromServer_columnOrderFromServerUsed() { - // given - openTestURL(); - assertColumnHeaderOrder(0, 1, 2); - toggleColumnReordering(); - - // when - selectMenuPath(new String[] { "Component", "Internals", - "Update column order without updating client" }); - dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(1, 0, 2); - } - - @Test - public void testColumnReordering_triggersReorderEvent_isUserInitiated() { - // given - openTestURL(); - toggleColumnReordering(); - - // when - toggleColumnReorderListener(); - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - - // then - assertColumnReorderEvent(true); - } - - @Test - public void testColumnReordering_addAndRemoveListener_registerUnRegisterWorks() { - // given - openTestURL(); - toggleColumnReordering(); - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - assertNoColumnReorderEvent(); - - // when - toggleColumnReorderListener(); - dragAndDropDefaultColumnHeader(0, 2, CellSide.RIGHT); - - // then - assertColumnReorderEvent(true); - - // when - toggleColumnReorderListener(); - dragAndDropDefaultColumnHeader(0, 3, CellSide.LEFT); - - // then - assertNoColumnReorderEvent(); - } - - @Test - public void testColumnReorderingEvent_serverSideReorder_triggersReorderEvent() { - openTestURL(); - - // when - toggleColumnReorderListener(); - moveColumnManuallyLeftByOne(3); - - // then - assertColumnReorderEvent(false); - } - - @Test - public void testColumnReorder_draggingFrozenColumns_impossible() { - // given - openTestURL(); - toggleColumnReordering(); - setFrozenColumns(2); - assertColumnHeaderOrder(0, 1, 2, 3); - - // when - dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); - - // then - assertColumnHeaderOrder(0, 1, 2, 3); - assertTrue(getGridElement().getHeaderCell(0, 0).isFrozen()); - assertTrue(getGridElement().getHeaderCell(0, 1).isFrozen()); - assertFalse(getGridElement().getHeaderCell(0, 2).isFrozen()); - } - - @Test - public void testColumnReorder_draggingColumnOnTopOfFrozenColumn_columnDroppedRightOfFrozenColumns() { - // given - openTestURL(); - toggleColumnReordering(); - setFrozenColumns(1); - assertColumnHeaderOrder(0, 1, 2, 3); - - // when - dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); - - // then - assertColumnHeaderOrder(0, 2, 1, 3); - } - - @Test - public void testColumnReorder_draggingColumnLeftOfMultiSelectionColumn_columnDroppedRight() { - // given - openTestURL(); - toggleColumnReordering(); - selectMenuPath("Component", "State", "Selection mode", "multi"); - List gridHeaderRowCells = getGridHeaderRowCells(); - assertTrue(gridHeaderRowCells.get(0).getText().equals("")); - assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); - assertColumnHeader("Column 1", gridHeaderRowCells.get(2)); - assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); - - // when - dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); - - // then - gridHeaderRowCells = getGridHeaderRowCells(); - assertTrue(gridHeaderRowCells.get(0).getText().equals("")); - assertColumnHeader("Column 1", gridHeaderRowCells.get(1)); - assertColumnHeader("Column 0", gridHeaderRowCells.get(2)); - assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); - } - - @Test - public void testColumnReorder_multiSelectionAndFrozenColumns_columnDroppedRight() { - // given - openTestURL(); - toggleColumnReordering(); - selectMenuPath("Component", "State", "Selection mode", "multi"); - setFrozenColumns(1); - List gridHeaderRowCells = getGridHeaderRowCells(); - assertTrue(gridHeaderRowCells.get(0).getText().equals("")); - assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); - assertColumnHeader("Column 1", gridHeaderRowCells.get(2)); - assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); - - // when - dragAndDropDefaultColumnHeader(3, 0, CellSide.LEFT); - - // then - gridHeaderRowCells = getGridHeaderRowCells(); - assertTrue(gridHeaderRowCells.get(0).getText().equals("")); - assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); - assertColumnHeader("Column 2", gridHeaderRowCells.get(2)); - assertColumnHeader("Column 1", gridHeaderRowCells.get(3)); - } - - @Test - public void testColumnReordering_multiSelectionColumnNotFrozen_stillCantDropLeftSide() { - // given - openTestURL(); - toggleColumnReordering(); - selectMenuPath("Component", "State", "Selection mode", "multi"); - setFrozenColumns(-1); - List gridHeaderRowCells = getGridHeaderRowCells(); - assertTrue(gridHeaderRowCells.get(0).getText().equals("")); - assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); - assertColumnHeader("Column 1", gridHeaderRowCells.get(2)); - assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); - - // when - dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); - - // then - gridHeaderRowCells = getGridHeaderRowCells(); - assertTrue(gridHeaderRowCells.get(0).getText().equals("")); - assertColumnHeader("Column 1", gridHeaderRowCells.get(1)); - assertColumnHeader("Column 0", gridHeaderRowCells.get(2)); - assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); - } - - @Test - public void testColumnReordering_twoHeaderRows_dndReorderingPossibleFromFirstRow() { - // given - openTestURL(); - toggleColumnReordering(); - selectMenuPath("Component", "Header", "Append row"); - assertColumnHeaderOrder(0, 1, 2, 3); - - // when - dragAndDropColumnHeader(0, 0, 2, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(1, 2, 0, 3); - } - - @Test - public void testColumnReordering_twoHeaderRows_dndReorderingPossibleFromSecondRow() { - // given - openTestURL(); - toggleColumnReordering(); - selectMenuPath("Component", "Header", "Append row"); - assertColumnHeaderOrder(0, 1, 2, 3); - - // when - dragAndDropColumnHeader(1, 0, 2, CellSide.RIGHT); - - // then - assertColumnHeaderOrder(1, 2, 0, 3); - } - - @Test - public void testColumnReordering_bigWidth_dragElementPositionCorrect() { - openTestURL(); - toggleColumnReordering(); - selectMenuPath("Component", "Size", "Width", "900px"); - assertColumnHeaderOrder(0, 1, 2, 3); - - GridCellElement draggedHeaderCell = getGridElement().getHeaderCell(0, - 1); - final int xOffset = 500; - new Actions(getDriver()).moveToElement(draggedHeaderCell, 20, 10) - .clickAndHold().moveByOffset(xOffset, 0).build().perform(); - - WebElement floatingDragElement = findElement( - By.className("dragged-column-header")); - - int expectedLeft = draggedHeaderCell.getLocation().getX() + xOffset + 20 - - (floatingDragElement.getSize().getWidth() / 2); - int realLeft = floatingDragElement.getLocation().getX(); - - assertTrue( - "Dragged element location wrong, expected " + expectedLeft - + " was " + realLeft, - Math.abs(expectedLeft - realLeft) < 10); - } - - @Test - public void testDropMarker_sidebarOpenButtonVisible_dropMarkerOnCorrectPosition() { - // using runo since there the sidebar opening button is wider than the - // scroll deco, and because using Valo has some TB issues - openTestURL("theme=runo"); - - selectMenuPath("Component", "Size", "Width", "100%"); - selectMenuPath("Component", "Columns", "All columns hidable"); - toggleColumnReordering(); - scrollGridHorizontallyTo(100000); - - new Actions(getDriver()).clickAndHold(getDefaultColumnHeader(10)) - .moveByOffset(800, 0).build().perform(); - - WebElement dragDropMarker = findElement( - By.className("v-grid-drop-marker")); - WebElement sidebar = findElement(By.className("v-grid-sidebar")); - - int dragDropMarkerX = dragDropMarker.getLocation().getX(); - int sidebarX = sidebar.getLocation().getX(); - assertTrue( - "Drop marker misplaced " + dragDropMarkerX - + " compared to sidebar open button " + sidebarX, - dragDropMarkerX <= sidebarX); - } - - private void toggleColumnReordering() { - selectMenuPath(COLUMN_REORDERING_PATH); - } - - private void toggleColumnReorderListener() { - selectMenuPath(COLUMN_REORDER_LISTENER_PATH); - } - - private void moveColumnManuallyLeftByOne(int index) { - selectMenuPath(new String[] { "Component", "Columns", "Column " + index, - "Move left" }); - } - - private void assertColumnReorderEvent(boolean userOriginated) { - final String logRow = getLogRow(0); - assertTrue(logRow.contains( - "Columns reordered, userOriginated: " + userOriginated)); - } - - private void assertNoColumnReorderEvent() { - final String logRow = getLogRow(0); - assertFalse(logRow.contains("Columns reordered")); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java deleted file mode 100644 index b36b893ee6..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java +++ /dev/null @@ -1,149 +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.components.grid.basicfeatures.server; - -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 org.openqa.selenium.Dimension; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -@TestCategory("grid") -public class GridColumnResizeTest extends GridBasicFeaturesTest { - - @Before - public void before() { - openTestURL(); - } - - @Test - public void testResizeHandlesPresentInDefaultHeader() { - for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { - assertResizable(i, true); - } - } - - @Test - public void testResizeHandlesNotInNonDefaultHeader() { - selectMenuPath("Component", "Header", "Prepend row"); - - for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { - assertResizable(getGridElement().getHeaderCell(0, i), false); - assertResizable(getGridElement().getHeaderCell(1, i), true); - } - } - - @Test - public void testResizeHandlesNotInFooter() { - selectMenuPath("Component", "Footer", "Visible"); - for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { - assertResizable(getGridElement().getFooterCell(0, i), false); - } - } - - @Test - public void testToggleSetResizable() { - selectMenuPath("Component", "Columns", "Column 1", "Resizable"); - - for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { - assertResizable(i, i != 1); - } - - selectMenuPath("Component", "Columns", "Column 1", "Resizable"); - - for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { - assertResizable(i, true); - } - } - - @Test - public void testResizeFirstColumn() { - dragResizeColumn(0, -1, -10); - assertTrue("Log should contain a resize event", - logContainsText("ColumnResizeEvent: isUserOriginated? true")); - } - - @Test - public void testDragHandleStraddlesColumns() { - dragResizeColumn(0, 4, -10); - assertTrue("Log should contain a resize event", - logContainsText("ColumnResizeEvent: isUserOriginated? true")); - } - - @Test - public void testColumnPixelSizesSetOnResize() { - selectMenuPath("Component", "Columns", "All columns auto width"); - dragResizeColumn(0, -1, -10); - for (String msg : getLogs()) { - assertTrue("Log should contain a resize event", - msg.contains("ColumnResizeEvent: isUserOriginated? true")); - } - } - - @Test - public void testResizeWithWidgetHeader() { - selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width", - "250px"); - selectMenuPath("Component", "Columns", "Column 0", "Header Type", - "Widget Header"); - - // IE9 and IE10 sometimes have a 1px gap between resize handle parts, so - // using posX 1px - dragResizeColumn(0, 1, 10); - - assertTrue("Log should contain a resize event", - logContainsText("ColumnResizeEvent: isUserOriginated? true")); - } - - private void dragResizeColumn(int columnIndex, int posX, int offset) { - GridCellElement headerCell = getGridElement().getHeaderCell(0, - columnIndex); - Dimension size = headerCell.getSize(); - new Actions(getDriver()) - .moveToElement(headerCell, size.getWidth() + posX, - size.getHeight() / 2) - .clickAndHold().moveByOffset(offset, 0).release().perform(); - } - - private void assertResizable(int columnIndex, boolean resizable) { - assertResizable(getGridElement().getHeaderCell(0, columnIndex), - resizable); - } - - private void assertResizable(GridCellElement cell, boolean resizable) { - assertEquals("Header resize handle present", resizable, - cell.isElementPresent( - By.cssSelector("div.v-grid-column-resize-handle"))); - } - - @Test - public void testShrinkColumnToZero() { - openTestURL(); - GridCellElement cell = getGridElement().getCell(0, 1); - dragResizeColumn(1, 0, cell.getSize().getWidth()); - - assertGreaterOrEqual("Cell got too small.", cell.getSize().getWidth(), - 10); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java deleted file mode 100644 index f40b61058e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java +++ /dev/null @@ -1,314 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -@TestCategory("grid") -public class GridColumnVisibilityTest extends GridBasicFeaturesTest { - - private static final String[] TOGGLE_LISTENER = new String[] { "Component", - "State", "ColumnVisibilityChangeListener" }; - private static final String[] TOGGLE_HIDE_COLUMN_0 = new String[] { - "Component", "Columns", "Column 0", "Hidden" }; - - private static final String COLUMN_0_BECAME_HIDDEN_MSG = "Visibility " - + "changed: propertyId: Column 0, isHidden: true"; - private static final String COLUMN_0_BECAME_UNHIDDEN_MSG = "Visibility " - + "changed: propertyId: Column 0, isHidden: false"; - private static final String USER_ORIGINATED_TRUE = "userOriginated: true"; - private static final String USER_ORIGINATED_FALSE = "userOriginated: false"; - - @Before - public void setUp() { - openTestURL(); - } - - @Test - public void columnIsNotShownWhenHidden() { - assertEquals("column 0", - getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); - - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - assertEquals("column 1", - getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); - } - - @Test - public void columnIsShownWhenUnhidden() { - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - assertEquals("column 0", - getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); - } - - @Test - public void registeringListener() { - assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); - selectMenuPath(TOGGLE_LISTENER); - assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); - - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); - assertTrue(logContainsText(USER_ORIGINATED_FALSE)); - - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG)); - assertTrue(logContainsText(USER_ORIGINATED_FALSE)); - } - - @Test - public void deregisteringListener() { - selectMenuPath(TOGGLE_LISTENER); - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - - selectMenuPath(TOGGLE_LISTENER); - selectMenuPath(TOGGLE_HIDE_COLUMN_0); - assertFalse(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG)); - } - - @Test - public void testColumnHiding_userOriginated_correctParams() { - selectMenuPath(TOGGLE_LISTENER); - toggleColumnHidable(0); - assertColumnHeaderOrder(0, 1, 2, 3); - - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - getSidebarOpenButton().click(); - - assertColumnHeaderOrder(1, 2, 3); - assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); - assertTrue(logContainsText(USER_ORIGINATED_TRUE)); - - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - getSidebarOpenButton().click(); - - assertColumnHeaderOrder(0, 1, 2, 3); - assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG)); - assertTrue(logContainsText(USER_ORIGINATED_TRUE)); - - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - getSidebarOpenButton().click(); - - assertColumnHeaderOrder(1, 2, 3); - assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); - assertTrue(logContainsText(USER_ORIGINATED_TRUE)); - } - - @Test - public void testColumnHiding_whenHidableColumnRemoved_toggleRemoved() { - toggleColumnHidable(0); - toggleColumnHidable(1); - getSidebarOpenButton().click(); - assertNotNull(getColumnHidingToggle(0)); - - addRemoveColumn(0); - - assertNull(getColumnHidingToggle(0)); - } - - @Test - public void testColumnHiding_whenHidableColumnAdded_toggleWithCorrectCaptionAdded() { - selectMenuPath("Component", "Size", "Width", "100%"); - toggleColumnHidable(0); - toggleColumnHidable(1); - toggleColumnHidingToggleCaptionChange(0); - getSidebarOpenButton().click(); - assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText()); - getSidebarOpenButton().click(); - - addRemoveColumn(0); - addRemoveColumn(4); - addRemoveColumn(5); - addRemoveColumn(6); - addRemoveColumn(7); - addRemoveColumn(8); - addRemoveColumn(9); - addRemoveColumn(10); - assertColumnHeaderOrder(1, 2, 3, 11); - - getSidebarOpenButton().click(); - assertNull(getColumnHidingToggle(0)); - getSidebarOpenButton().click(); - - addRemoveColumn(0); - assertColumnHeaderOrder(1, 2, 3, 11, 0); - - getSidebarOpenButton().click(); - assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText()); - } - - @Test - public void testColumnHidingToggleCaption_settingToggleCaption_updatesToggle() { - toggleColumnHidable(1); - getSidebarOpenButton().click(); - assertEquals("column 1", - getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Column 1", getColumnHidingToggle(1).getText()); - - toggleColumnHidingToggleCaptionChange(1); - - getSidebarOpenButton().click(); - assertEquals("column 1", - getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText()); - - toggleColumnHidingToggleCaptionChange(1); - getSidebarOpenButton().click(); - assertEquals("Column 1 caption 1", getColumnHidingToggle(1).getText()); - } - - @Test - public void testColumnHidingToggleCaption_settingWidgetToHeader_toggleCaptionStays() { - toggleColumnHidable(1); - getSidebarOpenButton().click(); - assertEquals("column 1", - getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Column 1", getColumnHidingToggle(1).getText()); - - selectMenuPath("Component", "Columns", "Column 1", "Header Type", - "Widget Header"); - - getSidebarOpenButton().click(); - assertEquals("Column 1", getColumnHidingToggle(1).getText()); - } - - @Test - public void testColumnHidingToggleCaption_settingColumnHeaderCaption_toggleCaptionIsEqual() { - toggleColumnHidable(1); - - selectMenuPath("Component", "Columns", "Column 1", - "Change header caption"); - - getSidebarOpenButton().click(); - assertEquals("column 1 header 0", - getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Column 1 header 0", getColumnHidingToggle(1).getText()); - } - - @Test - public void testColumnHidingToggleCaption_explicitlySet_toggleCaptionIsNotOverridden() { - toggleColumnHidable(1); - - selectMenuPath("Component", "Columns", "Column 1", - "Change hiding toggle caption"); - selectMenuPath("Component", "Columns", "Column 1", - "Change header caption"); - - getSidebarOpenButton().click(); - assertEquals("column 1 header 0", - getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); - assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText()); - } - - private void toggleColumnHidingToggleCaptionChange(int index) { - selectMenuPath("Component", "Columns", "Column " + index, - "Change hiding toggle caption"); - } - - @Test - public void testFrozenColumnHiding_hiddenColumnMadeFrozen_frozenWhenMadeVisible() { - selectMenuPath("Component", "Size", "Width", "100%"); - toggleColumnHidable(0); - toggleColumnHidable(1); - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - getColumnHidingToggle(1).click(); - - assertColumnHeaderOrder(2, 3, 4, 5); - - setFrozenColumns(2); - verifyColumnNotFrozen(0); - verifyColumnNotFrozen(1); - - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - assertColumnHeaderOrder(0, 2, 3, 4, 5); - verifyColumnFrozen(0); - verifyColumnNotFrozen(1); - - getColumnHidingToggle(1).click(); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5); - verifyColumnFrozen(0); - verifyColumnFrozen(1); - verifyColumnNotFrozen(2); - } - - @Test - public void testFrozenColumnHiding_hiddenFrozenColumnUnfrozen_notFrozenWhenMadeVisible() { - selectMenuPath("Component", "Size", "Width", "100%"); - toggleColumnHidable(0); - toggleColumnHidable(1); - setFrozenColumns(2); - verifyColumnFrozen(0); - verifyColumnFrozen(1); - verifyColumnNotFrozen(2); - verifyColumnNotFrozen(3); - - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - getColumnHidingToggle(1).click(); - assertColumnHeaderOrder(2, 3, 4, 5); - verifyColumnNotFrozen(0); - verifyColumnNotFrozen(1); - - setFrozenColumns(0); - verifyColumnNotFrozen(0); - verifyColumnNotFrozen(1); - - getSidebarOpenButton().click(); - getColumnHidingToggle(0).click(); - assertColumnHeaderOrder(0, 2, 3, 4, 5); - verifyColumnNotFrozen(0); - verifyColumnNotFrozen(1); - - getColumnHidingToggle(1).click(); - assertColumnHeaderOrder(0, 1, 2, 3, 4, 5); - verifyColumnNotFrozen(0); - verifyColumnNotFrozen(1); - verifyColumnNotFrozen(2); - } - - private void verifyColumnFrozen(int index) { - assertTrue(getGridElement().getHeaderCell(0, index).isFrozen()); - } - - private void verifyColumnNotFrozen(int index) { - assertFalse(getGridElement().getHeaderCell(0, index).isFrozen()); - } - - private void toggleColumnHidable(int index) { - selectMenuPath("Component", "Columns", "Column " + index, "Hidable"); - } - - private void addRemoveColumn(int index) { - selectMenuPath("Component", "Columns", "Column " + index, - "Add / Remove"); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java deleted file mode 100644 index 759476c67a..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java +++ /dev/null @@ -1,297 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.NoSuchElementException; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridDetailsServerTest extends GridBasicFeaturesTest { - /** - * The reason to why last item details wasn't selected is that since it will - * exist only after the viewport has been scrolled into view, we wouldn't be - * able to scroll that particular details row into view, making tests - * awkward with two scroll commands back to back. - */ - private static final int ALMOST_LAST_INDEX = 995; - private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = new String[] { - "Component", "Details", "Open " + ALMOST_LAST_INDEX }; - private static final String[] OPEN_FIRST_ITEM_DETAILS = new String[] { - "Component", "Details", "Open firstItemId" }; - private static final String[] TOGGLE_FIRST_ITEM_DETAILS = new String[] { - "Component", "Details", "Toggle firstItemId" }; - private static final String[] DETAILS_GENERATOR_NULL = new String[] { - "Component", "Details", "Generators", "NULL" }; - private static final String[] DETAILS_GENERATOR_WATCHING = new String[] { - "Component", "Details", "Generators", "\"Watching\"" }; - private static final String[] DETAILS_GENERATOR_PERSISTING = new String[] { - "Component", "Details", "Generators", "Persisting" }; - private static final String[] CHANGE_HIERARCHY = new String[] { "Component", - "Details", "Generators", "- Change Component" }; - - @Before - public void setUp() { - openTestURL(); - } - - @Test(expected = NoSuchElementException.class) - public void openWithNoGenerator() { - try { - getGridElement().getDetails(0); - fail("Expected NoSuchElementException"); - } catch (NoSuchElementException ignore) { - // expected - } - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - getGridElement().getDetails(0); - } - - @Test - public void openVisiblePopulatedDetails() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - assertNotNull("details should've populated", getGridElement() - .getDetails(0).findElement(By.className("v-widget"))); - } - - @Test(expected = NoSuchElementException.class) - public void closeVisiblePopulatedDetails() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - getGridElement().getDetails(0); - } - - @Test - public void openDetailsOutsideOfActiveRange() throws InterruptedException { - getGridElement().scroll(10000); - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - getGridElement().scroll(0); - Thread.sleep(50); - assertNotNull("details should've been opened", - getGridElement().getDetails(0)); - } - - @Test(expected = NoSuchElementException.class) - public void closeDetailsOutsideOfActiveRange() { - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - getGridElement().scroll(10000); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - getGridElement().scroll(0); - getGridElement().getDetails(0); - } - - @Test - public void componentIsVisibleClientSide() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - - TestBenchElement details = getGridElement().getDetails(0); - assertNotNull("No widget detected inside details", - details.findElement(By.className("v-widget"))); - } - - @Test - public void openingDetailsTwice() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // close - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open - - TestBenchElement details = getGridElement().getDetails(0); - assertNotNull("No widget detected inside details", - details.findElement(By.className("v-widget"))); - } - - @Test(expected = NoSuchElementException.class) - public void scrollingDoesNotCreateAFloodOfDetailsRows() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - - // scroll somewhere to hit uncached rows - getGridElement().scrollToRow(101); - - // this should throw - getGridElement().getDetails(100); - } - - @Test - public void openingDetailsOutOfView() { - getGridElement().scrollToRow(500); - - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - - getGridElement().scrollToRow(0); - - // if this fails, it'll fail before the assertNotNull - assertNotNull("unexpected null details row", - getGridElement().getDetails(0)); - } - - @Test - public void togglingAVisibleDetailsRowWithOneRoundtrip() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open - - assertTrue("Unexpected generator content", - getGridElement().getDetails(0).getText().endsWith("(0)")); - selectMenuPath(TOGGLE_FIRST_ITEM_DETAILS); - assertTrue("New component was not displayed in the client", - getGridElement().getDetails(0).getText().endsWith("(1)")); - } - - @Test - public void almostLastItemIdIsRendered() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_ALMOST_LAST_ITEM_DETAILS); - scrollGridVerticallyTo(100000); - - TestBenchElement details = getGridElement() - .getDetails(ALMOST_LAST_INDEX); - assertNotNull(details); - assertTrue("Unexpected details content", - details.getText().endsWith(ALMOST_LAST_INDEX + " (0)")); - } - - @Test - public void persistingChangesWorkInDetails() { - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - assertEquals("One", getGridElement().getDetails(0).getText()); - selectMenuPath(CHANGE_HIERARCHY); - assertEquals("Two", getGridElement().getDetails(0).getText()); - } - - @Test - public void persistingChangesWorkInDetailsWhileOutOfView() { - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - assertEquals("One", getGridElement().getDetails(0).getText()); - scrollGridVerticallyTo(10000); - selectMenuPath(CHANGE_HIERARCHY); - scrollGridVerticallyTo(0); - assertEquals("Two", getGridElement().getDetails(0).getText()); - } - - @Test - public void persistingChangesWorkInDetailsWhenNotAttached() { - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - assertEquals("One", getGridElement().getDetails(0).getText()); - - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - assertFalse("Details should be detached", - getGridElement().isElementPresent(By.vaadin("#details[0]"))); - - selectMenuPath(CHANGE_HIERARCHY); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - - assertEquals("Two", getGridElement().getDetails(0).getText()); - } - - @Test - public void swappingDetailsGenerators_noDetailsShown() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(DETAILS_GENERATOR_NULL); - assertFalse("Got some errors", $(NotificationElement.class).exists()); - } - - @Test - public void swappingDetailsGenerators_shownDetails() { - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - assertTrue("Details should contain 'One' at first", - getGridElement().getDetails(0).getText().contains("One")); - - selectMenuPath(DETAILS_GENERATOR_WATCHING); - assertFalse( - "Details should contain 'Watching' after swapping generator", - getGridElement().getDetails(0).getText().contains("Watching")); - } - - @Test - public void swappingDetailsGenerators_whileDetailsScrolledOut_showNever() { - scrollGridVerticallyTo(1000); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - selectMenuPath(DETAILS_GENERATOR_WATCHING); - assertFalse("Got some errors", $(NotificationElement.class).exists()); - } - - @Test - public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() { - scrollGridVerticallyTo(1000); - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - selectMenuPath(DETAILS_GENERATOR_WATCHING); - scrollGridVerticallyTo(0); - - assertFalse("Got some errors", $(NotificationElement.class).exists()); - assertNotNull("Could not find a details", - getGridElement().getDetails(0)); - } - - @Test - public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() { - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - selectMenuPath(DETAILS_GENERATOR_WATCHING); - scrollGridVerticallyTo(1000); - - assertFalse("Got some errors", $(NotificationElement.class).exists()); - assertNotNull("Could not find a details", - getGridElement().getDetails(0)); - } - - @Test - public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() { - selectMenuPath(DETAILS_GENERATOR_PERSISTING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - selectMenuPath(DETAILS_GENERATOR_WATCHING); - scrollGridVerticallyTo(1000); - scrollGridVerticallyTo(0); - - assertFalse("Got some errors", $(NotificationElement.class).exists()); - assertNotNull("Could not find a details", - getGridElement().getDetails(0)); - } - - @Test - public void noAssertErrorsOnEmptyDetailsAndScrollDown() { - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - scrollGridVerticallyTo(500); - assertFalse(logContainsText("AssertionError")); - } - - @Test - public void noAssertErrorsOnPopulatedDetailsAndScrollDown() { - selectMenuPath(DETAILS_GENERATOR_WATCHING); - selectMenuPath(OPEN_FIRST_ITEM_DETAILS); - scrollGridVerticallyTo(500); - assertFalse(logContainsText("AssertionError")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java deleted file mode 100644 index f20b40b622..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java +++ /dev/null @@ -1,314 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.v7.shared.ui.grid.GridConstants; - -public class GridEditorBufferedTest extends GridEditorTest { - - @Override - @Before - public void setUp() { - super.setUp(); - } - - @Test - public void testKeyboardSave() { - selectMenuPath(EDIT_ITEM_100); - - WebElement textField = getEditorWidgets().get(0); - - textField.click(); - // without this, the click in the middle of the field might not be after - // the old text on some browsers - new Actions(getDriver()).sendKeys(Keys.END).perform(); - - textField.sendKeys(" changed"); - - // Save from keyboard - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - assertEditorClosed(); - assertEquals("(100, 0) changed", - getGridElement().getCell(100, 0).getText()); - } - - @Test - public void testKeyboardSaveWithInvalidEdition() { - makeInvalidEdition(); - - GridEditorElement editor = getGridElement().getEditor(); - TestBenchElement field = editor.getField(7); - - field.click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - assertEditorOpen(); - assertEquals("Column 7: Could not convert value to Integer", - editor.getErrorMessage()); - assertTrue("Field 7 should have been marked with an error after error", - editor.isFieldErrorMarked(7)); - - editor.cancel(); - - selectMenuPath(EDIT_ITEM_100); - assertFalse("Exception should not exist", - isElementPresent(NotificationElement.class)); - assertEquals("There should be no editor error message", null, - getGridElement().getEditor().getErrorMessage()); - } - - @Test - public void testSave() { - selectMenuPath(EDIT_ITEM_100); - - WebElement textField = getEditorWidgets().get(0); - - textField.click(); - // without this, the click in the middle of the field might not be after - // the old text on some browsers - new Actions(getDriver()).sendKeys(Keys.END).perform(); - - textField.sendKeys(" changed"); - - WebElement saveButton = getEditor() - .findElement(By.className("v-grid-editor-save")); - - saveButton.click(); - - assertEquals("(100, 0) changed", - getGridElement().getCell(100, 0).getText()); - } - - @Test - public void testProgrammaticSave() { - selectMenuPath(EDIT_ITEM_100); - - WebElement textField = getEditorWidgets().get(0); - - textField.click(); - // without this, the click in the middle of the field might not be after - // the old text on some browsers - new Actions(getDriver()).sendKeys(Keys.END).perform(); - - textField.sendKeys(" changed"); - - selectMenuPath("Component", "Editor", "Save"); - - assertEquals("(100, 0) changed", - getGridElement().getCell(100, 0).getText()); - } - - @Test - public void testInvalidEdition() { - makeInvalidEdition(); - - GridEditorElement editor = getGridElement().getEditor(); - editor.save(); - - assertEquals("Column 7: Could not convert value to Integer", - editor.getErrorMessage()); - assertTrue("Field 7 should have been marked with an error after error", - editor.isFieldErrorMarked(7)); - editor.cancel(); - - selectMenuPath(EDIT_ITEM_100); - assertFalse("Exception should not exist", - isElementPresent(NotificationElement.class)); - assertEquals("There should be no editor error message", null, - getGridElement().getEditor().getErrorMessage()); - } - - private void makeInvalidEdition() { - selectMenuPath(EDIT_ITEM_5); - assertFalse(logContainsText( - "Exception occured, java.lang.IllegalStateException")); - - GridEditorElement editor = getGridElement().getEditor(); - - assertFalse( - "Field 7 should not have been marked with an error before error", - editor.isFieldErrorMarked(7)); - - WebElement intField = editor.getField(7); - intField.clear(); - intField.sendKeys("banana phone"); - } - - @Test - public void testEditorInDisabledGrid() { - int originalScrollPos = getGridVerticalScrollPos(); - - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - - selectMenuPath("Component", "State", "Enabled"); - assertEditorOpen(); - - GridEditorElement editor = getGridElement().getEditor(); - editor.save(); - assertEditorOpen(); - - editor.cancel(); - assertEditorOpen(); - - selectMenuPath("Component", "State", "Enabled"); - - scrollGridVerticallyTo(100); - assertEquals( - "Grid shouldn't scroll vertically while editing in buffered mode", - originalScrollPos, getGridVerticalScrollPos()); - } - - @Test - public void testCaptionChange() { - selectMenuPath(EDIT_ITEM_5); - assertEquals("Save button caption should've been \"" - + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with", - GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); - assertEquals("Cancel button caption should've been \"" - + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with", - GridConstants.DEFAULT_CANCEL_CAPTION, - getCancelButton().getText()); - - selectMenuPath("Component", "Editor", "Change save caption"); - assertNotEquals( - "Save button caption should've changed while editor is open", - GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); - - getCancelButton().click(); - - selectMenuPath("Component", "Editor", "Change cancel caption"); - selectMenuPath(EDIT_ITEM_5); - assertNotEquals( - "Cancel button caption should've changed while editor is closed", - GridConstants.DEFAULT_CANCEL_CAPTION, - getCancelButton().getText()); - } - - @Test(expected = NoSuchElementException.class) - public void testVerticalScrollLocking() { - selectMenuPath(EDIT_ITEM_5); - getGridElement().getCell(200, 0); - } - - @Test - public void testScrollDisabledOnProgrammaticOpen() { - int originalScrollPos = getGridVerticalScrollPos(); - - selectMenuPath(EDIT_ITEM_5); - - scrollGridVerticallyTo(100); - assertEquals( - "Grid shouldn't scroll vertically while editing in buffered mode", - originalScrollPos, getGridVerticalScrollPos()); - } - - @Test - public void testScrollDisabledOnMouseOpen() { - int originalScrollPos = getGridVerticalScrollPos(); - - GridCellElement cell_5_0 = getGridElement().getCell(5, 0); - new Actions(getDriver()).doubleClick(cell_5_0).perform(); - - scrollGridVerticallyTo(100); - assertEquals( - "Grid shouldn't scroll vertically while editing in buffered mode", - originalScrollPos, getGridVerticalScrollPos()); - } - - @Test - public void testScrollDisabledOnKeyboardOpen() { - int originalScrollPos = getGridVerticalScrollPos(); - - GridCellElement cell_5_0 = getGridElement().getCell(5, 0); - cell_5_0.click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - scrollGridVerticallyTo(100); - assertEquals( - "Grid shouldn't scroll vertically while editing in buffered mode", - originalScrollPos, getGridVerticalScrollPos()); - } - - @Test - public void testMouseOpeningClosing() { - - getGridElement().getCell(4, 0).doubleClick(); - assertEditorOpen(); - - getCancelButton().click(); - assertEditorClosed(); - - selectMenuPath(TOGGLE_EDIT_ENABLED); - getGridElement().getCell(4, 0).doubleClick(); - assertEditorClosed(); - } - - @Test - public void testMouseOpeningDisabledWhenOpen() { - selectMenuPath(EDIT_ITEM_5); - - getGridElement().getCell(4, 0).doubleClick(); - - assertEquals("Editor should still edit row 5", "(5, 0)", - getEditorWidgets().get(0).getAttribute("value")); - } - - @Test - public void testProgrammaticOpeningDisabledWhenOpen() { - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - assertEquals("Editor should edit row 5", "(5, 0)", - getEditorWidgets().get(0).getAttribute("value")); - - selectMenuPath(EDIT_ITEM_100); - boolean thrown = logContainsText( - "Exception occured, java.lang.IllegalStateException"); - assertTrue("IllegalStateException thrown", thrown); - - assertEditorOpen(); - assertEquals("Editor should still edit row 5", "(5, 0)", - getEditorWidgets().get(0).getAttribute("value")); - } - - @Test - public void testUserSortDisabledWhenOpen() { - selectMenuPath(EDIT_ITEM_5); - - getGridElement().getHeaderCell(0, 0).click(); - - assertEditorOpen(); - assertEquals("(2, 0)", getGridElement().getCell(2, 0).getText()); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java deleted file mode 100644 index c0a336c485..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java +++ /dev/null @@ -1,303 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridEditorElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public abstract class GridEditorTest extends GridBasicFeaturesTest { - - protected static final By BY_EDITOR_CANCEL = By - .className("v-grid-editor-cancel"); - protected static final By BY_EDITOR_SAVE = By - .className("v-grid-editor-save"); - protected static final String[] EDIT_ITEM_5 = new String[] { "Component", - "Editor", "Edit item 5" }; - protected static final String[] EDIT_ITEM_100 = new String[] { "Component", - "Editor", "Edit item 100" }; - protected static final String[] TOGGLE_EDIT_ENABLED = new String[] { - "Component", "Editor", "Enabled" }; - - @Before - public void setUp() { - setDebug(true); - openTestURL(); - selectMenuPath(TOGGLE_EDIT_ENABLED); - } - - @Test - public void testProgrammaticOpeningClosing() { - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - - selectMenuPath("Component", "Editor", "Cancel edit"); - assertEditorClosed(); - } - - @Test - public void testProgrammaticOpeningWhenDisabled() { - selectMenuPath(TOGGLE_EDIT_ENABLED); - selectMenuPath(EDIT_ITEM_5); - assertEditorClosed(); - boolean thrown = logContainsText( - "Exception occured, java.lang.IllegalStateException"); - assertTrue("IllegalStateException thrown", thrown); - } - - @Test - public void testDisablingWhileOpen() { - selectMenuPath(EDIT_ITEM_5); - selectMenuPath(TOGGLE_EDIT_ENABLED); - assertEditorOpen(); - boolean thrown = logContainsText( - "Exception occured, java.lang.IllegalStateException"); - assertTrue("IllegalStateException thrown", thrown); - } - - @Test - public void testProgrammaticOpeningWithScroll() { - selectMenuPath(EDIT_ITEM_100); - assertEditorOpen(); - } - - @Test - public void testKeyboardOpeningClosing() { - - getGridElement().getCell(4, 0).click(); - assertEditorClosed(); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertEditorOpen(); - - new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); - assertEditorClosed(); - - // Disable Editor - selectMenuPath(TOGGLE_EDIT_ENABLED); - getGridElement().getCell(5, 0).click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertEditorClosed(); - } - - @Test - public void testComponentBinding() { - selectMenuPath(EDIT_ITEM_100); - - List widgets = getEditorWidgets(); - assertEquals("Number of widgets", GridBasicFeatures.EDITABLE_COLUMNS, - widgets.size()); - - assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); - assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); - assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); - assertEquals("100", widgets.get(8).getAttribute("value")); - } - - protected void assertEditorOpen() { - assertEquals("Unexpected number of widgets", - GridBasicFeatures.EDITABLE_COLUMNS, getEditorWidgets().size()); - } - - protected void assertEditorClosed() { - assertNull("Editor is supposed to be closed", getEditor()); - } - - protected List getEditorWidgets() { - assertNotNull("Editor is supposed to be open", getEditor()); - return getEditor().findElements(By.className("v-textfield")); - - } - - @Test - public void testFocusOnMouseOpen() { - - GridCellElement cell = getGridElement().getCell(4, 2); - - cell.doubleClick(); - - WebElement focused = getFocusedElement(); - - assertEquals("", "input", focused.getTagName()); - assertEquals("", cell.getText(), focused.getAttribute("value")); - } - - @Test - public void testFocusOnKeyboardOpen() { - - GridCellElement cell = getGridElement().getCell(4, 2); - - cell.click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - WebElement focused = getFocusedElement(); - - assertEquals("", "input", focused.getTagName()); - assertEquals("", cell.getText(), focused.getAttribute("value")); - } - - @Test - public void testFocusOnProgrammaticOpenOnItemClick() { - selectMenuPath("Component", "State", "EditorOpeningItemClickListener"); - - GridCellElement cell = getGridElement().getCell(4, 2); - - cell.click(); - - WebElement focused = getFocusedElement(); - - assertEquals("", "input", focused.getTagName()); - assertEquals("", cell.getText(), focused.getAttribute("value")); - } - - @Test - public void testNoFocusOnProgrammaticOpen() { - - selectMenuPath(EDIT_ITEM_5); - - WebElement focused = getFocusedElement(); - - assertEquals("Focus should remain in the menu", "menu", - focused.getAttribute("id")); - } - - @Test - public void testUneditableColumn() { - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - - GridEditorElement editor = getGridElement().getEditor(); - assertFalse("Uneditable column should not have an editor widget", - editor.isEditable(3)); - - String classNames = editor - .findElements(By.className("v-grid-editor-cells")).get(1) - .findElements(By.xpath("./div")).get(3).getAttribute("class"); - - assertTrue("Noneditable cell should contain not-editable classname", - classNames.contains("not-editable")); - - assertTrue("Noneditable cell should contain v-grid-cell classname", - classNames.contains("v-grid-cell")); - - assertNoErrorNotifications(); - } - - @Test - public void testNoOpenFromHeaderOrFooter() { - selectMenuPath("Component", "Footer", "Visible"); - - getGridElement().getHeaderCell(0, 0).doubleClick(); - assertEditorClosed(); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertEditorClosed(); - - getGridElement().getFooterCell(0, 0).doubleClick(); - assertEditorClosed(); - - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - assertEditorClosed(); - } - - public void testEditorMoveOnResize() { - selectMenuPath("Component", "Size", "Height", "500px"); - getGridElement().getCell(22, 0).doubleClick(); - assertEditorOpen(); - - GridEditorElement editor = getGridElement().getEditor(); - TestBenchElement tableWrapper = getGridElement().getTableWrapper(); - - int tableWrapperBottom = tableWrapper.getLocation().getY() - + tableWrapper.getSize().getHeight(); - int editorBottom = editor.getLocation().getY() - + editor.getSize().getHeight(); - - assertTrue("Editor should not be initially outside grid", - tableWrapperBottom - editorBottom <= 2); - - selectMenuPath("Component", "Size", "Height", "300px"); - assertEditorOpen(); - - tableWrapperBottom = tableWrapper.getLocation().getY() - + tableWrapper.getSize().getHeight(); - editorBottom = editor.getLocation().getY() - + editor.getSize().getHeight(); - - assertTrue("Editor should not be outside grid after resize", - tableWrapperBottom - editorBottom <= 2); - } - - public void testEditorDoesNotMoveOnResizeIfNotNeeded() { - selectMenuPath("Component", "Size", "Height", "500px"); - - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - - GridEditorElement editor = getGridElement().getEditor(); - - int editorPos = editor.getLocation().getY(); - - selectMenuPath("Component", "Size", "Height", "300px"); - assertEditorOpen(); - - assertTrue("Editor should not have moved due to resize", - editorPos == editor.getLocation().getY()); - } - - @Test - public void testEditorClosedOnSort() { - selectMenuPath(EDIT_ITEM_5); - - selectMenuPath("Component", "State", "Sort by column", "Column 0, ASC"); - - assertEditorClosed(); - } - - @Test - public void testEditorClosedOnFilter() { - selectMenuPath(EDIT_ITEM_5); - - selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\""); - - assertEditorClosed(); - } - - protected WebElement getSaveButton() { - return getDriver().findElement(BY_EDITOR_SAVE); - } - - protected WebElement getCancelButton() { - return getDriver().findElement(BY_EDITOR_CANCEL); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java deleted file mode 100644 index fc708db5c4..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java +++ /dev/null @@ -1,282 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; - -public class GridEditorUnbufferedTest extends GridEditorTest { - - private static final String[] TOGGLE_EDITOR_BUFFERED = new String[] { - "Component", "Editor", "Buffered mode" }; - private static final String[] CANCEL_EDIT = new String[] { "Component", - "Editor", "Cancel edit" }; - - @Override - @Before - public void setUp() { - super.setUp(); - selectMenuPath(TOGGLE_EDITOR_BUFFERED); - } - - @Test - public void testEditorShowsNoButtons() { - selectMenuPath(EDIT_ITEM_5); - - assertEditorOpen(); - - assertFalse("Save button should not be visible in unbuffered mode.", - isElementPresent(BY_EDITOR_SAVE)); - - assertFalse("Cancel button should not be visible in unbuffered mode.", - isElementPresent(BY_EDITOR_CANCEL)); - } - - @Test - public void testToggleEditorUnbufferedWhileOpen() { - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - selectMenuPath(TOGGLE_EDITOR_BUFFERED); - boolean thrown = logContainsText( - "Exception occured, java.lang.IllegalStateException"); - assertTrue("IllegalStateException thrown", thrown); - } - - @Test - public void testEditorMoveWithMouse() { - selectMenuPath(EDIT_ITEM_5); - - assertEditorOpen(); - - String firstFieldValue = getEditorWidgets().get(0) - .getAttribute("value"); - assertEquals("Editor should be at row 5", "(5, 0)", firstFieldValue); - - getGridElement().getCell(10, 0).click(); - firstFieldValue = getEditorWidgets().get(0).getAttribute("value"); - - assertEquals("Editor should be at row 10", "(10, 0)", firstFieldValue); - } - - @Test - public void testEditorMoveWithKeyboard() throws InterruptedException { - selectMenuPath(EDIT_ITEM_100); - - assertEditorOpen(); - - getEditorWidgets().get(0).click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - String firstFieldValue = getEditorWidgets().get(0) - .getAttribute("value"); - assertEquals("Editor should move to row 101", "(101, 0)", - firstFieldValue); - - for (int i = 0; i < 10; i++) { - new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.ENTER) - .keyUp(Keys.SHIFT).perform(); - - firstFieldValue = getEditorWidgets().get(0).getAttribute("value"); - int row = 100 - i; - assertEquals("Editor should move to row " + row, "(" + row + ", 0)", - firstFieldValue); - } - } - - @Test - public void testValidationErrorPreventsMove() throws InterruptedException { - // Because of "out of view" issues, we need to move this for easy access - selectMenuPath("Component", "Columns", "Column 7", "Column 7 Width", - "50px"); - for (int i = 0; i < 6; ++i) { - selectMenuPath("Component", "Columns", "Column 7", "Move left"); - } - - selectMenuPath(EDIT_ITEM_5); - - getEditorWidgets().get(1).click(); - String faultyInt = "not a number"; - getEditorWidgets().get(1).sendKeys(faultyInt); - - getGridElement().getCell(10, 0).click(); - - assertEquals("Editor should not move from row 5", "(5, 0)", - getEditorWidgets().get(0).getAttribute("value")); - - getEditorWidgets().get(1).sendKeys(Keys.chord(Keys.CONTROL, "a")); - getEditorWidgets().get(1).sendKeys("5"); - // FIXME: Needs to trigger one extra validation round-trip for now - getGridElement().sendKeys(Keys.ENTER); - - getGridElement().getCell(10, 0).click(); - - assertEquals("Editor should move to row 10", "(10, 0)", - getEditorWidgets().get(0).getAttribute("value")); - - } - - @Test - public void testErrorMessageWrapperHidden() { - selectMenuPath(EDIT_ITEM_5); - - assertEditorOpen(); - - WebElement editorFooter = getEditor() - .findElement(By.className("v-grid-editor-footer")); - - assertTrue("Editor footer should not be visible when there's no error", - editorFooter.getCssValue("display").equalsIgnoreCase("none")); - } - - @Test - public void testScrollEnabledOnProgrammaticOpen() { - int originalScrollPos = getGridVerticalScrollPos(); - - selectMenuPath(EDIT_ITEM_5); - - scrollGridVerticallyTo(100); - assertGreater( - "Grid should scroll vertically while editing in unbuffered mode", - getGridVerticalScrollPos(), originalScrollPos); - } - - @Test - public void testScrollEnabledOnMouseOpen() { - int originalScrollPos = getGridVerticalScrollPos(); - - GridCellElement cell_5_0 = getGridElement().getCell(5, 0); - new Actions(getDriver()).doubleClick(cell_5_0).perform(); - - scrollGridVerticallyTo(100); - assertGreater( - "Grid should scroll vertically while editing in unbuffered mode", - getGridVerticalScrollPos(), originalScrollPos); - } - - @Test - public void testScrollEnabledOnKeyboardOpen() { - int originalScrollPos = getGridVerticalScrollPos(); - - GridCellElement cell_5_0 = getGridElement().getCell(5, 0); - cell_5_0.click(); - new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); - - scrollGridVerticallyTo(100); - assertGreater( - "Grid should scroll vertically while editing in unbuffered mode", - getGridVerticalScrollPos(), originalScrollPos); - } - - @Test - public void testEditorInDisabledGrid() { - selectMenuPath(EDIT_ITEM_5); - - selectMenuPath("Component", "State", "Enabled"); - assertEditorOpen(); - - assertTrue("Editor text field should be disabled", - null != getEditorWidgets().get(2).getAttribute("disabled")); - - selectMenuPath("Component", "State", "Enabled"); - assertEditorOpen(); - - assertFalse("Editor text field should not be disabled", - null != getEditorWidgets().get(2).getAttribute("disabled")); - } - - @Test - public void testMouseOpeningClosing() { - - getGridElement().getCell(4, 0).doubleClick(); - assertEditorOpen(); - - selectMenuPath(CANCEL_EDIT); - selectMenuPath(TOGGLE_EDIT_ENABLED); - - getGridElement().getCell(4, 0).doubleClick(); - assertEditorClosed(); - } - - @Test - public void testProgrammaticOpeningWhenOpen() { - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - assertEquals("Editor should edit row 5", "(5, 0)", - getEditorWidgets().get(0).getAttribute("value")); - - selectMenuPath(EDIT_ITEM_100); - assertEditorOpen(); - assertEquals("Editor should edit row 100", "(100, 0)", - getEditorWidgets().get(0).getAttribute("value")); - } - - @Test - public void testExternalValueChangePassesToEditor() { - selectMenuPath(EDIT_ITEM_5); - assertEditorOpen(); - - selectMenuPath("Component", "State", "ReactiveValueChanger"); - - getEditorWidgets().get(0).click(); - getEditorWidgets().get(0).sendKeys("changing value"); - - // Focus another field to cause the value to be sent to the server - getEditorWidgets().get(2).click(); - - assertEquals("Value of Column 2 in the editor was not changed", - "Modified", getEditorWidgets().get(2).getAttribute("value")); - } - - @Test - public void testEditorClosedOnUserSort() { - selectMenuPath(EDIT_ITEM_5); - - getGridElement().getHeaderCell(0, 0).click(); - - assertEditorClosed(); - } - - @Test - public void testEditorSaveOnRowChange() { - // Double click sets the focus programmatically - getGridElement().getCell(5, 2).doubleClick(); - - TestBenchElement editor = getGridElement().getEditor().getField(2); - editor.clear(); - // Click to ensure IE focus... - editor.click(5, 5); - editor.sendKeys("Foo", Keys.ENTER); - - assertEquals("Editor did not move.", "(6, 0)", - getGridElement().getEditor().getField(0).getAttribute("value")); - assertEquals("Editor field value did not update from server.", "(6, 2)", - getGridElement().getEditor().getField(2).getAttribute("value")); - - assertEquals("Edited value was not saved.", "Foo", - getGridElement().getCell(5, 2).getText()); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java deleted file mode 100644 index 4ea783723b..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java +++ /dev/null @@ -1,79 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.testbench.elements.MenuBarElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -/** - * Test for server-side Grid focus features. - * - * @since - * @author Vaadin Ltd - */ -public class GridFocusTest extends GridBasicFeaturesTest { - - @Before - public void setUp() { - openTestURL(); - } - - @Test - public void testFocusListener() { - selectMenuPath("Component", "Listeners", "Focus listener"); - - getGridElement().click(); - - assertTrue("Focus listener should be invoked", - getLogRow(0).contains("FocusEvent")); - } - - @Test - public void testBlurListener() { - selectMenuPath("Component", "Listeners", "Blur listener"); - - getGridElement().click(); - $(MenuBarElement.class).first().click(); - - assertTrue("Blur listener should be invoked", - getLogRow(0).contains("BlurEvent")); - } - - @Test - public void testProgrammaticFocus() { - selectMenuPath("Component", "State", "Set focus"); - - assertTrue("Grid cell (0, 0) should be focused", - getGridElement().getCell(0, 0).isFocused()); - } - - @Test - public void testTabIndex() { - assertEquals(getGridElement().getAttribute("tabindex"), "0"); - - selectMenuPath("Component", "State", "Tab index", "-1"); - assertEquals(getGridElement().getAttribute("tabindex"), "-1"); - - selectMenuPath("Component", "State", "Tab index", "10"); - assertEquals(getGridElement().getAttribute("tabindex"), "10"); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridItemClickTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridItemClickTest.java deleted file mode 100644 index a393a0cced..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridItemClickTest.java +++ /dev/null @@ -1,58 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridItemClickTest extends GridBasicFeaturesTest { - - @Test - public void testItemClick() { - openTestURL(); - - selectMenuPath("Component", "State", "ItemClickListener"); - - GridCellElement cell = getGridElement().getCell(3, 2); - new Actions(getDriver()).moveToElement(cell).click().perform(); - - assertTrue("No click in log", - logContainsText(itemClickOn(3, 2, false))); - } - - @Test - public void testItemDoubleClick() { - openTestURL(); - - selectMenuPath("Component", "State", "ItemClickListener"); - - GridCellElement cell = getGridElement().getCell(3, 2); - new Actions(getDriver()).moveToElement(cell).doubleClick().perform(); - - assertTrue("No double click in log", - logContainsText(itemClickOn(3, 2, true))); - } - - private String itemClickOn(int row, int column, boolean dblClick) { - return "Item " + (dblClick ? "double " : "") + "click on Column " - + column + ", item " + row; - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java deleted file mode 100644 index d80788b975..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java +++ /dev/null @@ -1,232 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { - - @Test - public void testCellFocusOnClick() { - openTestURL(); - - GridElement grid = getGridElement(); - assertTrue("Body cell 0, 0 is not focused on init.", - grid.getCell(0, 0).isFocused()); - grid.getCell(5, 2).click(); - assertFalse("Body cell 0, 0 was still focused after clicking", - grid.getCell(0, 0).isFocused()); - assertTrue("Body cell 5, 2 is not focused after clicking", - grid.getCell(5, 2).isFocused()); - } - - @Test - public void testCellNotFocusedWhenRendererHandlesEvent() { - openTestURL(); - - GridElement grid = getGridElement(); - assertTrue("Body cell 0, 0 is not focused on init.", - grid.getCell(0, 0).isFocused()); - grid.getHeaderCell(0, 3).click(); - assertFalse("Body cell 0, 0 is focused after click on header.", - grid.getCell(0, 0).isFocused()); - assertTrue("Header cell 0, 3 is not focused after click on header.", - grid.getHeaderCell(0, 3).isFocused()); - } - - @Test - public void testSimpleKeyboardNavigation() { - openTestURL(); - - GridElement grid = getGridElement(); - grid.getCell(0, 0).click(); - - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - assertTrue("Body cell 1, 0 is not focused after keyboard navigation.", - grid.getCell(1, 0).isFocused()); - - new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT).perform(); - assertTrue("Body cell 1, 1 is not focused after keyboard navigation.", - grid.getCell(1, 1).isFocused()); - - int i; - for (i = 1; i < 40; ++i) { - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - } - - assertFalse("Grid has not scrolled with cell focus", - isElementPresent(By.xpath("//td[text() = '(0, 0)']"))); - assertTrue("Cell focus is not visible", - isElementPresent(By.xpath("//td[text() = '(" + i + ", 0)']"))); - assertTrue("Body cell " + i + ", 1 is not focused", - grid.getCell(i, 1).isFocused()); - } - - @Test - public void testNavigateFromHeaderToBody() { - openTestURL(); - - GridElement grid = getGridElement(); - grid.scrollToRow(300); - new Actions(driver).moveToElement(grid.getHeaderCell(0, 7)).click() - .perform(); - grid.scrollToRow(280); - - assertTrue("Header cell is not focused.", - grid.getHeaderCell(0, 7).isFocused()); - new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); - assertTrue("Body cell 280, 7 is not focused", - grid.getCell(280, 7).isFocused()); - } - - @Test - public void testNavigationFromFooterToBody() { - openTestURL(); - - selectMenuPath("Component", "Footer", "Visible"); - - GridElement grid = getGridElement(); - grid.scrollToRow(300); - grid.getFooterCell(0, 2).click(); - - assertTrue("Footer cell does not have focus.", - grid.getFooterCell(0, 2).isFocused()); - new Actions(getDriver()).sendKeys(Keys.ARROW_UP).perform(); - assertTrue("Body cell 300, 2 does not have focus.", - grid.getCell(300, 2).isFocused()); - } - - @Test - public void testNavigateBetweenHeaderAndBodyWithTab() { - openTestURL(); - - GridElement grid = getGridElement(); - grid.getCell(10, 2).click(); - - assertTrue("Body cell 10, 2 does not have focus", - grid.getCell(10, 2).isFocused()); - new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) - .keyUp(Keys.SHIFT).perform(); - assertTrue("Header cell 0, 2 does not have focus", - grid.getHeaderCell(0, 2).isFocused()); - new Actions(getDriver()).sendKeys(Keys.TAB).perform(); - assertTrue("Body cell 10, 2 does not have focus", - grid.getCell(10, 2).isFocused()); - - // Navigate out of the Grid and try to navigate with arrow keys. - new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) - .sendKeys(Keys.TAB).keyUp(Keys.SHIFT).sendKeys(Keys.ARROW_DOWN) - .perform(); - assertTrue("Header cell 0, 2 does not have focus", - grid.getHeaderCell(0, 2).isFocused()); - } - - @Test - public void testNavigateBetweenFooterAndBodyWithTab() { - openTestURL(); - - selectMenuPath("Component", "Footer", "Visible"); - - GridElement grid = getGridElement(); - grid.getCell(10, 2).click(); - - assertTrue("Body cell 10, 2 does not have focus", - grid.getCell(10, 2).isFocused()); - new Actions(getDriver()).sendKeys(Keys.TAB).perform(); - assertTrue("Footer cell 0, 2 does not have focus", - grid.getFooterCell(0, 2).isFocused()); - new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) - .keyUp(Keys.SHIFT).perform(); - assertTrue("Body cell 10, 2 does not have focus", - grid.getCell(10, 2).isFocused()); - - // Navigate out of the Grid and try to navigate with arrow keys. - new Actions(getDriver()).sendKeys(Keys.TAB).sendKeys(Keys.TAB) - .sendKeys(Keys.ARROW_UP).perform(); - assertTrue("Footer cell 0, 2 does not have focus", - grid.getFooterCell(0, 2).isFocused()); - } - - @Test - public void testHomeEnd() throws Exception { - openTestURL(); - - getGridElement().getCell(100, 2).click(); - - new Actions(getDriver()).sendKeys(Keys.HOME).perform(); - assertTrue("First row is not visible", - getGridElement().getCell(0, 2).isDisplayed()); - - new Actions(getDriver()).sendKeys(Keys.END).perform(); - assertTrue("Last row cell not visible", getGridElement() - .getCell(GridBasicFeatures.ROWS - 1, 2).isDisplayed()); - } - - @Test - public void testPageUpPageDown() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Size", "HeightMode Row"); - - getGridElement().getCell(9, 2).click(); - new Actions(getDriver()).sendKeys(Keys.PAGE_DOWN).perform(); - assertTrue("Row 17 did not become visible", - isElementPresent(By.xpath("//td[text() = '(17, 2)']"))); - - new Actions(getDriver()).sendKeys(Keys.PAGE_DOWN).perform(); - assertTrue("Row 25 did not become visible", - isElementPresent(By.xpath("//td[text() = '(25, 2)']"))); - checkFocusedCell(29, 2, 4); - - getGridElement().getCell(41, 2).click(); - new Actions(getDriver()).sendKeys(Keys.PAGE_UP).perform(); - assertTrue("Row 33 did not become visible", - isElementPresent(By.xpath("//td[text() = '(33, 2)']"))); - - new Actions(getDriver()).sendKeys(Keys.PAGE_UP).perform(); - assertTrue("Row 25 did not become visible", - isElementPresent(By.xpath("//td[text() = '(25, 2)']"))); - checkFocusedCell(21, 2, 4); - } - - private void checkFocusedCell(int row, int column, int rowTolerance) { - WebElement focusedCell = getGridElement() - .findElement(By.className("v-grid-cell-focused")); - String cellContents = focusedCell.getText(); - String[] rowAndCol = cellContents.replaceAll("[()\\s]", "").split(","); - int focusedRow = Integer.parseInt(rowAndCol[0].trim()); - int focusedColumn = Integer.parseInt(rowAndCol[1].trim()); - // rowTolerance is the maximal allowed difference from the expected - // focused row. It is required because scrolling using page up/down - // may not move the position by exactly the visible height of the grid. - assertTrue( - "The wrong cell is focused. Expected (" + row + "," + column - + "), was " + cellContents, - column == focusedColumn - && Math.abs(row - focusedRow) <= rowTolerance); - } -} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridMultiSortingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridMultiSortingTest.java deleted file mode 100644 index 5984a21383..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridMultiSortingTest.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.tests.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridMultiSortingTest extends GridBasicFeaturesTest { - - @Override - public List getBrowsersToTest() { - return super.getBrowsersSupportingShiftClick(); - } - - @Test - public void testUserMultiColumnSorting() { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 11", "Column 11 Width", - "Auto"); - - GridCellElement cell = getGridElement().getHeaderCell(0, 11); - new Actions(driver).moveToElement(cell, 20, 10).click().perform(); - new Actions(driver).keyDown(Keys.SHIFT).perform(); - new Actions(driver) - .moveToElement(getGridElement().getHeaderCell(0, 0), 20, 10) - .click().perform(); - new Actions(driver).keyUp(Keys.SHIFT).perform(); - - String prev = getGridElement().getCell(0, 11).getAttribute("innerHTML"); - for (int i = 1; i <= 6; ++i) { - assertEquals("Column 11 should contain same values.", prev, - getGridElement().getCell(i, 11).getAttribute("innerHTML")); - } - - prev = getGridElement().getCell(0, 0).getText(); - for (int i = 1; i <= 6; ++i) { - assertTrue("Grid is not sorted by column 0.", prev - .compareTo(getGridElement().getCell(i, 0).getText()) < 0); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridRowAddRemoveTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridRowAddRemoveTest.java deleted file mode 100644 index 0327745c02..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridRowAddRemoveTest.java +++ /dev/null @@ -1,51 +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.components.grid.basicfeatures.server; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridRowAddRemoveTest extends GridBasicFeaturesTest { - - @Test - public void addRows_loadAllAtOnce() { - setDebug(true); - openTestURL(); - - selectMenuPath("Settings", "Clear log"); - selectMenuPath("Component", "Body rows", "Remove all rows"); - selectMenuPath("Component", "Body rows", "Add 18 rows"); - - Assert.assertTrue( - "All added rows should be fetched in the same round trip.", - logContainsText("Requested items 0 - 18")); - } - - @Test - public void testAdd18Rows() { - setDebug(true); - openTestURL(); - - selectMenuPath("Settings", "Clear log"); - selectMenuPath("Component", "Body rows", "Add 18 rows"); - - Assert.assertFalse("An error notification is present.", - isElementPresent(NotificationElement.class)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java deleted file mode 100644 index 6f4fea5eeb..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridScrollTest.java +++ /dev/null @@ -1,57 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridScrollTest extends GridBasicFeaturesTest { - - @Test - public void testCorrectItemRequestsOnScroll() { - openTestURL(); - - assertTrue("Initial push from server not found", - getLogRow(1).equals("0. Requested items 0 - 40")); - // Client response varies a bit between browsers as different amount of - // rows is cached. - assertTrue("First row request from client not found", - getLogRow(0).startsWith("1. Requested items 0 - ")); - - selectMenuPath("Component", "Size", "HeightMode Row"); - - selectMenuPath("Settings", "Clear log"); - $(GridElement.class).first().scrollToRow(40); - assertEquals("Log row did not contain expected item request", - "0. Requested items 0 - 86", getLogRow(0)); - assertEquals("There should be only one log row", " ", getLogRow(1)); - selectMenuPath("Settings", "Clear log"); - $(GridElement.class).first().scrollToRow(100); - assertEquals("Log row did not contain expected item request", - "0. Requested items 47 - 146", getLogRow(0)); - assertEquals("There should be only one log row", " ", getLogRow(1)); - selectMenuPath("Settings", "Clear log"); - $(GridElement.class).first().scrollToRow(300); - assertEquals("Log row did not contain expected item request", - "0. Requested items 247 - 346", getLogRow(0)); - assertEquals("There should be only one log row", " ", getLogRow(1)); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java deleted file mode 100644 index fdf36e9e9e..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java +++ /dev/null @@ -1,429 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.support.ui.ExpectedCondition; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridSelectionTest extends GridBasicFeaturesTest { - - @Test - public void testSelectOnOff() throws Exception { - openTestURL(); - - setSelectionModelMulti(); - - assertFalse("row shouldn't start out as selected", - getRow(0).isSelected()); - toggleFirstRowSelection(); - assertTrue("row should become selected", getRow(0).isSelected()); - toggleFirstRowSelection(); - assertFalse("row shouldn't remain selected", getRow(0).isSelected()); - } - - @Test - public void testSelectOnScrollOffScroll() throws Exception { - openTestURL(); - - setSelectionModelMulti(); - - assertFalse("row shouldn't start out as selected", - getRow(0).isSelected()); - toggleFirstRowSelection(); - assertTrue("row should become selected", getRow(0).isSelected()); - - scrollGridVerticallyTo(10000); // make sure the row is out of cache - scrollGridVerticallyTo(0); // scroll it back into view - - assertTrue("row should still be selected when scrolling " - + "back into view", getRow(0).isSelected()); - } - - @Test - public void testSelectScrollOnScrollOff() throws Exception { - openTestURL(); - - setSelectionModelMulti(); - - assertFalse("row shouldn't start out as selected", - getRow(0).isSelected()); - - scrollGridVerticallyTo(10000); // make sure the row is out of cache - toggleFirstRowSelection(); - - scrollGridVerticallyTo(0); // scroll it back into view - assertTrue("row should still be selected when scrolling " - + "back into view", getRow(0).isSelected()); - - toggleFirstRowSelection(); - assertFalse("row shouldn't remain selected", getRow(0).isSelected()); - } - - @Test - public void testSelectScrollOnOffScroll() throws Exception { - openTestURL(); - - setSelectionModelMulti(); - - assertFalse("row shouldn't start out as selected", - getRow(0).isSelected()); - - scrollGridVerticallyTo(10000); // make sure the row is out of cache - toggleFirstRowSelection(); - toggleFirstRowSelection(); - - scrollGridVerticallyTo(0); // make sure the row is out of cache - assertFalse( - "row shouldn't be selected when scrolling " + "back into view", - getRow(0).isSelected()); - } - - @Test - public void testSingleSelectionUpdatesFromServer() { - openTestURL(); - setSelectionModelSingle(); - - GridElement grid = getGridElement(); - assertFalse("First row was selected from start", - grid.getRow(0).isSelected()); - toggleFirstRowSelection(); - assertTrue("First row was not selected.", getRow(0).isSelected()); - assertTrue("Selection event was not correct", - logContainsText("Added 0, Removed none")); - grid.getCell(5, 0).click(); - assertTrue("Fifth row was not selected.", getRow(5).isSelected()); - assertFalse("First row was still selected.", getRow(0).isSelected()); - assertTrue("Selection event was not correct", - logContainsText("Added 5, Removed 0")); - grid.getCell(0, 6).click(); - assertTrue("Selection event was not correct", - logContainsText("Added 0, Removed 5")); - toggleFirstRowSelection(); - assertTrue("Selection event was not correct", - logContainsText("Added none, Removed 0")); - assertFalse("First row was still selected.", getRow(0).isSelected()); - assertFalse("Fifth row was still selected.", getRow(5).isSelected()); - - grid.scrollToRow(600); - grid.getCell(595, 3).click(); - assertTrue("Row 595 was not selected.", getRow(595).isSelected()); - assertTrue("Selection event was not correct", - logContainsText("Added 595, Removed none")); - toggleFirstRowSelection(); - assertFalse("Row 595 was still selected.", getRow(595).isSelected()); - assertTrue("First row was not selected.", getRow(0).isSelected()); - assertTrue("Selection event was not correct", - logContainsText("Added 0, Removed 595")); - } - - @Test - public void testKeyboardSelection() { - openTestURL(); - setSelectionModelMulti(); - - GridElement grid = getGridElement(); - grid.getCell(3, 1).click(); - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Grid row 3 was not selected with space key.", - grid.getRow(3).isSelected()); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Grid row 3 was not deselected with space key.", - !grid.getRow(3).isSelected()); - - grid.scrollToRow(500); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Grid row 3 was not selected with space key.", - grid.getRow(3).isSelected()); - } - - @Test - public void testKeyboardWithSingleSelection() { - openTestURL(); - setSelectionModelSingle(); - - GridElement grid = getGridElement(); - grid.getCell(3, 1).click(); - - assertTrue("Grid row 3 was not selected with clicking.", - grid.getRow(3).isSelected()); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Grid row 3 was not deselected with space key.", - !grid.getRow(3).isSelected()); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Grid row 3 was not selected with space key.", - grid.getRow(3).isSelected()); - - grid.scrollToRow(500); - - new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); - - assertTrue("Grid row 3 was not deselected with space key.", - !grid.getRow(3).isSelected()); - } - - @Test - public void testSelectAllCheckbox() { - openTestURL(); - - setSelectionModelMulti(); - GridCellElement header = getGridElement().getHeaderCell(0, 0); - - assertTrue("No checkbox", header.isElementPresent(By.tagName("input"))); - header.findElement(By.tagName("input")).click(); - - for (int i = 0; i < GridBasicFeatures.ROWS; i += 100) { - assertTrue("Row " + i + " was not selected.", - getGridElement().getRow(i).isSelected()); - } - - header.findElement(By.tagName("input")).click(); - assertFalse("Row 100 was still selected", - getGridElement().getRow(100).isSelected()); - } - - @Test - public void testSelectAllAndSort() { - openTestURL(); - - setSelectionModelMulti(); - GridCellElement header = getGridElement().getHeaderCell(0, 0); - - header.findElement(By.tagName("input")).click(); - - getGridElement().getHeaderCell(0, 1).click(); - - WebElement selectionBox = getGridElement().getCell(4, 0) - .findElement(By.tagName("input")); - selectionBox.click(); - selectionBox.click(); - - assertFalse("Exception occured on row reselection.", logContainsText( - "Exception occured, java.lang.IllegalStateException: No item id for key 101 found.")); - } - - @Test - public void testSelectAllCheckboxWhenChangingModels() { - openTestURL(); - - GridCellElement header; - header = getGridElement().getHeaderCell(0, 0); - assertFalse( - "Check box shouldn't have been in header for None Selection Model", - header.isElementPresent(By.tagName("input"))); - - setSelectionModelMulti(); - header = getGridElement().getHeaderCell(0, 0); - assertTrue("Multi Selection Model should have select all checkbox", - header.isElementPresent(By.tagName("input"))); - - setSelectionModelSingle(); - header = getGridElement().getHeaderCell(0, 0); - assertFalse( - "Check box shouldn't have been in header for Single Selection Model", - header.isElementPresent(By.tagName("input"))); - - // Single selection model shouldn't have selection column to begin with - assertFalse( - "Selection columnn shouldn't have been in grid for Single Selection Model", - getGridElement().getCell(0, 1) - .isElementPresent(By.tagName("input"))); - - setSelectionModelNone(); - header = getGridElement().getHeaderCell(0, 0); - assertFalse( - "Check box shouldn't have been in header for None Selection Model", - header.isElementPresent(By.tagName("input"))); - - } - - @Test - public void testSelectAllCheckboxWithHeaderOperations() { - openTestURL(); - - setSelectionModelMulti(); - selectMenuPath("Component", "Header", "Prepend row"); - selectMenuPath("Component", "Header", "Append row"); - - GridCellElement header = getGridElement().getHeaderCell(1, 0); - assertTrue("Multi Selection Model should have select all checkbox", - header.isElementPresent(By.tagName("input"))); - - } - - @Test - public void testToggleDeselectAllowed() { - openTestURL(); - - setSelectionModelSingle(); - // Deselect allowed already enabled - - getGridElement().getCell(5, 1).click(); - getGridElement().getCell(5, 1).click(); - assertFalse("Row should be not selected after two clicks", - getRow(5).isSelected()); - - selectMenuPath("Component", "State", "Single select allow deselect"); - getGridElement().getCell(5, 1).click(); - getGridElement().getCell(5, 1).click(); - assertTrue("Row should be selected after two clicks", - getRow(5).isSelected()); - - selectMenuPath("Component", "State", "Single select allow deselect"); - getGridElement().getCell(5, 1).click(); - assertFalse("Row should be not selected after another click", - getRow(5).isSelected()); - - // Also verify that state is updated together with the model - setSelectionModelNone(); - selectMenuPath("Component", "State", "Single select allow deselect"); - setSelectionModelSingle(); - - getGridElement().getCell(5, 1).click(); - getGridElement().getCell(5, 1).click(); - - assertTrue("Row should stay selected after two clicks", - getRow(5).isSelected()); - } - - @Test - public void testChangeSelectionModelUpdatesUI() { - openTestURL(); - - setSelectionModelSingle(); - - getGridElement().getCell(5, 1).click(); - assertTrue("Row should be selected after clicking", - getRow(5).isSelected()); - - setSelectionModelNone(); - assertFalse("Row should not be selected after changing selection model", - getRow(5).isSelected()); - } - - @Test - public void testSelectionCheckBoxesHaveStyleNames() { - openTestURL(); - - setSelectionModelMulti(); - - assertTrue( - "Selection column CheckBox should have the proper style name set", - getGridElement().getCell(0, 0).findElement(By.tagName("span")) - .getAttribute("class") - .contains("v-grid-selection-checkbox")); - - GridCellElement header = getGridElement().getHeaderCell(0, 0); - assertTrue("Select all CheckBox should have the proper style name set", - header.findElement(By.tagName("span")).getAttribute("class") - .contains("v-grid-select-all-checkbox")); - } - - @Test - public void testServerSideSelectTogglesSelectAllCheckBox() { - openTestURL(); - - setSelectionModelMulti(); - GridCellElement header = getGridElement().getHeaderCell(0, 0); - - WebElement selectAll = header.findElement(By.tagName("input")); - - selectMenuPath("Component", "State", "Select all"); - waitUntilCheckBoxValue(selectAll, true); - assertTrue("Select all CheckBox wasn't selected as expected", - selectAll.isSelected()); - - selectMenuPath("Component", "State", "Select none"); - waitUntilCheckBoxValue(selectAll, false); - assertFalse("Select all CheckBox was selected unexpectedly", - selectAll.isSelected()); - - selectMenuPath("Component", "State", "Select all"); - waitUntilCheckBoxValue(selectAll, true); - getGridElement().getCell(5, 0).click(); - waitUntilCheckBoxValue(selectAll, false); - assertFalse("Select all CheckBox was selected unexpectedly", - selectAll.isSelected()); - } - - @Test - public void testRemoveSelectedRow() { - openTestURL(); - - setSelectionModelSingle(); - getGridElement().getCell(0, 0).click(); - - selectMenuPath("Component", "Body rows", "Remove selected rows"); - - assertFalse( - "Unexpected NullPointerException when removing selected rows", - logContainsText( - "Exception occured, java.lang.NullPointerException: null")); - } - - private void waitUntilCheckBoxValue(final WebElement checkBoxElememnt, - final boolean expectedValue) { - waitUntil(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver input) { - return expectedValue ? checkBoxElememnt.isSelected() - : !checkBoxElememnt.isSelected(); - } - }, 5); - } - - private void setSelectionModelMulti() { - selectMenuPath("Component", "State", "Selection mode", "multi"); - } - - private void setSelectionModelSingle() { - selectMenuPath("Component", "State", "Selection mode", "single"); - } - - private void setSelectionModelNone() { - selectMenuPath("Component", "State", "Selection mode", "none"); - } - - private void toggleFirstRowSelection() { - selectMenuPath("Component", "Body rows", "Select first row"); - } - - private GridRowElement getRow(int i) { - return getGridElement().getRow(i); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java deleted file mode 100644 index 44e3d0c4d3..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java +++ /dev/null @@ -1,84 +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.components.grid.basicfeatures.server; - -import java.io.IOException; -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.remote.DesiredCapabilities; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.tests.components.grid.basicfeatures.GridSidebarFeatures; - -public class GridSidebarThemeTest extends GridBasicFeaturesTest { - - @Test - public void testValo() throws Exception { - runTestSequence("valo"); - } - - @Test - public void testValoDark() throws Exception { - runTestSequence("tests-valo-dark"); - } - - @Override - protected Class getUIClass() { - return GridSidebarFeatures.class; - } - - private void runTestSequence(String theme) throws IOException { - openTestURL("theme=" + theme); - - compareScreen(theme + "-SidebarClosed"); - getSidebarOpenButton().click(); - - compareScreen(theme + "-SidebarOpen"); - - new Actions(getDriver()).moveToElement(getColumnHidingToggle(2), 5, 5) - .perform(); - - compareScreen(theme + "-OnMouseOverNotHiddenToggle"); - - getColumnHidingToggle(2).click(); - getColumnHidingToggle(3).click(); - getColumnHidingToggle(6).click(); - - new Actions(getDriver()).moveToElement(getSidebarOpenButton()) - .perform(); - ; - - compareScreen(theme + "-TogglesTriggered"); - - new Actions(getDriver()).moveToElement(getColumnHidingToggle(2)) - .perform(); - ; - - compareScreen(theme + "-OnMouseOverHiddenToggle"); - - getSidebarOpenButton().click(); - - compareScreen(theme + "-SidebarClosed2"); - } - - @Override - public List getBrowsersToTest() { - // phantom JS looks wrong from the beginning, so not tested - return getBrowsersExcludingPhantomJS(); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java deleted file mode 100644 index bcfaab2be7..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridSortingTest.java +++ /dev/null @@ -1,408 +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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.Keys; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.testbench.By; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridSortingTest extends GridBasicFeaturesTest { - - private static class SortInfo { - public final int sortOrder; - public final SortDirection sortDirection; - - private SortInfo(int sortOrder, SortDirection sortDirection) { - this.sortOrder = sortOrder; - this.sortDirection = sortDirection; - } - } - - private static class SortInfoWithColumn extends SortInfo { - public final int columnIndex; - - private SortInfoWithColumn(int columnIndex, int sortOrder, - SortDirection sortDirection) { - super(sortOrder, sortDirection); - this.columnIndex = columnIndex; - } - } - - private static SortInfo _(int sortOrder, SortDirection sortDirection) { - return new SortInfo(sortOrder, sortDirection); - } - - private static SortInfoWithColumn _(int columnIndex, int sortOrder, - SortDirection sortDirection) { - return new SortInfoWithColumn(columnIndex, sortOrder, sortDirection); - } - - @Test - public void testProgrammaticSorting() throws Exception { - openTestURL(); - - // Sorting by column 9 is sorting by row index that is represented as a - // String. - // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) - sortBy("Column 9, DESC"); - assertLastSortIsUserOriginated(false); - - // Verify that programmatic sorting calls are identified as originating - // from API - assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); - - String row = ""; - for (int i = 0; i < 3; ++i) { - row += "9"; - String expected = "(" + row + ", 0)"; - String cellValue = getGridElement().getCell(i, 0).getText(); - assertEquals( - "Grid is not sorted by Column 9 " - + "using descending direction.", - expected, cellValue); - } - - // Column 10 is random numbers from Random with seed 13334 - sortBy("Column 10, ASC"); - - assertFalse("Column 9 should no longer have the sort-desc stylename", - getGridElement().getHeaderCell(0, 9).getAttribute("class") - .contains("sort-desc")); - - assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); - - for (int i = 0; i < 5; ++i) { - Integer firstRow = Integer - .valueOf(getGridElement().getCell(i + 1, 10).getText()); - Integer secondRow = Integer - .valueOf(getGridElement().getCell(i, 10).getText()); - assertGreater("Grid is not sorted by Column 10 using" - + " ascending direction", firstRow, secondRow); - - } - - // Column 7 is row index as a number. Last three row are original rows - // 2, 1 and 0. - sortBy("Column 7, DESC"); - for (int i = 0; i < 3; ++i) { - String expected = "(" + i + ", 0)"; - String cellContent = getGridElement() - .getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText(); - assertEquals("Grid is not sorted by Column 7 using " - + "descending direction", expected, cellContent); - } - - assertFalse("Column 10 should no longer have the sort-asc stylename", - getGridElement().getHeaderCell(0, 10).getAttribute("class") - .contains("sort-asc")); - - assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); - } - - @Test - public void testMouseSorting() throws Exception { - setDebug(true); - openTestURL(); - - GridElement grid = getGridElement(); - - selectMenuPath("Component", "Columns", "Column 9", "Column 9 Width", - "Auto"); - - // Sorting by column 9 is sorting by row index that is represented as a - // String. - - // Click header twice to sort descending - clickHeader(grid.getHeaderCell(0, 9)); - - assertLastSortIsUserOriginated(true); - - assertColumnsAreSortedAs(_(9, 1, SortDirection.ASCENDING)); - clickHeader(grid.getHeaderCell(0, 9)); - assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); - - // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) - String row = ""; - for (int i = 0; i < 3; ++i) { - row += "9"; - String expected = "(" + row + ", 0)"; - String actual = grid.getCell(i, 0).getText(); - assertEquals("Grid is not sorted by Column 9" - + " using descending direction.", expected, actual); - } - - selectMenuPath("Component", "Columns", "Column 10", "Column 10 Width", - "Auto"); - // Column 10 is random numbers from Random with seed 13334 - // Click header to sort ascending - clickHeader(grid.getHeaderCell(0, 10)); - assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); - - for (int i = 0; i < 5; ++i) { - Integer firstRow = Integer - .valueOf(grid.getCell(i + 1, 10).getText()); - Integer secondRow = Integer.valueOf(grid.getCell(i, 10).getText()); - assertGreater( - "Grid is not sorted by Column 10 using ascending direction", - firstRow, secondRow); - - } - - selectMenuPath("Component", "Columns", "Column 7", "Column 7 Width", - "Auto"); - // Column 7 is row index as a number. Last three row are original rows - // 2, 1 and 0. - // Click header twice to sort descending - clickHeader(grid.getHeaderCell(0, 7)); - assertColumnsAreSortedAs(_(7, 1, SortDirection.ASCENDING)); - clickHeader(grid.getHeaderCell(0, 7)); - assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); - - for (int i = 0; i < 3; ++i) { - assertEquals( - "Grid is not sorted by Column 7 using descending direction", - "(" + i + ", 0)", - grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0) - .getText()); - } - - } - - private void clickHeader(GridCellElement headerCell) { - new Actions(getDriver()).moveToElement(headerCell, 20, 10).click() - .perform(); - } - - private void sendKey(Keys seq) { - new Actions(getDriver()).sendKeys(seq).perform(); - } - - private void holdKey(Keys key) { - new Actions(getDriver()).keyDown(key).perform(); - } - - private void releaseKey(Keys key) { - new Actions(getDriver()).keyUp(key).perform(); - } - - @Test - public void testKeyboardSortingMultipleHeaders() { - openTestURL(); - selectMenuPath("Component", "Header", "Append row"); - - // Sort according to first column by clicking - getGridElement().getHeaderCell(0, 0).click(); - assertColumnIsSorted(0); - - // Try to sort according to second column by pressing enter on the new - // header - sendKey(Keys.ARROW_RIGHT); - sendKey(Keys.ARROW_DOWN); - sendKey(Keys.ENTER); - - // Should not have sorted - assertColumnIsSorted(0); - - // Sort using default header - sendKey(Keys.ARROW_UP); - sendKey(Keys.ENTER); - - // Should have sorted - assertColumnIsSorted(1); - - } - - @Test - public void testKeyboardSorting() { - openTestURL(); - - /* - * We can't click on the header directly, since it will sort the header - * immediately. We need to focus some other column first, and only then - * navigate there. - */ - getGridElement().getCell(0, 0).click(); - sendKey(Keys.ARROW_UP); - - // Sort ASCENDING on first column - sendKey(Keys.ENTER); - assertLastSortIsUserOriginated(true); - assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING)); - - // Move to next column - sendKey(Keys.RIGHT); - - // Add this column to the existing sorting group - holdKey(Keys.SHIFT); - sendKey(Keys.ENTER); - releaseKey(Keys.SHIFT); - assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), - _(2, SortDirection.ASCENDING)); - - // Move to next column - sendKey(Keys.RIGHT); - - // Add a third column to the sorting group - holdKey(Keys.SHIFT); - sendKey(Keys.ENTER); - releaseKey(Keys.SHIFT); - assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), - _(2, SortDirection.ASCENDING), _(3, SortDirection.ASCENDING)); - - // Move back to the second column - sendKey(Keys.LEFT); - - // Change sort direction of the second column to DESCENDING - holdKey(Keys.SHIFT); - sendKey(Keys.ENTER); - releaseKey(Keys.SHIFT); - assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), - _(2, SortDirection.DESCENDING), _(3, SortDirection.ASCENDING)); - - // Move back to the third column - sendKey(Keys.RIGHT); - - // Set sorting to third column, ASCENDING - sendKey(Keys.ENTER); - assertColumnsAreSortedAs(_(2, 1, SortDirection.ASCENDING)); - - // Move to the fourth column - sendKey(Keys.RIGHT); - - // Make sure that single-column sorting also works as expected - sendKey(Keys.ENTER); - assertColumnsAreSortedAs(_(3, 1, SortDirection.ASCENDING)); - - } - - private void assertColumnsAreSortedAs(SortInfoWithColumn... sortInfos) { - for (SortInfoWithColumn sortInfo : sortInfos) { - assertSort(sortInfo, sortInfo.columnIndex, - onlyOneColumnIsSorted(sortInfos)); - } - } - - /** - * @param sortDirections - * null if not interested in that index, otherwise a - * direction that the column needs to be sorted as - */ - private void assertColumnsAreSortedAs(SortInfo... sortInfos) { - for (int column = 0; column < sortInfos.length; column++) { - SortInfo sortInfo = sortInfos[column]; - assertSort(sortInfo, column, onlyOneColumnIsSorted(sortInfos)); - } - } - - private void assertSort(SortInfo sortInfo, int column, - boolean onlyOneColumnIsSorted) { - if (sortInfo == null) { - return; - } - - GridCellElement headerCell = getGridElement().getHeaderCell(0, column); - String classValue = headerCell.getAttribute("class"); - - boolean isSortedAscending = sortInfo.sortDirection == SortDirection.ASCENDING - && classValue.contains("sort-asc"); - boolean isSortedDescending = sortInfo.sortDirection == SortDirection.DESCENDING - && classValue.contains("sort-desc"); - - if (isSortedAscending || isSortedDescending) { - String sortOrderAttribute = headerCell.getAttribute("sort-order"); - - if (sortOrderAttribute == null) { - if (!(sortInfo.sortOrder == 1 && onlyOneColumnIsSorted)) { - fail("missing sort-order element attribute from column " - + column); - } - } else { - assertEquals("sort order was not as expected", - String.valueOf(sortInfo.sortOrder), sortOrderAttribute); - } - } else { - fail("column index " + column + " was not sorted as " - + sortInfo.sortDirection + " (class: " + classValue + ")"); - } - } - - private static boolean onlyOneColumnIsSorted(SortInfo[] sortInfos) { - - boolean foundSortedColumn = false; - for (SortInfo sortInfo : sortInfos) { - if (sortInfo == null) { - continue; - } - - if (!foundSortedColumn) { - foundSortedColumn = true; - } else { - // two columns were sorted - return false; - } - } - return foundSortedColumn; - } - - private void sortBy(String column) { - selectMenuPath("Component", "State", "Sort by column", column); - } - - private void assertLastSortIsUserOriginated(boolean isUserOriginated) { - // Find a message in the log - List userOriginatedMessages = getDriver().findElements(By - .xpath("//div[@id='Log']//*[contains(text(),'SortEvent: isUserOriginated')]")); - - Collections.sort(userOriginatedMessages, new Comparator() { - @Override - public int compare(WebElement o1, WebElement o2) { - return o1.getText().compareTo(o2.getText()); - } - }); - - String newestEntry = userOriginatedMessages - .get(userOriginatedMessages.size() - 1).getText(); - - String[] parts = newestEntry.split(" "); - boolean wasUserOriginated = Boolean - .parseBoolean(parts[parts.length - 1]); - if (isUserOriginated) { - assertTrue("expected the sort to be user originated, but wasn't", - wasUserOriginated); - } else { - assertFalse( - "expected the sort not to be user originated, but it was", - wasUserOriginated); - } - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridStaticSectionComponentTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridStaticSectionComponentTest.java deleted file mode 100644 index 03fe26069d..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridStaticSectionComponentTest.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.components.grid.basicfeatures.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridStaticSectionComponentTest extends GridBasicFeaturesTest { - - @Test - public void testNativeButtonInHeader() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Columns", "Column 1", "Header Type", - "Widget Header"); - - getGridElement().$(ButtonElement.class).first().click(); - - assertTrue("Button click should be logged", - logContainsText("Button clicked!")); - } - - @Test - public void testNativeButtonInFooter() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Footer", "Visible"); - selectMenuPath("Component", "Footer", "Append row"); - selectMenuPath("Component", "Columns", "Column 1", "Footer Type", - "Widget Footer"); - - getGridElement().$(ButtonElement.class).first().click(); - - assertTrue("Button click should be logged", - logContainsText("Button clicked!")); - } - - @Test - public void testRemoveComponentFromHeader() throws Exception { - openTestURL(); - selectMenuPath("Component", "Columns", "Column 1", "Header Type", - "Widget Header"); - selectMenuPath("Component", "Columns", "Column 1", "Header Type", - "Text Header"); - assertTrue("No notifications should've been shown", - !$(NotificationElement.class).exists()); - assertEquals("Header should've been reverted back to text header", - "text header", - getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); - } - -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java deleted file mode 100644 index 2c018bccb2..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java +++ /dev/null @@ -1,517 +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.components.grid.basicfeatures.server; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.junit.Test; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.TestBenchElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class GridStructureTest extends GridBasicFeaturesTest { - - @Test - public void testRemovingAllColumns() { - setDebug(true); - openTestURL(); - for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { - selectMenuPath("Component", "Columns", "Column " + i, - "Add / Remove"); - assertFalse(isElementPresent(NotificationElement.class)); - } - - assertEquals("Headers still visible.", 0, - getGridHeaderRowCells().size()); - } - - @Test - public void testRemoveAndAddColumn() { - setDebug(true); - openTestURL(); - - assertEquals("column 0", - getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); - selectMenuPath("Component", "Columns", "Column 0", "Add / Remove"); - assertEquals("column 1", - getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); - selectMenuPath("Component", "Columns", "Column 0", "Add / Remove"); - - // Column 0 is now the last column in Grid. - assertEquals("Unexpected column content", "(0, 0)", - getGridElement().getCell(0, 11).getText()); - } - - @Test - public void testRemovingColumn() throws Exception { - openTestURL(); - - // Column 0 should be visible - List cells = getGridHeaderRowCells(); - assertEquals("column 0", cells.get(0).getText().toLowerCase()); - - // Hide column 0 - selectMenuPath("Component", "Columns", "Column 0", "Add / Remove"); - - // Column 1 should now be the first cell - cells = getGridHeaderRowCells(); - assertEquals("column 1", cells.get(0).getText().toLowerCase()); - } - - @Test - public void testDataLoadingAfterRowRemoval() throws Exception { - openTestURL(); - - // Remove columns 2,3,4 - selectMenuPath("Component", "Columns", "Column 2", "Add / Remove"); - selectMenuPath("Component", "Columns", "Column 3", "Add / Remove"); - selectMenuPath("Component", "Columns", "Column 4", "Add / Remove"); - - // Scroll so new data is lazy loaded - scrollGridVerticallyTo(1000); - - // Let lazy loading do its job - sleep(1000); - - // Check that row is loaded - assertThat(getGridElement().getCell(11, 0).getText(), not("...")); - } - - @Test - public void testFreezingColumn() throws Exception { - openTestURL(); - - // Freeze column 1 - selectMenuPath("Component", "State", "Frozen column count", "1"); - - WebElement cell = getGridElement().getCell(0, 0); - assertTrue(cell.getAttribute("class").contains("frozen")); - - cell = getGridElement().getCell(0, 1); - assertFalse(cell.getAttribute("class").contains("frozen")); - } - - @Test - public void testInitialColumnWidths() throws Exception { - openTestURL(); - - WebElement cell = getGridElement().getCell(0, 0); - assertEquals(100, cell.getSize().getWidth()); - - cell = getGridElement().getCell(0, 1); - assertEquals(150, cell.getSize().getWidth()); - - cell = getGridElement().getCell(0, 2); - assertEquals(200, cell.getSize().getWidth()); - } - - @Test - public void testColumnWidths() throws Exception { - openTestURL(); - - // Default column width is 100px - WebElement cell = getGridElement().getCell(0, 0); - assertEquals(100, cell.getSize().getWidth()); - - // Set first column to be 200px wide - selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width", - "200px"); - - cell = getGridElement().getCell(0, 0); - assertEquals(200, cell.getSize().getWidth()); - - // Set second column to be 150px wide - selectMenuPath("Component", "Columns", "Column 1", "Column 1 Width", - "150px"); - cell = getGridElement().getCell(0, 1); - assertEquals(150, cell.getSize().getWidth()); - - selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width", - "Auto"); - - // since the column 0 was previously 200, it should've shrunk when - // autoresizing. - cell = getGridElement().getCell(0, 0); - assertLessThan("", cell.getSize().getWidth(), 200); - } - - @Test - public void testPrimaryStyleNames() throws Exception { - openTestURL(); - - // v-grid is default primary style namea - assertPrimaryStylename("v-grid"); - - selectMenuPath("Component", "State", "Primary style name", - "v-escalator"); - assertPrimaryStylename("v-escalator"); - - selectMenuPath("Component", "State", "Primary style name", "my-grid"); - assertPrimaryStylename("my-grid"); - - selectMenuPath("Component", "State", "Primary style name", "v-grid"); - assertPrimaryStylename("v-grid"); - } - - /** - * Test that the current view is updated when a server-side container change - * occurs (without scrolling back and forth) - */ - @Test - public void testItemSetChangeEvent() throws Exception { - openTestURL(); - - final org.openqa.selenium.By newRow = By - .xpath("//td[text()='newcell: 0']"); - - assertTrue("Unexpected initial state", !isElementPresent(newRow)); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue("Add row failed", isElementPresent(newRow)); - - selectMenuPath("Component", "Body rows", "Remove first row"); - assertTrue("Remove row failed", !isElementPresent(newRow)); - } - - /** - * Test that the current view is updated when a property's value is reflect - * to the client, when the value is modified server-side. - */ - @Test - public void testPropertyValueChangeEvent() throws Exception { - openTestURL(); - - assertEquals("Unexpected cell initial state", "(0, 0)", - getGridElement().getCell(0, 0).getText()); - - selectMenuPath("Component", "Body rows", - "Modify first row (getItemProperty)"); - assertEquals("(First) modification with getItemProperty failed", - "modified: 0", getGridElement().getCell(0, 0).getText()); - - selectMenuPath("Component", "Body rows", - "Modify first row (getContainerProperty)"); - assertEquals("(Second) modification with getItemProperty failed", - "modified: Column 0", getGridElement().getCell(0, 0).getText()); - } - - @Test - public void testRemovingAllItems() throws Exception { - openTestURL(); - - selectMenuPath("Component", "Body rows", "Remove all rows"); - - assertEquals(0, getGridElement().findElement(By.tagName("tbody")) - .findElements(By.tagName("tr")).size()); - } - - @Test - public void testRemoveFirstRowTwice() { - openTestURL(); - - selectMenuPath("Component", "Body rows", "Remove first row"); - selectMenuPath("Component", "Body rows", "Remove first row"); - - getGridElement().scrollToRow(50); - assertFalse("Listener setup problem occurred.", - logContainsText("AssertionError: Value change listeners")); - } - - @Test - public void testVerticalScrollBarVisibilityWhenEnoughRows() - throws Exception { - openTestURL(); - - assertTrue(verticalScrollbarIsPresent()); - - selectMenuPath("Component", "Body rows", "Remove all rows"); - assertFalse(verticalScrollbarIsPresent()); - - selectMenuPath("Component", "Size", "HeightMode Row"); - selectMenuPath("Component", "Size", "Height by Rows", "2.33 rows"); - selectMenuPath("Component", "Body rows", "Add first row"); - selectMenuPath("Component", "Body rows", "Add first row"); - assertFalse(verticalScrollbarIsPresent()); - - selectMenuPath("Component", "Body rows", "Add first row"); - assertTrue(verticalScrollbarIsPresent()); - } - - @Test - public void testBareItemSetChange() throws Exception { - openTestURL(); - filterSomeAndAssert(); - } - - @Test - public void testBareItemSetChangeRemovingAllRows() throws Exception { - openTestURL(); - selectMenuPath("Component", "Filter", "Impassable filter"); - assertFalse("A notification shouldn't have been displayed", - $(NotificationElement.class).exists()); - assertTrue("No body cells should've been found", getGridElement() - .getBody().findElements(By.tagName("td")).isEmpty()); - } - - @Test - public void testBareItemSetChangeWithMidScroll() throws Exception { - openTestURL(); - getGridElement().scrollToRow(GridBasicFeatures.ROWS / 2); - filterSomeAndAssert(); - } - - @Test - public void testBareItemSetChangeWithBottomScroll() throws Exception { - openTestURL(); - getGridElement().scrollToRow(GridBasicFeatures.ROWS); - filterSomeAndAssert(); - } - - @Test - public void testBareItemSetChangeWithBottomScrollAndSmallViewport() - throws Exception { - openTestURL(); - selectMenuPath("Component", "Size", "HeightMode Row"); - getGridElement().getRow(GridBasicFeatures.ROWS - 1); - // filter - selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\""); - - String text = getGridElement().getCell(10, 0).getText(); - - assertFalse(text.isEmpty()); - } - - private void filterSomeAndAssert() { - selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\""); - boolean foundElements = false; - for (int row = 0; row < 100; row++) { - try { - GridCellElement cell = getGridElement().getCell(row, 1); - foundElements = true; - assertTrue( - "Unexpected cell contents. " - + "Did the ItemSetChange work after all?", - cell.getText().startsWith("(23")); - } catch (NoSuchElementException e) { - assertTrue("No rows were found", foundElements); - return; - } - } - fail("unexpected amount of rows post-filter. Did the ItemSetChange work after all?"); - } - - @Test - public void testRemoveLastColumn() { - setDebug(true); - openTestURL(); - - int col = GridBasicFeatures.COLUMNS; - String columnName = "Column " + (GridBasicFeatures.COLUMNS - 1); - assertTrue(columnName + " was not present in DOM", - isElementPresent(By.xpath("//th[" + col + "]/div[1]"))); - selectMenuPath("Component", "Columns", columnName, "Add / Remove"); - assertFalse(isElementPresent(NotificationElement.class)); - assertFalse(columnName + " was still present in DOM", - isElementPresent(By.xpath("//th[" + col + "]/div[1]"))); - } - - @Test - public void testReverseColumns() { - openTestURL(); - - String[] gridData = new String[GridBasicFeatures.COLUMNS]; - GridElement grid = getGridElement(); - for (int i = 0; i < gridData.length; ++i) { - gridData[i] = grid.getCell(0, i).getAttribute("innerHTML"); - } - - selectMenuPath("Component", "State", "Reverse Grid Columns"); - - // Compare with reversed order - for (int i = 0; i < gridData.length; ++i) { - final int column = gridData.length - 1 - i; - final String newText = grid.getCell(0, column) - .getAttribute("innerHTML"); - assertEquals( - "Grid contained unexpected values. (0, " + column + ")", - gridData[i], newText); - } - } - - @Test - public void testAddingProperty() { - setDebug(true); - openTestURL(); - - assertNotEquals("property value", - getGridElement().getCell(0, 0).getText()); - selectMenuPath("Component", "Properties", "Prepend property"); - assertEquals("property value", - getGridElement().getCell(0, 0).getText()); - } - - @Test - public void testRemovingAddedProperty() { - openTestURL(); - - assertEquals("(0, 0)", getGridElement().getCell(0, 0).getText()); - assertNotEquals("property value", - getGridElement().getCell(0, 0).getText()); - - selectMenuPath("Component", "Properties", "Prepend property"); - selectMenuPath("Component", "Properties", "Prepend property"); - - assertNotEquals("property value", - getGridElement().getCell(0, 0).getText()); - assertEquals("(0, 0)", getGridElement().getCell(0, 0).getText()); - } - - private boolean verticalScrollbarIsPresent() { - return "scroll" - .equals(getGridVerticalScrollbar().getCssValue("overflow-y")); - } - - @Test - public void testAddRowAboveViewport() { - setDebug(true); - openTestURL(); - - GridCellElement cell = getGridElement().getCell(500, 1); - String cellContent = cell.getText(); - selectMenuPath("Component", "Body rows", "Add first row"); - - assertFalse("Error notification was present", - isElementPresent(NotificationElement.class)); - - assertEquals("Grid scrolled unexpectedly", cellContent, cell.getText()); - } - - @Test - public void testRemoveAndAddRowAboveViewport() { - setDebug(true); - openTestURL(); - - GridCellElement cell = getGridElement().getCell(500, 1); - String cellContent = cell.getText(); - selectMenuPath("Component", "Body rows", "Remove first row"); - - assertFalse("Error notification was present after removing row", - isElementPresent(NotificationElement.class)); - - assertEquals("Grid scrolled unexpectedly", cellContent, cell.getText()); - - selectMenuPath("Component", "Body rows", "Add first row"); - - assertFalse("Error notification was present after adding row", - isElementPresent(NotificationElement.class)); - - assertEquals("Grid scrolled unexpectedly", cellContent, cell.getText()); - } - - @Test - public void testScrollAndRemoveAll() { - setDebug(true); - openTestURL(); - - getGridElement().scrollToRow(500); - selectMenuPath("Component", "Body rows", "Remove all rows"); - - assertFalse("Error notification was present after removing all rows", - isElementPresent(NotificationElement.class)); - - assertFalse( - getGridElement().isElementPresent(By.vaadin("#cell[0][0]"))); - } - - private void assertPrimaryStylename(String stylename) { - assertTrue(getGridElement().getAttribute("class").contains(stylename)); - - String tableWrapperStyleName = getGridElement().getTableWrapper() - .getAttribute("class"); - assertTrue(tableWrapperStyleName.contains(stylename + "-tablewrapper")); - - String hscrollStyleName = getGridElement().getHorizontalScroller() - .getAttribute("class"); - assertTrue(hscrollStyleName.contains(stylename + "-scroller")); - assertTrue( - hscrollStyleName.contains(stylename + "-scroller-horizontal")); - - String vscrollStyleName = getGridElement().getVerticalScroller() - .getAttribute("class"); - assertTrue(vscrollStyleName.contains(stylename + "-scroller")); - assertTrue(vscrollStyleName.contains(stylename + "-scroller-vertical")); - } - - @Test - public void testScrollPosDoesNotChangeAfterStateChange() { - openTestURL(); - scrollGridVerticallyTo(1000); - int scrollPos = getGridVerticalScrollPos(); - selectMenuPath("Component", "Editor", "Enabled"); - assertEquals("Scroll position should've not have changed", scrollPos, - getGridVerticalScrollPos()); - } - - @Test - public void testReloadPage() throws InterruptedException { - setDebug(true); - openTestURL(); - - reopenTestURL(); - - // After opening the URL Grid can be stuck in a state where it thinks it - // should wait for something that's not going to happen. - testBench().disableWaitForVaadin(); - - // Wait until page is loaded completely. - int count = 0; - while (!$(GridElement.class).exists()) { - if (count == 100) { - fail("Reloading page failed"); - } - sleep(100); - ++count; - } - - // Wait a bit more for notification to occur. - sleep(1000); - - assertFalse("Exception occurred when reloading page", - isElementPresent(NotificationElement.class)); - } - - @Test - public void testAddThirdRowToGrid() { - openTestURL(); - selectMenuPath("Component", "Body rows", "Add third row"); - assertFalse(logContainsText("Exception occured")); - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java deleted file mode 100644 index 488a9d61d9..0000000000 --- a/uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java +++ /dev/null @@ -1,85 +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.components.grid.basicfeatures.server; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -import com.vaadin.v7.testbench.customelements.GridElement; - -public class LoadingIndicatorTest extends GridBasicFeaturesTest { - @Test - public void testLoadingIndicator() throws InterruptedException { - setDebug(true); - openTestURL(); - - selectMenuPath("Component", "State", "Container delay", "2000"); - - GridElement gridElement = $(GridElement.class).first(); - - Assert.assertFalse( - "Loading indicator should not be visible before disabling waitForVaadin", - isLoadingIndicatorVisible()); - - testBench().disableWaitForVaadin(); - - // Scroll to a completely new location - gridElement.getCell(200, 1); - - // Wait for loading indicator delay - waitUntil(ExpectedConditions.visibilityOfElementLocated( - By.className("v-loading-indicator"))); - - waitUntilNot(ExpectedConditions.visibilityOfElementLocated( - By.className("v-loading-indicator"))); - - // Scroll so much that more data gets fetched, but not so much that - // missing rows are shown - gridElement.getCell(230, 1); - - // Wait for potentially triggered loading indicator to become visible - Thread.sleep(500); - - Assert.assertFalse( - "Loading indicator should not be visible when fetching rows that are not visible", - isLoadingIndicatorVisible()); - - // Finally verify that there was actually a request going on - waitUntilLogContains("Requested items"); - } - - private void waitUntilLogContains(final String value) { - waitUntil(new ExpectedCondition() { - @Override - public Boolean apply(WebDriver input) { - return getLogRow(0).contains(value); - } - - @Override - public String toString() { - // Timed out after 10 seconds waiting for ... - return "first log row to contain '" + value + "' (was: '" - + getLogRow(0) + "')"; - } - }); - } - -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/AbstractGridColumnAutoWidthTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/AbstractGridColumnAutoWidthTest.java new file mode 100644 index 0000000000..9994be2451 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/AbstractGridColumnAutoWidthTest.java @@ -0,0 +1,110 @@ +/* + * 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 java.io.IOException; + +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 { + compareScreen("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/v7/tests/components/grid/CustomRendererTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/CustomRendererTest.java new file mode 100644 index 0000000000..be3c4660b0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/CustomRendererTest.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.v7.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.CustomRenderer; + +@TestCategory("grid") +public class CustomRendererTest extends MultiBrowserTest { + @Test + public void testIntArrayIsRendered() throws Exception { + openTestURL(); + + GridElement grid = findGrid(); + assertEquals("1 :: 1 :: 2 :: 3 :: 5 :: 8 :: 13", + grid.getCell(0, 0).getText()); + } + + @Test + public void testRowAwareRenderer() throws Exception { + openTestURL(); + + GridElement grid = findGrid(); + assertEquals("Click me!", grid.getCell(0, 1).getText()); + assertEquals(CustomRenderer.INIT_DEBUG_LABEL_CAPTION, + findDebugLabel().getText()); + + grid.getCell(0, 1).click(); + assertEquals("row: 0, key: 1", grid.getCell(0, 1).getText()); + assertEquals("key: 1, itemId: " + CustomRenderer.ITEM_ID, + findDebugLabel().getText()); + } + + @Test + public void testBeanRenderer() throws Exception { + openTestURL(); + + assertEquals("SimpleTestBean(42)", findGrid().getCell(0, 2).getText()); + } + + private GridElement findGrid() { + List elements = $(GridElement.class).all(); + return elements.get(0); + } + + private LabelElement findDebugLabel() { + return $(LabelElement.class).id(CustomRenderer.DEBUG_LABEL_ID); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridAddAndRemoveDataOnInitTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridAddAndRemoveDataOnInitTest.java new file mode 100644 index 0000000000..7e0fca9043 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridAddAndRemoveDataOnInitTest.java @@ -0,0 +1,46 @@ +/* + * 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.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridAddAndRemoveDataOnInitTest extends MultiBrowserTest { + + @Test + public void verifyGridSizes() { + openTestURL(); + + GridElement gridAdd = $(GridElement.class).first(); + if (!gridAdd.isElementPresent(By.vaadin("#cell[9][0]")) + || gridAdd.isElementPresent(By.vaadin("#cell[10][0]"))) { + Assert.fail("Grid with added data contained incorrect rows"); + } + + GridElement gridRemove = $(GridElement.class).get(1); + if (!gridRemove.isElementPresent(By.vaadin("#cell[4][0]")) + || gridRemove.isElementPresent(By.vaadin("#cell[5][0]"))) { + Assert.fail("Grid with removed data contained incorrect rows"); + } + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridAddRowTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridAddRowTest.java new file mode 100644 index 0000000000..50acaf6ff7 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridAddRowTest.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.v7.tests.components.grid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridAddRowTest extends MultiBrowserTest { + @Test + public void testAddRow() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertEquals("Lorem", grid.getCell(0, 1).getText()); + Assert.assertEquals("2", grid.getCell(1, 2).getText()); + + addRow(); + + Assert.assertEquals("Dolor", grid.getCell(2, 1).getText()); + + addRow(); + + Assert.assertEquals("Dolor", grid.getCell(3, 1).getText()); + } + + private void addRow() { + $(ButtonElement.class).caption("Add new row").first().click(); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCellFocusOnResetSizeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCellFocusOnResetSizeTest.java new file mode 100644 index 0000000000..b64a78c2dc --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCellFocusOnResetSizeTest.java @@ -0,0 +1,59 @@ +/* + * 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 java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elementsbase.ServerClass; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridCellFocusOnResetSizeTest extends MultiBrowserTest { + + @ServerClass("com.vaadin.tests.widgetset.server.TestWidgetComponent") + public static class MyGridElement extends GridElement { + } + + @Test + public void testCellFocusOnSizeReset() throws IOException { + openTestURL(); + + GridElement grid = $(MyGridElement.class).first(); + int rowIndex = 9; + grid.getCell(rowIndex, 0).click(); + assertTrue("Row was not focused after click.", + grid.getRow(rowIndex).isFocused()); + + // Clicking the button decreases size until it is down to 5 rows. + while (rowIndex > 4) { + findElement(By.tagName("button")).click(); + assertTrue("Row focus was not moved when size decreased", + grid.getRow(--rowIndex).isFocused()); + } + + // Next click increases size back to 10, this should not move focus. + findElement(By.tagName("button")).click(); + assertTrue("Row focus should not have moved when size increased", + grid.getRow(4).isFocused()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCheckBoxDisplayTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCheckBoxDisplayTest.java new file mode 100644 index 0000000000..70d96f832b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCheckBoxDisplayTest.java @@ -0,0 +1,72 @@ +/* + * 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.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.CheckBoxElement; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridCheckBoxDisplayTest extends SingleBrowserTest { + @Test + public void testAddRow() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertEquals("First item had wrong value", "true", + grid.getCell(0, 0).getText()); + Assert.assertEquals("Second item had wrong value", "false", + grid.getCell(1, 0).getText()); + + // First edit false item and see that the CheckBox is unchecked + grid.getCell(1, 0).doubleClick(); + + CheckBoxElement checkbox = $(CheckBoxElement.class).first(); + Assert.assertEquals("CheckBox was checked", "unchecked", + checkbox.getValue()); + + closeEditor(); + + // Edit true item and see that the CheckBox is checked + grid.getCell(0, 0).doubleClick(); + + checkbox = $(CheckBoxElement.class).first(); + Assert.assertEquals("CheckBox was not checked.", "checked", + checkbox.getValue()); + + closeEditor(); + + // Edit false item and confirm that the CheckBox is unchecked again + grid.getCell(1, 0).doubleClick(); + + checkbox = $(CheckBoxElement.class).first(); + Assert.assertEquals("CheckBox was checked", "unchecked", + checkbox.getValue()); + } + + /** + * Closes the grids editor using the cancel button + */ + private void closeEditor() { + findElement(By.className("v-grid-editor-cancel")).click(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridClientDataChangeHandlerTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridClientDataChangeHandlerTest.java new file mode 100644 index 0000000000..1ff8de9100 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridClientDataChangeHandlerTest.java @@ -0,0 +1,40 @@ +/* + * 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 org.junit.Test; + +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridClientDataChangeHandlerTest extends SingleBrowserTest { + + @Test + public void testNoErrorsOnGridInit() throws InterruptedException { + setDebug(true); + openTestURL(); + + // Wait for delayed functionality. + sleep(1000); + + assertFalse("Unexpected exception is visible.", + $(NotificationElement.class).exists()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridClientRenderers.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridClientRenderers.java new file mode 100644 index 0000000000..980dafe355 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridClientRenderers.java @@ -0,0 +1,282 @@ +/* + * 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.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elements.NativeButtonElement; +import com.vaadin.testbench.elementsbase.ServerClass; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.widgetset.client.v7.grid.GridClientColumnRendererConnector.Renderers; +import com.vaadin.tests.widgetset.server.v7.grid.GridClientColumnRenderers; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.NativeSelectElement; + +/** + * Tests Grid client side renderers + * + * @since + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridClientRenderers extends MultiBrowserTest { + + private static final double SLEEP_MULTIPLIER = 1.2; + private int latency = 0; + + @Override + protected Class getUIClass() { + return GridClientColumnRenderers.class; + } + + @Override + protected String getDeploymentPath(Class uiClass) { + String path = super.getDeploymentPath(uiClass); + if (latency > 0) { + path += (path.contains("?") ? "&" : "?") + "latency=" + latency; + } + return path; + } + + @ServerClass("com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers.GridController") + public static class MyClientGridElement extends GridElement { + } + + @Override + public void setup() throws Exception { + latency = 0; // reset + super.setup(); + } + + @Test + public void addWidgetRenderer() throws Exception { + openTestURL(); + + // Add widget renderer column + $(NativeSelectElement.class).first() + .selectByText(Renderers.WIDGET_RENDERER.toString()); + $(NativeButtonElement.class).caption("Add").first().click(); + + // Click the button in cell 1,1 + TestBenchElement cell = getGrid().getCell(1, 2); + WebElement gwtButton = cell.findElement(By.tagName("button")); + gwtButton.click(); + + // Should be an alert visible + assertEquals("Button did not contain text \"Clicked\"", "Clicked", + gwtButton.getText()); + } + + @Test + public void detachAndAttachGrid() { + openTestURL(); + + // Add widget renderer column + $(NativeSelectElement.class).first() + .selectByText(Renderers.WIDGET_RENDERER.toString()); + $(NativeButtonElement.class).caption("Add").first().click(); + + // Detach and re-attach the Grid + $(NativeButtonElement.class).caption("DetachAttach").first().click(); + + // Click the button in cell 1,1 + TestBenchElement cell = getGrid().getCell(1, 2); + WebElement gwtButton = cell.findElement(By.tagName("button")); + gwtButton.click(); + + // Should be an alert visible + assertEquals("Button did not contain text \"Clicked\"", + gwtButton.getText(), "Clicked"); + } + + @Test + public void rowsWithDataHasStyleName() throws Exception { + + testBench().disableWaitForVaadin(); + + // Simulate network latency with 2000ms + latency = 2000; + + openTestURL(); + + sleep((int) (latency * SLEEP_MULTIPLIER)); + + TestBenchElement row = getGrid().getRow(51); + String className = row.getAttribute("class"); + assertFalse("Row should not yet contain style name v-grid-row-has-data", + className.contains("v-grid-row-has-data")); + + // Wait for data to arrive + sleep((int) (latency * SLEEP_MULTIPLIER)); + + row = getGrid().getRow(51); + className = row.getAttribute("class"); + assertTrue("Row should now contain style name v-grid-row-has-data", + className.contains("v-grid-row-has-data")); + } + + @Test + public void complexRendererSetVisibleContent() throws Exception { + + DesiredCapabilities desiredCapabilities = getDesiredCapabilities(); + + // Simulate network latency with 2000ms + latency = 2000; + + // Chrome uses RGB instead of RGBA + String colorRed = "rgba(255, 0, 0, 1)"; + String colorWhite = "rgba(255, 255, 255, 1)"; + String colorDark = "rgba(239, 240, 241, 1)"; + + openTestURL(); + + getGrid(); + + testBench().disableWaitForVaadin(); + + // Test initial renderering with contentVisible = False + TestBenchElement cell = getGrid().getCell(51, 1); + String backgroundColor = cell.getCssValue("backgroundColor"); + assertEquals("Background color was not red.", colorRed, + backgroundColor); + + // data arrives... + sleep((int) (latency * SLEEP_MULTIPLIER)); + + // Content becomes visible + cell = getGrid().getCell(51, 1); + backgroundColor = cell.getCssValue("backgroundColor"); + assertNotEquals("Background color was red.", colorRed, backgroundColor); + + // scroll down, new cells becomes contentVisible = False + getGrid().scrollToRow(60); + + // Cell should be red (setContentVisible set cell red) + cell = getGrid().getCell(55, 1); + backgroundColor = cell.getCssValue("backgroundColor"); + assertEquals("Background color was not red.", colorRed, + backgroundColor); + + // data arrives... + sleep((int) (latency * SLEEP_MULTIPLIER)); + + // Cell should no longer be red + backgroundColor = cell.getCssValue("backgroundColor"); + assertTrue("Background color was not reset", + backgroundColor.equals(colorWhite) + || backgroundColor.equals(colorDark)); + } + + @Test + public void testSortingEvent() throws Exception { + openTestURL(); + + $(NativeButtonElement.class).caption("Trigger sorting event").first() + .click(); + + String consoleText = $(LabelElement.class).id("testDebugConsole") + .getText(); + + assertTrue("Console text as expected", + consoleText.contains("Columns: 1, order: Column 1: ASCENDING")); + + } + + @Test + public void testListSorter() throws Exception { + openTestURL(); + + $(NativeButtonElement.class).caption("Shuffle").first().click(); + + GridElement gridElem = $(MyClientGridElement.class).first(); + + // XXX: DANGER! We'll need to know how many rows the Grid has! + // XXX: Currently, this is impossible; hence the hardcoded value of 70. + + boolean shuffled = false; + for (int i = 1, l = 70; i < l; ++i) { + + String str_a = gridElem.getCell(i - 1, 0).getAttribute("innerHTML"); + String str_b = gridElem.getCell(i, 0).getAttribute("innerHTML"); + + int value_a = Integer.parseInt(str_a); + int value_b = Integer.parseInt(str_b); + + if (value_a > value_b) { + shuffled = true; + break; + } + } + assertTrue("Grid shuffled", shuffled); + + $(NativeButtonElement.class).caption("Test sorting").first().click(); + + for (int i = 1, l = 70; i < l; ++i) { + + String str_a = gridElem.getCell(i - 1, 0).getAttribute("innerHTML"); + String str_b = gridElem.getCell(i, 0).getAttribute("innerHTML"); + + int value_a = Integer.parseInt(str_a); + int value_b = Integer.parseInt(str_b); + + if (value_a > value_b) { + assertTrue("Grid sorted", false); + } + } + } + + @Test + public void testComplexRendererOnActivate() { + openTestURL(); + + GridCellElement cell = getGrid().getCell(3, 1); + cell.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertEquals("onActivate was not called on KeyDown Enter.", + "Activated!", cell.getText()); + + cell = getGrid().getCell(4, 1); + cell.click(); + new Actions(getDriver()).moveToElement(cell).doubleClick().perform(); + assertEquals("onActivate was not called on double click.", "Activated!", + cell.getText()); + } + + private GridElement getGrid() { + return $(MyClientGridElement.class).first(); + } + + private void addColumn(Renderers renderer) { + // Add widget renderer column + $(NativeSelectElement.class).first().selectByText(renderer.toString()); + $(NativeButtonElement.class).caption("Add").first().click(); + } +} 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 new file mode 100644 index 0000000000..c05e7675ca --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColspansTest.java @@ -0,0 +1,101 @@ +/* + * 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.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@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 new file mode 100644 index 0000000000..a5370d5ba3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoExpandTest.java @@ -0,0 +1,39 @@ +/* + * 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.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +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 new file mode 100644 index 0000000000..38bc158065 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthClientTest.java @@ -0,0 +1,28 @@ +/* + * 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; +import com.vaadin.v7.tests.components.grid.GridColumnAutoWidthClient; + +@TestCategory("grid") +public class GridColumnAutoWidthClientTest + extends AbstractGridColumnAutoWidthTest { + @Override + protected Class getUIClass() { + return GridColumnAutoWidthClient.class; + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..8235d87696 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnAutoWidthServerTest.java @@ -0,0 +1,28 @@ +/* + * 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; +import com.vaadin.v7.tests.components.grid.GridColumnAutoWidth; + +@TestCategory("grid") +public class GridColumnAutoWidthServerTest + extends AbstractGridColumnAutoWidthTest { + @Override + protected Class getUIClass() { + return GridColumnAutoWidth.class; + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..40e57fffd9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridColumnWidthRecalculationTest.java @@ -0,0 +1,82 @@ +/* + * 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.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@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 new file mode 100644 index 0000000000..c6c9352656 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/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.v7.tests.components.grid; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.NativeSelectElement; + +@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/GridCustomSelectionModelTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCustomSelectionModelTest.java new file mode 100644 index 0000000000..76b0d40ebd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridCustomSelectionModelTest.java @@ -0,0 +1,58 @@ +/* + * 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 org.openqa.selenium.By; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridCustomSelectionModelTest extends MultiBrowserTest { + + @Test + public void testCustomSelectionModel() { + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + GridCellElement cell = grid.getCell(0, 0); + assertTrue("First column of Grid should not have an input element", + cell.findElements(By.className("input")).isEmpty()); + + assertFalse("Row should not be selected initially", + grid.getRow(0).isSelected()); + + cell.click(5, 5); + assertTrue("Click should select row", grid.getRow(0).isSelected()); + cell.click(5, 5); + assertFalse("Click should deselect row", grid.getRow(0).isSelected()); + + grid.sendKeys(Keys.SPACE); + assertTrue("Space should select row", grid.getRow(0).isSelected()); + grid.sendKeys(Keys.SPACE); + assertFalse("Space should deselect row", grid.getRow(0).isSelected()); + + assertNoErrorNotifications(); + } +} 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 new file mode 100644 index 0000000000..7c1214dc4d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/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.v7.tests.components.grid; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +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/GridDefaultSelectionModeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDefaultSelectionModeTest.java new file mode 100644 index 0000000000..4534c13192 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDefaultSelectionModeTest.java @@ -0,0 +1,84 @@ +/* + * 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.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridDefaultSelectionModeTest extends MultiBrowserTest { + + @Test + public void testSelectionFromServer() { + setDebug(true); + openTestURL(); + + $(ButtonElement.class).caption("Select on server").first().click(); + + assertTrue("Row should be selected.", + $(GridElement.class).first().getRow(0).isSelected()); + + $(ButtonElement.class).caption("Deselect on server").first().click(); + + assertFalse("Row should not be selected.", + $(GridElement.class).first().getRow(0).isSelected()); + + assertNoErrorNotifications(); + } + + @Test + public void testSelectionWithSort() { + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + grid.getCell(0, 0).click(); + + GridCellElement header = grid.getHeaderCell(0, 1); + header.click(); + header.click(); + + assertTrue("Row should be selected.", grid.getRow(1).isSelected()); + + assertNoErrorNotifications(); + } + + @Test + public void testReselectDeselectedRow() { + setDebug(true); + openTestURL(); + + $(ButtonElement.class).caption("Select on server").first().click(); + + GridElement grid = $(GridElement.class).first(); + assertTrue("Row should be selected.", grid.getRow(0).isSelected()); + + $(ButtonElement.class).caption("Deselect on server").first().click(); + + assertFalse("Row should not be selected.", grid.getRow(0).isSelected()); + + grid.getCell(0, 0).click(); + assertTrue("Row should be selected.", grid.getRow(0).isSelected()); + + assertNoErrorNotifications(); + } +} 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 new file mode 100644 index 0000000000..3047d5dd2f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/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.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.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@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 new file mode 100644 index 0000000000..a3a507fca2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/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.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.elements.LabelElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +/** + * 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/GridDetailsLocationTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsLocationTest.java new file mode 100644 index 0000000000..c2b5c3f1cb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDetailsLocationTest.java @@ -0,0 +1,319 @@ +/* + * 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.Collection; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.StaleElementReferenceException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridDetailsLocationTest extends MultiBrowserTest { + + private static final int detailsDefaultHeight = 51; + private static final int detailsDefinedHeight = 33; + + private static class Param { + private final int rowIndex; + private final boolean useGenerator; + private final boolean scrollFirstToBottom; + + public Param(int rowIndex, boolean useGenerator, + boolean scrollFirstToBottom) { + this.rowIndex = rowIndex; + this.useGenerator = useGenerator; + this.scrollFirstToBottom = scrollFirstToBottom; + } + + public int getRowIndex() { + return rowIndex; + } + + public boolean useGenerator() { + return useGenerator; + } + + public boolean scrollFirstToBottom() { + return scrollFirstToBottom; + } + + @Override + public String toString() { + return "Param [rowIndex=" + getRowIndex() + ", useGenerator=" + + useGenerator() + ", scrollFirstToBottom=" + + scrollFirstToBottom() + "]"; + } + + } + + public static Collection parameters() { + List data = new ArrayList(); + + int[] params = new int[] { 0, 500, 999 }; + + for (int rowIndex : params) { + + data.add(new Param(rowIndex, true, false)); + data.add(new Param(rowIndex, true, true)); + } + + return data; + } + + @Before + public void setUp() { + setDebug(true); + } + + @Test + public void toggleAndScroll() throws Throwable { + for (Param param : parameters()) { + try { + openTestURL(); + useGenerator(param.useGenerator()); + scrollToBottom(param.scrollFirstToBottom()); + + // the tested method + toggleAndScroll(param.getRowIndex()); + + verifyLocation(param); + } catch (Throwable t) { + throw new Throwable("" + param, t); + } + } + } + + @Test + public void scrollAndToggle() throws Throwable { + for (Param param : parameters()) { + try { + openTestURL(); + useGenerator(param.useGenerator()); + scrollToBottom(param.scrollFirstToBottom()); + + // the tested method + scrollAndToggle(param.getRowIndex()); + + verifyLocation(param); + + } catch (Throwable t) { + throw new Throwable("" + param, t); + } + } + } + + @Test + public void testDetailsHeightWithGenerator() { + openTestURL(); + useGenerator(true); + toggleAndScroll(5); + + verifyDetailsRowHeight(5, detailsDefinedHeight, 0); + verifyDetailsDecoratorLocation(5, 0, 0); + + toggleAndScroll(0); + + verifyDetailsRowHeight(0, detailsDefinedHeight, 0); + // decorator elements are in DOM in the order they have been added + verifyDetailsDecoratorLocation(0, 0, 1); + + verifyDetailsRowHeight(5, detailsDefinedHeight, 1); + verifyDetailsDecoratorLocation(5, 1, 0); + } + + private void verifyDetailsRowHeight(int rowIndex, int expectedHeight, + int visibleIndexOfSpacer) { + waitForDetailsVisible(); + WebElement details = getDetailsElement(visibleIndexOfSpacer); + Assert.assertEquals("Wrong details row height", expectedHeight, + details.getSize().getHeight()); + } + + private void verifyDetailsDecoratorLocation(int row, + int visibleIndexOfSpacer, int visibleIndexOfDeco) { + WebElement detailsElement = getDetailsElement(visibleIndexOfSpacer); + WebElement detailsDecoElement = getDetailsDecoElement( + visibleIndexOfDeco); + GridRowElement rowElement = getGrid().getRow(row); + + Assert.assertEquals( + "Details deco top position does not match row top pos", + rowElement.getLocation().getY(), + detailsDecoElement.getLocation().getY()); + Assert.assertEquals( + "Details deco bottom position does not match details bottom pos", + detailsElement.getLocation().getY() + + detailsElement.getSize().getHeight(), + detailsDecoElement.getLocation().getY() + + detailsDecoElement.getSize().getHeight()); + } + + private void verifyLocation(Param param) { + Assert.assertFalse("Notification was present", + isElementPresent(By.className("v-Notification"))); + + TestBenchElement headerRow = getGrid().getHeaderRow(0); + final int topBoundary = headerRow.getLocation().getX() + + headerRow.getSize().height; + final int bottomBoundary = getGrid().getLocation().getX() + + getGrid().getSize().getHeight() + - getHorizontalScrollbar().getSize().height; + + GridRowElement row = getGrid().getRow(param.getRowIndex()); + final int rowTop = row.getLocation().getX(); + + waitForDetailsVisible(); + WebElement details = getDetailsElement(); + final int detailsBottom = details.getLocation().getX() + + details.getSize().getHeight(); + + assertGreaterOrEqual("Row top should be inside grid, gridTop:" + + topBoundary + " rowTop" + rowTop, topBoundary, rowTop); + assertLessThanOrEqual( + "Decorator bottom should be inside grid, gridBottom:" + + bottomBoundary + " decoratorBotton:" + detailsBottom, + detailsBottom, bottomBoundary); + + verifyDetailsRowHeight(param.getRowIndex(), param.useGenerator() + ? detailsDefinedHeight : detailsDefaultHeight, 0); + verifyDetailsDecoratorLocation(param.getRowIndex(), 0, 0); + + Assert.assertFalse("Notification was present", + isElementPresent(By.className("v-Notification"))); + } + + private final By locator = By.className("v-grid-spacer"); + + private WebElement getDetailsElement() { + return getDetailsElement(0); + } + + private WebElement getDetailsElement(int index) { + return findElements(locator).get(index); + } + + private WebElement getDetailsDecoElement(int index) { + return findElements(By.className("v-grid-spacer-deco")).get(index); + } + + private void waitForDetailsVisible() { + waitUntil(new ExpectedCondition() { + + @Override + public WebElement apply(WebDriver driver) { + try { + WebElement detailsElement = getDetailsElement(); + return detailsElement.isDisplayed() + && detailsElement.getSize().getHeight() > 3 + ? detailsElement : null; + } catch (StaleElementReferenceException e) { + return null; + } + } + + @Override + public String toString() { + return "visibility of element located by " + locator; + } + + }, 5); + waitForElementVisible(By.className("v-grid-spacer")); + } + + private void scrollToBottom(boolean scrollFirstToBottom) { + if (scrollFirstToBottom) { + executeScript("arguments[0].scrollTop = 9999999", + getVerticalScrollbar()); + } + } + + private void useGenerator(boolean use) { + CheckBoxElement checkBox = $(CheckBoxElement.class).first(); + boolean isChecked = isCheckedValo(checkBox); + if (use != isChecked) { + clickValo(checkBox); + } + } + + @SuppressWarnings("boxing") + private boolean isCheckedValo(CheckBoxElement checkBoxElement) { + WebElement checkbox = checkBoxElement.findElement(By.tagName("input")); + Object value = executeScript("return arguments[0].checked;", checkbox); + return (Boolean) value; + } + + private void clickValo(CheckBoxElement checkBoxElement) { + checkBoxElement.click(5, 5); + } + + private void scrollAndToggle(int row) { + setRow(row); + getScrollAndToggle().click(); + } + + private void toggleAndScroll(int row) { + setRow(row); + getToggleAndScroll().click(); + } + + private ButtonElement getScrollAndToggle() { + return $(ButtonElement.class).caption("Scroll and toggle").first(); + } + + private ButtonElement getToggleAndScroll() { + return $(ButtonElement.class).caption("Toggle and scroll").first(); + } + + private void setRow(int row) { + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys(String.valueOf(row), + Keys.ENTER, Keys.TAB); + } + + private GridElement getGrid() { + return $(GridElement.class).first(); + } + + private WebElement getVerticalScrollbar() { + WebElement scrollBar = getGrid() + .findElement(By.className("v-grid-scroller-vertical")); + return scrollBar; + } + + private WebElement getHorizontalScrollbar() { + WebElement scrollBar = getGrid() + .findElement(By.className("v-grid-scroller-horizontal")); + return scrollBar; + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..458a0eeeb1 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/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.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.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@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()); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDisabledMultiselectTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDisabledMultiselectTest.java new file mode 100644 index 0000000000..44f3aab1aa --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDisabledMultiselectTest.java @@ -0,0 +1,80 @@ +package com.vaadin.v7.tests.components.grid; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridDisabledMultiselectTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(); + } + + private void disable() { + $(ButtonElement.class).caption("Disable").first().click(); + } + + private void setMultiselect() { + $(ButtonElement.class).caption("Multi").first().click(); + } + + private WebElement getSelectAllCheckBox() { + return findCheckBoxes().get(0); + } + + private List findCheckBoxes() { + return findElements(By.cssSelector("span input")); + } + + private WebElement getFirstSelectCheckBox() { + return findCheckBoxes().get(1); + } + + @Test + public void checkBoxesAreDisabledAfterModeChange() { + disable(); + + setMultiselect(); + + assertThat(getSelectAllCheckBox().isEnabled(), is(false)); + assertThat(getFirstSelectCheckBox().isEnabled(), is(false)); + } + + @Test + public void checkBoxesAreDisabledAfterDisabled() { + setMultiselect(); + + assertThat(getSelectAllCheckBox().isEnabled(), is(true)); + assertThat(getFirstSelectCheckBox().isEnabled(), is(true)); + + disable(); + + assertThat(getSelectAllCheckBox().isEnabled(), is(false)); + assertThat(getFirstSelectCheckBox().isEnabled(), is(false)); + } + + @Test + public void parentSpanCannotBeClickedWhenDisabled() { + setMultiselect(); + disable(); + + WebElement firstCheckBoxSpan = findElements(By.cssSelector("span")) + .get(1); + new Actions(driver).moveToElement(firstCheckBoxSpan, 1, 1).click() + .perform(); + + assertThat(getFirstSelectCheckBox().isSelected(), is(false)); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDisabledSideBarTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDisabledSideBarTest.java new file mode 100644 index 0000000000..0471fd77d5 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDisabledSideBarTest.java @@ -0,0 +1,88 @@ +package com.vaadin.v7.tests.components.grid; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridDisabledSideBarTest extends GridBasicClientFeaturesTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(); + } + + private void makeColumnHidable() { + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + } + + private void toggleSideBarMenuAndDisable() { + selectMenuPath("Component", "Sidebar", "Open sidebar and disable grid"); + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + return !findElement(By.className("v-grid-sidebar-button")) + .isEnabled(); + } + }); + } + + private void clickSideBarButton() { + findElement(By.cssSelector(".v-grid-sidebar-button")).click(); + } + + private void toggleEnabled() { + selectMenuPath("Component", "State", "Enabled"); + } + + private void assertSideBarContainsClass(String cssClass) { + assertThat(findElement(By.cssSelector(".v-grid-sidebar")) + .getAttribute("class"), containsString(cssClass)); + } + + @Test + public void sidebarButtonIsDisabledOnCreation() { + selectMenuPath("Component", "State", "Enabled"); + makeColumnHidable(); + + clickSideBarButton(); + + assertSideBarContainsClass("closed"); + } + + @Test + public void sidebarButtonCanBeEnabled() { + makeColumnHidable(); + + clickSideBarButton(); + + assertSideBarContainsClass("open"); + } + + @Test + public void sidebarButtonCanBeDisabled() { + makeColumnHidable(); + toggleEnabled(); + + clickSideBarButton(); + + assertSideBarContainsClass("closed"); + } + + @Test + public void sidebarIsClosedOnDisable() { + makeColumnHidable(); + + toggleSideBarMenuAndDisable(); + + assertSideBarContainsClass("closed"); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDragSelectionWhileScrolledTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDragSelectionWhileScrolledTest.java new file mode 100644 index 0000000000..9e3f8a49cc --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridDragSelectionWhileScrolledTest.java @@ -0,0 +1,61 @@ +/* + * 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 java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridDragSelectionWhileScrolledTest extends MultiBrowserTest { + + @Override + protected boolean requireWindowFocusForIE() { + return true; + } + + @Test + public void testDragSelect() throws IOException { + openTestURL(); + + // Scroll grid to view + GridElement grid = $(GridElement.class).first(); + ((JavascriptExecutor) getDriver()) + .executeScript("arguments[0].scrollIntoView(true);", grid); + + // Drag select 2 rows + new Actions(getDriver()).moveToElement(grid.getCell(3, 0), 5, 5) + .clickAndHold().moveToElement(grid.getCell(2, 0), 5, 5) + .release().perform(); + + // Assert only those are selected. + assertTrue("Row 3 should be selected", grid.getRow(3).isSelected()); + assertTrue("Row 2 should be selected", grid.getRow(2).isSelected()); + assertFalse("Row 4 should not be selected", + grid.getRow(4).isSelected()); + assertFalse("Row 1 should not be selected", + grid.getRow(1).isSelected()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBarsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBarsTest.java new file mode 100644 index 0000000000..32225283b7 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBarsTest.java @@ -0,0 +1,38 @@ +/* + * 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 org.junit.Test; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridEditingWithNoScrollBarsTest extends MultiBrowserTest { + + @Test + public void testEditorWideEnough() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + grid.getCell(1, 1).doubleClick(); + assertEquals(grid.getEditor().getSize().width, + grid.getTableWrapper().getSize().width); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFoundTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFoundTest.java new file mode 100644 index 0000000000..4f330c6af2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFoundTest.java @@ -0,0 +1,43 @@ +/* + * 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 org.junit.Test; + +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.GridEditorConverterNotFound; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridEditorConverterNotFoundTest extends GridBasicFeaturesTest { + + @Override + protected Class getUIClass() { + // Use the correct UI with helpers from GridBasicFeatures + return GridEditorConverterNotFound.class; + } + + @Test + public void testConverterNotFound() { + openTestURL(); + + $(GridElement.class).first().getCell(0, 0).doubleClick(); + + assertEquals("1. com.vaadin.v7.data.Buffered$SourceException", + getLogRow(0)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorCustomFieldTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorCustomFieldTest.java new file mode 100644 index 0000000000..e330b4e16f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorCustomFieldTest.java @@ -0,0 +1,46 @@ +/* + * 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.Test; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.ComboBoxElement; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridEditorCustomFieldTest extends MultiBrowserTest { + + @Test + public void testCustomFieldWorksInEditorRow() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Stockholm", grid.getCell(0, 2).getText()); + grid.getCell(0, 1).doubleClick(); + GridEditorElement editor = grid.getEditor(); + TestBenchElement customField = editor.getField(2); + + ComboBoxElement comboBox = customField.$(ComboBoxElement.class).first(); + comboBox.selectByText("Oslo"); + editor.save(); + Assert.assertEquals("Oslo", grid.getCell(0, 2).getText()); + + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUITest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUITest.java new file mode 100644 index 0000000000..4675a8e89f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUITest.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.v7.tests.components.grid; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridEditorFrozenColumnsUITest extends MultiBrowserTest { + + @Test + public void testEditorWithFrozenColumns() throws IOException { + openTestURL(); + + openEditor(10); + + compareScreen("noscroll"); + + scrollGridHorizontallyTo(100); + + compareScreen("scrolled"); + } + + private void openEditor(int rowIndex) { + GridElement grid = $(GridElement.class).first(); + + GridCellElement cell = grid.getCell(rowIndex, 1); + + new Actions(driver).moveToElement(cell).doubleClick().build().perform(); + } + + private void scrollGridHorizontallyTo(double px) { + executeScript("arguments[0].scrollLeft = " + px, + getGridHorizontalScrollbar()); + } + + private Object executeScript(String script, WebElement element) { + final WebDriver driver = getDriver(); + if (driver instanceof JavascriptExecutor) { + final JavascriptExecutor je = (JavascriptExecutor) driver; + return je.executeScript(script, element); + } else { + throw new IllegalStateException("current driver " + + getDriver().getClass().getName() + " is not a " + + JavascriptExecutor.class.getSimpleName()); + } + } + + private WebElement getGridHorizontalScrollbar() { + return getDriver().findElement(By.xpath( + "//div[contains(@class, \"v-grid-scroller-horizontal\")]")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselectTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselectTest.java new file mode 100644 index 0000000000..f144615227 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselectTest.java @@ -0,0 +1,58 @@ +package com.vaadin.v7.tests.components.grid; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridEditorMultiselectTest extends MultiBrowserTest { + + @Test + public void testSelectCheckboxesDisabled() { + openTestURL(); + GridElement grid = openEditor(); + assertCheckboxesEnabled(grid, false); + } + + @Test + public void testSelectCheckboxesEnabledBackOnSave() { + openTestURL(); + GridElement grid = openEditor(); + grid.getEditor().save(); + assertCheckboxesEnabled(grid, true); + } + + @Test + public void testSelectCheckboxesEnabledBackOnCancel() { + openTestURL(); + GridElement grid = openEditor(); + grid.getEditor().cancel(); + assertCheckboxesEnabled(grid, true); + } + + private GridElement openEditor() { + GridElement grid = $(GridElement.class).first(); + grid.getRow(0).doubleClick(); + Assert.assertTrue("Grid editor should be displayed.", + grid.getEditor().isDisplayed()); + return grid; + } + + private void assertCheckboxesEnabled(GridElement grid, boolean isEnabled) { + List checkboxes = grid + .findElements(By.xpath("//input[@type='checkbox']")); + for (WebElement checkbox : checkboxes) { + Assert.assertEquals( + "Select checkboxes should be " + + (isEnabled ? "enabled" : "disabled"), + isEnabled, checkbox.isEnabled()); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorUITest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorUITest.java new file mode 100644 index 0000000000..e51b5fd20c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorUITest.java @@ -0,0 +1,96 @@ +/* + * 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.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.PasswordFieldElement; + +@TestCategory("grid") +public class GridEditorUITest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + setDebug(true); + openTestURL(); + } + + private void openEditor(int rowIndex) { + GridElement grid = $(GridElement.class).first(); + + GridCellElement cell = grid.getCell(rowIndex, 1); + + new Actions(driver).moveToElement(cell).doubleClick().build().perform(); + } + + private void saveEditor() { + findElement(By.cssSelector(".v-grid-editor-save")).click(); + } + + private GridCellElement getHeaderCell(int rowIndex, int colIndex) { + GridElement grid = $(GridElement.class).first(); + + GridCellElement headerCell = grid.getHeaderCell(rowIndex, colIndex); + + return headerCell; + } + + @Test + public void testEditor() { + assertFalse("Sanity check", + isElementPresent(PasswordFieldElement.class)); + + openEditor(5); + new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); + + openEditor(10); + + assertTrue("Editor should be opened with a password field", + isElementPresent(PasswordFieldElement.class)); + + assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + } + + @Test + public void savingResetsSortingIndicator() { + GridCellElement headerCell = getHeaderCell(0, 0); + headerCell.click(); + + openEditor(1); + + saveEditor(); + + assertThat(headerCell.getAttribute("class"), + not(containsString("sort-"))); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunicationTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunicationTest.java new file mode 100644 index 0000000000..2991cc5c19 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunicationTest.java @@ -0,0 +1,47 @@ +/* + * 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 org.junit.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridExtensionCommunicationTest extends SingleBrowserTest { + + @Test + public void testMouseClickIsSentToExtension() { + openTestURL(); + + GridCellElement cell = $(GridElement.class).first().getCell(0, 4); + cell.click(5, 5); + + int expectedX = cell.getLocation().getX() + 5; + int expectedY = cell.getLocation().getY() + 5; + + assertEquals( + "1. Click on Person Nina Brown on column Column[propertyId:gender]", + getLogRow(1)); + assertEquals("2. MouseEventDetails: left (" + expectedX + ", " + + expectedY + ")", getLogRow(0)); + + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridGeneratedPropertiesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridGeneratedPropertiesTest.java new file mode 100644 index 0000000000..57ebb51239 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridGeneratedPropertiesTest.java @@ -0,0 +1,90 @@ +/* + * 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.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridGeneratedPropertiesTest extends MultiBrowserTest { + + @Test + public void testMilesColumnExists() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + assertEquals("Miles header wasn't present.", "miles", + grid.getHeaderCell(0, 2).getText().toLowerCase()); + } + + @Test + public void testUnsortableGeneratedProperty() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Overwritten foo property should not be sortable + GridCellElement fooHeader = grid.getHeaderCell(0, 0); + fooHeader.click(); + assertFalse("Column foo was unexpectedly sorted.", + fooHeader.getAttribute("class").contains("sort")); + + // Generated property miles is not sortable + GridCellElement milesHeader = grid.getHeaderCell(0, 2); + milesHeader.click(); + assertFalse("Column miles was unexpectedly sorted.", + milesHeader.getAttribute("class").contains("sort")); + } + + @Test + public void testSortableGeneratedProperty() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Generated property baz is sortable + GridCellElement bazHeader = grid.getHeaderCell(0, 3); + bazHeader.click(); + assertTrue("Column baz was not sorted ascending", + bazHeader.getAttribute("class").contains("sort-asc")); + bazHeader.click(); + assertTrue("Column baz was not sorted descending", + bazHeader.getAttribute("class").contains("sort-desc")); + } + + @Test + public void testInitialSorting() { + // Grid is sorted in this case by one visible and one nonexistent + // column. There should be no sort indicator. + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + GridCellElement kmHeader = grid.getHeaderCell(0, 1); + assertFalse("Column km was unexpectedly sorted", + kmHeader.getAttribute("class").contains("sort-asc") || kmHeader + .getAttribute("class").contains("sort-desc")); + assertFalse("Unexpected client-side exception was visible", + isElementPresent(NotificationElement.class)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponentsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponentsTest.java new file mode 100644 index 0000000000..bc11ab3411 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponentsTest.java @@ -0,0 +1,138 @@ +/* + * 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.Before; +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridHeaderFooterComponentsTest extends SingleBrowserTest { + + @Before + public void setUp() { + setDebug(true); + + openTestURL(); + } + + @Test + public void hideAndShowComponentsInHeader() { + GridElement grid = $(GridElement.class).first(); + + int filterRow = 2; + Assert.assertNull(getHeaderElement(grid, filterRow, 1)); + Assert.assertNotNull(getHeaderElement(grid, filterRow, 2)); + Assert.assertNotNull(getHeaderElement(grid, filterRow, 3)); + + // Show (1,2) + grid.getHeaderCell(1, 1).$(ButtonElement.class).first().click(); + + TextFieldElement textfield = getHeaderElement(grid, filterRow, 1); + Assert.assertNotNull(textfield); + Assert.assertEquals("Filter: string", textfield.getValue()); + + textfield.setValue("foo"); + Assert.assertEquals("1. value change for field in string to foo", + getLogRow(0)); + + assertNoErrorNotifications(); + } + + private TextFieldElement getHeaderElement(GridElement grid, int row, + int col) { + GridCellElement cell = grid.getHeaderCell(row, col); + List all = cell.$(TextFieldElement.class).all(); + if (all.size() == 0) { + return null; + } else if (all.size() == 1) { + return all.get(0); + } else { + throw new RuntimeException( + "Multiple elements found in the header cell at " + row + "," + + col); + } + } + + @Test + public void hideAndShowComponentsInFooter() { + GridElement grid = $(GridElement.class).first(); + + int filterRow = 0; + Assert.assertNull(getFooterElement(grid, filterRow, 1)); + Assert.assertNotNull(getFooterElement(grid, filterRow, 2)); + Assert.assertNotNull(getFooterElement(grid, filterRow, 3)); + + // Show (1,2) + grid.getFooterCell(1, 1).$(ButtonElement.class).first().click(); + + TextFieldElement textfield = getFooterElement(grid, filterRow, 1); + Assert.assertNotNull(textfield); + Assert.assertEquals("Filter: string", textfield.getValue()); + + textfield.setValue("foo"); + Assert.assertEquals("1. value change for field in string to foo", + getLogRow(0)); + + assertNoErrorNotifications(); + } + + private TextFieldElement getFooterElement(GridElement grid, int row, + int col) { + GridCellElement cell = grid.getFooterCell(row, col); + List all = cell.$(TextFieldElement.class).all(); + if (all.size() == 0) { + return null; + } else if (all.size() == 1) { + return all.get(0); + } else { + throw new RuntimeException( + "Multiple elements found in the footer cell at " + row + "," + + col); + } + } + + @Test + public void testRemoveAllHeadersAndFooters() { + openTestURL(); + + for (int i = 2; i >= 0; --i) { + // Remove Header + $(GridElement.class).first().getHeaderCell(i, 0) + .$(ButtonElement.class).first().click(); + Assert.assertFalse("Header " + i + " should not be present.", + $(GridElement.class).first() + .isElementPresent(By.vaadin("#header[" + i + "]"))); + + // Remove Footer + $(GridElement.class).first().getFooterCell(i, 0) + .$(ButtonElement.class).first().click(); + Assert.assertFalse("Footer " + i + " should not be present.", + $(GridElement.class).first() + .isElementPresent(By.vaadin("#footer[" + i + "]"))); + } + + assertNoErrorNotifications(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChangeTest.java new file mode 100644 index 0000000000..39dd75ef88 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChangeTest.java @@ -0,0 +1,151 @@ +/* + * 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.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridHeaderFormatChangeTest extends MultiBrowserTest { + + @Test + public void testHeaderRetainsSelectAllForColumnRemoval() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Assert that we do not have the select all checkbox + Assert.assertTrue( + "Found input in header even though none should exist.", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Set grid into multiselection mode + toggleSelectionMode(); + + // Assert that we now have a select all checkbox in the header + Assert.assertFalse("Expected one input field in header", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Hide the firstName column from the grid. + toggleFirstName(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse("Header was missing checkbox after hiding column", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Show the firstName column. + toggleFirstName(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse( + "Header was missing checkbox after bringing back column", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + } + + @Test + public void testHeaderRetainsSelectAllForJoinColumnAdd() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Assert that we do not have the select all checkbox + Assert.assertTrue( + "Found input in header even though none should exist.", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Set grid into multiselection mode + toggleSelectionMode(); + + // Assert that we now have a select all checkbox in the header + Assert.assertFalse("Expected one input field in header", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Add Join columns header + toggleJoin(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse("Header was missing checkbox after hiding column", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // remove Join Columns header + toggleJoin(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse( + "Header was missing checkbox after bringing back column", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + } + + @Test + public void selectAllShouldKeepState() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Assert that we do not have the select all checkbox + Assert.assertTrue( + "Found input in header even though none should exist.", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Set grid into multiselection mode + toggleSelectionMode(); + + // Assert that we now have a select all checkbox in the header + Assert.assertFalse("Should not be selected after adding", + grid.getHeader().findElement(By.tagName("input")).isSelected()); + + grid.getHeader().findElement(By.tagName("input")).click(); + + // Assert that checkbox is checked + assertSelectAllChecked( + "Not selected even though we just clicked selection", grid); + + // Hide the firstName column from the grid. + toggleFirstName(); + + // Assert that checkbox is still checked + assertSelectAllChecked("Selection disappeared after removing column", + grid); + + // Show the firstName column. + toggleFirstName(); + + // Assert that checkbox is still checked + assertSelectAllChecked("Selection disappeared after adding column", + grid); + + } + + private void assertSelectAllChecked(String message, GridElement grid) { + Assert.assertTrue(message, + grid.getHeader().findElement(By.tagName("input")).isSelected()); + } + + private void toggleSelectionMode() { + $(ButtonElement.class).id("selection_mode").click(); + } + + private void toggleFirstName() { + $(ButtonElement.class).id("show_hide").click(); + } + + private void toggleJoin() { + $(ButtonElement.class).id("join").click(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderStyleNamesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderStyleNamesTest.java new file mode 100644 index 0000000000..ba7eca515c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderStyleNamesTest.java @@ -0,0 +1,174 @@ +/* + * 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.By; +import org.openqa.selenium.WebElement; + +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; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridHeaderStyleNamesTest extends SingleBrowserTest { + + private GridElement grid; + + @Before + public void findGridCells() { + openTestURL(); + grid = $(GridElement.class).first(); + } + + private GridCellElement getMergedHeaderCell() { + return grid.getHeaderCell(0, 3); + } + + private WebElement getMergedHeaderCellContent() { + return getMergedHeaderCell().findElement( + By.cssSelector("div.v-grid-column-header-content")); + } + + private GridCellElement getAgeFooterCell() { + return grid.getFooterCell(0, 2); + } + + private WebElement getAgeFooterCellContent() { + return getAgeFooterCell().findElement( + By.cssSelector("div.v-grid-column-footer-content")); + } + + @Test + public void cellStyleNamesCanBeAddedAndRemoved() { + ButtonElement toggleStyles = $(ButtonElement.class) + .caption("Toggle styles").first(); + + assertStylesSet(true); + toggleStyles.click(); + assertStylesSet(false); + toggleStyles.click(); + assertStylesSet(true); + } + + @Test + public void rowStyleNamesCanBeAddedAndRemoved() { + ButtonElement toggleStyles = $(ButtonElement.class) + .caption("Toggle styles").first(); + + assertRowStylesSet(true); + toggleStyles.click(); + assertRowStylesSet(false); + toggleStyles.click(); + assertRowStylesSet(true); + + } + + private void assertStylesSet(boolean set) { + if (set) { + assertHasStyleName( + "Footer cell should have the assigned 'age-footer' class name", + getAgeFooterCell(), "age-footer"); + assertHasStyleName( + "Header cell should have the assigned 'age' class name", + getAgeHeaderCell(), "age"); + assertHasStyleName( + "The merged header cell should have the assigned 'city-country' class name", + getMergedHeaderCell(), "city-country"); + } else { + assertHasNotStyleName( + "Footer cell should not have the removed 'age-footer' class name", + getAgeFooterCell(), "age-footer"); + assertHasNotStyleName( + "Header cell should not have the removed 'age' class name", + getAgeHeaderCell(), "age"); + assertHasNotStyleName( + "Ther merged header cell should not have the removed 'city-country' class name", + getMergedHeaderCell(), "city-country"); + } + assertHasStyleName( + "The default v-grid-cell style name should not be removed from the header cell", + getAgeHeaderCell(), "v-grid-cell"); + assertHasStyleName( + "The default v-grid-cell style name should not be removed from the footer cell", + getAgeFooterCell(), "v-grid-cell"); + assertHasStyleName( + "The default v-grid-cell style name should not be removed from the merged header cell", + getMergedHeaderCell(), "v-grid-cell"); + + } + + private void assertRowStylesSet(boolean set) { + if (set) { + assertHasStyleName( + "Footer row should have the assigned 'custom-row' class name", + getFooterRow(), "custom-row"); + assertHasStyleName( + "Header row should have the assigned 'custom-row' class name", + getHeaderRow(), "custom-row"); + } else { + assertHasNotStyleName( + "Footer row should not have the removed 'custom-row' class name", + getFooterRow(), "custom-row"); + assertHasNotStyleName( + "Header row should not have the removed 'custom-row' class name", + getHeaderRow(), "custom-row"); + } + assertHasStyleName( + "The default v-grid-row style name should not be removed from the header row", + getHeaderRow(), "v-grid-row"); + assertHasStyleName( + "The default v-grid-row style name should not be removed from the footer row", + getFooterRow(), "v-grid-row"); + + } + + private WebElement getAgeHeaderCell() { + return grid.getHeaderCell(1, 2); + } + + private WebElement getAgeHeaderCellContent() { + return getAgeHeaderCell().findElement( + By.cssSelector("div.v-grid-column-header-content")); + } + + private WebElement getFooterRow() { + return grid.getFooterRow(0); + } + + private WebElement getHeaderRow() { + return grid.getHeaderRow(0); + } + + private void assertHasStyleName(String message, WebElement element, + String stylename) { + if (!hasCssClass(element, stylename)) { + Assert.fail(message); + } + } + + private void assertHasNotStyleName(String message, WebElement element, + String stylename) { + if (hasCssClass(element, stylename)) { + Assert.fail(message); + } + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeightTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeightTest.java new file mode 100644 index 0000000000..776cbfb57d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeightTest.java @@ -0,0 +1,177 @@ +/* + * 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.Matchers.is; +import static org.hamcrest.number.IsCloseTo.closeTo; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.OptionGroupElement; +import com.vaadin.v7.tests.components.grid.GridHeight; + +/** + * Tests that Grid gets correct height based on height mode, and resizes + * properly with details row if height is undefined. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridHeightTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-grid")); + } + + @Test + public void testGridHeightAndResizingUndefined() + throws InterruptedException { + assertNoErrors(testGridHeightAndResizing(GridHeight.UNDEFINED)); + } + + @Test + public void testGridHeightAndResizingRow() throws InterruptedException { + assertNoErrors(testGridHeightAndResizing(GridHeight.ROW3)); + } + + @Test + public void testGridHeightAndResizingFull() throws InterruptedException { + assertNoErrors(testGridHeightAndResizing(GridHeight.FULL)); + } + + private Map testGridHeightAndResizing( + Object gridHeight) throws InterruptedException { + Map errors = new HashMap(); + String caption; + if (GridHeight.ROW3.equals(gridHeight)) { + caption = gridHeight + " rows"; + } else { + caption = (String) gridHeight; + } + $(OptionGroupElement.class).id("gridHeightSelector") + .selectByText(caption); + for (String gridWidth : GridHeight.gridWidths) { + $(OptionGroupElement.class).id("gridWidthSelector") + .selectByText(gridWidth); + for (String detailsRowHeight : GridHeight.detailsRowHeights) { + $(OptionGroupElement.class).id("detailsHeightSelector") + .selectByText(detailsRowHeight); + sleep(500); + + GridElement grid = $(GridElement.class).first(); + int initialHeight = grid.getSize().getHeight(); + try { + // check default height + assertGridHeight(getExpectedInitialHeight(gridHeight), + initialHeight); + } catch (AssertionError e) { + errors.put(e, new Object[] { gridHeight, gridWidth, + detailsRowHeight, "initial" }); + } + + grid.getRow(2).click(5, 5); + waitForElementPresent(By.id("lbl1")); + + int openHeight = grid.getSize().getHeight(); + try { + // check height with details row opened + assertGridHeight(getExpectedOpenedHeight(gridHeight, + detailsRowHeight), openHeight); + } catch (AssertionError e) { + errors.put(e, new Object[] { gridHeight, gridWidth, + detailsRowHeight, "opened" }); + } + + grid.getRow(2).click(5, 5); + waitForElementNotPresent(By.id("lbl1")); + + int afterHeight = grid.getSize().getHeight(); + try { + // check height with details row closed again + assertThat("Unexpected Grid Height", afterHeight, + is(initialHeight)); + } catch (AssertionError e) { + errors.put(e, new Object[] { gridHeight, gridWidth, + detailsRowHeight, "closed" }); + } + } + } + return errors; + } + + private void assertNoErrors(Map errors) { + if (!errors.isEmpty()) { + StringBuilder sb = new StringBuilder("Exceptions: "); + for (Entry entry : errors.entrySet()) { + sb.append("\n"); + for (Object value : entry.getValue()) { + sb.append(value); + sb.append(" - "); + } + sb.append(entry.getKey().getMessage()); + } + Assert.fail(sb.toString()); + } + } + + private int getExpectedInitialHeight(Object gridHeight) { + int result = 0; + if (GridHeight.UNDEFINED.equals(gridHeight) + || GridHeight.ROW3.equals(gridHeight)) { + result = 81; + } else if (GridHeight.FULL.equals(gridHeight)) { + // pre-existing issue + result = 400; + } + return result; + } + + private int getExpectedOpenedHeight(Object gridHeight, + Object detailsRowHeight) { + int result = 0; + if (GridHeight.UNDEFINED.equals(gridHeight)) { + if (GridHeight.PX100.equals(detailsRowHeight)) { + result = 182; + } else if (GridHeight.FULL.equals(detailsRowHeight)) { + result = 131; + } else if (GridHeight.UNDEFINED.equals(detailsRowHeight)) { + result = 100; + } + } else if (GridHeight.ROW3.equals(gridHeight) + || GridHeight.FULL.equals(gridHeight)) { + result = getExpectedInitialHeight(gridHeight); + } + return result; + } + + private void assertGridHeight(int expected, int actual) { + assertThat("Unexpected Grid Height", (double) actual, + closeTo(expected, 1)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInTabSheetTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInTabSheetTest.java new file mode 100644 index 0000000000..775d79397c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInTabSheetTest.java @@ -0,0 +1,102 @@ +/* + * 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.assertFalse; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridInTabSheetTest extends MultiBrowserTest { + + @Test + public void testRemoveAllRowsAndAddThreeNewOnes() { + setDebug(true); + openTestURL(); + + for (int i = 0; i < 3; ++i) { + removeGridRow(); + } + + for (int i = 0; i < 3; ++i) { + addGridRow(); + assertEquals("" + (100 + i), + getGridElement().getCell(i, 1).getText()); + } + + assertNoNotification(); + } + + private void assertNoNotification() { + assertFalse("There was an unexpected error notification", + isElementPresent(NotificationElement.class)); + } + + @Test + public void testAddManyRowsWhenGridIsHidden() { + setDebug(true); + openTestURL(); + + TabSheetElement tabsheet = $(TabSheetElement.class).first(); + tabsheet.openTab("Label"); + for (int i = 0; i < 50; ++i) { + addGridRow(); + } + + tabsheet.openTab("Grid"); + + assertNoNotification(); + } + + @Test + public void testAddCellStyleGeneratorWhenGridIsHidden() { + setDebug(true); + openTestURL(); + + TabSheetElement tabsheet = $(TabSheetElement.class).first(); + tabsheet.openTab("Label"); + addCellStyleGenerator(); + + tabsheet.openTab("Grid"); + + assertNoNotification(); + } + + private void removeGridRow() { + $(ButtonElement.class).caption("Remove row from Grid").first().click(); + } + + private void addGridRow() { + $(ButtonElement.class).caption("Add row to Grid").first().click(); + } + + private void addCellStyleGenerator() { + $(ButtonElement.class).caption("Add CellStyleGenerator").first() + .click(); + } + + private GridElement getGridElement() { + return $(GridElement.class).first(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInWindowResizeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInWindowResizeTest.java new file mode 100644 index 0000000000..6f859a015e --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInWindowResizeTest.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.v7.tests.components.grid; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridInWindowResizeTest extends MultiBrowserTest { + @Override + public List getBrowsersToTest() { + // Must test on a browser with animations + return Collections + .singletonList(Browser.CHROME.getDesiredCapabilities()); + } + + @Test + public void resizeWindow() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + int col1WidthBefore = grid.getCell(0, 0).getSize().getWidth(); + $(ButtonElement.class).caption("resize").first().click(); + int col1WidthAfter = grid.getCell(0, 0).getSize().getWidth(); + + Assert.assertTrue(col1WidthAfter < col1WidthBefore); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumnsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumnsTest.java new file mode 100644 index 0000000000..509ef262db --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridInitiallyHiddenColumnsTest.java @@ -0,0 +1,84 @@ +/* + * 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.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest { + + @Test + public void ensureCorrectlyRendered() { + openTestURL("debug"); + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals("Rowling", grid.getCell(0, 0).getText()); + Assert.assertEquals("Scott", grid.getCell(1, 0).getText()); + + getSidebarOpenButton(grid).click(); + getColumnHidingToggle(grid, "First 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("25", grid.getCell(0, 2).getText()); + Assert.assertEquals("Dan", grid.getCell(1, 0).getText()); + Assert.assertEquals("Scott", grid.getCell(1, 1).getText()); + Assert.assertEquals("54", grid.getCell(1, 2).getText()); + + } + + // TODO: as to the getX methods reuse ones from GridBasicFeaturesTest? + + protected WebElement getSidebarOpenButton(GridElement grid) { + List elements = grid + .findElements(By.className("v-grid-sidebar-button")); + return elements.isEmpty() ? null : elements.get(0); + } + + /** + * Returns the toggle inside the sidebar for hiding the column at the given + * index, or null if not found. + */ + protected WebElement getColumnHidingToggle(GridElement grid, + String caption) { + WebElement sidebar = getSidebar(grid); + List elements = sidebar + .findElements(By.className("column-hiding-toggle")); + for (WebElement e : elements) { + if (caption.equalsIgnoreCase(e.getText())) { + return e; + } + } + return null; + } + + protected WebElement getSidebar(GridElement grid) { + List elements = findElements( + By.className("v-grid-sidebar-popup")); + return elements.isEmpty() ? null : elements.get(0); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridItemSetChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridItemSetChangeTest.java new file mode 100644 index 0000000000..e43e5a22a6 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridItemSetChangeTest.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.v7.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridItemSetChangeTest extends SingleBrowserTest { + + @Test + public void testValueChangeListenersWorkAfterItemSetChange() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + assertEquals("Last name initially wrong", "Bar", + grid.getCell(0, 1).getText()); + + $(ButtonElement.class).caption("Modify").first().click(); + assertEquals("Last name was not updated", "Spam", + grid.getCell(0, 1).getText()); + + $(ButtonElement.class).caption("Reset").first().click(); + assertEquals("Last name was not updated on reset", "Baz", + grid.getCell(0, 1).getText()); + + $(ButtonElement.class).caption("Modify").first().click(); + assertEquals("Last name was not updated after reset modification", + "Spam", grid.getCell(0, 1).getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRowTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRowTest.java new file mode 100644 index 0000000000..72de2efdf2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridLayoutDetailsRowTest.java @@ -0,0 +1,65 @@ +/* + * 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 org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +/** + * Tests that details row displays GridLayout contents properly. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridLayoutDetailsRowTest extends MultiBrowserTest { + + @Test + public void testLabelHeights() { + openTestURL(); + waitForElementPresent(By.className("v-grid")); + + GridElement grid = $(GridElement.class).first(); + + grid.getRow(2).click(5, 5); + waitForElementPresent(By.id("lbl2")); + + GridLayoutElement gridLayout = $(GridLayoutElement.class).first(); + int gridLayoutHeight = gridLayout.getSize().height; + + // height should be divided equally + double expectedHeight = gridLayoutHeight / 4; + assertLabelHeight("lbl1", expectedHeight); + assertLabelHeight("lbl2", expectedHeight); + assertLabelHeight("lbl3", expectedHeight); + assertLabelHeight("lbl4", expectedHeight); + } + + private void assertLabelHeight(String id, double expectedHeight) { + // 1px leeway for calculations + assertThat("Unexpected label height.", + (double) $(LabelElement.class).id(id).getSize().height, + closeTo(expectedHeight, 1d)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionOnInitTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionOnInitTest.java new file mode 100644 index 0000000000..d976b586fb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionOnInitTest.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.v7.tests.components.grid; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridMultiSelectionOnInitTest extends MultiBrowserTest { + + @Test + public void testSelectAllCheckBoxExists() { + openTestURL(); + assertTrue("The select all checkbox was missing.", + $(GridElement.class).first().getHeaderCell(0, 0) + .isElementPresent(By.tagName("input"))); + } + + @Test + public void testSetSelectedUpdatesClient() { + openTestURL(); + assertFalse("Rows should not be selected initially.", + $(GridElement.class).first().getRow(0).isSelected()); + $(ButtonElement.class).first().click(); + assertTrue("Rows should be selected after button click.", + $(GridElement.class).first().getRow(0).isSelected()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionScrollBarTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionScrollBarTest.java new file mode 100644 index 0000000000..757e577d78 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridMultiSelectionScrollBarTest.java @@ -0,0 +1,43 @@ +/* + * 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 java.io.IOException; + +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridMultiSelectionScrollBarTest extends MultiBrowserTest { + + @Test + public void testNoVisibleScrollBar() throws IOException { + setDebug(true); + openTestURL(); + + assertTrue("Horizontal scrollbar should not be visible.", + $(GridElement.class).first().getHorizontalScroller() + .getAttribute("style").toLowerCase() + .contains("display: none;")); + + // Just to make sure nothing odd happened. + assertNoErrorNotifications(); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRendererChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRendererChangeTest.java new file mode 100644 index 0000000000..0b078b3b7d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRendererChangeTest.java @@ -0,0 +1,59 @@ +/* + * 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 java.util.Collections; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridRendererChangeTest extends MultiBrowserTest { + + @Test + public void testChangeRenderer() { + setDebug(true); + openTestURL(); + + GridCellElement cell = $(GridElement.class).first().getCell(0, 0); + assertTrue("No button in the first cell.", + cell.isElementPresent(By.tagName("button"))); + int width = cell.getSize().getWidth(); + + List buttons = $(ButtonElement.class).all(); + Collections.reverse(buttons); + + // Order: TextRenderer, HTMLRenderer, ButtonRenderer + for (ButtonElement button : buttons) { + button.click(); + assertNoErrorNotifications(); + cell = $(GridElement.class).first().getCell(0, 0); + assertEquals("Cell size changed", width, cell.getSize().getWidth()); + } + + assertTrue("No button in the first cell.", + cell.isElementPresent(By.tagName("button"))); + } + +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReplaceContainerTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReplaceContainerTest.java new file mode 100644 index 0000000000..8e0071018b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridReplaceContainerTest.java @@ -0,0 +1,39 @@ +/* + * 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.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridReplaceContainerTest extends SingleBrowserTest { + + @Test + public void selectAfterContainerChange() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + grid.getCell(0, 0).click(); + Assert.assertTrue(grid.getRow(0).isSelected()); + + $(ButtonElement.class).first().click(); + Assert.assertFalse(grid.getRow(0).isSelected()); + grid.getCell(0, 0).click(); + Assert.assertTrue(grid.getRow(0).isSelected()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridResizeAndScrollTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridResizeAndScrollTest.java new file mode 100644 index 0000000000..5e6d99e6d4 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridResizeAndScrollTest.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.v7.tests.components.grid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridResizeAndScrollTest extends MultiBrowserTest { + + @Test + public void scrollAndClick() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + grid.scrollToRow(49); + // select a row (click on checkbox) + grid.getCell(49, 0).click(); + + // verify rows are what they should be + GridCellElement cell = grid.getCell(33, 1); + String textBefore = cell.getText(); + cell.click(); + + Assert.assertEquals("String contents changed on click", textBefore, + cell.getText()); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridResizeHiddenColumnTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridResizeHiddenColumnTest.java new file mode 100644 index 0000000000..af8b8fe3ed --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridResizeHiddenColumnTest.java @@ -0,0 +1,116 @@ +/* + * 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.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridResizeHiddenColumnTest extends MultiBrowserTest { + + @Before + public void before() { + openTestURL(); + } + + @Test + public void testDragResizeHiddenColumnSize() { + GridElement grid = $(GridElement.class).first(); + Actions action = new Actions(getDriver()); + + // Check if column 'Gender' hidden + List headerCells = grid.getHeaderCells(0); + Assert.assertEquals("There should be two visible columns", 2, + headerCells.size()); + Assert.assertFalse("Gender column should be hidden", + containsText("Gender", headerCells)); + + // Resize first column + int dragOffset = -100; + int headerCellWidth = headerCells.get(0).getSize().getWidth(); + dragResizeColumn(headerCells.get(0), 1, dragOffset); + + // When dragging the resizer on IE8, the final offset will be smaller + // (might be an issue with the feature that doesn't start resizing until + // the cursor moved a few pixels) + double delta = BrowserUtil.isIE8(getDesiredCapabilities()) ? 5d : 0; + Assert.assertEquals( + "Column width should've changed by " + dragOffset + "px", + headerCellWidth + dragOffset, + headerCells.get(0).getSize().getWidth(), delta); + + // Make column 'Gender' visible + WebElement menuButton = grid.findElement(By.className("v-contextmenu")) + .findElement(By.tagName("button")); + action.click(menuButton).perform(); // Click on menu button + + WebElement sidebarPopup = findElement( + By.className("v-grid-sidebar-popup")); + WebElement visibilityToggle = findElementByText("Gender", + sidebarPopup.findElements(By.className("gwt-MenuItem"))); + action.click(visibilityToggle).perform(); // Click on 'Gender' menu item + + // Check if column 'Gender' is visible + headerCells = grid.getHeaderCells(0); + Assert.assertEquals("There should be three visible columns", 3, + headerCells.size()); + Assert.assertTrue("Gender column should be visible", + containsText("Gender", headerCells)); + + // Check if column 'Gender' has expanded width + int widthSum = 0; + for (GridCellElement e : headerCells) { + widthSum += e.getSize().getWidth(); + } + Assert.assertEquals("Gender column should take up the remaining space", + grid.getHeader().getSize().getWidth(), widthSum, 1d); + } + + private WebElement findElementByText(String text, + List elements) { + for (WebElement e : elements) { + if (text.equalsIgnoreCase(e.getText())) { + return e; + } + } + return null; + } + + private boolean containsText(String text, + List elements) { + return !(findElementByText(text, elements) == null); + } + + private void dragResizeColumn(GridCellElement headerCell, int posX, + int offset) { + Dimension size = headerCell.getSize(); + new Actions(getDriver()) + .moveToElement(headerCell, size.getWidth() + posX, + size.getHeight() / 2) + .clickAndHold().moveByOffset(offset, 0).release().perform(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRowHeightChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRowHeightChangeTest.java new file mode 100644 index 0000000000..0962ef5118 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridRowHeightChangeTest.java @@ -0,0 +1,43 @@ +package com.vaadin.v7.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.NativeSelectElement; + +public class GridRowHeightChangeTest extends MultiBrowserTest { + + private final List themes = Arrays.asList("valo", "reindeer", + "runo", "chameleon", "base"); + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + @Test + public void changeThemeAndMeasureGridHeight() { + for (String theme : themes) { + // select theme + $(NativeSelectElement.class).first().selectByText(theme); + + GridElement grid = $(GridElement.class).first(); + + int gridHeight = grid.getSize().getHeight(); + int tabsheetHeight = findElements( + By.className("v-tabsheet-content")).get(0).getSize() + .getHeight(); + + assertEquals("Grid's visible height should be equal to Grid height", + gridHeight, tabsheetHeight, 1); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridScrollToLineWhileResizingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridScrollToLineWhileResizingTest.java new file mode 100644 index 0000000000..bcb23a759c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridScrollToLineWhileResizingTest.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.v7.tests.components.grid; + +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridScrollToLineWhileResizingTest extends MultiBrowserTest { + + @Test + public void testScrollToLineWorksWhileMovingSplitProgrammatically() { + openTestURL(); + + $(GridElement.class).first().getCell(21, 0).click(); + + List cells = findElements(By.className("v-grid-cell")); + boolean foundCell21 = false; + for (WebElement cell : cells) { + if ("cell21".equals(cell.getText())) { + foundCell21 = true; + } + } + + assertTrue(foundCell21); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSelectAllCellTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSelectAllCellTest.java new file mode 100644 index 0000000000..56f6a01047 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSelectAllCellTest.java @@ -0,0 +1,37 @@ +package com.vaadin.v7.tests.components.grid; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridSelectAllCellTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(); + } + + @Test + public void selectAllCellCanBeClicked() throws IOException { + GridElement.GridCellElement selectAllCell = $(GridElement.class).first() + .getHeaderCell(0, 0); + + new Actions(getDriver()).moveToElement(selectAllCell, 2, 2).click() + .perform(); + + WebElement selectAllCheckbox = selectAllCell + .findElement(By.cssSelector("input")); + assertThat(selectAllCheckbox.isSelected(), is(true)); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSidebarPositionTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSidebarPositionTest.java new file mode 100644 index 0000000000..0c8451d9ac --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSidebarPositionTest.java @@ -0,0 +1,88 @@ +/* + * 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.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.GridSidebarPosition; + +public class GridSidebarPositionTest extends MultiBrowserTest { + + @Test + public void heightRestrictedToBrowserWindow() { + openTestURL(); + GridElement gridWithVeryManyColumns = $(GridElement.class) + .id(GridSidebarPosition.POPUP_WINDOW_HEIGHT); + getSidebarOpenButton(gridWithVeryManyColumns).click(); + Dimension popupSize = getSidebarPopup().getSize(); + Dimension browserWindowSize = getDriver().manage().window().getSize(); + + Assert.assertTrue( + popupSize.getHeight() <= browserWindowSize.getHeight()); + } + + @Test + public void popupNotBelowBrowserWindow() { + openTestURL(); + GridElement gridAtBottom = $(GridElement.class) + .id(GridSidebarPosition.POPUP_WINDOW_MOVED_UP); + getSidebarOpenButton(gridAtBottom).click(); + WebElement sidebarPopup = getSidebarPopup(); + Dimension popupSize = sidebarPopup.getSize(); + Point popupLocation = sidebarPopup.getLocation(); + int popupBottom = popupLocation.getY() + popupSize.getHeight(); + Dimension browserWindowSize = getDriver().manage().window().getSize(); + + Assert.assertTrue(popupBottom <= browserWindowSize.getHeight()); + } + + @Test + public void popupAbove() { + openTestURL(); + GridElement gridPopupAbove = $(GridElement.class) + .id(GridSidebarPosition.POPUP_ABOVE); + WebElement sidebarOpenButton = getSidebarOpenButton(gridPopupAbove); + sidebarOpenButton.click(); + WebElement sidebarPopup = getSidebarPopup(); + Dimension popupSize = sidebarPopup.getSize(); + Point popupLocation = sidebarPopup.getLocation(); + int popupBottom = popupLocation.getY() + popupSize.getHeight(); + int sideBarButtonTop = sidebarOpenButton.getLocation().getY(); + Assert.assertTrue(popupBottom <= sideBarButtonTop); + } + + protected WebElement getSidebarOpenButton(GridElement grid) { + List elements = grid + .findElements(By.className("v-grid-sidebar-button")); + return elements.isEmpty() ? null : elements.get(0); + } + + protected WebElement getSidebarPopup() { + List elements = findElements( + By.className("v-grid-sidebar-popup")); + return elements.isEmpty() ? null : elements.get(0); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSingleColumnTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSingleColumnTest.java new file mode 100644 index 0000000000..23903f74ad --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSingleColumnTest.java @@ -0,0 +1,47 @@ +/* + * 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.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridSingleColumnTest extends MultiBrowserTest { + + @Test + public void testHeaderIsVisible() { + openTestURL(); + + GridCellElement cell = $(GridElement.class).first().getHeaderCell(0, 0); + Assert.assertTrue("No header available", + cell.getText().equalsIgnoreCase("header")); + } + + @Test + public void testScrollDidNotThrow() { + setDebug(true); + openTestURL(); + + Assert.assertFalse("Exception when scrolling on init", + isElementPresent(NotificationElement.class)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSortIndicatorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSortIndicatorTest.java new file mode 100644 index 0000000000..5f35acc507 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSortIndicatorTest.java @@ -0,0 +1,53 @@ +/* + * 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.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridSortIndicatorTest extends MultiBrowserTest { + + @Test + public void testIndicators() throws InterruptedException { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + // Clicking the left header cell should set ascending sort order for + // both columns. + grid.getHeaderCell(0, 0).click(); + assertTrue(grid.getHeaderCell(0, 0).getAttribute("class") + .contains("sort-asc")); + assertTrue(grid.getHeaderCell(0, 1).getAttribute("class") + .contains("sort-asc")); + // Click the left column to change the sort direction. + grid.getHeaderCell(0, 0).click(); + assertTrue(grid.getHeaderCell(0, 0).getAttribute("class") + .contains("sort-desc")); + assertTrue(grid.getHeaderCell(0, 1).getAttribute("class") + .contains("sort-desc")); + // Clicking on the right column should have no effect. + grid.getHeaderCell(0, 1).click(); + assertTrue(grid.getHeaderCell(0, 0).getAttribute("class") + .contains("sort-desc")); + assertTrue(grid.getHeaderCell(0, 1).getAttribute("class") + .contains("sort-desc")); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSpacerDecoClipTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSpacerDecoClipTest.java new file mode 100644 index 0000000000..ed392d848f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSpacerDecoClipTest.java @@ -0,0 +1,98 @@ +/* + * 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.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.SearchContext; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.minitutorials.v7_5.ShowingExtraDataForRows; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +/** + * Test for "Grid detail row outline overflows" (#17826) + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridSpacerDecoClipTest extends MultiBrowserTest { + + private static final String SPACER_CSS_CLASS_DECO = "v-grid-spacer-deco"; + + @Override + protected Class getUIClass() { + return ShowingExtraDataForRows.class; + } + + @Test + public void testNewSpacerClip() { + openTestURL(); + + GridElement gridElement = $(GridElement.class).first(); + gridElement.scrollToRow(999); + GridElement.GridRowElement nextToLastRow = gridElement.getRow(998); + nextToLastRow.doubleClick(); + + TestBenchElement deco = getSpacerDeco(0); + System.out.println("Lower deco.clip = " + deco.getCssValue("clip")); + GridElement.GridRowElement nearToBottomRow = gridElement.getRow(993); + nearToBottomRow.doubleClick(); + deco = getSpacerDeco(0); + System.out.println("Lower deco.clip = " + deco.getCssValue("clip")); + Assert.assertNotEquals( + "Spacer deco clipping is not updated after opening another spacer", + "auto", deco.getCssValue("clip")); + } + + @Test + public void testRemovedSpacerClip() throws InterruptedException { + openTestURL(); + + GridElement gridElement = $(GridElement.class).first(); + gridElement.scrollToRow(999); + GridElement.GridRowElement lastRow = gridElement.getRow(999); + lastRow.doubleClick(); // Open lowest Row Details + + TestBenchElement deco = getSpacerDeco(0); + System.out.println("deco.rect = " + deco.getCssValue("clip")); + + GridElement.GridRowElement nearToBottomRow = gridElement.getRow(993); + + nearToBottomRow.doubleClick(); // Open upper Row Details, lower Row + // Details goes out of visible range + Thread.sleep(500); + nearToBottomRow.doubleClick(); // Close upper Row Details, lower Row + // Details goes back to visible range + + deco = getSpacerDeco(0); + String clip = deco.getCssValue("clip"); + System.out.println("deco.rect = " + clip); + + Assert.assertTrue( + "Part of lower Row Details is visible, its deco clip height should be positive, but it is negative", + clip.indexOf('-') < 0); + } + + private TestBenchElement getSpacerDeco(int index) { + SearchContext context = getContext(); + return (TestBenchElement) context + .findElements(By.className(SPACER_CSS_CLASS_DECO)).get(index); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSubPixelProblemWrappingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSubPixelProblemWrappingTest.java new file mode 100644 index 0000000000..f47f2f2c05 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSubPixelProblemWrappingTest.java @@ -0,0 +1,57 @@ +/* + * 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.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridSubPixelProblemWrappingTest extends MultiBrowserTest { + + @Test + public void addedRowShouldNotWrap() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + // Cells in first row should be at the same y coordinate as the row + assertRowAndCellTops(grid, 0); + + // Add a row + $(ButtonElement.class).first().click(); + + // Cells in the first row should be at the same y coordinate as the row + assertRowAndCellTops(grid, 0); + // Cells in the second row should be at the same y coordinate as the row + assertRowAndCellTops(grid, 1); + } + + private void assertRowAndCellTops(GridElement grid, int rowIndex) { + GridRowElement row = grid.getRow(rowIndex); + int rowTop = row.getLocation().y; + + int cell0Top = grid.getCell(rowIndex, 0).getLocation().y; + int cell1Top = grid.getCell(rowIndex, 1).getLocation().y; + Assert.assertEquals(rowTop, cell0Top); + Assert.assertEquals(rowTop, cell1Top); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSwitchRenderersTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSwitchRenderersTest.java new file mode 100644 index 0000000000..79c2e45a28 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridSwitchRenderersTest.java @@ -0,0 +1,86 @@ +/* + * 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.Test; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridSwitchRenderersTest extends MultiBrowserTest { + + @Test + public void testRendererSwitch() { + + // The UI should start with TEXT rendering in the second column + // Clicking the checkbox will toggle rendering to HTML mode + // Clicking it again should return TEXT rendering mode. + + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertTrue( + "Initial rendering of column 1 is not unformatted text", + cellTextIsUnformatted(grid.getCell(0, 1).getText())); + + // NOTE: must click at 5,5 because of Valo and rendering in Chrome + // This is a TestBench bug that may be fixed sometime in the future + CheckBoxElement cb = $(CheckBoxElement.class).first(); + cb.click(5, 5); + + Assert.assertTrue( + "Column 1 data has not been rendered with HTMLRenderer after renderer swap", + cellTextIsHTMLFormatted(grid.getCell(0, 1).getText())); + cb.click(5, 5); + + Assert.assertTrue( + "Column 1 data has not been re-rendered as text after renderer swap", + cellTextIsUnformatted(grid.getCell(0, 1).getText())); + } + + /** + * Attempts to match a string to a string like {@code (4, 1)}. + * + * @param cellText + * input string + * @return true if input string is formatted like a raw HTML string + */ + private boolean cellTextIsUnformatted(String cellText) { + String regex = "\\(\\d+, \\d+\\)"; + return cellText.matches(regex); + } + + /** + * Attempts to match a string to a string like {@code (4, 1)}, i.e. the HTML + * formatted version of the above (the bold tags should be consumed by the + * renderer). + * + * @param cellText + * input string + * @return true if input string is formatted like plain text (i.e. HTML bits + * have been consumed by renderer) + */ + private boolean cellTextIsHTMLFormatted(String cellText) { + String regex = "\\(\\d+, \\d+\\)"; + return cellText.matches(regex); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridThemeChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridThemeChangeTest.java new file mode 100644 index 0000000000..175dd1e11a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridThemeChangeTest.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.v7.tests.components.grid; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class GridThemeChangeTest extends MultiBrowserTest { + @Override + public List getBrowsersToTest() { + // Seems like stylesheet onload is not fired on PhantomJS + // https://github.com/ariya/phantomjs/issues/12332 + return super.getBrowsersExcludingPhantomJS(); + } + + @Test + public void testThemeChange() { + openTestURL("debug"); + + GridElement grid = $(GridElement.class).first(); + + int reindeerHeight = grid.getRow(0).getSize().getHeight(); + + grid.getCell(0, 0).click(); + + grid = $(GridElement.class).first(); + int valoHeight = grid.getRow(0).getSize().getHeight(); + + Assert.assertTrue( + "Row height should increase when changing from Reindeer to Valo", + valoHeight > reindeerHeight); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridThemeUITest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridThemeUITest.java new file mode 100644 index 0000000000..7b2f8ae356 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridThemeUITest.java @@ -0,0 +1,109 @@ +/* + * 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.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserThemeTest; +import com.vaadin.v7.testbench.customelements.DateFieldElement; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.NativeSelectElement; +import com.vaadin.v7.testbench.customelements.TextFieldElement; + +@TestCategory("grid") +public class GridThemeUITest extends MultiBrowserThemeTest { + + private GridElement grid; + + @Test + public void grid() throws Exception { + openTestURL(); + selectPage("Editor"); + compareScreen("basic"); + } + + @Test + public void headerAndFooter() throws Exception { + openTestURL(); + selectPage("HeaderFooter"); + compareScreen("basic"); + grid.getHeaderCell(0, 6).$(ButtonElement.class).first().click(); + compareScreen("additional-header"); + grid.getHeaderCell(2, 1).click(); + compareScreen("sorted-last-name"); + grid.getHeaderCell(2, 4).click(); + compareScreen("sorted-age"); + } + + @Test + public void editor() throws Exception { + openTestURL(); + selectPage("Editor"); + GridCellElement ritaBirthdate = grid.getCell(2, 3); + // Open editor row + openEditor(ritaBirthdate); + + compareScreen("initial"); + + GridEditorElement editor = grid.getEditor(); + + DateFieldElement dateField = editor.$(DateFieldElement.class).first(); + WebElement input = dateField.findElement(By.xpath("input")); + input.sendKeys("Invalid", Keys.TAB); + editor.save(); + compareScreen("one-invalid"); + + TextFieldElement age = editor.$(TextFieldElement.class).caption("Age") + .first(); + age.sendKeys("abc", Keys.TAB); + editor.save(); + + compareScreen("two-invalid"); + } + + private void openEditor(GridCellElement targetCell) { + new Actions(getDriver()).doubleClick(targetCell).perform(); + try { + if (grid.getEditor().isDisplayed()) { + return; + } + } catch (Exception e) { + + } + + // Try again if IE happen to fail.. + new Actions(getDriver()).doubleClick(targetCell).perform(); + } + + /** + * @since + * @param string + */ + private void selectPage(String string) { + $(NativeSelectElement.class).id("page").selectByText(string); + grid = $(GridElement.class).first(); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidgetRendererChangeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidgetRendererChangeTest.java new file mode 100644 index 0000000000..1d78358ad2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidgetRendererChangeTest.java @@ -0,0 +1,63 @@ +/* + * 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.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridWidgetRendererChangeTest extends SingleBrowserTest { + + @Test + public void testChangeWidgetRenderer() { + setDebug(true); + openTestURL(); + + selectMenuPath("Component", "Change first renderer"); + + assertNoErrorNotifications(); + + selectMenuPath("Component", "Change first renderer"); + + assertNoErrorNotifications(); + + // First renderer OK + + selectMenuPath("Component", "Change second renderer"); + + assertNoErrorNotifications(); + + selectMenuPath("Component", "Change second renderer"); + + assertNoErrorNotifications(); + + } + + @Override + protected void selectMenu(String menuCaption) { + // GWT menu does not need to be clicked. + selectMenu(menuCaption, false); + } + + @Override + protected WebElement getMenuElement(String menuCaption) { + return getDriver() + .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidthIncreaseTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidthIncreaseTest.java new file mode 100644 index 0000000000..fda1984ccf --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWidthIncreaseTest.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.v7.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.GridWidthIncrease; + +@TestCategory("grid") +public class GridWidthIncreaseTest extends MultiBrowserTest { + + private static int INCREASE_COUNT = 3; + + @Test + public void testColumnsExpandWithGrid() throws IOException { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + double accuracy = 1.0d; + DesiredCapabilities cap = getDesiredCapabilities(); + if (BrowserUtil.isIE(cap, 8) || BrowserUtil.isIE(cap, 9) + || BrowserUtil.isPhantomJS(cap)) { + accuracy = 2.0d; + } + + for (int i = 0; i < INCREASE_COUNT; ++i) { + $(ButtonElement.class).first().click(); + int prevWidth = 0; + for (int c = 0; c < GridWidthIncrease.COLUMN_COUNT; ++c) { + int width = grid.getCell(0, c).getSize().getWidth(); + if (c > 0) { + // check that columns are roughly the same width. + assertEquals("Difference in column widths", prevWidth, + width, accuracy); + } + prevWidth = width; + } + /* + * Column widths should be the same as table wrapper size. Since + * Selenium doesn't support subpixels correctly, we use a rough + * estimation. + */ + assertEquals(grid.getRow(0).getSize().getWidth(), + grid.getTableWrapper().getSize().getWidth(), accuracy); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithBrokenRendererTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithBrokenRendererTest.java new file mode 100644 index 0000000000..a6efe88e32 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithBrokenRendererTest.java @@ -0,0 +1,41 @@ +/* + * 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.Test; + +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridWithBrokenRendererTest extends SingleBrowserTest { + + @Test + public void ensureRendered() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + assertRow(grid, 0, "FI", "", "Finland"); + assertRow(grid, 1, "SE", "", "Sweden"); + } + + private void assertRow(GridElement grid, int row, String... texts) { + for (int column = 0; column < texts.length; column++) { + Assert.assertEquals("Cell " + row + "," + column, texts[column], + grid.getCell(row, column).getText()); + } + + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithLabelEditorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithLabelEditorTest.java new file mode 100644 index 0000000000..6524ee261d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithLabelEditorTest.java @@ -0,0 +1,37 @@ +/* + * 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 org.junit.Test; + +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class GridWithLabelEditorTest extends SingleBrowserTest { + + @Test + public void testNoExceptionOnEdit() { + setDebug(true); + openTestURL(); + + assertNoErrorNotifications(); + + assertEquals("LabelEditor content not correct.", "FooFoo", + $(GridElement.class).first().getEditor().getField(0).getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithoutRendererTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithoutRendererTest.java new file mode 100644 index 0000000000..5ed29705bb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridWithoutRendererTest.java @@ -0,0 +1,43 @@ +/* + * 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.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridWithoutRendererTest extends SingleBrowserTest { + + @Test + public void ensureNoError() { + openTestURL(); + // WebElement errorIndicator = findElement(By + // .cssSelector("v-error-indicator")); + // System.out.println(errorIndicator); + List errorIndicator = findElements( + By.xpath("//span[@class='v-errorindicator']")); + Assert.assertTrue("There should not be an error indicator", + errorIndicator.isEmpty()); + } + +} 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 new file mode 100644 index 0000000000..f5c6bf9889 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/InitialFrozenColumnsTest.java @@ -0,0 +1,42 @@ +/* + * 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.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@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")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/JavaScriptRenderersTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/JavaScriptRenderersTest.java new file mode 100644 index 0000000000..206d597cc1 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/JavaScriptRenderersTest.java @@ -0,0 +1,52 @@ +/* + * 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.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class JavaScriptRenderersTest extends MultiBrowserTest { + + @Test + public void testJavaScriptRenderer() { + setDebug(true); + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + GridCellElement cell_1_1 = grid.getCell(1, 1); + + GridCellElement cell_2_2 = grid.getCell(2, 2); + + // Verify render functionality + Assert.assertEquals("Bean(2, 0)", cell_1_1.getText()); + + Assert.assertEquals("string2", cell_2_2.getText()); + + // Verify init functionality + Assert.assertEquals("1", cell_1_1.getAttribute("column")); + + // Verify onbrowserevent + cell_1_1.click(); + Assert.assertTrue( + cell_1_1.getText().startsWith("Clicked 1 with key 2 at")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/NullHeadersTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/NullHeadersTest.java new file mode 100644 index 0000000000..fa1a9a7318 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/NullHeadersTest.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.v7.tests.components.grid; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +public class NullHeadersTest extends SingleBrowserTest { + + @Test + public void gridWithNullHeadersShouldBeRendered() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertEquals(1, grid.getHeaderCount()); + Assert.assertEquals(3, grid.getHeaderCells(0).size()); + for (int i = 0; i < 3; i++) { + Assert.assertEquals("", grid.getHeaderCell(0, 0).getText()); + } + assertRow(grid, 0, "Finland", "foo", "1"); + assertRow(grid, 1, "Swaziland", "bar", "2"); + assertRow(grid, 2, "Japan", "baz", "3"); + } + + private void assertRow(GridElement grid, int row, String... contents) { + for (int col = 0; col < contents.length; col++) { + Assert.assertEquals(contents[col], + grid.getCell(row, col).getText()); + } + + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/NullRenderersTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/NullRenderersTest.java new file mode 100644 index 0000000000..a8114467d7 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/NullRenderersTest.java @@ -0,0 +1,65 @@ +/* + * 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 org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.CustomRenderer; + +@TestCategory("grid") +public class NullRenderersTest extends MultiBrowserTest { + @Test + public void testDefaults() throws Exception { + openTestURL(); + + GridElement grid = findGridWithDefaults(); + assertEquals("-- No Text --", grid.getCell(0, 0).getText()); + assertEquals("-- No Jokes --", grid.getCell(0, 1).getText()); + assertEquals("-- Never --", grid.getCell(0, 2).getText()); + assertEquals("-- Nothing --", grid.getCell(0, 3).getText()); + assertEquals("-- No Control --", grid.getCell(0, 5).getText()); + } + + @Test + public void testNoDefaults() throws Exception { + openTestURL(); + + GridElement grid = findGridNoDefaults(); + assertEquals("", grid.getCell(0, 0).getText()); + assertEquals("", grid.getCell(0, 1).getText()); + assertEquals("", grid.getCell(0, 2).getText()); + assertEquals("", grid.getCell(0, 3).getText()); + assertEquals("", grid.getCell(0, 5).getText()); + } + + private GridElement findGridWithDefaults() { + return $(GridElement.class).id("test-grid-defaults"); + } + + private GridElement findGridNoDefaults() { + return $(GridElement.class).id("test-grid"); + } + + private LabelElement findDebugLabel() { + return $(LabelElement.class).id(CustomRenderer.DEBUG_LABEL_ID); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/ProgrammaticEditorControlTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/ProgrammaticEditorControlTest.java new file mode 100644 index 0000000000..aae82d1188 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/ProgrammaticEditorControlTest.java @@ -0,0 +1,64 @@ +/* + * 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.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class ProgrammaticEditorControlTest extends SingleBrowserTest { + + @Test + public void multipleOpenFromServerSide() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + ButtonElement editButton = $(ButtonElement.class).caption("Edit") + .first(); + ButtonElement cancelButton = $(ButtonElement.class).caption("Cancel") + .first(); + + editButton.click(); + assertEditorFieldContents(grid, "test"); + cancelButton.click(); + + assertEditorNotPresent(grid); + + editButton.click(); + assertEditorFieldContents(grid, "test"); + } + + private void assertEditorFieldContents(GridElement grid, String text) { + TextFieldElement editorField = wrap(TextFieldElement.class, + grid.getEditor().getField(0)); + Assert.assertEquals(text, editorField.getValue()); + } + + private void assertEditorNotPresent(GridElement grid) { + try { + grid.getEditor(); + Assert.fail("Editor should not be present"); + } catch (Exception e) { + + } + } + +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/SelectDuringInitTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/SelectDuringInitTest.java new file mode 100644 index 0000000000..7d9d62b45c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/SelectDuringInitTest.java @@ -0,0 +1,37 @@ +/* + * 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.Test; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@TestCategory("grid") +public class SelectDuringInitTest extends SingleBrowserTest { + + @Test + public void testSelectDuringInit() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertTrue(grid.getRow(1).isSelected()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/SortableHeaderStylesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/SortableHeaderStylesTest.java new file mode 100644 index 0000000000..3d731e1285 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/SortableHeaderStylesTest.java @@ -0,0 +1,51 @@ +/* + * 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.Test; + +import com.vaadin.tests.tb3.SingleBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.testbench.customelements.OptionGroupElement; + +public class SortableHeaderStylesTest extends SingleBrowserTest { + @Test + public void testSortableHeaderStyles() { + openTestURL(); + + Assert.assertFalse(hasSortableStyle(0)); + for (int i = 1; i < 8; i++) { + Assert.assertTrue(hasSortableStyle(i)); + } + + OptionGroupElement sortableSelector = $(OptionGroupElement.class) + .first(); + + // Toggle sortability + sortableSelector.selectByText("lastName"); + Assert.assertFalse(hasSortableStyle(3)); + + // Toggle back + sortableSelector.selectByText("lastName"); + Assert.assertTrue(hasSortableStyle(3)); + } + + private boolean hasSortableStyle(int column) { + return $(GridElement.class).first().getHeaderCell(0, column) + .getAttribute("class").contains("sortable"); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/WidgetRenderersTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/WidgetRenderersTest.java new file mode 100644 index 0000000000..e3e6c5ba98 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/WidgetRenderersTest.java @@ -0,0 +1,168 @@ +/* + * 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.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.WidgetRenderers; + +/** + * TB tests for the various builtin widget-based renderers. + * + * @since + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class WidgetRenderersTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + + openTestURL(); + } + + @Test + public void testProgressBarRenderer() { + assertTrue(getGridCell(0, 0) + .isElementPresent(By.className("v-progressbar"))); + } + + @Test + public void testButtonRenderer() { + WebElement button = getGridCell(0, 1) + .findElement(By.className("v-nativebutton")); + + button.click(); + + waitUntilTextUpdated(button, "Clicked!"); + } + + @Test + public void testButtonRendererAfterCellBeingFocused() { + GridCellElement buttonCell = getGridCell(0, 1); + assertFalse("cell should not be focused before focusing", + buttonCell.isFocused()); + + // avoid clicking on the button + buttonCell.click(buttonCell.getSize().getWidth() - 10, 5); + assertTrue("cell should be focused after focusing", + buttonCell.isFocused()); + + WebElement button = buttonCell + .findElement(By.className("v-nativebutton")); + assertNotEquals("Button should not be clicked before click", "Clicked!", + button.getText()); + + new Actions(getDriver()).moveToElement(button).click().perform(); + + waitUntilTextUpdated(button, "Clicked!"); + } + + @Test + public void testImageRenderer() { + final WebElement image = getGridCell(0, 2) + .findElement(By.className("gwt-Image")); + + waitUntilmageSrcEndsWith(image, "window/img/close.png"); + + image.click(); + + waitUntilmageSrcEndsWith(image, "window/img/maximize.png"); + } + + private void waitUntilmageSrcEndsWith(final WebElement image, + final String expectedText) { + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + return image.getAttribute("src").endsWith(expectedText); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return String.format( + "image source to update. Supposed to end with '%s' (was: '%s').", + expectedText, image.getAttribute("src")); + } + }); + } + + @Test + public void testColumnReorder() { + $(ButtonElement.class).caption("Change column order").first().click(); + + assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + + assertTrue( + getGridCell(0, 0).isElementPresent(By.className("gwt-Image"))); + assertTrue(getGridCell(0, 1) + .isElementPresent(By.className("v-progressbar"))); + assertTrue(getGridCell(0, 2) + .isElementPresent(By.className("v-nativebutton"))); + } + + @Test + public void testPropertyIdInEvent() { + WebElement button = getGridCell(0, 3) + .findElement(By.className("v-nativebutton")); + + button.click(); + + waitUntilTextUpdated(button, WidgetRenderers.PROPERTY_ID); + } + + GridCellElement getGridCell(int row, int col) { + return $(GridElement.class).first().getCell(row, col); + } + + private void waitUntilTextUpdated(final WebElement button, + final String expectedText) { + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + return button.getText().equals(expectedText); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return String.format("button's text to become '%s' (was: '').", + expectedText, button.getText()); + } + + }); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java new file mode 100644 index 0000000000..356834942d --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -0,0 +1,317 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeatures; + +@TestCategory("grid") +public abstract class EscalatorBasicClientFeaturesTest + extends MultiBrowserTest { + + private static final String LOGICAL_ROW_ATTRIBUTE_NAME = "vLogicalRow"; + private static final String SPACER_CSS_CLASS = "v-escalator-spacer"; + + protected static final String COLUMNS_AND_ROWS = "Columns and Rows"; + + protected static final String COLUMNS = "Columns"; + protected static final String ADD_ONE_COLUMN_TO_BEGINNING = "Add one column to beginning"; + protected static final String ADD_ONE_ROW_TO_BEGINNING = "Add one row to beginning"; + protected static final String ADD_ONE_ROW_TO_END = "Add one row to end"; + protected static final String REMOVE_ONE_COLUMN_FROM_BEGINNING = "Remove one column from beginning"; + protected static final String REMOVE_ONE_ROW_FROM_BEGINNING = "Remove one row from beginning"; + protected static final String REMOVE_ALL_ROWS = "Remove all rows"; + protected static final String REMOVE_50_ROWS_FROM_BOTTOM = "Remove 50 rows from bottom"; + protected static final String REMOVE_50_ROWS_FROM_ALMOST_BOTTOM = "Remove 50 rows from almost bottom"; + protected static final String ADD_ONE_OF_EACH_ROW = "Add one of each row"; + protected static final String RESIZE_FIRST_COLUMN_TO_MAX_WIDTH = "Resize first column to max width"; + protected static final String RESIZE_FIRST_COLUMN_TO_100PX = "Resize first column to 100 px"; + + protected static final String HEADER_ROWS = "Header Rows"; + protected static final String BODY_ROWS = "Body Rows"; + protected static final String FOOTER_ROWS = "Footer Rows"; + + protected static final String SCROLL_TO = "Scroll to..."; + + protected static final String REMOVE_ALL_INSERT_SCROLL = "Remove all, insert 30 and scroll 40px"; + + protected static final String GENERAL = "General"; + protected static final String DETACH_ESCALATOR = "Detach Escalator"; + protected static final String ATTACH_ESCALATOR = "Attach Escalator"; + protected static final String POPULATE_COLUMN_ROW = "Populate Escalator (columns, then rows)"; + protected static final String POPULATE_ROW_COLUMN = "Populate Escalator (rows, then columns)"; + protected static final String CLEAR_COLUMN_ROW = "Clear (columns, then rows)"; + protected static final String CLEAR_ROW_COLUMN = "Clear (rows, then columns)"; + + protected static final String FEATURES = "Features"; + protected static final String FROZEN_COLUMNS = "Frozen columns"; + protected static final String FREEZE_1_COLUMN = "Freeze 1 column"; + protected static final String FREEZE_0_COLUMNS = "Freeze 0 columns"; + protected static final String COLUMN_SPANNING = "Column spanning"; + protected static final String COLSPAN_NORMAL = "Apply normal colspan"; + protected static final String COLSPAN_NONE = "Apply no colspan"; + protected static final String SET_100PX = "Set 100px"; + protected static final String SPACERS = "Spacers"; + protected static final String FOCUSABLE_UPDATER = "Focusable Updater"; + protected static final String SCROLL_HERE_ANY_0PADDING = "Scroll here (ANY, 0)"; + protected static final String SCROLL_HERE_SPACERBELOW_ANY_0PADDING = "Scroll here row+spacer below (ANY, 0)"; + protected static final String REMOVE = "Remove"; + + protected static final String ROW_MINUS1 = "Row -1"; + protected static final String ROW_0 = "Row 0"; + protected static final String ROW_1 = "Row 1"; + protected static final String ROW_25 = "Row 25"; + protected static final String ROW_50 = "Row 50"; + protected static final String ROW_75 = "Row 75"; + protected static final String ROW_99 = "Row 99"; + + @Override + public void setup() throws Exception { + super.setup(); + + setDebug(true); + } + + @Override + protected Class getUIClass() { + return EscalatorBasicClientFeatures.class; + } + + protected TestBenchElement getEscalator() { + By className = By.className("v-escalator"); + if (isElementPresent(className)) { + return (TestBenchElement) findElement(className); + } + return null; + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + protected TestBenchElement getHeaderRow(int row) { + return getRow("thead", row); + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + protected TestBenchElement getBodyRow(int row) { + return getRow("tbody", row); + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + protected TestBenchElement getFooterRow(int row) { + return getRow("tfoot", row); + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + protected TestBenchElement getHeaderCell(int row, int col) { + return getCell("thead", row, col); + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + protected TestBenchElement getBodyCell(int row, int col) { + return getCell("tbody", row, col); + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + protected TestBenchElement getFooterCell(int row, int col) { + return getCell("tfoot", row, col); + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + private TestBenchElement getCell(String sectionTag, int row, int col) { + TestBenchElement rowElement = getRow(sectionTag, row); + By xpath = By.xpath("*[" + (col + 1) + "]"); + if (rowElement != null && rowElement.isElementPresent(xpath)) { + return (TestBenchElement) rowElement.findElement(xpath); + } + return null; + } + + /** + * @param row + * the index of the row element in the section. If negative, the + * calculation starts from the end (-1 is the last, -2 is the + * second-to-last etc) + */ + private TestBenchElement getRow(String sectionTag, int row) { + TestBenchElement escalator = getEscalator(); + WebElement tableSection = escalator.findElement(By.tagName(sectionTag)); + + String xpathExpression = "tr[not(@class='" + SPACER_CSS_CLASS + "')]"; + if (row >= 0) { + int fromFirst = row + 1; + xpathExpression += "[" + fromFirst + "]"; + } else { + int fromLast = Math.abs(row + 1); + xpathExpression += "[last() - " + fromLast + "]"; + } + By xpath = By.xpath(xpathExpression); + if (tableSection != null + && ((TestBenchElement) tableSection).isElementPresent(xpath)) { + return (TestBenchElement) tableSection.findElement(xpath); + } + return null; + } + + @Override + protected void selectMenu(String menuCaption) { + // GWT menu does not need to be clicked. + selectMenu(menuCaption, false); + } + + @Override + protected WebElement getMenuElement(String menuCaption) { + return getDriver() + .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); + } + + protected void assertLogContains(String substring) { + assertTrue("log should've contained, but didn't: " + substring, + getLogText().contains(substring)); + } + + protected void assertLogDoesNotContain(String substring) { + assertFalse("log shouldn't have contained, but did: " + substring, + getLogText().contains(substring)); + } + + private String getLogText() { + WebElement log = findElement(By.cssSelector("#log")); + return log.getText(); + } + + protected void assertLogContainsInOrder(String... substrings) { + String log = getLogText(); + int cursor = 0; + for (String substring : substrings) { + String remainingLog = log.substring(cursor, log.length()); + int substringIndex = remainingLog.indexOf(substring); + if (substringIndex == -1) { + fail("substring \"" + substring + + "\" was not found in order from log."); + } + + cursor += substringIndex + substring.length(); + } + } + + protected void scrollVerticallyTo(int px) { + getVerticalScrollbar().scroll(px); + } + + protected long getScrollTop() { + return ((Long) executeScript("return arguments[0].scrollTop;", + getVerticalScrollbar())).longValue(); + } + + private TestBenchElement getVerticalScrollbar() { + return (TestBenchElement) getEscalator() + .findElement(By.className("v-escalator-scroller-vertical")); + } + + protected void scrollHorizontallyTo(int px) { + getHorizontalScrollbar().scrollLeft(px); + } + + protected long getScrollLeft() { + return ((Long) executeScript("return arguments[0].scrollLeft;", + getHorizontalScrollbar())).longValue(); + } + + protected TestBenchElement getHorizontalScrollbar() { + return (TestBenchElement) getEscalator() + .findElement(By.className("v-escalator-scroller-horizontal")); + } + + @Override + protected Object executeScript(String script, Object... args) { + return ((JavascriptExecutor) getDriver()).executeScript(script, args); + } + + protected void populate() { + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + } + + private List getSpacers() { + return getEscalator().findElements(By.className(SPACER_CSS_CLASS)); + } + + protected boolean spacersAreFoundInDom() { + List spacers = getSpacers(); + return spacers != null && !spacers.isEmpty(); + } + + @SuppressWarnings("boxing") + protected WebElement getSpacer(int logicalRowIndex) { + List spacers = getSpacers(); + System.out.println("size: " + spacers.size()); + for (WebElement spacer : spacers) { + System.out.println(spacer + ", " + logicalRowIndex); + Boolean isInDom = (Boolean) executeScript("return arguments[0]['" + + LOGICAL_ROW_ATTRIBUTE_NAME + "'] === arguments[1]", + spacer, logicalRowIndex); + if (isInDom) { + return spacer; + } + } + return null; + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java new file mode 100644 index 0000000000..f4bd915cce --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicClientFeaturesTest.java @@ -0,0 +1,116 @@ +/* + * 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.basicfeatures; + +import java.util.List; + +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeatures; + +/** + * GridBasicClientFeatures. + * + * @since + * @author Vaadin Ltd + */ +public abstract class GridBasicClientFeaturesTest + extends GridBasicFeaturesTest { + + private boolean composite = false; + + @Override + protected Class getUIClass() { + return GridBasicClientFeatures.class; + } + + @Override + protected String getDeploymentPath() { + String path = super.getDeploymentPath(); + if (composite) { + path += (path.contains("?") ? "&" : "?") + "composite"; + } + return path; + } + + protected void setUseComposite(boolean useComposite) { + composite = useComposite; + } + + @Override + protected void selectMenu(String menuCaption) { + // GWT menu does not need to be clicked. + selectMenu(menuCaption, false); + } + + @Override + protected WebElement getMenuElement(String menuCaption) { + return getDriver() + .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); + } + + @Override + protected GridElement getGridElement() { + if (composite) { + // Composite requires the basic client features widget for subparts + return ((TestBenchElement) findElement( + By.vaadin("//TestWidgetComponent"))) + .wrap(GridElement.class); + } else { + return super.getGridElement(); + } + } + + @Override + protected void assertColumnHeaderOrder(int... indices) { + List headers = getGridHeaderRowCells(); + for (int i = 0; i < indices.length; i++) { + assertColumnHeader("HEADER (0," + indices[i] + ")", headers.get(i)); + } + } + + protected void toggleColumnReorder() { + selectMenuPath("Component", "State", "Column Reordering"); + } + + protected boolean isRowSelected(int index) { + boolean selected = getGridElement().getRow(index).isSelected(); + return selected; + } + + protected void setSelectionModelMulti() { + setSelectionModel("multi"); + } + + protected void setSelectionModelSingle(boolean deselectAllowed) { + String mode = "single"; + if (!deselectAllowed) { + mode += " (no deselect)"; + } + setSelectionModel(mode); + } + + protected void setSelectionModelNone() { + setSelectionModel("none"); + } + + protected void setSelectionModel(String model) { + selectMenuPath("Component", "State", "Selection mode", model); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java new file mode 100644 index 0000000000..7a0c80f11a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridBasicFeaturesTest.java @@ -0,0 +1,255 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; + +@TestCategory("grid") +public abstract class GridBasicFeaturesTest extends MultiBrowserTest { + + public enum CellSide { + LEFT, RIGHT; + } + + @Override + protected boolean requireWindowFocusForIE() { + return true; + } + + @Override + protected Class getUIClass() { + return GridBasicFeatures.class; + } + + protected GridElement getGridElement() { + return ((TestBenchElement) findElement(By.id("testComponent"))) + .wrap(GridElement.class); + } + + protected void scrollGridVerticallyTo(double px) { + executeScript("arguments[0].scrollTop = " + px, + getGridVerticalScrollbar()); + } + + protected void scrollGridHorizontallyTo(double px) { + executeScript("arguments[0].scrollLeft = " + px, + getGridHorizontalScrollbar()); + } + + protected int getGridVerticalScrollPos() { + return ((Number) executeScript("return arguments[0].scrollTop", + getGridVerticalScrollbar())).intValue(); + } + + protected List getGridHeaderRowCells() { + List headerCells = new ArrayList(); + for (int i = 0; i < getGridElement().getHeaderCount(); ++i) { + headerCells.addAll(getGridElement().getHeaderCells(i)); + } + return headerCells; + } + + protected List getGridFooterRowCells() { + List footerCells = new ArrayList(); + for (int i = 0; i < getGridElement().getFooterCount(); ++i) { + footerCells.addAll(getGridElement().getFooterCells(i)); + } + return footerCells; + } + + protected WebElement getEditor() { + List elems = getGridElement() + .findElements(By.className("v-grid-editor")); + + assertLessThanOrEqual("number of editors", elems.size(), 1); + + return elems.isEmpty() ? null : elems.get(0); + } + + private Object executeScript(String script, WebElement element) { + final WebDriver driver = getDriver(); + if (driver instanceof JavascriptExecutor) { + final JavascriptExecutor je = (JavascriptExecutor) driver; + return je.executeScript(script, element); + } else { + throw new IllegalStateException("current driver " + + getDriver().getClass().getName() + " is not a " + + JavascriptExecutor.class.getSimpleName()); + } + } + + protected WebElement getGridVerticalScrollbar() { + return getDriver().findElement(By.xpath( + "//div[contains(@class, \"v-grid-scroller-vertical\")]")); + } + + protected WebElement getGridHorizontalScrollbar() { + return getDriver().findElement(By.xpath( + "//div[contains(@class, \"v-grid-scroller-horizontal\")]")); + } + + /** + * Reloads the page without restartApplication. This occasionally breaks + * stuff. + */ + protected void reopenTestURL() { + String testUrl = getTestUrl(); + testUrl = testUrl.replace("?restartApplication", "?"); + testUrl = testUrl.replace("?&", "?"); + driver.get(testUrl); + } + + protected void focusCell(int row, int column) { + getGridElement().getCell(row, column).click(); + } + + protected void setFrozenColumns(int numberOfFrozenColumns) { + selectMenuPath("Component", "State", "Frozen column count", + Integer.toString(numberOfFrozenColumns)); + } + + protected void assertColumnHeaderOrder(int... indices) { + List headers = getGridHeaderRowCells(); + for (int i = 0; i < indices.length; i++) { + assertColumnHeader("Column " + indices[i], headers.get(i)); + } + } + + protected void assertColumnHeader(String expectedHeaderCaption, + TestBenchElement testBenchElement) { + assertEquals(expectedHeaderCaption.toLowerCase(), + testBenchElement.getText().toLowerCase()); + } + + protected GridCellElement getDefaultColumnHeader(int index) { + List headerRowCells = getGridElement() + .getHeaderCells(0); + return headerRowCells.get(index); + } + + protected void dragAndDropDefaultColumnHeader(int draggedColumnHeaderIndex, + int onTopOfColumnHeaderIndex, CellSide cellSide) { + GridCellElement columnHeader = getDefaultColumnHeader( + onTopOfColumnHeaderIndex); + new Actions(getDriver()) + .clickAndHold(getDefaultColumnHeader(draggedColumnHeaderIndex)) + .moveToElement(columnHeader, getHorizontalOffsetForDragAndDrop( + columnHeader, cellSide), 0) + .release().perform(); + } + + private int getHorizontalOffsetForDragAndDrop(GridCellElement columnHeader, + CellSide cellSide) { + if (cellSide == CellSide.LEFT) { + return 5; + } else { + int half = columnHeader.getSize().getWidth() / 2; + return half + (half / 2); + } + } + + protected void dragAndDropColumnHeader(int headerRow, + int draggedColumnHeaderIndex, int onTopOfColumnHeaderIndex, + CellSide cellSide) { + GridCellElement headerCell = getGridElement().getHeaderCell(headerRow, + onTopOfColumnHeaderIndex); + new Actions(getDriver()) + .clickAndHold(getGridElement().getHeaderCell(headerRow, + draggedColumnHeaderIndex)) + .moveToElement(headerCell, + getHorizontalOffsetForDragAndDrop(headerCell, cellSide), + 0) + .release().perform(); + } + + protected void dragAndDropColumnHeader(int headerRow, + int draggedColumnHeaderIndex, int onTopOfColumnHeaderIndex, + int horizontalOffset) { + GridCellElement headerCell = getGridElement().getHeaderCell(headerRow, + onTopOfColumnHeaderIndex); + new Actions(getDriver()) + .clickAndHold(getGridElement().getHeaderCell(headerRow, + draggedColumnHeaderIndex)) + .moveToElement(headerCell, horizontalOffset, 0).release() + .perform(); + } + + protected void assertColumnIsSorted(int index) { + WebElement columnHeader = getDefaultColumnHeader(index); + assertTrue(columnHeader.getAttribute("class").contains("sort")); + } + + protected void assertFocusedCell(int row, int column) { + assertTrue(getGridElement().getCell(row, column).getAttribute("class") + .contains("focused")); + } + + protected WebElement getSidebarPopup() { + List elements = findElements( + By.className("v-grid-sidebar-popup")); + if (elements.isEmpty()) { + getSidebarOpenButton().click(); + elements = findElements(By.className("v-grid-sidebar-popup")); + } + return elements.isEmpty() ? null : elements.get(0); + } + + protected WebElement getSidebarPopupIfPresent() { + List elements = findElements( + By.className("v-grid-sidebar-popup")); + return elements.isEmpty() ? null : elements.get(0); + } + + protected WebElement getSidebarOpenButton() { + List elements = findElements( + By.className("v-grid-sidebar-button")); + return elements.isEmpty() ? null : elements.get(0); + } + + /** + * Returns the toggle inside the sidebar for hiding the column at the given + * index, or null if not found. + */ + protected WebElement getColumnHidingToggle(int columnIndex) { + WebElement sidebar = getSidebarPopup(); + List elements = sidebar + .findElements(By.className("column-hiding-toggle")); + for (WebElement e : elements) { + if ((e.getText().toLowerCase()) + .startsWith("column " + columnIndex)) { + return e; + } + } + return null; + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java new file mode 100644 index 0000000000..02e1b7f6e4 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientDataSourcesTest.java @@ -0,0 +1,166 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridClientDataSourcesTest extends MultiBrowserTest { + + @Before + public void before() { + openTestURL(); + } + + @Test + public void normalRestishDatasource() throws Exception { + selectMenuPath("DataSources", "RESTish", "Use"); + assertCellPresent("cell 0 #0"); + + scrollToBottom(); + assertCellPresent("cell 199 #0"); + assertCellNotPresent("cell 200 #0"); + } + + @Test + public void growOnRequestRestishDatasource() throws Exception { + selectMenuPath("DataSources", "RESTish", "Use"); + selectMenuPath("DataSources", "RESTish", "Next request +10"); + + scrollToBottom(); + /* second scroll needed because of scrollsize change after scrolling */ + scrollToBottom(); + + assertCellPresent("cell 209 #1"); + assertCellNotPresent("cell 210 #1"); + } + + @Test + public void shrinkOnRequestRestishDatasource() throws Exception { + selectMenuPath("DataSources", "RESTish", "Use"); + scrollToBottom(); + + selectMenuPath("DataSources", "RESTish", "Next request -10"); + scrollToTop(); + + assertCellPresent("cell 0 #1"); + } + + @Test + public void pushChangeRestishDatasource() throws Exception { + selectMenuPath("DataSources", "RESTish", "Use"); + selectMenuPath("DataSources", "RESTish", "Push data change"); + assertCellPresent("cell 0 #1"); + assertCellNotPresent("cell 0 #0"); + } + + @Test + public void growOnPushRestishDatasource() throws Exception { + selectMenuPath("DataSources", "RESTish", "Use"); + selectMenuPath("DataSources", "RESTish", "Push data change +10"); + assertCellPresent("cell 0 #1"); + assertCellNotPresent("cell 0 #0"); + scrollToBottom(); + assertCellPresent("cell 209 #1"); + } + + @Test + public void shrinkOnPushRestishDatasource() throws Exception { + selectMenuPath("DataSources", "RESTish", "Use"); + scrollToBottom(); + + selectMenuPath("DataSources", "RESTish", "Push data change -10"); + assertCellPresent("cell 189 #1"); + assertCellNotPresent("cell 189 #0"); + assertCellNotPresent("cell 199 #1"); + assertCellNotPresent("cell 199 #0"); + } + + private void assertCellPresent(String content) { + assertNotNull( + "A cell with content \"" + content + "\" should've been found", + findByXPath("//td[text()='" + content + "']")); + } + + private void assertCellNotPresent(String content) { + assertNull( + "A cell with content \"" + content + + "\" should've not been found", + findByXPath("//td[text()='" + content + "']")); + } + + private void scrollToTop() { + scrollVerticallyTo(0); + } + + private void scrollToBottom() { + scrollVerticallyTo(9999); + } + + private WebElement findByXPath(String string) { + if (isElementPresent(By.xpath(string))) { + return findElement(By.xpath(string)); + } else { + return null; + } + } + + private void scrollVerticallyTo(int px) { + executeScript("arguments[0].scrollTop = " + px, + findVerticalScrollbar()); + } + + private Object executeScript(String script, Object args) { + final WebDriver driver = getDriver(); + if (driver instanceof JavascriptExecutor) { + final JavascriptExecutor je = (JavascriptExecutor) driver; + return je.executeScript(script, args); + } else { + throw new IllegalStateException("current driver " + + getDriver().getClass().getName() + " is not a " + + JavascriptExecutor.class.getSimpleName()); + } + } + + private WebElement findVerticalScrollbar() { + return getDriver().findElement(By.xpath( + "//div[contains(@class, " + "\"v-grid-scroller-vertical\")]")); + } + + @Override + protected void selectMenu(String menuCaption) { + // GWT menu does not need to be clicked. + selectMenu(menuCaption, false); + } + + @Override + protected WebElement getMenuElement(String menuCaption) { + return getDriver() + .findElement(By.xpath("//td[text() = '" + menuCaption + "']")); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientHeightByRowOnInitTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientHeightByRowOnInitTest.java new file mode 100644 index 0000000000..3d77afe01e --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridClientHeightByRowOnInitTest.java @@ -0,0 +1,20 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@SuppressWarnings("all") +@TestCategory("grid") +public class GridClientHeightByRowOnInitTest extends MultiBrowserTest { + @Test + public void gridHeightIsMoreThanACoupleOfRows() { + openTestURL(); + int height = findElement(By.className("v-grid")).getSize().getHeight(); + assertGreater( + "Grid should be much taller than 150px (was " + height + "px)", + height, 150); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridColumnHidingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridColumnHidingTest.java new file mode 100644 index 0000000000..f038aa165b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridColumnHidingTest.java @@ -0,0 +1,1096 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; + +@TestCategory("grid") +public class GridColumnHidingTest extends GridBasicClientFeaturesTest { + + private static final String CAPTION_0_1 = "Join column cells 0, 1"; + private static final String CAPTION_1_2 = "Join columns 1, 2"; + private static final String CAPTION_3_4_5 = "Join columns 3, 4, 5"; + private static final String CAPTION_ALL = "Join all columns"; + + @Before + public void before() { + openTestURL(); + } + + @Test + public void testColumnHiding_hidingColumnsFromAPI_works() { + selectMenuPath("Component", "State", "Width", "1000px"); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(1); + toggleHideColumnAPI(2); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(4, 5, 6, 7, 8); + } + + @Test + public void testColumnHiding_unhidingColumnsFromAPI_works() { + selectMenuPath("Component", "State", "Width", "1000px"); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(1); + toggleHideColumnAPI(2); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 4, 5, 6, 7, 8); + + toggleHideColumnAPI(1); + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 2, 4, 5, 6); + } + + @Test + public void testColumnHiding_hidingUnhidingFromAPI_works() { + selectMenuPath("Component", "State", "Width", "1000px"); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 3, 4, 5, 6); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 3, 4, 5, 6); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6); + } + + @Test + public void testColumnHiding_changeVisibilityAPI_triggersClientSideEvent() { + assertColumnHeaderOrder(0, 1, 2, 3, 4); + selectMenuPath("Component", "Internals", "Listeners", + "Add Column Visibility Change listener"); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 3, 4); + + WebElement webElement = findElement(By.id("columnvisibility")); + int counter = Integer.parseInt(webElement.getAttribute("counter")); + int columnIndex = Integer + .parseInt(webElement.getAttribute("columnindex")); + boolean userOriginated = Boolean + .parseBoolean(webElement.getAttribute("useroriginated")); + boolean hidden = Boolean + .parseBoolean(webElement.getAttribute("ishidden")); + + assertNotNull("no event fired", webElement); + assertEquals(1, counter); + assertEquals(2, columnIndex); + assertEquals(false, userOriginated); + assertEquals(true, hidden); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + webElement = findElement(By.id("columnvisibility")); + counter = Integer.parseInt(webElement.getAttribute("counter")); + columnIndex = Integer.parseInt(webElement.getAttribute("columnIndex")); + userOriginated = Boolean + .parseBoolean(webElement.getAttribute("userOriginated")); + hidden = Boolean.parseBoolean(webElement.getAttribute("ishidden")); + + assertNotNull("no event fired", webElement); + assertEquals(2, counter); + assertEquals(2, columnIndex); + assertEquals(false, userOriginated); + assertEquals(false, hidden); + } + + @Test + public void testColumnHiding_changeVisibilityToggle_triggersClientSideEvent() { + assertColumnHeaderOrder(0, 1, 2, 3, 4); + selectMenuPath("Component", "Internals", "Listeners", + "Add Column Visibility Change listener"); + + toggleHidableColumnAPI(2); + clickSidebarOpenButton(); + getColumnHidingToggle(2).click(); + assertColumnHeaderOrder(0, 1, 3, 4); + + WebElement webElement = findElement(By.id("columnvisibility")); + int counter = Integer.parseInt(webElement.getAttribute("counter")); + int columnIndex = Integer + .parseInt(webElement.getAttribute("columnindex")); + boolean userOriginated = Boolean + .parseBoolean(webElement.getAttribute("useroriginated")); + boolean hidden = Boolean + .parseBoolean(webElement.getAttribute("ishidden")); + + assertNotNull("no event fired", webElement); + assertEquals(1, counter); + assertEquals(2, columnIndex); + assertEquals(true, userOriginated); + assertEquals(true, hidden); + + getColumnHidingToggle(2).click(); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + webElement = findElement(By.id("columnvisibility")); + counter = Integer.parseInt(webElement.getAttribute("counter")); + columnIndex = Integer.parseInt(webElement.getAttribute("columnIndex")); + userOriginated = Boolean + .parseBoolean(webElement.getAttribute("userOriginated")); + hidden = Boolean.parseBoolean(webElement.getAttribute("ishidden")); + + assertNotNull("no event fired", webElement); + assertEquals(2, counter); + assertEquals(2, columnIndex); + assertEquals(true, userOriginated); + assertEquals(false, hidden); + } + + @Test + public void testColumnHidability_onTriggerColumnHidability_showsSidebarButton() { + WebElement sidebar = getSidebarOpenButton(); + assertNull(sidebar); + + toggleHidableColumnAPI(0); + + sidebar = getSidebarOpenButton(); + assertNotNull(sidebar); + } + + @Test + public void testColumnHidability_triggeringColumnHidabilityWithSeveralColumns_showsAndHidesSiderbarButton() { + verifySidebarNotVisible(); + + toggleHidableColumnAPI(3); + toggleHidableColumnAPI(4); + + verifySidebarVisible(); + + toggleHidableColumnAPI(3); + + verifySidebarVisible(); + + toggleHidableColumnAPI(4); + + verifySidebarNotVisible(); + } + + @Test + public void testColumnHidability_clickingSidebarButton_opensClosesSidebar() { + toggleHidableColumnAPI(0); + verifySidebarClosed(); + + clickSidebarOpenButton(); + + verifySidebarOpened(); + + clickSidebarOpenButton(); + + verifySidebarClosed(); + } + + @Test + public void testColumnHidability_settingColumnHidable_showsToggleInSidebar() { + toggleHidableColumnAPI(0); + verifySidebarClosed(); + clickSidebarOpenButton(); + verifySidebarOpened(); + + verifyColumnHidingOption(0, false); + } + + @Test + public void testColumnHiding_hidingColumnWithToggle_works() { + assertColumnHeaderOrder(0, 1, 2, 3, 4); + toggleHidableColumnAPI(0); + verifySidebarClosed(); + clickSidebarOpenButton(); + verifySidebarOpened(); + verifyColumnHidingOption(0, false); + + getColumnHidingToggle(0).click(); + verifyColumnHidingOption(0, true); + assertColumnHeaderOrder(1, 2, 3, 4); + + getColumnHidingToggle(0).click(); + verifyColumnHidingOption(0, false); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + } + + @Test + public void testColumnHiding_updatingHiddenWhileSidebarClosed_updatesToggleValue() { + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(3); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 1, 2, 4); + verifySidebarClosed(); + + clickSidebarOpenButton(); + verifySidebarOpened(); + verifyColumnHidingOption(0, false); + verifyColumnHidingOption(3, true); + + clickSidebarOpenButton(); + verifySidebarClosed(); + + toggleHideColumnAPI(0); + toggleHideColumnAPI(3); + + clickSidebarOpenButton(); + verifySidebarOpened(); + verifyColumnHidingOption(0, true); + verifyColumnHidingOption(3, false); + + } + + @Test + public void testColumnHiding_hidingMultipleColumnsWithToggle_hidesColumns() { + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + toggleHideColumnAPI(1); + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(1); + toggleHidableColumnAPI(2); + toggleHidableColumnAPI(3); + toggleHidableColumnAPI(4); + verifySidebarClosed(); + assertColumnHeaderOrder(0, 2, 3, 4); + + clickSidebarOpenButton(); + verifySidebarOpened(); + verifyColumnHidingOption(0, false); + verifyColumnHidingOption(1, true); + verifyColumnHidingOption(2, false); + verifyColumnHidingOption(3, false); + verifyColumnHidingOption(4, false); + + // must be done in a funny order so that the header indexes won't break + // (because of data source uses counter) + getColumnHidingToggle(1).click(); + getColumnHidingToggle(2).click(); + getColumnHidingToggle(3).click(); + getColumnHidingToggle(4).click(); + getColumnHidingToggle(0).click(); + verifyColumnHidingOption(0, true); + verifyColumnHidingOption(1, false); + verifyColumnHidingOption(2, true); + verifyColumnHidingOption(3, true); + verifyColumnHidingOption(4, true); + + assertColumnHeaderOrder(1, 5, 6, 7); + + getColumnHidingToggle(0).click(); + getColumnHidingToggle(2).click(); + getColumnHidingToggle(1).click(); + verifyColumnHidingOption(0, false); + verifyColumnHidingOption(1, true); + verifyColumnHidingOption(2, false); + assertColumnHeaderOrder(0, 2, 5, 6); + } + + @Test + public void testColumnHidability_changingHidabilityWhenSidebarClosed_addsRemovesToggles() { + toggleHideColumnAPI(0); + toggleHideColumnAPI(4); + assertColumnHeaderOrder(1, 2, 3, 5); + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(3); + toggleHidableColumnAPI(4); + verifySidebarClosed(); + + clickSidebarOpenButton(); + verifySidebarOpened(); + verifyColumnHidingOption(0, true); + verifyColumnHidingOption(3, false); + verifyColumnHidingOption(4, true); + + clickSidebarOpenButton(); + verifySidebarClosed(); + + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(3); + + verifySidebarClosed(); + clickSidebarOpenButton(); + verifySidebarOpened(); + verifyColumnHidingOption(4, true); + + assertNull(getColumnHidingToggle(0)); + assertNull(getColumnHidingToggle(3)); + } + + @Test + public void testColumnHidability_togglingHidability_placesTogglesInRightOrder() { + toggleHidableColumnAPI(3); + toggleHidableColumnAPI(2); + clickSidebarOpenButton(); + + verifyColumnHidingTogglesOrder(2, 3); + + toggleHidableColumnAPI(1); + toggleHidableColumnAPI(2); + toggleHidableColumnAPI(6); + toggleHidableColumnAPI(0); + + // Selecting from the menu closes the sidebar + clickSidebarOpenButton(); + + verifyColumnHidingTogglesOrder(0, 1, 3, 6); + + toggleHidableColumnAPI(2); + toggleHidableColumnAPI(4); + toggleHidableColumnAPI(7); + + clickSidebarOpenButton(); + + verifyColumnHidingTogglesOrder(0, 1, 2, 3, 4, 6, 7); + } + + @Test + public void testColumnHidability_reorderingColumns_updatesColumnToggleOrder() { + selectMenuPath("Component", "State", "Width", "1000px"); + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(1); + toggleHidableColumnAPI(3); + toggleHidableColumnAPI(4); + clickSidebarOpenButton(); + verifyColumnHidingTogglesOrder(0, 1, 3, 4); + clickSidebarOpenButton(); + + toggleColumnReorder(); + dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); + + assertColumnHeaderOrder(3, 0, 1, 2, 4); + clickSidebarOpenButton(); + verifyColumnHidingTogglesOrder(3, 0, 1, 4); + + clickSidebarOpenButton(); + dragAndDropColumnHeader(0, 1, 3, CellSide.RIGHT); + dragAndDropColumnHeader(0, 4, 0, CellSide.LEFT); + dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); + + assertColumnHeaderOrder(2, 4, 3, 1, 0); + clickSidebarOpenButton(); + verifyColumnHidingTogglesOrder(4, 3, 1, 0); + } + + @Test + public void testColumnHidingAndReorder_reorderingOverHiddenColumn_orderIsKept() { + selectMenuPath("Component", "State", "Width", "1000px"); + toggleColumnReorder(); + toggleHideColumnAPI(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + + dragAndDropColumnHeader(0, 1, 0, CellSide.LEFT); + assertColumnHeaderOrder(2, 1, 3, 4, 5); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(0, 2, 1, 3, 4, 5); + + toggleHideColumnAPI(1); + assertColumnHeaderOrder(0, 2, 3, 4, 5); + + // right side of hidden column + dragAndDropColumnHeader(0, 0, 2, CellSide.LEFT); + assertColumnHeaderOrder(2, 0, 3, 4, 5); + + toggleHideColumnAPI(1); + assertColumnHeaderOrder(2, 1, 0, 3, 4, 5); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(2, 1, 3, 4, 5); + + // left side of hidden column + dragAndDropColumnHeader(0, 0, 1, CellSide.RIGHT); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(1, 0, 2, 3, 4, 5); + } + + @Test + public void testColumnHidingAndReorder_reorderingWithMultipleHiddenColumns_works() { + selectMenuPath("Component", "State", "Width", "1000px"); + toggleColumnReorder(); + toggleHideColumnAPI(2); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 1, 4, 5, 6); + + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + assertColumnHeaderOrder(1, 0, 4, 5, 6); + + toggleHideColumnAPI(3); + assertColumnHeaderOrder(1, 3, 0, 4, 5, 6); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(1, 2, 3, 0, 4, 5, 6); + + toggleHideColumnAPI(0); + toggleHideColumnAPI(4); + assertColumnHeaderOrder(1, 2, 3, 5, 6); + + dragAndDropDefaultColumnHeader(4, 3, CellSide.LEFT); + assertColumnHeaderOrder(1, 2, 3, 6, 5); + + dragAndDropDefaultColumnHeader(4, 2, CellSide.RIGHT); + assertColumnHeaderOrder(1, 2, 3, 5, 6); + + toggleHideColumnAPI(0); + assertColumnHeaderOrder(1, 2, 3, 0, 5, 6); + + toggleHideColumnAPI(4); + assertColumnHeaderOrder(1, 2, 3, 0, 4, 5, 6); + } + + @Test + public void testReorderingHiddenColumns_movingHiddenColumn_indexIsUpdated() { + selectMenuPath("Component", "State", "Width", "1000px"); + toggleHideColumnAPI(2); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 1, 4, 5, 6); + + moveColumnLeft(3); + assertColumnHeaderOrder(0, 1, 4, 5, 6); + + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 1, 3, 4, 5, 6); + toggleHideColumnAPI(2); + assertColumnHeaderOrder(0, 1, 3, 2, 4, 5, 6); + + toggleHideColumnAPI(2); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 1, 4, 5, 6); + + moveColumnLeft(2); + moveColumnLeft(2); + moveColumnLeft(2); + assertColumnHeaderOrder(0, 1, 4, 5, 6); + + toggleHideColumnAPI(2); + assertColumnHeaderOrder(2, 0, 1, 4, 5, 6); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(2, 0, 1, 3, 4, 5, 6); + } + + // keyboard actions not working in client side test case? + @Test + @Ignore + public void testNavigationWithHiddenColumns_navigatingOverHiddenColumn_goesToNextVisibleColumn() { + selectMenuPath("Component", "State", "Width", "1000px"); + toggleHideColumnAPI(2); + toggleHideColumnAPI(3); + assertColumnHeaderOrder(0, 1, 4, 5, 6); + + getGridElement().getCell(2, 4).click(); + GridCellElement cell = getGridElement().getCell(2, 4); + assertTrue(cell.isFocused()); + + new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT); + cell = getGridElement().getCell(2, 1); + assertTrue(cell.isFocused()); + + new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT); + cell = getGridElement().getCell(2, 4); + assertTrue(cell.isFocused()); + } + + @Test + public void testNavigationWithHiddenColumns_hiddenFirstAndLastColumn_keepsNavigation() { + selectMenuPath("Component", "State", "Width", "1000px"); + toggleHideColumnAPI(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5, 6); + + getGridElement().getCell(2, 1).click(); + assertTrue(getGridElement().getCell(2, 1).isFocused()); + + new Actions(getDriver()).sendKeys(Keys.ARROW_LEFT); + GridCellElement cell = getGridElement().getCell(2, 1); + assertTrue(cell.isFocused()); + + scrollGridHorizontallyTo(10000); + + // + getGridElement().getHeaderCell(0, 9).click(); + cell = getGridElement().getHeaderCell(0, 9); + assertTrue(cell.isFocused()); + toggleHideColumnAPI(10); + toggleHideColumnAPI(11); + + new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT); + new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT); + toggleHideColumnAPI(10); + toggleHideColumnAPI(11); + cell = getGridElement().getHeaderCell(0, 9); + assertTrue(cell.isFocused()); + } + + @Test + public void testFrozenColumnHiding_lastFrozenColumnHidden_isFrozenWhenMadeVisible() { + toggleFrozenColumns(2); + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(1); + getSidebarOpenButton().click(); + verifyColumnIsFrozen(0); + verifyColumnIsFrozen(1); + verifyColumnIsNotFrozen(2); + assertColumnHeaderOrder(0, 1, 2, 3); + + getColumnHidingToggle(1).click(); + verifyColumnIsFrozen(0); + // the grid element indexing doesn't take hidden columns into account! + verifyColumnIsNotFrozen(1); + assertColumnHeaderOrder(0, 2, 3); + + getColumnHidingToggle(0).click(); + verifyColumnIsNotFrozen(0); + assertColumnHeaderOrder(2, 3, 4); + + getColumnHidingToggle(0).click(); + assertColumnHeaderOrder(0, 2, 3); + verifyColumnIsFrozen(0); + verifyColumnIsNotFrozen(1); + + getColumnHidingToggle(1).click(); + assertColumnHeaderOrder(0, 1, 2, 3); + verifyColumnIsFrozen(0); + verifyColumnIsFrozen(1); + verifyColumnIsNotFrozen(2); + } + + @Test + public void testFrozenColumnHiding_columnHiddenFrozenCountChanged_columnIsFrozenWhenVisible() { + toggleHidableColumnAPI(1); + toggleHidableColumnAPI(2); + getSidebarOpenButton().click(); + getColumnHidingToggle(1).click(); + getColumnHidingToggle(2).click(); + assertColumnHeaderOrder(0, 3, 4); + + toggleFrozenColumns(3); + verifyColumnIsFrozen(0); + // the grid element indexing doesn't take hidden columns into account! + verifyColumnIsNotFrozen(1); + verifyColumnIsNotFrozen(2); + + getSidebarOpenButton().click(); + getColumnHidingToggle(2).click(); + verifyColumnIsFrozen(0); + verifyColumnIsFrozen(1); + verifyColumnIsNotFrozen(2); + verifyColumnIsNotFrozen(3); + + getColumnHidingToggle(1).click(); + verifyColumnIsFrozen(0); + verifyColumnIsFrozen(1); + verifyColumnIsFrozen(2); + verifyColumnIsNotFrozen(3); + verifyColumnIsNotFrozen(4); + } + + @Test + public void testSpannedCells_hidingColumnInBeginning_rendersSpannedCellCorrectly() { + loadSpannedCellsFixture(); + verifySpannedCellsFixtureStart(); + + toggleHideColumnAPI(0); + + verifyNumberOfCellsInHeader(0, 7); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 6); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 2, CAPTION_3_4_5); + verifyHeaderCellContent(2, 0, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 1); + verifyHeaderCellColspan(1, 2, 3); + verifyHeaderCellColspan(2, 1, 2); + + toggleHideColumnAPI(0); + + verifySpannedCellsFixtureStart(); + + toggleHideColumnAPI(1); + + verifyNumberOfCellsInHeader(0, 7); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 7); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 2, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 1); + verifyHeaderCellColspan(1, 2, 3); + verifyHeaderCellColspan(2, 1, 1); + + toggleHideColumnAPI(3); + + verifyNumberOfCellsInHeader(0, 6); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 6); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 2, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 1); + verifyHeaderCellColspan(1, 2, 2); + verifyHeaderCellColspan(2, 1, 1); + + toggleHideColumnAPI(1); + + verifyNumberOfCellsInHeader(0, 7); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 6); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 3, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 2); + verifyHeaderCellColspan(1, 3, 2); + verifyHeaderCellColspan(2, 1, 2); + + toggleHideColumnAPI(3); + + verifySpannedCellsFixtureStart(); + } + + @Test + public void testSpannedCells_hidingColumnInMiddle_rendersSpannedCellCorrectly() { + loadSpannedCellsFixture(); + verifySpannedCellsFixtureStart(); + + toggleHideColumnAPI(4); + + verifyNumberOfCellsInHeader(0, 7); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 6); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 3, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 2); + verifyHeaderCellColspan(1, 3, 2); + verifyHeaderCellColspan(2, 1, 2); + + toggleHideColumnAPI(4); + + verifySpannedCellsFixtureStart(); + } + + @Test + public void testSpannedCells_hidingColumnInEnd_rendersSpannedCellCorrectly() { + loadSpannedCellsFixture(); + verifySpannedCellsFixtureStart(); + + toggleHideColumnAPI(1); + + verifyNumberOfCellsInHeader(0, 7); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 7); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 2, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 1, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 1); + verifyHeaderCellColspan(1, 2, 3); + verifyHeaderCellColspan(2, 1, 1); + + toggleHideColumnAPI(1); + + verifySpannedCellsFixtureStart(); + + toggleHideColumnAPI(2); + + verifyNumberOfCellsInHeader(0, 7); + verifyNumberOfCellsInHeader(1, 4); + verifyNumberOfCellsInHeader(2, 7); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 3, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 2); + verifyHeaderCellColspan(1, 3, 3); + verifyHeaderCellColspan(2, 1, 1); + + toggleHideColumnAPI(5); + + verifyNumberOfCellsInHeader(0, 6); + verifyNumberOfCellsInHeader(1, 4); + verifyNumberOfCellsInHeader(2, 6); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 3, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 2); + verifyHeaderCellColspan(1, 3, 2); + verifyHeaderCellColspan(2, 1, 1); + + toggleHideColumnAPI(5); + toggleHideColumnAPI(2); + + verifySpannedCellsFixtureStart(); + } + + @Test + public void testSpannedCells_spanningCellOverHiddenColumn_rendersSpannedCellCorrectly() { + selectMenuPath("Component", "State", "Width", "1000px"); + appendHeaderRow(); + toggleHideColumnAPI(4); + toggleHideColumnAPI(8); + toggleHideColumnAPI(9); + toggleHideColumnAPI(10); + toggleHideColumnAPI(11); + assertColumnHeaderOrder(0, 1, 2, 3, 5, 6, 7); + verifyNumberOfCellsInHeader(1, 7); + + mergeHeaderCellsTwoThreeFour(2); + + verifyNumberOfCellsInHeader(1, 6); + verifyHeaderCellContent(1, 3, CAPTION_3_4_5); + verifyHeaderCellColspan(1, 3, 2); + } + + @Test + public void testSpannedCells_spanningCellAllHiddenColumns_rendersSpannedCellCorrectly() { + selectMenuPath("Component", "State", "Width", "1000px"); + appendHeaderRow(); + toggleHideColumnAPI(3); + toggleHideColumnAPI(4); + toggleHideColumnAPI(5); + toggleHideColumnAPI(8); + toggleHideColumnAPI(9); + toggleHideColumnAPI(10); + toggleHideColumnAPI(11); + assertColumnHeaderOrder(0, 1, 2, 6, 7); + verifyNumberOfCellsInHeader(1, 5); + + mergeHeaderCellsTwoThreeFour(2); + + verifyNumberOfCellsInHeader(1, 5); + verifyHeaderCellColspan(1, 0, 1); + verifyHeaderCellColspan(1, 1, 1); + verifyHeaderCellColspan(1, 2, 1); + verifyHeaderCellColspan(1, 3, 1); + verifyHeaderCellColspan(1, 4, 1); + } + + @Test + public void testColumnHiding_detailsRowIsOpen_renderedCorrectly() { + selectMenuPath("Component", "Row details", "Set generator"); + selectMenuPath("Component", "Row details", "Toggle details for...", + "Row 1"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + Assert.assertNotNull("Details not found", + getGridElement().getDetails(1)); + + toggleHideColumnAPI(0); + + assertColumnHeaderOrder(1, 2, 3, 4); + Assert.assertNotNull("Details not found", + getGridElement().getDetails(1)); + + toggleHideColumnAPI(0); + + assertColumnHeaderOrder(0, 1, 2, 3, 4); + Assert.assertNotNull("Details not found", + getGridElement().getDetails(1)); + } + + @Test + public void testHideShowAllColumns() { + selectMenuPath("Component", "State", "Width", "1000px"); + int colCount = 12; + for (int i = 0; i < colCount; i++) { + toggleHidableColumnAPI(i); + } + clickSidebarOpenButton(); + for (int i = 0; i < colCount; i++) { + getColumnHidingToggle(i).click(); + } + + clickSidebarOpenButton(); + // All columns hidden + assertEquals(0, getGridHeaderRowCells().size()); + clickSidebarOpenButton(); + for (int i = 0; i < colCount; i++) { + getColumnHidingToggle(i).click(); + } + + assertEquals(colCount, getGridHeaderRowCells().size()); + } + + @Test + public void testColumnHidingPopupClosedWhenClickingOutside() { + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + getSidebarOpenButton().click(); + verifySidebarOpened(); + // Click somewhere far from Grid. + new Actions(getDriver()) + .moveToElement(findElement(By.className("v-app")), 600, 600) + .click().perform(); + verifySidebarClosed(); + } + + @Test + public void hideScrollAndShow() { + toggleHidableColumnAPI(1); + toggleHideColumnAPI(1); + + getGridElement().scrollToRow(500); + Assert.assertEquals("(500, 0)", + getGridElement().getCell(500, 0).getText()); + Assert.assertEquals("(500, 2)", + getGridElement().getCell(500, 1).getText()); + + toggleHideColumnAPI(1); + + Assert.assertEquals("(500, 0)", + getGridElement().getCell(500, 0).getText()); + Assert.assertEquals("(500, 1)", + getGridElement().getCell(500, 1).getText()); + } + + @Test + public void scrollHideAndShow() { + toggleHidableColumnAPI(0); + toggleHidableColumnAPI(1); + + Assert.assertEquals("(500, 0)", + getGridElement().getCell(500, 0).getText()); + Assert.assertEquals("(500, 1)", + getGridElement().getCell(500, 1).getText()); + + toggleHideColumnAPI(0); + toggleHideColumnAPI(1); + + Assert.assertEquals("(500, 2)", + getGridElement().getCell(500, 0).getText()); + Assert.assertEquals("(500, 3)", + getGridElement().getCell(500, 1).getText()); + + toggleHideColumnAPI(0); + toggleHideColumnAPI(1); + + Assert.assertEquals("(500, 0)", + getGridElement().getCell(500, 0).getText()); + Assert.assertEquals("(500, 1)", + getGridElement().getCell(500, 1).getText()); + } + + private void loadSpannedCellsFixture() { + selectMenuPath("Component", "State", "Width", "1000px"); + appendHeaderRow(); + appendHeaderRow(); + appendHeaderRow(); + mergeHeaderCellsTwoThreeFour(2); + mergeHeaderCellsZeroOne(2); + mergeHeaderCellsOneTwo(3); + mergeHeaderCellsAll(4); + toggleHideColumnAPI(8); + toggleHideColumnAPI(9); + toggleHideColumnAPI(10); + toggleHideColumnAPI(11); + } + + private void verifySpannedCellsFixtureStart() { + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5, 6, 7); + verifyNumberOfCellsInHeader(0, 8); + verifyNumberOfCellsInHeader(1, 5); + verifyNumberOfCellsInHeader(2, 7); + verifyNumberOfCellsInHeader(3, 1); + verifyHeaderCellContent(1, 0, CAPTION_0_1); + verifyHeaderCellContent(1, 3, CAPTION_3_4_5); + verifyHeaderCellContent(2, 1, CAPTION_1_2); + verifyHeaderCellContent(3, 0, CAPTION_ALL); + verifyHeaderCellColspan(1, 0, 2); + verifyHeaderCellColspan(1, 3, 3); + verifyHeaderCellColspan(2, 1, 2); + } + + private void toggleFrozenColumns(int count) { + selectMenuPath("Component", "State", "Frozen column count", + count + " columns"); + } + + private void verifyHeaderCellColspan(int row, int column, int colspan) { + try { + assertEquals(Integer.valueOf(colspan), + Integer.valueOf(Integer.parseInt( + getGridElement().getHeaderCell(row, column) + .getAttribute("colspan")))); + } catch (NumberFormatException nfe) { + // IE8 has colSpan + assertEquals(Integer.valueOf(colspan), + Integer.valueOf(Integer.parseInt( + getGridElement().getHeaderCell(row, column) + .getAttribute("colSpan")))); + } + } + + private void verifyNumberOfCellsInHeader(int row, int numberOfCells) { + int size = 0; + for (TestBenchElement cell : getGridElement().getHeaderCells(row)) { + if (cell.isDisplayed()) { + size++; + } + } + assertEquals(numberOfCells, size); + } + + private void verifyHeaderCellContent(int row, int column, String content) { + GridCellElement headerCell = getGridElement().getHeaderCell(row, + column); + assertEquals(content.toLowerCase(), headerCell.getText().toLowerCase()); + assertTrue(headerCell.isDisplayed()); + } + + private void verifyColumnIsFrozen(int index) { + assertTrue(getGridElement().getHeaderCell(0, index).isFrozen()); + } + + private void verifyColumnIsNotFrozen(int index) { + assertFalse(getGridElement().getHeaderCell(0, index).isFrozen()); + } + + private void verifyColumnHidingTogglesOrder(int... indices) { + WebElement sidebar = getSidebarPopup(); + List elements = sidebar + .findElements(By.className("column-hiding-toggle")); + for (int i = 0; i < indices.length; i++) { + WebElement e = elements.get(i); + assertTrue(("Header (0," + indices[i] + ")") + .equalsIgnoreCase(e.getText())); + } + } + + private void verifyColumnHidingOption(int columnIndex, boolean hidden) { + WebElement columnHidingToggle = getColumnHidingToggle(columnIndex); + assertEquals(hidden, + columnHidingToggle.getAttribute("class").contains("hidden")); + } + + private void verifySidebarOpened() { + WebElement sidebar = getSidebarPopupIfPresent(); + assertNotNull(sidebar); + } + + private void verifySidebarClosed() { + WebElement sidebar = getSidebarPopupIfPresent(); + assertNull(sidebar); + } + + private void verifySidebarNotVisible() { + WebElement sidebar = getSidebarOpenButton(); + assertNull(sidebar); + } + + private void verifySidebarVisible() { + WebElement sidebar = getSidebarOpenButton(); + assertNotNull(sidebar); + } + + /** + * Returns the toggle inside the sidebar for hiding the column at the given + * index, or null if not found. + */ + @Override + protected WebElement getColumnHidingToggle(int columnIndex) { + WebElement sidebar = getSidebarPopup(); + List elements = sidebar + .findElements(By.className("column-hiding-toggle")); + for (WebElement e : elements) { + if (("Header (0," + columnIndex + ")") + .equalsIgnoreCase(e.getText())) { + return e; + } + } + return null; + } + + private void clickSidebarOpenButton() { + getSidebarOpenButton().click(); + } + + private void moveColumnLeft(int index) { + selectMenuPath("Component", "Columns", "Column " + index, + "Move column left"); + } + + private void toggleHidableColumnAPI(int columnIndex) { + selectMenuPath("Component", "Columns", "Column " + columnIndex, + "Hidable"); + } + + private void toggleHideColumnAPI(int columnIndex) { + selectMenuPath("Component", "Columns", "Column " + columnIndex, + "Hidden"); + } + + private void appendHeaderRow() { + selectMenuPath("Component", "Header", "Append row"); + } + + private void mergeHeaderCellsZeroOne(int row) { + selectMenuPath("Component", "Header", "Row " + row, CAPTION_0_1); + } + + private void mergeHeaderCellsOneTwo(int row) { + selectMenuPath("Component", "Header", "Row " + row, CAPTION_1_2); + } + + private void mergeHeaderCellsTwoThreeFour(int row) { + selectMenuPath("Component", "Header", "Row " + row, CAPTION_3_4_5); + } + + private void mergeHeaderCellsAll(int row) { + selectMenuPath("Component", "Header", "Row " + row, CAPTION_ALL); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridColumnReorderTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridColumnReorderTest.java new file mode 100644 index 0000000000..e0e2d7fb2a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridColumnReorderTest.java @@ -0,0 +1,653 @@ +/* + * 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.basicfeatures; + +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 org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; + +/** + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridColumnReorderTest extends GridBasicClientFeaturesTest { + + @Before + public void before() { + openTestURL(); + } + + @Test + public void columnReorderEventTriggered() { + final int firstIndex = 3; + final int secondIndex = 4; + final String firstHeaderText = getGridElement() + .getHeaderCell(0, firstIndex).getText(); + final String secondHeaderText = getGridElement() + .getHeaderCell(0, secondIndex).getText(); + selectMenuPath("Component", "Internals", "Listeners", + "Add ColumnReorder listener"); + selectMenuPath("Component", "Columns", "Column " + secondIndex, + "Move column left"); + // columns 3 and 4 should have swapped to 4 and 3 + GridCellElement headerCell = getGridElement().getHeaderCell(0, + firstIndex); + assertEquals(secondHeaderText, headerCell.getText()); + headerCell = getGridElement().getHeaderCell(0, secondIndex); + assertEquals(firstHeaderText, headerCell.getText()); + + // the reorder event should have typed the order to this label + WebElement columnReorderElement = findElement(By.id("columnreorder")); + int eventIndex = Integer + .parseInt(columnReorderElement.getAttribute("columns")); + assertEquals(1, eventIndex); + + // trigger another event + selectMenuPath("Component", "Columns", "Column " + secondIndex, + "Move column left"); + columnReorderElement = findElement(By.id("columnreorder")); + eventIndex = Integer + .parseInt(columnReorderElement.getAttribute("columns")); + assertEquals(2, eventIndex); + } + + @Test + public void testColumnReorder_onReorder_columnReorderEventTriggered() { + final int firstIndex = 3; + final int secondIndex = 4; + final String firstHeaderText = getGridElement() + .getHeaderCell(0, firstIndex).getText(); + final String secondHeaderText = getGridElement() + .getHeaderCell(0, secondIndex).getText(); + selectMenuPath("Component", "Internals", "Listeners", + "Add ColumnReorder listener"); + selectMenuPath("Component", "Columns", "Column " + secondIndex, + "Move column left"); + // columns 3 and 4 should have swapped to 4 and 3 + GridCellElement headerCell = getGridElement().getHeaderCell(0, + firstIndex); + assertEquals(secondHeaderText, headerCell.getText()); + headerCell = getGridElement().getHeaderCell(0, secondIndex); + assertEquals(firstHeaderText, headerCell.getText()); + + // the reorder event should have typed the order to this label + WebElement columnReorderElement = findElement(By.id("columnreorder")); + int eventIndex = Integer + .parseInt(columnReorderElement.getAttribute("columns")); + assertEquals(1, eventIndex); + + // trigger another event + selectMenuPath("Component", "Columns", "Column " + secondIndex, + "Move column left"); + columnReorderElement = findElement(By.id("columnreorder")); + eventIndex = Integer + .parseInt(columnReorderElement.getAttribute("columns")); + assertEquals(2, eventIndex); + } + + @Test + public void testColumnReorder_draggingSortedColumn_sortIndicatorShownOnDraggedElement() { + // given + toggleColumnReorder(); + toggleSortableColumn(0); + sortColumn(0); + + // when + startDragButDontDropOnDefaultColumnHeader(0); + + // then + WebElement draggedElement = getDraggedHeaderElement(); + assertTrue(draggedElement.getAttribute("class").contains("sort")); + } + + @Test + public void testColumnReorder_draggingSortedColumn_sortStays() { + // given + toggleColumnReorder(); + toggleSortableColumn(0); + sortColumn(0); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + + // then + assertColumnIsSorted(1); + } + + @Test + public void testColumnReorder_draggingFocusedHeader_focusShownOnDraggedElement() { + // given + toggleColumnReorder(); + focusDefaultHeader(0); + + // when + startDragButDontDropOnDefaultColumnHeader(0); + + // then + WebElement draggedElement = getDraggedHeaderElement(); + assertTrue(draggedElement.getAttribute("class").contains("focused")); + } + + @Test + public void testColumnReorder_draggingFocusedHeader_focusIsKeptOnHeader() { + // given + toggleColumnReorder(); + focusDefaultHeader(0); + + // when + dragAndDropDefaultColumnHeader(0, 3, CellSide.LEFT); + + // then + WebElement defaultColumnHeader = getDefaultColumnHeader(2); + String attribute = defaultColumnHeader.getAttribute("class"); + assertTrue(attribute.contains("focused")); + } + + @Test + public void testColumnReorder_draggingFocusedCellColumn_focusIsKeptOnCell() { + // given + toggleColumnReorder(); + focusCell(2, 2); + + // when + dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); + + // then + assertFocusedCell(2, 0); + } + + @Test + public void testColumnReorderWithHiddenColumn_draggingFocusedCellColumnOverHiddenColumn_focusIsKeptOnCell() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Columns", "Column 1", "Hidden"); + focusCell(2, 2); + assertFocusedCell(2, 2); + + // when + dragAndDropDefaultColumnHeader(1, 0, CellSide.LEFT); + + // then + assertFocusedCell(2, 2); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + + // then + assertFocusedCell(2, 2); + } + + @Test + public void testColumnReorder_dragColumnFromRightToLeftOfFocusedCellColumn_focusIsKept() { + // given + toggleColumnReorder(); + focusCell(1, 3); + + // when + dragAndDropDefaultColumnHeader(4, 1, CellSide.LEFT); + + // then + assertFocusedCell(1, 4); + } + + @Test + public void testColumnReorder_dragColumnFromLeftToRightOfFocusedCellColumn_focusIsKept() { + // given + toggleColumnReorder(); + focusCell(4, 2); + + // when + dragAndDropDefaultColumnHeader(0, 4, CellSide.LEFT); + + // then + assertFocusedCell(4, 1); + } + + @Test + public void testColumnReorder_draggingHeaderRowThatHasColumnHeadersSpanned_cantDropInsideSpannedHeaderFromOutside() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + int horizontalOffset = (getGridElement().getHeaderCell(1, 1).getSize() + .getWidth() / 2) - 10; + dragAndDropColumnHeader(1, 3, 1, horizontalOffset); + + // then + assertColumnHeaderOrder(0, 3, 1, 2, 4); + } + + @Test + public void testColumnReorder_anotherRowHasColumnHeadersSpanned_cantDropInsideSpannedHeaderFromOutside() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + int horizontalOffset = (getGridElement().getHeaderCell(1, 1).getSize() + .getWidth() / 2) + 10; + dragAndDropColumnHeader(0, 0, 2, horizontalOffset); + + // then + assertColumnHeaderOrder(1, 2, 0, 3, 4); + } + + @Test + public void testColumnReorder_cellInsideSpannedHeader_cantBeDroppedOutsideSpannedArea() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(0, 2, 1, 3, 4); + } + + @Test + public void testColumnReorder_cellInsideTwoCrossingSpanningHeaders_cantTouchThis() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", + "Join column cells 0, 1"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); + assertColumnHeaderOrder(3, 0, 1, 2, 4); + + // when + dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(3, 0, 1, 2, 4); + } + + @Test + public void testColumnReorder_cellsInsideSpannedHeaderAndBlockedByOtherSpannedCells_cantTouchThose() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", + "Join column cells 0, 1"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); + assertColumnHeaderOrder(3, 0, 1, 2, 4); + + // when then + dragAndDropColumnHeader(0, 1, 3, CellSide.LEFT); + assertColumnHeaderOrder(3, 0, 1, 2, 4); + + dragAndDropColumnHeader(1, 2, 1, CellSide.LEFT); + assertColumnHeaderOrder(3, 0, 1, 2, 4); + + dragAndDropColumnHeader(2, 1, 2, CellSide.RIGHT); + assertColumnHeaderOrder(3, 0, 1, 2, 4); + } + + @Test + public void testColumnReorder_cellsInsideSpannedHeaderAndBlockedByOtherSpannedCells_reorderingLimited() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + dragAndDropColumnHeader(0, 0, 4, CellSide.RIGHT); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + + // when then + dragAndDropColumnHeader(0, 1, 4, CellSide.LEFT); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + + dragAndDropColumnHeader(0, 2, 4, CellSide.LEFT); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + + dragAndDropColumnHeader(0, 3, 4, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 5, 4); + + dragAndDropColumnHeader(0, 4, 2, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + + dragAndDropColumnHeader(2, 3, 4, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 5, 4); + + dragAndDropColumnHeader(2, 4, 2, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + assertColumnHeaderOrder(1, 2, 3, 4, 5); + } + + @Test + public void testColumnReorder_cellsInsideTwoAdjacentSpannedHeaders_reorderingLimited() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + dragAndDropColumnHeader(0, 0, 4, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + dragAndDropColumnHeader(0, 1, 4, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + assertColumnHeaderOrder(1, 3, 4, 5, 2); + + // when then + dragAndDropColumnHeader(0, 1, 4, CellSide.LEFT); + assertColumnHeaderOrder(1, 4, 3, 5, 2); + + dragAndDropColumnHeader(0, 2, 4, CellSide.LEFT); + assertColumnHeaderOrder(1, 4, 3, 5, 2); + + dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); + assertColumnHeaderOrder(1, 3, 4, 5, 2); + } + + @Test + public void testColumnReorder_footerHasSpannedCells_cantDropInside() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Footer", "Append row"); + selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(0, 3, 1, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(0, 3, 1, 2, 4); + } + + @Test + public void testColumnReorder_cellInsideASpannedFooter_cantBeDroppedOutsideSpannedArea() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Footer", "Append row"); + selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(0, 2, 1, 3, 4); + } + + @Test + public void testColumnReorder_cellInsideTwoCrossingSpanningFooters_cantTouchThis() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Footer", "Append row"); + selectMenuPath("Component", "Footer", "Append row"); + selectMenuPath("Component", "Footer", "Row 1", + "Join column cells 0, 1"); + selectMenuPath("Component", "Footer", "Row 2", "Join columns 1, 2"); + dragAndDropColumnHeader(0, 3, 0, CellSide.LEFT); + assertColumnHeaderOrder(3, 0, 1, 2, 4); + + // when + dragAndDropColumnHeader(0, 2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(3, 0, 1, 2, 4); + } + + @Test + public void testColumnReorder_cellsInsideTwoAdjacentSpannedHeaderAndFooter_reorderingLimited() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Footer", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + dragAndDropColumnHeader(0, 0, 5, CellSide.LEFT); + scrollGridHorizontallyTo(0); + dragAndDropColumnHeader(0, 1, 5, CellSide.LEFT); + scrollGridHorizontallyTo(0); + selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); + assertColumnHeaderOrder(1, 3, 4, 5, 2); + + // when then + dragAndDropColumnHeader(0, 1, 3, CellSide.RIGHT); + assertColumnHeaderOrder(1, 4, 3, 5, 2); + + dragAndDropColumnHeader(0, 2, 4, CellSide.RIGHT); + assertColumnHeaderOrder(1, 4, 3, 5, 2); + + dragAndDropColumnHeader(0, 2, 0, CellSide.RIGHT); + assertColumnHeaderOrder(1, 3, 4, 5, 2); + } + + @Test + public void testColumnReorder_draggingASpannedCell_dragWorksNormally() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(1, 1, 4, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 3, 1, 2, 4); + } + + @Test + public void testColumnReorder_twoEqualSpannedCells_bothCanBeDragged() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(1, 1, 4, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 3, 1, 2, 4); + + // when + dragAndDropColumnHeader(2, 3, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(1, 2, 0, 3, 4); + } + + @Test + public void testColumReorder_twoCrossingSpanningHeaders_neitherCanBeDragged() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 3", + "Join column cells 0, 1"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(1, 1, 4, CellSide.LEFT); + + // then + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(2, 0, 3, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(0, 1, 2, 3, 4); + } + + @Test + public void testColumnReorder_spannedCellHasAnotherSpannedCellInside_canBeDraggedNormally() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + dragAndDropColumnHeader(1, 3, 1, CellSide.LEFT); + scrollGridHorizontallyTo(0); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 3, 4, 5, 1); + + // when + dragAndDropColumnHeader(1, 1, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(3, 4, 5, 0, 1); + } + + @Test + public void testColumnReorder_spannedCellInsideAnotherSpanned_canBeDraggedWithBoundaries() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + dragAndDropColumnHeader(1, 3, 1, CellSide.LEFT); + scrollGridHorizontallyTo(0); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 3, 4, 5, 1); + + // when + dragAndDropColumnHeader(2, 1, 3, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 5, 3, 4, 1); + + // when + dragAndDropColumnHeader(2, 2, 0, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 3, 4, 5, 1); + } + + @Test + public void testColumnReorder_cellInsideAndNextToSpannedCells_canBeDraggedWithBoundaries() { + // given + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + dragAndDropColumnHeader(1, 3, 1, CellSide.LEFT); + scrollGridHorizontallyTo(0); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 3, 4, 5, 1); + + // when + dragAndDropColumnHeader(2, 3, 0, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 5, 3, 4, 1); + + // when + dragAndDropColumnHeader(2, 1, 4, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 3, 4, 5, 1); + } + + @Test + public void testColumnReorder_multipleSpannedCells_dragWorksNormally() { + toggleColumnReorder(); + selectMenuPath("Component", "State", "Width", "750px"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 2", "Join columns 3, 4, 5"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "Header", "Row 3", "Join columns 1, 2"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(1, 3, 1, CellSide.RIGHT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 3, 4, 5, 1); + + // when + scrollGridHorizontallyTo(100); + dragAndDropColumnHeader(2, 4, 2, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(0, 1, 2, 3, 4); + + // when + dragAndDropColumnHeader(0, 0, 3, CellSide.LEFT); + scrollGridHorizontallyTo(0); + + // then + assertColumnHeaderOrder(1, 2, 0, 3, 4); + } + + private void toggleSortableColumn(int index) { + selectMenuPath("Component", "Columns", "Column " + index, "Sortable"); + } + + private void startDragButDontDropOnDefaultColumnHeader(int index) { + new Actions(getDriver()) + .clickAndHold(getGridHeaderRowCells().get(index)) + .moveByOffset(100, 0).perform(); + } + + private void sortColumn(int index) { + getGridHeaderRowCells().get(index).click(); + } + + private void focusDefaultHeader(int index) { + getGridHeaderRowCells().get(index).click(); + } + + private WebElement getDraggedHeaderElement() { + return findElement(By.className("dragged-column-header")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java new file mode 100644 index 0000000000..4766a29018 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDefaultTextRendererTest.java @@ -0,0 +1,63 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.GridCellFocusOnResetSizeTest.MyGridElement; + +@TestCategory("grid") +public class GridDefaultTextRendererTest extends MultiBrowserTest { + + private GridElement grid; + + @Before + public void init() { + setDebug(true); + openTestURL(); + grid = $(MyGridElement.class).first(); + assertFalse("There was an unexpected notification during init", + $(NotificationElement.class).exists()); + } + + @Test + public void testNullIsRenderedAsEmptyStringByDefaultTextRenderer() { + assertTrue("First cell should've been empty", + grid.getCell(0, 0).getText().isEmpty()); + } + + @Test + public void testStringIsRenderedAsStringByDefaultTextRenderer() { + assertEquals("Second cell should've been populated ", "string", + grid.getCell(1, 0).getText()); + } + + @Test + public void testWarningShouldNotBeInDebugLog() { + assertFalse("Warning visible with string content.", isElementPresent( + By.xpath("//span[contains(.,'attached:#1')]"))); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java new file mode 100644 index 0000000000..9e31a0e096 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridDescriptionGeneratorTest.java @@ -0,0 +1,83 @@ +/* + * 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.basicfeatures; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.DesiredCapabilities; + +public class GridDescriptionGeneratorTest extends GridBasicFeaturesTest { + + @Test + public void testCellDescription() { + openTestURL(); + selectMenuPath("Component", "State", "Cell description generator"); + + getGridElement().getCell(1, 0).showTooltip(); + String tooltipText = findElement(By.className("v-tooltip-text")) + .getText(); + assertEquals("Tooltip text", "Cell tooltip for row 1, column 0", + tooltipText); + + getGridElement().getCell(1, 1).showTooltip(); + assertTrue("Tooltip should not be present in cell (1, 1) ", + findElement(By.className("v-tooltip-text")).getText() + .isEmpty()); + } + + @Test + public void testRowDescription() { + openTestURL(); + selectMenuPath("Component", "State", "Row description generator"); + + getGridElement().getCell(5, 3).showTooltip(); + String tooltipText = findElement(By.className("v-tooltip-text")) + .getText(); + assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText); + + getGridElement().getCell(15, 3).showTooltip(); + tooltipText = findElement(By.className("v-tooltip-text")).getText(); + assertEquals("Tooltip text", "Row tooltip for row 15", tooltipText); + } + + @Test + public void testRowAndCellDescription() { + openTestURL(); + selectMenuPath("Component", "State", "Row description generator"); + selectMenuPath("Component", "State", "Cell description generator"); + + getGridElement().getCell(5, 0).showTooltip(); + String tooltipText = findElement(By.className("v-tooltip-text")) + .getText(); + assertEquals("Tooltip text", "Cell tooltip for row 5, column 0", + tooltipText); + + getGridElement().getCell(5, 3).showTooltip(); + tooltipText = findElement(By.className("v-tooltip-text")).getText(); + assertEquals("Tooltip text", "Row tooltip for row 5", tooltipText); + } + + @Override + public List getBrowsersToTest() { + return getBrowsersExcludingFirefox(); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridHeightByRowOnInitTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridHeightByRowOnInitTest.java new file mode 100644 index 0000000000..de51053535 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridHeightByRowOnInitTest.java @@ -0,0 +1,21 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures; + +import org.junit.Test; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +@SuppressWarnings("all") +@TestCategory("grid") +public class GridHeightByRowOnInitTest extends MultiBrowserTest { + + @Test + public void gridHeightIsMoreThanACoupleOfRows() { + openTestURL(); + int height = $(GridElement.class).first().getSize().getHeight(); + assertGreater( + "Grid should be much taller than 150px (was " + height + "px)", + height, 150); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java new file mode 100644 index 0000000000..0f16027939 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/GridSortingIndicatorsTest.java @@ -0,0 +1,47 @@ +/* + * 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.basicfeatures; + +import java.io.IOException; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridSortingIndicatorsTest extends MultiBrowserTest { + + @Override + public List getBrowsersToTest() { + List browsers = getBrowsersExcludingPhantomJS(); + browsers.add(PHANTOMJS2()); + return browsers; + } + + @Test + public void testSortingIndicators() throws IOException { + openTestURL(); + compareScreen("initialSort"); + + $(ButtonElement.class).first().click(); + + compareScreen("reversedSort"); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java new file mode 100644 index 0000000000..a9b0a03737 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/DisabledGridClientTest.java @@ -0,0 +1,59 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class DisabledGridClientTest extends GridBasicClientFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "State", "Enabled"); + } + + @Test + public void testSelection() { + selectMenuPath("Component", "State", "Selection mode", "single"); + + GridRowElement row = getGridElement().getRow(0); + GridCellElement cell = getGridElement().getCell(0, 0); + cell.click(); + assertFalse("disabled row should not be selected", row.isSelected()); + } + + @Test + public void testEditorOpening() { + selectMenuPath("Component", "Editor", "Enabled"); + GridRowElement row = getGridElement().getRow(0); + GridCellElement cell = getGridElement().getCell(0, 0); + cell.click(); + assertNull("Editor should not open", getEditor()); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertNull("Editor should not open", getEditor()); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridCellStyleGeneratorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridCellStyleGeneratorTest.java new file mode 100644 index 0000000000..2168d92074 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridCellStyleGeneratorTest.java @@ -0,0 +1,145 @@ +/* + * 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.basicfeatures.client; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.tests.widgetset.client.v7.grid.GridBasicClientFeaturesWidget; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridCellStyleGeneratorTest extends GridBasicClientFeaturesTest { + + @Test + public void testStyleNameGeneratorScrolling() throws Exception { + openTestURL(); + + selectCellStyleNameGenerator( + GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); + selectRowStyleNameGenerator( + GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); + + GridRowElement row2 = getGridElement().getRow(2); + GridCellElement cell4_2 = getGridElement().getCell(4, 2); + + Assert.assertTrue(hasCssClass(row2, "2")); + Assert.assertTrue(hasCssClass(cell4_2, "4_2")); + + // Scroll down and verify that the old elements don't have the + // stylename any more + + getGridElement().getRow(350); + + Assert.assertFalse(hasCssClass(row2, "2")); + Assert.assertFalse(hasCssClass(cell4_2, "4_2")); + } + + @Test + public void testDisableStyleNameGenerator() throws Exception { + openTestURL(); + + selectCellStyleNameGenerator( + GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); + selectRowStyleNameGenerator( + GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); + + // Just verify that change was effective + GridRowElement row2 = getGridElement().getRow(2); + GridCellElement cell4_2 = getGridElement().getCell(4, 2); + + Assert.assertTrue(hasCssClass(row2, "2")); + Assert.assertTrue(hasCssClass(cell4_2, "4_2")); + + // Disable the generator and check again + selectCellStyleNameGenerator( + GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_NONE); + selectRowStyleNameGenerator( + GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE); + + Assert.assertFalse(hasCssClass(row2, "2")); + Assert.assertFalse(hasCssClass(cell4_2, "4_2")); + } + + @Test + public void testChangeStyleNameGenerator() throws Exception { + openTestURL(); + + selectCellStyleNameGenerator( + GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); + selectRowStyleNameGenerator( + GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); + + // Just verify that change was effective + GridRowElement row2 = getGridElement().getRow(2); + GridCellElement cell4_2 = getGridElement().getCell(4, 2); + + Assert.assertTrue(hasCssClass(row2, "2")); + Assert.assertTrue(hasCssClass(cell4_2, "4_2")); + + // Change the generator and check again + selectRowStyleNameGenerator( + GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_NONE); + selectCellStyleNameGenerator( + GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_SIMPLE); + + // Old styles removed? + Assert.assertFalse(hasCssClass(row2, "2")); + Assert.assertFalse(hasCssClass(cell4_2, "4_2")); + + // New style present? + Assert.assertTrue(hasCssClass(cell4_2, "two")); + } + + @Test + public void testStyleNameGeneratorChangePrimary() throws Exception { + openTestURL(); + + selectCellStyleNameGenerator( + GridBasicClientFeaturesWidget.CELL_STYLE_GENERATOR_COL_INDEX); + selectRowStyleNameGenerator( + GridBasicClientFeaturesWidget.ROW_STYLE_GENERATOR_ROW_INDEX); + + // Just verify that change was effective + GridRowElement row2 = getGridElement().getRow(2); + GridCellElement cell4_2 = getGridElement().getCell(4, 2); + + Assert.assertTrue(hasCssClass(row2, "2")); + Assert.assertTrue(hasCssClass(cell4_2, "4_2")); + + // Change primary stylename + selectMenuPath("Component", "State", "Primary Stylename", + "v-escalator"); + + // Styles still present + Assert.assertTrue(hasCssClass(row2, "2")); + Assert.assertTrue(hasCssClass(cell4_2, "4_2")); + + // New styles present? + Assert.assertFalse(hasCssClass(row2, "v-escalator-row-2")); + Assert.assertFalse( + hasCssClass(cell4_2, "v-escalator-cell-content-4_2")); + } + + private void selectCellStyleNameGenerator(String name) { + selectMenuPath("Component", "State", "Cell style generator", name); + } + + private void selectRowStyleNameGenerator(String name) { + selectMenuPath("Component", "State", "Row style generator", name); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java new file mode 100644 index 0000000000..5413e7a0b1 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientColumnPropertiesTest.java @@ -0,0 +1,183 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.tests.widgetset.client.v7.grid.GridBasicClientFeaturesWidget; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridClientColumnPropertiesTest + extends GridBasicClientFeaturesTest { + + @Test + public void initialColumnWidths() { + openTestURL(); + + for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) { + int width = getGridElement().getCell(0, col).getSize().getWidth(); + if (col <= 6) { + // Growing column widths + int expectedWidth = 50 + col * 25; + assertEquals("column " + col + " has incorrect width", + expectedWidth, width); + } + } + } + + @Test + public void testChangingColumnWidth() { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Width", "50px"); + int width = getGridElement().getCell(0, 0).getSize().getWidth(); + assertEquals(50, width); + + selectMenuPath("Component", "Columns", "Column 0", "Width", "200px"); + width = getGridElement().getCell(0, 0).getSize().getWidth(); + assertEquals(200, width); + + selectMenuPath("Component", "Columns", "Column 0", "Width", "auto"); + int autoWidth = getGridElement().getCell(0, 0).getSize().getWidth(); + assertLessThan("Automatic sizing should've shrunk the column", + autoWidth, width); + } + + @Test + public void testFrozenColumns() { + openTestURL(); + + assertFalse(cellIsFrozen(0, 0)); + assertFalse(cellIsFrozen(0, 1)); + + selectMenuPath("Component", "State", "Frozen column count", + "1 columns"); + + assertTrue(cellIsFrozen(1, 0)); + assertFalse(cellIsFrozen(1, 1)); + + selectMenuPath("Component", "State", "Selection mode", "multi"); + + assertTrue(cellIsFrozen(1, 1)); + assertFalse(cellIsFrozen(1, 2)); + + selectMenuPath("Component", "State", "Frozen column count", + "0 columns"); + + assertTrue(cellIsFrozen(1, 0)); + assertFalse(cellIsFrozen(1, 1)); + + selectMenuPath("Component", "State", "Frozen column count", + "-1 columns"); + + assertFalse(cellIsFrozen(1, 0)); + } + + @Test + public void testFrozenColumns_columnsReordered_frozenColumnsKept() { + openTestURL(); + + selectMenuPath("Component", "State", "Frozen column count", + "2 columns"); + + assertTrue(cellIsFrozen(1, 0)); + assertTrue(cellIsFrozen(1, 1)); + assertFalse(cellIsFrozen(1, 2)); + + selectMenuPath("Component", "State", "Reverse grid columns"); + + assertTrue(cellIsFrozen(1, 0)); + assertTrue(cellIsFrozen(1, 1)); + assertFalse(cellIsFrozen(1, 2)); + } + + @Test + public void testBrokenRenderer() { + setDebug(true); + openTestURL(); + + GridElement gridElement = getGridElement(); + + // Scroll first row out of view + gridElement.getRow(50); + + // Enable broken renderer for the first row + selectMenuPath("Component", "Columns", "Column 0", "Broken renderer"); + + // Shouldn't have an error notification yet + assertFalse("Notification was present", + isElementPresent(NotificationElement.class)); + + // Scroll broken row into view and enjoy the chaos + gridElement.getRow(0); + + assertTrue("Notification was not present", + isElementPresent(NotificationElement.class)); + + assertFalse("Text in broken cell should have old value", + "(0, 0)".equals(gridElement.getCell(0, 0).getText())); + + assertEquals("Neighbour cell should be updated", "(0, 1)", + gridElement.getCell(0, 1).getText()); + + assertEquals("Neighbour cell should be updated", "(1, 0)", + gridElement.getCell(1, 0).getText()); + } + + @Test + public void testColumnWidths_onColumnReorder_columnWidthsKeptTheSame() { + // given + openTestURL(); + GridElement gridElement = getGridElement(); + List headerCells = gridElement.getHeaderCells(0); + + final List columnWidths = new ArrayList(); + for (GridCellElement cell : headerCells) { + columnWidths.add(cell.getSize().getWidth()); + } + + // when + selectMenuPath("Component", "State", "Reverse grid columns"); + + // then + gridElement = getGridElement(); + headerCells = gridElement.getHeaderCells(0); + final int size = headerCells.size(); + for (int i = 0; i < size; i++) { + // Avoid issues with inaccuracies regarding subpixels. + assertEquals( + "Column widths don't match after reset, index after flip " + + i, + columnWidths.get(i), + headerCells.get(size - 1 - i).getSize().getWidth(), 1.0d); + } + + } + + private boolean cellIsFrozen(int row, int col) { + return getGridElement().getCell(row, col).isFrozen(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java new file mode 100644 index 0000000000..1380181e53 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeEditorTest.java @@ -0,0 +1,13 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.client; + +import org.junit.Before; + +public class GridClientCompositeEditorTest extends GridEditorClientTest { + + @Override + @Before + public void setUp() { + setUseComposite(true); + super.setUp(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeFooterTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeFooterTest.java new file mode 100644 index 0000000000..1238832488 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeFooterTest.java @@ -0,0 +1,11 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.client; + +import org.junit.Before; + +public class GridClientCompositeFooterTest extends GridFooterTest { + + @Before + public void setUp() { + setUseComposite(true); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeHeaderTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeHeaderTest.java new file mode 100644 index 0000000000..e63e058199 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeHeaderTest.java @@ -0,0 +1,11 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.client; + +import org.junit.Before; + +public class GridClientCompositeHeaderTest extends GridHeaderTest { + + @Before + public void setUp() { + setUseComposite(true); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeKeyEventsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeKeyEventsTest.java new file mode 100644 index 0000000000..e0bf9214d6 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeKeyEventsTest.java @@ -0,0 +1,11 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.client; + +import org.junit.Before; + +public class GridClientCompositeKeyEventsTest extends GridClientKeyEventsTest { + + @Before + public void setUp() { + setUseComposite(true); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeSelectionTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeSelectionTest.java new file mode 100644 index 0000000000..0083afee46 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientCompositeSelectionTest.java @@ -0,0 +1,11 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.client; + +import org.junit.Before; + +public class GridClientCompositeSelectionTest extends GridClientSelectionTest { + + @Before + public void setUp() { + setUseComposite(true); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java new file mode 100644 index 0000000000..b6b139d495 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientContextMenuEventTest.java @@ -0,0 +1,64 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridClientContextMenuEventTest + extends GridBasicClientFeaturesTest { + + @Override + public List getBrowsersToTest() { + // PhantomJS doesn't support context click.. + return getBrowsersExcludingPhantomJS(); + } + + @Test + public void testContextMenuEventIsHandledCorrectly() { + setDebug(true); + openTestURL(); + + selectMenuPath("Component", "Internals", "Listeners", + "Add context menu listener"); + + openDebugLogTab(); + clearDebugMessages(); + + new Actions(getDriver()) + .moveToElement(getGridElement().getCell(0, 0), 5, 5) + .contextClick().perform(); + + assertTrue("Debug log was not visible", isElementPresent(By.xpath( + "//span[text() = 'Prevented opening a context menu in grid body']"))); + + new Actions(getDriver()) + .moveToElement(getGridElement().getHeaderCell(0, 0), 5, 5) + .contextClick().perform(); + + assertTrue("Debug log was not visible", isElementPresent(By.xpath( + "//span[text() = 'Prevented opening a context menu in grid header']"))); + + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java new file mode 100644 index 0000000000..0321159bcd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientKeyEventsTest.java @@ -0,0 +1,167 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridClientKeyEventsTest extends GridBasicClientFeaturesTest { + + private List eventOrder = Arrays.asList("Down", "Up", "Press"); + + @Test + public void testBodyKeyEvents() throws IOException { + openTestURL(); + + getGridElement().getCell(2, 2).click(); + + new Actions(getDriver()).sendKeys("a").perform(); + + for (int i = 0; i < 3; ++i) { + assertEquals("Body key event handler was not called.", + "(2, 2) event: GridKey" + eventOrder.get(i) + "Event:[" + + (eventOrder.get(i).equals("Press") ? "a" : 65) + + "]", + findElements(By.className("v-label")).get(i * 3).getText()); + + assertTrue("Header key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3 + 1) + .getText().isEmpty()); + assertTrue("Footer key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3 + 2) + .getText().isEmpty()); + } + + } + + @Test + public void testHeaderKeyEvents() throws IOException { + openTestURL(); + + getGridElement().getHeaderCell(0, 2).click(); + + new Actions(getDriver()).sendKeys("a").perform(); + + for (int i = 0; i < 3; ++i) { + assertEquals("Header key event handler was not called.", + "(0, 2) event: GridKey" + eventOrder.get(i) + "Event:[" + + (eventOrder.get(i).equals("Press") ? "a" : 65) + + "]", + findElements(By.className("v-label")).get(i * 3 + 1) + .getText()); + + assertTrue("Body key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3).getText() + .isEmpty()); + assertTrue("Footer key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3 + 2) + .getText().isEmpty()); + } + } + + @Test + public void selectAllUsingKeyboard() { + openTestURL(); + + selectMenuPath("Component", "Header", "Prepend row"); + selectMenuPath("Component", "Header", "Append row"); + selectMenuPath("Component", "State", "Selection mode", "multi"); + + // IE8 does not handle 1k rows well with assertions enabled. Less rows! + selectMenuPath("Component", "DataSource", + "Reset with 100 rows of Data"); + + // Focus cell above select all checkbox + getGridElement().getHeaderCell(0, 0).click(); + Assert.assertFalse(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); + Assert.assertFalse(isRowSelected(1)); + + // Move down to select all checkbox cell + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + Assert.assertFalse(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); // select all + Assert.assertTrue(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); // deselect all + Assert.assertFalse(isRowSelected(1)); + + // Move down to header below select all checkbox cell + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + Assert.assertFalse(isRowSelected(1)); + new Actions(getDriver()).sendKeys(" ").perform(); // deselect all + Assert.assertFalse(isRowSelected(1)); + + } + + @Test + public void testFooterKeyEvents() throws IOException { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + getGridElement().getFooterCell(0, 2).click(); + + new Actions(getDriver()).sendKeys("a").perform(); + + for (int i = 0; i < 3; ++i) { + assertEquals("Footer key event handler was not called.", + "(0, 2) event: GridKey" + eventOrder.get(i) + "Event:[" + + (eventOrder.get(i).equals("Press") ? "a" : 65) + + "]", + findElements(By.className("v-label")).get(i * 3 + 2) + .getText()); + + assertTrue("Body key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3).getText() + .isEmpty()); + assertTrue("Header key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3 + 1) + .getText().isEmpty()); + + } + } + + @Test + public void testNoKeyEventsFromWidget() { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 2", "Header Type", + "Widget Header"); + GridCellElement header = getGridElement().getHeaderCell(0, 2); + header.findElement(By.tagName("button")).click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + for (int i = 0; i < 3; ++i) { + assertTrue("Header key event handler got called unexpectedly.", + findElements(By.className("v-label")).get(i * 3 + 1) + .getText().isEmpty()); + + } + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java new file mode 100644 index 0000000000..76788ba820 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java @@ -0,0 +1,212 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridClientSelectionTest extends GridBasicClientFeaturesTest { + + @Test + public void testChangeSelectionMode() { + openTestURL(); + + setSelectionModelNone(); + assertTrue("First column was selection column", + getGridElement().getCell(0, 0).getText().equals("(0, 0)")); + setSelectionModelMulti(); + assertTrue("First column was not selection column", + getGridElement().getCell(0, 1).getText().equals("(0, 0)")); + } + + @Test + public void testSelectAllCheckbox() { + openTestURL(); + + setSelectionModelMulti(); + selectMenuPath("Component", "DataSource", + "Reset with 100 rows of Data"); + GridCellElement header = getGridElement().getHeaderCell(0, 0); + + assertTrue("No checkbox", header.isElementPresent(By.tagName("input"))); + header.findElement(By.tagName("input")).click(); + + for (int i = 0; i < 100; i += 10) { + assertTrue("Row " + i + " was not selected.", + getGridElement().getRow(i).isSelected()); + } + + header.findElement(By.tagName("input")).click(); + assertFalse("Row 52 was still selected", + getGridElement().getRow(52).isSelected()); + } + + @Test + public void testSelectAllCheckboxWhenChangingModels() { + openTestURL(); + + GridCellElement header; + header = getGridElement().getHeaderCell(0, 0); + assertFalse( + "Check box shouldn't have been in header for None Selection Model", + header.isElementPresent(By.tagName("input"))); + + setSelectionModelMulti(); + header = getGridElement().getHeaderCell(0, 0); + assertTrue("Multi Selection Model should have select all checkbox", + header.isElementPresent(By.tagName("input"))); + + setSelectionModelSingle(true); + header = getGridElement().getHeaderCell(0, 0); + assertFalse( + "Check box shouldn't have been in header for Single Selection Model", + header.isElementPresent(By.tagName("input"))); + + setSelectionModelNone(); + header = getGridElement().getHeaderCell(0, 0); + assertFalse( + "Check box shouldn't have been in header for None Selection Model", + header.isElementPresent(By.tagName("input"))); + + } + + @Test + public void testDeselectAllowedMouseInput() { + openTestURL(); + + setSelectionModelSingle(true); + + getGridElement().getCell(5, 1).click(); + + assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); + + getGridElement().getCell(7, 1).click(); + + assertFalse("Row 5 should be deselected after clicking another row", + isRowSelected(5)); + assertTrue("Row 7 should be selected after clicking", isRowSelected(7)); + + getGridElement().getCell(7, 1).click(); + + assertFalse("Row should be deselected after clicking again", + isRowSelected(7)); + } + + @Test + public void testDeselectAllowedKeyboardInput() { + openTestURL(); + + setSelectionModelSingle(true); + + getGridElement().getHeaderCell(0, 0).click(); + + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Row 0 should be selected after pressing space", + isRowSelected(0)); + + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertFalse( + "Row 0 should be deselected after pressing space another row", + isRowSelected(0)); + assertTrue("Row 1 should be selected after pressing space", + isRowSelected(1)); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertFalse("Row should be deselected after pressing space again", + isRowSelected(1)); + } + + @Test + public void testDeselectNotAllowedMouseInput() { + openTestURL(); + + setSelectionModelSingle(false); + + getGridElement().getCell(5, 1).click(); + + assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); + + getGridElement().getCell(7, 1).click(); + + assertFalse("Row 5 should be deselected after clicking another row", + isRowSelected(5)); + assertTrue("Row 7 should be selected after clicking", isRowSelected(7)); + + getGridElement().getCell(7, 1).click(); + + assertTrue("Row should remain selected after clicking again", + isRowSelected(7)); + } + + @Test + public void testDeselectNotAllowedKeyboardInput() { + openTestURL(); + + setSelectionModelSingle(false); + + getGridElement().getHeaderCell(0, 0).click(); + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Row 0 should be selected after pressing space", + isRowSelected(0)); + + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertFalse( + "Row 0 should be deselected after pressing space another row", + isRowSelected(0)); + assertTrue("Row 1 should be selected after pressing space", + isRowSelected(1)); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Row should remain selected after pressing space again", + isRowSelected(1)); + } + + @Test + public void testChangeSelectionModelUpdatesUI() { + openTestURL(); + + setSelectionModelSingle(true); + getGridElement().getCell(5, 1).click(); + assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); + setSelectionModelNone(); + assertFalse( + "Row 5 should not be selected after changing selection model", + isRowSelected(5)); + + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientStructureTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientStructureTest.java new file mode 100644 index 0000000000..1aa7a311f3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridClientStructureTest.java @@ -0,0 +1,37 @@ +/* + * 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.basicfeatures.client; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +@SuppressWarnings("all") +public class GridClientStructureTest extends GridBasicClientFeaturesTest { + @Test + public void haederDecoSizeShouldBeRecalculated() { + // it's easier to notice with valo + openTestURL("theme=valo"); + + WebElement topDeco = getGridElement() + .findElement(By.className("v-grid-header-deco")); + assertGreater( + "The header deco in Valo hasn't been recalculated after initial rendering", + topDeco.getSize().getHeight(), 20); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java new file mode 100644 index 0000000000..77ddafcedd --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridDetailsClientTest.java @@ -0,0 +1,252 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; + +import com.vaadin.shared.Range; +import com.vaadin.testbench.By; +import com.vaadin.testbench.ElementQuery; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.customelements.FixedNotificationElement; +import com.vaadin.v7.shared.ui.grid.ScrollDestination; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridDetailsClientTest extends GridBasicClientFeaturesTest { + + private static final String[] SET_GENERATOR = new String[] { "Component", + "Row details", "Set generator" }; + private static final String[] SET_FAULTY_GENERATOR = new String[] { + "Component", "Row details", "Set faulty generator" }; + private static final String[] SET_EMPTY_GENERATOR = new String[] { + "Component", "Row details", "Set empty generator" }; + + @Before + public void setUp() { + setDebug(true); + openTestURL(); + } + + @Test(expected = NoSuchElementException.class) + public void noDetailsByDefault() { + assertNull("details for row 1 should not exist at the start", + getGridElement().getDetails(1)); + } + + @Test(expected = NoSuchElementException.class) + public void nullRendererDoesNotShowDetailsPlaceholder() { + toggleDetailsFor(1); + getGridElement().getDetails(1); + } + + @Test + public void applyRendererThenOpenDetails() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + + TestBenchElement details = getGridElement().getDetails(1); + assertTrue("Unexpected details content", + details.getText().startsWith("Row: 1.")); + } + + @Test(expected = NoSuchElementException.class) + public void openDetailsThenAppyRendererShouldNotShowDetails() { + toggleDetailsFor(1); + selectMenuPath(SET_GENERATOR); + + getGridElement().getDetails(1); + } + + @Test + public void openHiddenDetailsThenScrollToIt() { + try { + getGridElement().getDetails(100); + fail("details row for 100 was apparently found, while it shouldn't have been."); + } catch (NoSuchElementException e) { + // expected + } + + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(100); + + // scroll a bit beyond so we see below. + getGridElement().scrollToRow(101); + + TestBenchElement details = getGridElement().getDetails(100); + assertTrue("Unexpected details content", + details.getText().startsWith("Row: 100.")); + } + + @Test + public void errorUpdaterShowsErrorNotification() { + assertFalse("No notifications should've been at the start", + $(FixedNotificationElement.class).exists()); + + selectMenuPath(SET_FAULTY_GENERATOR); + toggleDetailsFor(1); + + ElementQuery notification = $( + FixedNotificationElement.class); + assertTrue("Was expecting an error notification here", + notification.exists()); + notification.first().close(); + + assertEquals("The error details element should be empty", "", + getGridElement().getDetails(1).getText()); + } + + @Test(expected = NoSuchElementException.class) + public void detailsClosedWhenResettingGenerator() { + + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + + selectMenuPath(SET_FAULTY_GENERATOR); + getGridElement().getDetails(1); + } + + @Test + public void settingNewGeneratorStillWorksAfterError() { + selectMenuPath(SET_FAULTY_GENERATOR); + toggleDetailsFor(1); + $(FixedNotificationElement.class).first().close(); + toggleDetailsFor(1); + + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + + assertNotEquals("New details should've been generated even after error", + "", getGridElement().getDetails(1).getText()); + } + + @Test + public void updaterRendersExpectedWidgets() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + + TestBenchElement detailsElement = getGridElement().getDetails(1); + assertNotNull(detailsElement.findElement(By.className("gwt-Label"))); + assertNotNull(detailsElement.findElement(By.className("gwt-Button"))); + } + + @Test + public void widgetsInUpdaterWorkAsExpected() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + + TestBenchElement detailsElement = getGridElement().getDetails(1); + WebElement button = detailsElement + .findElement(By.className("gwt-Button")); + button.click(); + + WebElement label = detailsElement + .findElement(By.className("gwt-Label")); + assertEquals("clicked", label.getText()); + } + + @Test + public void emptyGenerator() { + selectMenuPath(SET_EMPTY_GENERATOR); + toggleDetailsFor(1); + + assertEquals("empty generator did not produce an empty details row", "", + getGridElement().getDetails(1).getText()); + } + + @Test(expected = NoSuchElementException.class) + public void removeDetailsRow() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + toggleDetailsFor(1); + + getGridElement().getDetails(1); + } + + @Test + public void rowElementClassNames() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(0); + toggleDetailsFor(1); + + List elements = getGridElement() + .findElements(By.className("v-grid-spacer")); + assertEquals("v-grid-spacer", elements.get(0).getAttribute("class")); + assertEquals("v-grid-spacer stripe", + elements.get(1).getAttribute("class")); + } + + @Test + public void scrollDownToRowWithDetails() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(100); + scrollToRow(100, ScrollDestination.ANY); + + Range validScrollRange = Range.between(1691, 1706); + assertTrue(validScrollRange.contains(getGridVerticalScrollPos())); + } + + @Test + public void scrollUpToRowWithDetails() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(100); + scrollGridVerticallyTo(999999); + scrollToRow(100, ScrollDestination.ANY); + + Range validScrollRange = Range.between(1981, 2001); + assertTrue(validScrollRange.contains(getGridVerticalScrollPos())); + } + + @Test + public void cannotScrollBeforeTop() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(1); + scrollToRow(0, ScrollDestination.END); + assertEquals(0, getGridVerticalScrollPos()); + } + + @Test + public void cannotScrollAfterBottom() { + selectMenuPath(SET_GENERATOR); + toggleDetailsFor(999); + scrollToRow(999, ScrollDestination.START); + + Range expectedRange = Range.withLength(19671, 20); + assertTrue(expectedRange.contains(getGridVerticalScrollPos())); + } + + private void scrollToRow(int rowIndex, ScrollDestination destination) { + selectMenuPath(new String[] { "Component", "State", "Scroll to...", + "Row " + rowIndex + "...", "Destination " + destination }); + } + + private void toggleDetailsFor(int rowIndex) { + selectMenuPath(new String[] { "Component", "Row details", + "Toggle details for...", "Row " + rowIndex }); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridEditorClientTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridEditorClientTest.java new file mode 100644 index 0000000000..aaa2bd66f9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridEditorClientTest.java @@ -0,0 +1,301 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.v7.shared.ui.grid.GridConstants; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; + +public class GridEditorClientTest extends GridBasicClientFeaturesTest { + + private static final String[] EDIT_ROW_100 = new String[] { "Component", + "Editor", "Edit row 100" }; + private static final String[] EDIT_ROW_5 = new String[] { "Component", + "Editor", "Edit row 5" }; + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "Editor", "Enabled"); + } + + @Test + public void testProgrammaticOpeningClosing() { + selectMenuPath(EDIT_ROW_5); + assertNotNull(getEditor()); + + selectMenuPath("Component", "Editor", "Cancel edit"); + assertNull(getEditor()); + assertEquals("Row 5 edit cancelled", + findElement(By.className("grid-editor-log")).getText()); + } + + @Test + public void testProgrammaticOpeningWithScroll() { + selectMenuPath(EDIT_ROW_100); + assertNotNull(getEditor()); + } + + @Test(expected = NoSuchElementException.class) + public void testVerticalScrollLocking() { + selectMenuPath(EDIT_ROW_5); + getGridElement().getCell(200, 0); + } + + @Test + public void testMouseOpeningClosing() { + + getGridElement().getCell(4, 0).doubleClick(); + assertNotNull(getEditor()); + + // Move focus to the third input field + getEditor().findElements(By.className("gwt-TextBox")).get(2).click(); + + // Press save button + getSaveButton().click(); + + // Make sure the editor went away + assertNull(getEditor()); + + // Check that focus has moved to cell 4,2 - the last one that was + // focused in Editor + assertTrue(getGridElement().getCell(4, 2).isFocused()); + + // Disable editor + selectMenuPath("Component", "Editor", "Enabled"); + + getGridElement().getCell(4, 0).doubleClick(); + assertNull(getEditor()); + } + + @Test + public void testKeyboardOpeningClosing() { + + getGridElement().getCell(4, 0).click(); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertNotNull(getEditor()); + + new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); + assertNull(getEditor()); + assertEquals("Row 4 edit cancelled", + findElement(By.className("grid-editor-log")).getText()); + + // Disable editor + selectMenuPath("Component", "Editor", "Enabled"); + + getGridElement().getCell(5, 0).click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertNull(getEditor()); + } + + @Test + public void testWidgetBinding() throws Exception { + selectMenuPath(EDIT_ROW_100); + WebElement editor = getEditor(); + + List widgets = editor + .findElements(By.className("gwt-TextBox")); + + assertEquals(GridBasicFeatures.EDITABLE_COLUMNS, widgets.size()); + + assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); + assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); + assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); + + assertEquals("100", widgets.get(6).getAttribute("value")); + assertEquals("100", widgets.get(8).getAttribute("value")); + } + + @Test + public void testWithSelectionColumn() throws Exception { + selectMenuPath("Component", "State", "Selection mode", "multi"); + selectMenuPath("Component", "State", "Frozen column count", + "-1 columns"); + selectMenuPath(EDIT_ROW_5); + + WebElement editorCells = findElements( + By.className("v-grid-editor-cells")).get(1); + List selectorDivs = editorCells + .findElements(By.cssSelector("div")); + + assertFalse("selector column cell should've had contents", + selectorDivs.get(0).getAttribute("innerHTML").isEmpty()); + assertFalse("normal column cell shoul've had contents", + selectorDivs.get(1).getAttribute("innerHTML").isEmpty()); + } + + @Test + public void testSave() { + selectMenuPath(EDIT_ROW_100); + + WebElement textField = getEditor() + .findElements(By.className("gwt-TextBox")).get(0); + + textField.clear(); + textField.sendKeys("Changed"); + + WebElement saveButton = getEditor() + .findElement(By.className("v-grid-editor-save")); + + saveButton.click(); + + assertEquals("Changed", getGridElement().getCell(100, 0).getText()); + } + + @Test + public void testProgrammaticSave() { + selectMenuPath(EDIT_ROW_100); + + WebElement textField = getEditor() + .findElements(By.className("gwt-TextBox")).get(0); + + textField.clear(); + textField.sendKeys("Changed"); + + selectMenuPath("Component", "Editor", "Save"); + + assertEquals("Changed", getGridElement().getCell(100, 0).getText()); + } + + @Test + public void testCaptionChange() { + selectMenuPath(EDIT_ROW_5); + assertEquals("Save button caption should've been \"" + + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with", + GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); + assertEquals("Cancel button caption should've been \"" + + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with", + GridConstants.DEFAULT_CANCEL_CAPTION, + getCancelButton().getText()); + + selectMenuPath("Component", "Editor", "Change Save Caption"); + assertNotEquals( + "Save button caption should've changed while editor is open", + GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); + + getCancelButton().click(); + + selectMenuPath("Component", "Editor", "Change Cancel Caption"); + selectMenuPath(EDIT_ROW_5); + assertNotEquals( + "Cancel button caption should've changed while editor is closed", + GridConstants.DEFAULT_CANCEL_CAPTION, + getCancelButton().getText()); + } + + @Test + public void testUneditableColumn() { + selectMenuPath("Component", "Editor", "Edit row 5"); + + assertFalse("Uneditable column should not have an editor widget", + getGridElement().getEditor().isEditable(3)); + } + + @Test + public void testErrorField() { + selectMenuPath(EDIT_ROW_5); + + GridEditorElement editor = getGridElement().getEditor(); + + assertTrue("No errors should be present", + editor.findElements(By.className("error")).isEmpty()); + assertEquals("No error message should be present", null, + editor.getErrorMessage()); + + selectMenuPath("Component", "Editor", "Toggle second editor error"); + getSaveButton().click(); + + assertEquals("Unexpected amount of error fields", 1, + editor.findElements(By.className("error")).size()); + assertEquals("Unexpedted error message", + "Syntethic fail of editor in column 2. " + + "This message is so long that it doesn't fit into its box", + editor.getErrorMessage()); + } + + @Test + public void testFocusOnMouseOpen() { + + GridCellElement cell = getGridElement().getCell(4, 2); + + cell.doubleClick(); + + WebElement focused = getFocusedElement(); + + assertEquals("", "input", focused.getTagName()); + assertEquals("", cell.getText(), focused.getAttribute("value")); + } + + @Test + public void testFocusOnKeyboardOpen() { + + GridCellElement cell = getGridElement().getCell(4, 2); + + cell.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + WebElement focused = getFocusedElement(); + + assertEquals("", "input", focused.getTagName()); + assertEquals("", cell.getText(), focused.getAttribute("value")); + } + + @Test + public void testNoFocusOnProgrammaticOpen() { + + selectMenuPath(EDIT_ROW_5); + + WebElement focused = getFocusedElement(); + + if (BrowserUtil.isIE(getDesiredCapabilities())) { + assertEquals("Focus should be nowhere", null, focused); + } else { + // GWT menubar loses focus after clicking a menuitem + assertEquals("Focus should be in body", "body", + focused.getTagName()); + } + } + + protected WebElement getSaveButton() { + return getEditor().findElement(By.className("v-grid-editor-save")); + } + + protected WebElement getCancelButton() { + return getEditor().findElement(By.className("v-grid-editor-cancel")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridFooterTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridFooterTest.java new file mode 100644 index 0000000000..906f1fedba --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridFooterTest.java @@ -0,0 +1,220 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; + +public class GridFooterTest extends GridStaticSectionTest { + + @Test + public void testDefaultFooter() { + openTestURL(); + + // Footer should have zero rows by default + assertFooterCount(0); + } + + @Test + public void testFooterVisibility() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Visible"); + + assertFooterCount(0); + + selectMenuPath("Component", "Footer", "Append row"); + + assertFooterCount(0); + + selectMenuPath("Component", "Footer", "Visible"); + + assertFooterCount(1); + } + + @Test + public void testAddRows() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + assertFooterCount(1); + assertFooterTexts(0, 0); + + selectMenuPath("Component", "Footer", "Prepend row"); + + assertFooterCount(2); + assertFooterTexts(1, 0); + assertFooterTexts(0, 1); + + selectMenuPath("Component", "Footer", "Append row"); + + assertFooterCount(3); + assertFooterTexts(1, 0); + assertFooterTexts(0, 1); + assertFooterTexts(2, 2); + } + + @Test + public void testRemoveRows() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Prepend row"); + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Remove top row"); + + assertFooterCount(1); + assertFooterTexts(1, 0); + + selectMenuPath("Component", "Footer", "Remove bottom row"); + assertFooterCount(0); + } + + @Test + public void joinColumnsByCells() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Row 1", + "Join column cells 0, 1"); + + GridCellElement spannedCell = getGridElement().getFooterCell(0, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + // TestBench returns the spanned cell for all columns + assertEquals(spannedCell.getText(), + getGridElement().getFooterCell(0, 1).getText()); + } + + @Test + public void joinColumnsByColumns() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Row 1", "Join columns 1, 2"); + + GridCellElement spannedCell = getGridElement().getFooterCell(0, 1); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + // TestBench returns the spanned cell for all columns + assertEquals(spannedCell.getText(), + getGridElement().getFooterCell(0, 2).getText()); + } + + @Test + public void joinAllColumnsInRow() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Footer", "Row 1", "Join all columns"); + + GridCellElement spannedCell = getGridElement().getFooterCell(0, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("" + GridBasicFeatures.COLUMNS, + spannedCell.getAttribute("colspan")); + + for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) { + GridCellElement hiddenCell = getGridElement().getFooterCell(0, + columnIndex); + // TestBench returns the spanned cell for all columns + assertEquals(spannedCell.getText(), hiddenCell.getText()); + } + } + + @Test + public void testInitialCellTypes() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + GridCellElement textCell = getGridElement().getFooterCell(0, 0); + /* + * Reindeer has a CSS text transformation that changes the casing so + * that we can't rely on it being what we set + */ + assertEquals("footer (0,0)", textCell.getText().toLowerCase()); + + GridCellElement widgetCell = getGridElement().getFooterCell(0, 1); + assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML"))); + + GridCellElement htmlCell = getGridElement().getFooterCell(0, 2); + assertHTML("Footer (0,2)", htmlCell); + } + + @Test + public void testDynamicallyChangingCellType() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Columns", "Column 0", "Footer Type", + "Widget Footer"); + GridCellElement widgetCell = getGridElement().getFooterCell(0, 0); + assertTrue(widgetCell.isElementPresent(By.className("gwt-Button"))); + + selectMenuPath("Component", "Columns", "Column 1", "Footer Type", + "HTML Footer"); + GridCellElement htmlCell = getGridElement().getFooterCell(0, 1); + assertHTML("HTML Footer", htmlCell); + + selectMenuPath("Component", "Columns", "Column 2", "Footer Type", + "Text Footer"); + GridCellElement textCell = getGridElement().getFooterCell(0, 2); + + /* + * Reindeer has a CSS text transformation that changes the casing so + * that we can't rely on it being what we set + */ + assertEquals("text footer", textCell.getText().toLowerCase()); + } + + @Test + public void testCellWidgetInteraction() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Append row"); + + selectMenuPath("Component", "Columns", "Column 0", "Footer Type", + "Widget Footer"); + GridCellElement widgetCell = getGridElement().getFooterCell(0, 0); + WebElement button = widgetCell.findElement(By.className("gwt-Button")); + + assertNotEquals("clicked", button.getText().toLowerCase()); + + new Actions(getDriver()).moveToElement(button, 5, 5).click().perform(); + + assertEquals("clicked", button.getText().toLowerCase()); + } + + private void assertFooterCount(int count) { + assertEquals("footer count", count, getGridElement().getFooterCount()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridHeaderTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridHeaderTest.java new file mode 100644 index 0000000000..0f4a10a1af --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridHeaderTest.java @@ -0,0 +1,282 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; + +public class GridHeaderTest extends GridStaticSectionTest { + + @Test + public void testDefaultHeader() throws Exception { + openTestURL(); + + assertHeaderCount(1); + assertHeaderTexts(0, 0); + } + + @Test + public void testHeaderVisibility() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Visible"); + + assertHeaderCount(0); + + selectMenuPath("Component", "Header", "Append row"); + + assertHeaderCount(0); + + selectMenuPath("Component", "Header", "Visible"); + + assertHeaderCount(2); + } + + @Test + public void testHeaderCaptions() throws Exception { + openTestURL(); + + assertHeaderTexts(0, 0); + } + + @Test + public void testAddRows() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + assertHeaderCount(2); + assertHeaderTexts(0, 0); + assertHeaderTexts(1, 1); + + selectMenuPath("Component", "Header", "Prepend row"); + + assertHeaderCount(3); + assertHeaderTexts(2, 0); + assertHeaderTexts(0, 1); + assertHeaderTexts(1, 2); + + selectMenuPath("Component", "Header", "Append row"); + + assertHeaderCount(4); + assertHeaderTexts(2, 0); + assertHeaderTexts(0, 1); + assertHeaderTexts(1, 2); + assertHeaderTexts(3, 3); + } + + @Test + public void testRemoveRows() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Prepend row"); + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Remove top row"); + + assertHeaderCount(2); + assertHeaderTexts(0, 0); + assertHeaderTexts(2, 1); + + selectMenuPath("Component", "Header", "Remove bottom row"); + assertHeaderCount(1); + assertHeaderTexts(0, 0); + } + + @Test + public void testDefaultRow() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Sortable"); + + GridCellElement headerCell = getGridElement().getHeaderCell(0, 0); + + headerCell.click(); + + assertTrue(hasClassName(headerCell, "sort-asc")); + + headerCell.click(); + + assertFalse(hasClassName(headerCell, "sort-asc")); + assertTrue(hasClassName(headerCell, "sort-desc")); + + selectMenuPath("Component", "Header", "Prepend row"); + selectMenuPath("Component", "Header", "Default row", "Top"); + + assertFalse(hasClassName(headerCell, "sort-desc")); + headerCell = getGridElement().getHeaderCell(0, 0); + assertTrue(hasClassName(headerCell, "sort-desc")); + + selectMenuPath("Component", "Header", "Default row", "Unset"); + + assertFalse(hasClassName(headerCell, "sort-desc")); + } + + @Test + public void joinHeaderColumnsByCells() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Row 2", + "Join column cells 0, 1"); + + GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + // TestBench returns the spanned cell for all spanned columns + GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 1); + assertEquals(spannedCell.getText(), hiddenCell.getText()); + } + + @Test + public void joinHeaderColumnsByColumns() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Row 2", "Join columns 1, 2"); + + GridCellElement spannedCell = getGridElement().getHeaderCell(1, 1); + assertTrue(spannedCell.isDisplayed()); + assertEquals("2", spannedCell.getAttribute("colspan")); + + // TestBench returns the spanned cell for all spanned columns + GridCellElement hiddenCell = getGridElement().getHeaderCell(1, 2); + assertEquals(spannedCell.getText(), hiddenCell.getText()); + } + + @Test + public void joinAllColumnsInHeaderRow() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Header", "Append row"); + + selectMenuPath("Component", "Header", "Row 2", "Join all columns"); + + GridCellElement spannedCell = getGridElement().getHeaderCell(1, 0); + assertTrue(spannedCell.isDisplayed()); + assertEquals("" + GridBasicFeatures.COLUMNS, + spannedCell.getAttribute("colspan")); + + for (int columnIndex = 1; columnIndex < GridBasicFeatures.COLUMNS; columnIndex++) { + // TestBench returns the spanned cell for all spanned columns + GridCellElement hiddenCell = getGridElement().getHeaderCell(1, + columnIndex); + assertEquals(spannedCell.getText(), hiddenCell.getText()); + } + } + + @Test + public void testInitialCellTypes() throws Exception { + openTestURL(); + + GridCellElement textCell = getGridElement().getHeaderCell(0, 0); + + /* + * Reindeer has a CSS text transformation that changes the casing so + * that we can't rely on it being what we set + */ + assertEquals("header (0,0)", textCell.getText().toLowerCase()); + + GridCellElement widgetCell = getGridElement().getHeaderCell(0, 1); + assertTrue(widgetCell.isElementPresent(By.className("gwt-HTML"))); + + GridCellElement htmlCell = getGridElement().getHeaderCell(0, 2); + assertHTML("Header (0,2)", htmlCell); + } + + @Test + public void testDynamicallyChangingCellType() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Header Type", + "Widget Header"); + GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0); + assertTrue(widgetCell.isElementPresent(By.className("gwt-Button"))); + + selectMenuPath("Component", "Columns", "Column 1", "Header Type", + "HTML Header"); + GridCellElement htmlCell = getGridElement().getHeaderCell(0, 1); + assertHTML("HTML Header", htmlCell); + + selectMenuPath("Component", "Columns", "Column 2", "Header Type", + "Text Header"); + GridCellElement textCell = getGridElement().getHeaderCell(0, 2); + + /* + * Reindeer has a CSS text transformation that changes the casing so + * that we can't rely on it being what we set + */ + assertEquals("text header", textCell.getText().toLowerCase()); + } + + @Test + public void testCellWidgetInteraction() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Header Type", + "Widget Header"); + GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0); + WebElement button = widgetCell.findElement(By.className("gwt-Button")); + + new Actions(getDriver()).moveToElement(button, 5, 5).click().perform(); + + assertEquals("clicked", button.getText().toLowerCase()); + } + + @Test + public void widgetInSortableCellInteraction() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Header Type", + "Widget Header"); + + selectMenuPath("Component", "Columns", "Column 0", "Sortable"); + + GridCellElement widgetCell = getGridElement().getHeaderCell(0, 0); + WebElement button = widgetCell.findElement(By.className("gwt-Button")); + + assertNotEquals("clicked", button.getText().toLowerCase()); + + new Actions(getDriver()).moveToElement(button, 5, 5).click().perform(); + + assertEquals("clicked", button.getText().toLowerCase()); + } + + private void assertHeaderCount(int count) { + assertEquals("header count", count, getGridElement().getHeaderCount()); + } + + private boolean hasClassName(TestBenchElement element, String name) { + return Arrays.asList(element.getAttribute("class").split(" ")) + .contains(name); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridRowHandleRefreshTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridRowHandleRefreshTest.java new file mode 100644 index 0000000000..95c5d056db --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridRowHandleRefreshTest.java @@ -0,0 +1,65 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridRowHandleRefreshTest extends GridBasicClientFeaturesTest { + + @Test + public void testRefreshingThroughRowHandle() { + openTestURL(); + + assertEquals("Unexpected initial state", "(0, 0)", + getGridElement().getCell(0, 0).getText()); + selectMenuPath("Component", "State", "Edit and refresh Row 0"); + assertEquals("Cell contents did not update correctly", "Foo", + getGridElement().getCell(0, 0).getText()); + } + + @Test + public void testDelayedRefreshingThroughRowHandle() + throws InterruptedException { + openTestURL(); + + assertEquals("Unexpected initial state", "(0, 0)", + getGridElement().getCell(0, 0).getText()); + selectMenuPath("Component", "State", "Delayed edit of Row 0"); + // Still the same data + assertEquals("Cell contents did not update correctly", "(0, 0)", + getGridElement().getCell(0, 0).getText()); + sleep(5000); + // Data should be updated + assertEquals("Cell contents did not update correctly", "Bar", + getGridElement().getCell(0, 0).getText()); + } + + @Test + public void testRefreshingWhenNotInViewThroughRowHandle() { + openTestURL(); + + assertEquals("Unexpected initial state", "(0, 0)", + getGridElement().getCell(0, 0).getText()); + getGridElement().scrollToRow(100); + selectMenuPath("Component", "State", "Edit and refresh Row 0"); + assertEquals("Cell contents did not update correctly", "Foo", + getGridElement().getCell(0, 0).getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridSidebarContentTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridSidebarContentTest.java new file mode 100644 index 0000000000..5adae48d62 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridSidebarContentTest.java @@ -0,0 +1,147 @@ +/* + * 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.basicfeatures.client; + +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.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; + +public class GridSidebarContentTest extends GridBasicClientFeaturesTest { + + @Test + public void testSidebarWithHidableColumn() { + openTestURL(); + + Assert.assertEquals("Sidebar should not be initially present", 0, + countBySelector(".v-grid-sidebar-button")); + + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + + getSidebarOpenButton().click(); + + WebElement toggle = getSidebarPopup() + .findElement(By.className("column-hiding-toggle")); + + Assert.assertEquals("Column 0 should be togglable", "Header (0,0)", + toggle.getText()); + + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + Assert.assertEquals("Sidebar should disappear without toggable column", + 0, countBySelector(".v-grid-sidebar-button")); + + } + + @Test + public void testAddingCustomSidebarItem() { + openTestURL(); + GridElement gridElement = getGridElement(); + + selectMenuPath("Component", "Sidebar", "Add item to end"); + + gridElement.findElement(By.className("v-grid-sidebar-button")).click(); + + WebElement sidebarItem = getSidebarPopup().findElement( + By.cssSelector(".v-grid-sidebar-content .gwt-MenuItem")); + + sidebarItem.click(); + + Assert.assertEquals("Sidebar should be closed after clicking item 0", 0, + countBySelector(".v-grid-sidebar-content")); + } + + @Test + public void testProgrammaticSidebarOpen() { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + + selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); + + Assert.assertEquals("Sidebar should be open", 1, + countBySelector(".v-grid-sidebar-content")); + } + + @Test + public void testBasicSidebarOrder() { + openTestURL(); + + // First add custom content + selectMenuPath("Component", "Sidebar", "Add separator to end"); + selectMenuPath("Component", "Sidebar", "Add item to end"); + + // Then make one column togglable + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + + selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); + + assertSidebarMenuItems("Header (0,0)", null, "Custom menu item 0"); + } + + @Test + public void testSidebarOrderAbuse() { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 0", "Hidable"); + selectMenuPath("Component", "Columns", "Column 1", "Hidable"); + + // Inserts a menu item between the two visibility toggles + selectMenuPath("Component", "Sidebar", "Add item before index 1"); + + selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); + + // Total order enforcement not implemented at this point. Test can be + // updated when it is. + assertSidebarMenuItems("Header (0,0)", "Custom menu item 0", + "Header (0,1)"); + + selectMenuPath("Component", "Columns", "Column 2", "Hidable"); + selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility"); + + // Adding a new togglable column should have restored the expected order + assertSidebarMenuItems("Header (0,0)", "Header (0,1)", "Header (0,2)", + "Custom menu item 0"); + } + + private void assertSidebarMenuItems(String... items) { + List menuItems = getSidebarPopup() + .findElements(By.cssSelector(".v-grid-sidebar-content td")); + + Assert.assertEquals("Expected " + items.length + " menu items", + items.length, menuItems.size()); + + for (int i = 0; i < items.length; i++) { + String expectedItem = items[i]; + if (expectedItem == null) { + Assert.assertEquals("Item " + i + " should be a separator", + "gwt-MenuItemSeparator", + menuItems.get(i).getAttribute("class")); + } else { + Assert.assertEquals("Unexpected content for item " + i, + expectedItem, menuItems.get(i).getText()); + } + } + } + + private int countBySelector(String cssSelector) { + return findElements(By.cssSelector(cssSelector)).size(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridStaticSectionTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridStaticSectionTest.java new file mode 100644 index 0000000000..835e9d576c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridStaticSectionTest.java @@ -0,0 +1,101 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; + +/** + * Abstract base class for header and footer tests. + * + * @since + * @author Vaadin Ltd + */ +public abstract class GridStaticSectionTest + extends GridBasicClientFeaturesTest { + + protected void assertHeaderTexts(int headerId, int rowIndex) { + int i = 0; + for (TestBenchElement cell : getGridElement() + .getHeaderCells(rowIndex)) { + WebElement content = cell.findElement(By.tagName("div")); + + if (i % 3 == 0) { + assertText(String.format("Header (%d,%d)", headerId, i), + content); + } else if (i % 2 == 0) { + assertHTML(String.format("Header (%d,%d)", headerId, i), + content); + } else { + assertHTML(String.format( + "
Header (%d,%d)
", + headerId, i), content); + } + + i++; + } + assertEquals("number of header columns", GridBasicFeatures.COLUMNS, i); + } + + protected void assertFooterTexts(int footerId, int rowIndex) { + int i = 0; + for (TestBenchElement cell : getGridElement() + .getFooterCells(rowIndex)) { + WebElement content = cell.findElement(By.tagName("div")); + + if (i % 3 == 0) { + assertText(String.format("Footer (%d,%d)", footerId, i), + content); + } else if (i % 2 == 0) { + assertHTML(String.format("Footer (%d,%d)", footerId, i), + content); + } else { + assertHTML(String.format( + "
Footer (%d,%d)
", + footerId, i), content); + } + i++; + } + assertEquals("number of footer columns", GridBasicFeatures.COLUMNS, i); + } + + protected static void assertText(String text, WebElement e) { + // TBE.getText returns "" if the element is scrolled out of view + assertEquals(text, e.getAttribute("innerHTML")); + } + + protected static void assertHTML(String text, WebElement e) { + String html = e.getAttribute("innerHTML"); + + // IE 8 returns tags as upper case while other browsers do not, make the + // comparison non-casesensive + html = html.toLowerCase(); + text = text.toLowerCase(); + + // IE 8 returns attributes without quotes, make the comparison without + // quotes + html = html.replaceAll("\"", ""); + text = html.replaceAll("\"", ""); + + assertEquals(text, html); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridStylingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridStylingTest.java new file mode 100644 index 0000000000..b3cd8a23a9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/client/GridStylingTest.java @@ -0,0 +1,115 @@ +/* + * 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.basicfeatures.client; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; + +public class GridStylingTest extends GridStaticSectionTest { + + @Test + public void testGridPrimaryStyle() throws Exception { + openTestURL(); + + validateStylenames("v-grid"); + } + + @Test + public void testChangingPrimaryStyleName() throws Exception { + openTestURL(); + + selectMenuPath("Component", "State", "Primary Stylename", + "v-custom-style"); + + validateStylenames("v-custom-style"); + } + + private void validateStylenames(String stylename) { + + String classNames = getGridElement().getAttribute("class"); + assertEquals(stylename, classNames); + + classNames = getGridElement().getVerticalScroller() + .getAttribute("class"); + assertTrue(classNames.contains(stylename + "-scroller")); + assertTrue(classNames.contains(stylename + "-scroller-vertical")); + + classNames = getGridElement().getHorizontalScroller() + .getAttribute("class"); + assertTrue(classNames.contains(stylename + "-scroller")); + assertTrue(classNames.contains(stylename + "-scroller-horizontal")); + + classNames = getGridElement().getTableWrapper().getAttribute("class"); + assertEquals(stylename + "-tablewrapper", classNames); + + classNames = getGridElement().getHeader().getAttribute("class"); + assertEquals(stylename + "-header", classNames); + + for (int row = 0; row < getGridElement().getHeaderCount(); row++) { + classNames = getGridElement().getHeaderRow(row) + .getAttribute("class"); + assertEquals(stylename + "-row", classNames); + + for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) { + classNames = getGridElement().getHeaderCell(row, col) + .getAttribute("class"); + assertTrue(classNames.contains(stylename + "-cell")); + } + } + + classNames = getGridElement().getBody().getAttribute("class"); + assertEquals(stylename + "-body", classNames); + + int rowsInBody = getGridElement().getBody() + .findElements(By.tagName("tr")).size(); + for (int row = 0; row < rowsInBody; row++) { + classNames = getGridElement().getRow(row).getAttribute("class"); + assertTrue(classNames.contains(stylename + "-row")); + assertTrue(classNames.contains(stylename + "-row-has-data")); + + for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) { + classNames = getGridElement().getCell(row, col) + .getAttribute("class"); + assertTrue(classNames.contains(stylename + "-cell")); + + if (row == 0 && col == 0) { + assertTrue( + classNames.contains(stylename + "-cell-focused")); + } + } + } + + classNames = getGridElement().getFooter().getAttribute("class"); + assertEquals(stylename + "-footer", classNames); + + for (int row = 0; row < getGridElement().getFooterCount(); row++) { + classNames = getGridElement().getFooterRow(row) + .getAttribute("class"); + assertEquals(stylename + "-row", classNames); + + for (int col = 0; col < GridBasicFeatures.COLUMNS; col++) { + classNames = getGridElement().getFooterCell(row, col) + .getAttribute("class"); + assertTrue(classNames.contains(stylename + "-cell")); + } + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java new file mode 100644 index 0000000000..63e43f4c1a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorBasicsTest.java @@ -0,0 +1,80 @@ +/* + * 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.basicfeatures.escalator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +public class EscalatorBasicsTest extends EscalatorBasicClientFeaturesTest { + + @Before + public void setUp() { + setDebug(true); + openTestURL(); + } + + @Test + public void testDetachingAnEmptyEscalator() { + selectMenuPath(GENERAL, DETACH_ESCALATOR); + assertEscalatorIsRemovedCorrectly(); + } + + @Test + public void testDetachingASemiPopulatedEscalator() throws IOException { + selectMenuPath(COLUMNS_AND_ROWS, ADD_ONE_OF_EACH_ROW); + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + selectMenuPath(GENERAL, DETACH_ESCALATOR); + assertEscalatorIsRemovedCorrectly(); + } + + @Test + public void testDetachingAPopulatedEscalator() { + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + selectMenuPath(GENERAL, DETACH_ESCALATOR); + assertEscalatorIsRemovedCorrectly(); + } + + @Test + public void testDetachingAndReattachingAnEscalator() { + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + scrollVerticallyTo(50); + scrollHorizontallyTo(50); + + selectMenuPath(GENERAL, DETACH_ESCALATOR); + selectMenuPath(GENERAL, ATTACH_ESCALATOR); + + assertEquals("Vertical scroll position", 50, getScrollTop()); + assertEquals("Horizontal scroll position", 50, getScrollLeft()); + + assertEquals("First cell of first visible row", "Row 2: 0,2", + getBodyCell(0, 0).getText()); + } + + private void assertEscalatorIsRemovedCorrectly() { + assertFalse($(NotificationElement.class).exists()); + assertNull(getEscalator()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java new file mode 100644 index 0000000000..294c44cdbb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorColspanTest.java @@ -0,0 +1,80 @@ +/* + * 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.basicfeatures.escalator; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +public class EscalatorColspanTest extends EscalatorBasicClientFeaturesTest { + private static final int NO_COLSPAN = 1; + + @Test + public void testNoColspan() { + openTestURL(); + populate(); + + assertEquals(NO_COLSPAN, getColSpan(getHeaderCell(0, 0))); + assertEquals(NO_COLSPAN, getColSpan(getBodyCell(0, 0))); + assertEquals(NO_COLSPAN, getColSpan(getFooterCell(0, 0))); + } + + @Test + public void testColspan() { + openTestURL(); + populate(); + + int firstCellWidth = getBodyCell(0, 0).getSize().getWidth(); + int secondCellWidth = getBodyCell(0, 1).getSize().getWidth(); + int doubleCellWidth = firstCellWidth + secondCellWidth; + + selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL); + + WebElement bodyCell = getBodyCell(0, 0); + assertEquals("Cell was not spanned correctly", 2, getColSpan(bodyCell)); + assertEquals( + "Spanned cell's width was not the sum of the previous cells (" + + firstCellWidth + " + " + secondCellWidth + ")", + doubleCellWidth, bodyCell.getSize().getWidth(), 1); + } + + @Test + public void testColspanToggle() { + openTestURL(); + populate(); + + int singleCellWidth = getBodyCell(0, 0).getSize().getWidth(); + + selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL); + selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NONE); + + WebElement bodyCell = getBodyCell(0, 0); + assertEquals(NO_COLSPAN, getColSpan(bodyCell)); + assertEquals(singleCellWidth, bodyCell.getSize().getWidth(), 1); + } + + private static int getColSpan(WebElement cell) { + String attribute = cell.getAttribute("colspan"); + if (attribute == null) { + return NO_COLSPAN; + } else { + return Integer.parseInt(attribute); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java new file mode 100644 index 0000000000..715464ff82 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorColumnFreezingTest.java @@ -0,0 +1,111 @@ +/* + * 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.basicfeatures.escalator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +public class EscalatorColumnFreezingTest + extends EscalatorBasicClientFeaturesTest { + + private final static Pattern TRANSFORM_PATTERN = Pattern.compile(// @formatter:off + // any start of the string + ".*" + + // non-capturing group for "webkitTransform: " or "transform: " + + "(?:webkitT|t)ransform: " + + // non-capturing group for "translate" or "translate3d" + + "translate(?:3d)?" + + // capturing the digits in e.g "(100px," + + "\\((\\d+)px," + + // any end of the string + + ".*", Pattern.CASE_INSENSITIVE); + + // @formatter:on + + private final static Pattern LEFT_PATTERN = Pattern + .compile(".*left: (\\d+)px.*", Pattern.CASE_INSENSITIVE); + + private static final int NO_FREEZE = -1; + + @Test + public void testNoFreeze() { + openTestURL(); + populate(); + + WebElement bodyCell = getBodyCell(0, 0); + assertFalse(isFrozen(bodyCell)); + assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell)); + } + + @Test + public void testOneFreeze() { + openTestURL(); + populate(); + + selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); + int scrollPx = 60; + scrollHorizontallyTo(scrollPx); + + WebElement bodyCell = getBodyCell(0, 0); + assertTrue(isFrozen(bodyCell)); + assertEquals(scrollPx, getFrozenScrollCompensation(bodyCell)); + } + + @Test + public void testFreezeToggle() { + openTestURL(); + populate(); + + selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); + scrollHorizontallyTo(100); + selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_0_COLUMNS); + + WebElement bodyCell = getBodyCell(0, 0); + assertFalse(isFrozen(bodyCell)); + assertEquals(NO_FREEZE, getFrozenScrollCompensation(bodyCell)); + } + + private static boolean isFrozen(WebElement cell) { + return cell.getAttribute("class").contains("frozen"); + } + + private static int getFrozenScrollCompensation(WebElement cell) { + String styleAttribute = cell.getAttribute("style"); + Matcher transformMatcher = TRANSFORM_PATTERN.matcher(styleAttribute); + Matcher leftMatcher = LEFT_PATTERN.matcher(styleAttribute); + + if (transformMatcher.find()) { + return Integer.parseInt(transformMatcher.group(1)); + } else if (leftMatcher.find()) { + return Integer.parseInt(leftMatcher.group(1)); + } else { + return NO_FREEZE; + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.java new file mode 100644 index 0000000000..e8aaf823f9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.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.v7.tests.components.grid.basicfeatures.escalator; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +/** + * Test class to test the escalator level issue for ticket #16832 + */ +public class EscalatorRemoveAndAddRowsTest + extends EscalatorBasicClientFeaturesTest { + + @Test + public void testRemoveAllRowsAndAddThirtyThenScroll() throws IOException { + openTestURL(); + + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + scrollVerticallyTo(99999); + assertTrue("Escalator is not scrolled to bottom.", + isElementPresent(By.xpath("//td[text() = 'Row 99: 0,99']"))); + + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_INSERT_SCROLL); + + scrollVerticallyTo(99999); + assertTrue("Escalator is not scrolled to bottom.", + isElementPresent(By.xpath("//td[text() = 'Row 29: 0,129']"))); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java new file mode 100644 index 0000000000..446e4f4d9a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorRowColumnTest.java @@ -0,0 +1,316 @@ +/* + * 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.basicfeatures.escalator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +public class EscalatorRowColumnTest extends EscalatorBasicClientFeaturesTest { + + /** + * The scroll position of the Escalator when scrolled all the way down, to + * reveal the 100:th row. + */ + private static final int BOTTOM_SCROLL_POSITION = 1857; + + @Test + public void testInit() { + openTestURL(); + assertNotNull(getEscalator()); + assertNull(getHeaderRow(0)); + assertNull(getBodyRow(0)); + assertNull(getFooterRow(0)); + + assertLogContains("Columns: 0"); + assertLogContains("Header rows: 0"); + assertLogContains("Body rows: 0"); + assertLogContains("Footer rows: 0"); + } + + @Test + public void testInsertAColumn() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + assertNull(getHeaderRow(0)); + assertNull(getBodyRow(0)); + assertNull(getFooterRow(0)); + assertLogContains("Columns: 1"); + } + + @Test + public void testInsertAHeaderRow() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Header rows: 1"); + } + + @Test + public void testInsertABodyRow() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Body rows: 1"); + } + + @Test + public void testInsertAFooterRow() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Footer rows: 1"); + } + + @Test + public void testInsertAColumnAndAHeaderRow() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING); + assertNotNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Columns: 1"); + assertLogContains("Header rows: 1"); + } + + @Test + public void testInsertAColumnAndABodyRow() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNotNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Columns: 1"); + assertLogContains("Body rows: 1"); + } + + @Test + public void testInsertAColumnAndAFooterRow() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNotNull(getFooterCell(0, 0)); + assertLogContains("Columns: 1"); + assertLogContains("Footer rows: 1"); + } + + @Test + public void testInsertAHeaderRowAndAColumn() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + assertNotNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Columns: 1"); + assertLogContains("Header rows: 1"); + } + + @Test + public void testInsertABodyRowAndAColumn() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNotNull(getBodyCell(0, 0)); + assertNull(getFooterCell(0, 0)); + assertLogContains("Columns: 1"); + assertLogContains("Body rows: 1"); + } + + @Test + public void testInsertAFooterRowAndAColumn() { + openTestURL(); + + selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING); + assertNull(getHeaderCell(0, 0)); + assertNull(getBodyCell(0, 0)); + assertNotNull(getFooterCell(0, 0)); + assertLogContains("Columns: 1"); + assertLogContains("Footer rows: 1"); + } + + @Test + public void testFillColRow() { + openTestURL(); + + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + scrollVerticallyTo(2000); // more like 1857, but this should be enough. + + // if not found, an exception is thrown here + assertTrue("Wanted cell was not visible", + isElementPresent(By.xpath("//td[text()='Cell: 9,99']"))); + } + + @Test + public void testFillRowCol() { + openTestURL(); + + selectMenuPath(GENERAL, POPULATE_ROW_COLUMN); + scrollVerticallyTo(2000); // more like 1857, but this should be enough. + + // if not found, an exception is thrown here + assertTrue("Wanted cell was not visible", + isElementPresent(By.xpath("//td[text()='Cell: 9,99']"))); + } + + @Test + public void testClearColRow() { + openTestURL(); + + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + selectMenuPath(GENERAL, CLEAR_COLUMN_ROW); + + assertNull(getBodyCell(0, 0)); + } + + @Test + public void testClearRowCol() { + openTestURL(); + + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + selectMenuPath(GENERAL, CLEAR_ROW_COLUMN); + + assertNull(getBodyCell(0, 0)); + } + + @Test + public void testResizeColToFit() { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, RESIZE_FIRST_COLUMN_TO_100PX); + int originalWidth = getBodyCell(0, 0).getSize().getWidth(); + + assertEquals(100, originalWidth); + + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, + RESIZE_FIRST_COLUMN_TO_MAX_WIDTH); + int newWidth = getBodyCell(0, 0).getSize().getWidth(); + assertNotEquals("Column width should've changed", originalWidth, + newWidth); + } + + @Test + public void testRemoveMoreThanPagefulAtBottomWhileScrolledToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + scrollVerticallyTo(BOTTOM_SCROLL_POSITION); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM); + assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } + + @Test + public void testRemoveMoreThanPagefulAtBottomWhileScrolledAlmostToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + // bottom minus 15 rows. + scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_50_ROWS_FROM_BOTTOM); + assertEquals("Row 49: 0,49", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } + + @Test + public void testRemoveMoreThanPagefulNearBottomWhileScrolledToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + scrollVerticallyTo(BOTTOM_SCROLL_POSITION); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_50_ROWS_FROM_ALMOST_BOTTOM); + assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } + + @Test + public void testRemoveMoreThanPagefulNearBottomWhileScrolledAlmostToBottom() + throws Exception { + openTestURL(); + selectMenuPath(GENERAL, POPULATE_COLUMN_ROW); + + // bottom minus 15 rows. + scrollVerticallyTo(BOTTOM_SCROLL_POSITION - 15 * 20); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_50_ROWS_FROM_ALMOST_BOTTOM); + + // let the DOM organize itself + Thread.sleep(500); + assertEquals("Row 49: 0,99", getBodyCell(-1, 0).getText()); + + scrollVerticallyTo(0); + + // let the DOM organize itself + Thread.sleep(500); + + // if something goes wrong, it'll explode before this. + assertEquals("Row 0: 0,0", getBodyCell(0, 0).getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.java new file mode 100644 index 0000000000..b456b16406 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorScrollTest.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.v7.tests.components.grid.basicfeatures.escalator; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +@SuppressWarnings("all") +public class EscalatorScrollTest extends EscalatorBasicClientFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + populate(); + } + + /** + * Before the fix, removing and adding rows and also scrolling would put the + * scroll state in an internally inconsistent state. The scrollbar would've + * been scrolled correctly, but the body wasn't. + * + * This was due to optimizations that didn't keep up with the promises, so + * to say. So the optimizations were removed. + */ + @Test + public void testScrollRaceCondition() { + scrollVerticallyTo(40); + String originalStyle = getTBodyStyle(); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_INSERT_SCROLL); + + // body should be scrolled to exactly the same spot. (not 0) + assertEquals(originalStyle, getTBodyStyle()); + } + + @Test + public void scrollToBottomAndRemoveHeader() throws Exception { + scrollVerticallyTo(999999); // to bottom + + /* + * apparently the scroll event isn't fired by the time the next assert + * would've been done. + */ + Thread.sleep(50); + + assertEquals("Unexpected last row cell before header removal", + "Row 99: 0,99", getBodyCell(-1, 0).getText()); + selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, + REMOVE_ONE_ROW_FROM_BEGINNING); + assertEquals("Unexpected last row cell after header removal", + "Row 99: 0,99", getBodyCell(-1, 0).getText()); + + } + + @Test + public void scrollToBottomAndRemoveFooter() throws Exception { + scrollVerticallyTo(999999); // to bottom + + /* + * apparently the scroll event isn't fired by the time the next assert + * would've been done. + */ + Thread.sleep(50); + + assertEquals("Unexpected last row cell before footer removal", + "Row 99: 0,99", getBodyCell(-1, 0).getText()); + selectMenuPath(COLUMNS_AND_ROWS, FOOTER_ROWS, + REMOVE_ONE_ROW_FROM_BEGINNING); + assertEquals("Unexpected last row cell after footer removal", + "Row 99: 0,99", getBodyCell(-1, 0).getText()); + } + + private String getTBodyStyle() { + WebElement tbody = getEscalator().findElement(By.tagName("tbody")); + return tbody.getAttribute("style"); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java new file mode 100644 index 0000000000..f5dc489165 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java @@ -0,0 +1,592 @@ +/* + * 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.basicfeatures.escalator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Before; +import org.junit.ComparisonFailure; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; + +import com.vaadin.client.WidgetUtil; +import com.vaadin.shared.Range; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; + +@SuppressWarnings("boxing") +public class EscalatorSpacerTest extends EscalatorBasicClientFeaturesTest { + + //@formatter:off + // separate strings made so that eclipse can show the concatenated string by hovering the mouse over the constant + + // translate3d(0px, 40px, 123px); + // translate3d(24px, 15.251px, 0); + // translate(0, 40px); + private final static String TRANSLATE_VALUE_REGEX = + "translate(?:3d|)" // "translate" or "translate3d" + + "\\(" // literal "(" + + "(" // start capturing the x argument + + "[0-9]+" // the integer part of the value + + "(?:" // start of the subpixel part of the value + + "\\.[0-9]" // if we have a period, there must be at least one number after it + + "[0-9]*" // any amount of accuracy afterwards is fine + + ")?" // the subpixel part is optional + + ")" + + "(?:px)?" // we don't care if the values are suffixed by "px" or not. + + ", " + + "(" // start capturing the y argument + + "[0-9]+" // the integer part of the value + + "(?:" // start of the subpixel part of the value + + "\\.[0-9]" // if we have a period, there must be at least one number after it + + "[0-9]*" // any amount of accuracy afterwards is fine + + ")?" // the subpixel part is optional + + ")" + + "(?:px)?" // we don't care if the values are suffixed by "px" or not. + + "(?:, .*?)?" // the possible z argument, uninteresting (translate doesn't have one, translate3d does) + + "\\)" // literal ")" + + ";?"; // optional ending semicolon + + // 40px; + // 12.34px + private final static String PIXEL_VALUE_REGEX = + "(" // capture the pixel value + + "[0-9]+" // the pixel argument + + "(?:" // start of the subpixel part of the value + + "\\.[0-9]" // if we have a period, there must be at least one number after it + + "[0-9]*" // any amount of accuracy afterwards is fine + + ")?" // the subpixel part is optional + + ")" + + "(?:px)?" // optional "px" string + + ";?"; // optional semicolon + //@formatter:on + + // also matches "-webkit-transform"; + private final static Pattern TRANSFORM_CSS_PATTERN = Pattern + .compile("transform: (.*?);"); + private final static Pattern TOP_CSS_PATTERN = Pattern.compile( + "top: ([0-9]+(?:\\.[0-9]+)?(?:px)?);?", Pattern.CASE_INSENSITIVE); + private final static Pattern LEFT_CSS_PATTERN = Pattern.compile( + "left: ([0-9]+(?:\\.[0-9]+)?(?:px)?);?", Pattern.CASE_INSENSITIVE); + + private final static Pattern TRANSLATE_VALUE_PATTERN = Pattern + .compile(TRANSLATE_VALUE_REGEX); + private final static Pattern PIXEL_VALUE_PATTERN = Pattern + .compile(PIXEL_VALUE_REGEX, Pattern.CASE_INSENSITIVE); + + @Before + public void before() { + setDebug(true); + openTestURL(); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, "Set 20px default height"); + populate(); + } + + @Test + public void openVisibleSpacer() { + assertFalse("No spacers should be shown at the start", + spacersAreFoundInDom()); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + assertNotNull("Spacer should be shown after setting it", getSpacer(1)); + } + + @Test + public void closeVisibleSpacer() { + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_1, REMOVE); + assertNull("Spacer should not exist after removing it", getSpacer(1)); + } + + @Test + public void spacerPushesVisibleRowsDown() { + double oldTop = getElementTop(getBodyRow(2)); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + double newTop = getElementTop(getBodyRow(2)); + + assertGreater("Row below a spacer was not pushed down", newTop, oldTop); + } + + @Test + public void addingRowAboveSpacerPushesItDown() { + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_ROWS); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + double oldTop = getElementTop(getSpacer(1)); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + double newTop = getElementTop(getSpacer(2)); + + assertGreater("Spacer should've been pushed down (oldTop: " + oldTop + + ", newTop: " + newTop + ")", newTop, oldTop); + } + + @Test + public void addingRowBelowSpacerDoesNotPushItDown() { + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_ROWS); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + double oldTop = getElementTop(getSpacer(1)); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_END); + double newTop = getElementTop(getSpacer(1)); + + assertEquals("Spacer should've not been pushed down", newTop, oldTop, + WidgetUtil.PIXEL_EPSILON); + } + + @Test + public void addingRowBelowSpacerIsActuallyRenderedBelowWhenEscalatorIsEmpty() { + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_ALL_ROWS); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_BEGINNING); + + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + double spacerTop = getElementTop(getSpacer(1)); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_ONE_ROW_TO_END); + double rowTop = getElementTop(getBodyRow(2)); + + assertEquals("Next row should've been rendered below the spacer", + spacerTop + 100, rowTop, WidgetUtil.PIXEL_EPSILON); + } + + @Test + public void addSpacerAtBottomThenScrollThere() { + selectMenuPath(FEATURES, SPACERS, ROW_99, SET_100PX); + scrollVerticallyTo(999999); + + assertFalse("Did not expect a notification", + $(NotificationElement.class).exists()); + } + + @Test + public void scrollToBottomThenAddSpacerThere() { + scrollVerticallyTo(999999); + long oldBottomScrollTop = getScrollTop(); + selectMenuPath(FEATURES, SPACERS, ROW_99, SET_100PX); + + assertEquals( + "Adding a spacer underneath the current viewport should " + + "not scroll anywhere", + oldBottomScrollTop, getScrollTop()); + assertFalse("Got an unexpected notification", + $(NotificationElement.class).exists()); + + scrollVerticallyTo(999999); + + assertFalse("Got an unexpected notification", + $(NotificationElement.class).exists()); + assertGreater("Adding a spacer should've made the scrollbar scroll " + + "further", getScrollTop(), oldBottomScrollTop); + } + + @Test + public void removingRowAboveSpacerMovesSpacerUp() { + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + WebElement spacer = getSpacer(1); + double originalElementTop = getElementTop(spacer); + + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_ONE_ROW_FROM_BEGINNING); + assertLessThan("spacer should've moved up", getElementTop(spacer), + originalElementTop); + assertNull("No spacer for row 1 should be found after removing the " + + "top row", getSpacer(1)); + } + + @Test + public void removingSpacedRowRemovesSpacer() { + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + assertTrue("Spacer should've been found in the DOM", + spacersAreFoundInDom()); + + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_ONE_ROW_FROM_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, + REMOVE_ONE_ROW_FROM_BEGINNING); + + assertFalse("No spacers should be in the DOM after removing " + + "associated spacer", spacersAreFoundInDom()); + + } + + @Test + public void spacersAreFixedInViewport_firstFreezeThenScroll() { + selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + assertEquals( + "Spacer's left position should've been 0 at the " + "beginning", + 0d, getElementLeft(getSpacer(1)), WidgetUtil.PIXEL_EPSILON); + + int scrollTo = 10; + scrollHorizontallyTo(scrollTo); + assertEquals( + "Spacer's left position should've been " + scrollTo + + " after scrolling " + scrollTo + "px", + scrollTo, getElementLeft(getSpacer(1)), + WidgetUtil.PIXEL_EPSILON); + } + + @Test + public void spacersAreFixedInViewport_firstScrollThenFreeze() { + selectMenuPath(FEATURES, FROZEN_COLUMNS, FREEZE_1_COLUMN); + int scrollTo = 10; + scrollHorizontallyTo(scrollTo); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + assertEquals( + "Spacer's left position should've been " + scrollTo + + " after scrolling " + scrollTo + "px", + scrollTo, getElementLeft(getSpacer(1)), + WidgetUtil.PIXEL_EPSILON); + } + + @Test + public void addingMinusOneSpacerDoesNotScrollWhenScrolledAtTop() { + scrollVerticallyTo(5); + selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, SET_100PX); + assertEquals( + "No scroll adjustment should've happened when adding the -1 spacer", + 5, getScrollTop()); + } + + @Test + public void removingMinusOneSpacerScrolls() { + scrollVerticallyTo(5); + selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, REMOVE); + assertEquals("Scroll adjustment should've happened when removing the " + + "-1 spacer", 0, getScrollTop()); + } + + @Test + public void scrollToRowWorksProperlyWithSpacers() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_MINUS1, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + + /* + * we check for row -2 instead of -1, because escalator has the one row + * buffered underneath the footer + */ + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_75); + Thread.sleep(500); + assertEquals("Row 75: 0,75", getBodyCell(-2, 0).getText()); + + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_25); + Thread.sleep(500); + + try { + assertEquals("Row 25: 0,25", getBodyCell(0, 0).getText()); + } catch (ComparisonFailure retryForIE10andIE11) { + /* + * This seems to be some kind of subpixel/off-by-one-pixel error. + * Everything's scrolled correctly, but Escalator still loads one + * row above to the DOM, underneath the header. It's there, but it's + * not visible. We'll allow for that one pixel error. + */ + assertEquals("Row 24: 0,24", getBodyCell(0, 0).getText()); + } + } + + @Test + public void scrollToSpacerFromAbove() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + // Browsers might vary with a few pixels. + Range allowableScrollRange = Range.between(765, 780); + int scrollTop = (int) getScrollTop(); + assertTrue("Scroll position was not " + allowableScrollRange + ", but " + + scrollTop, allowableScrollRange.contains(scrollTop)); + } + + @Test + public void scrollToSpacerFromBelow() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + scrollVerticallyTo(999999); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + // Browsers might vary with a few pixels. + Range allowableScrollRange = Range.between(1015, 1025); + int scrollTop = (int) getScrollTop(); + assertTrue("Scroll position was not " + allowableScrollRange + ", but " + + scrollTop, allowableScrollRange.contains(scrollTop)); + } + + @Test + public void scrollToSpacerAlreadyInViewport() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + scrollVerticallyTo(1000); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + assertEquals(getScrollTop(), 1000); + } + + @Test + public void scrollToRowAndSpacerFromAbove() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_50, + SCROLL_HERE_SPACERBELOW_ANY_0PADDING); + + // Browsers might vary with a few pixels. + Range allowableScrollRange = Range.between(765, 780); + int scrollTop = (int) getScrollTop(); + assertTrue("Scroll position was not " + allowableScrollRange + ", but " + + scrollTop, allowableScrollRange.contains(scrollTop)); + } + + @Test + public void scrollToRowAndSpacerFromBelow() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + scrollVerticallyTo(999999); + selectMenuPath(FEATURES, SPACERS, ROW_50, + SCROLL_HERE_SPACERBELOW_ANY_0PADDING); + + // Browsers might vary with a few pixels. + Range allowableScrollRange = Range.between(995, 1005); + int scrollTop = (int) getScrollTop(); + assertTrue("Scroll position was not " + allowableScrollRange + ", but " + + scrollTop, allowableScrollRange.contains(scrollTop)); + } + + @Test + public void scrollToRowAndSpacerAlreadyInViewport() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + scrollVerticallyTo(950); + selectMenuPath(FEATURES, SPACERS, ROW_50, + SCROLL_HERE_SPACERBELOW_ANY_0PADDING); + + assertEquals(getScrollTop(), 950); + } + + @Test + public void domCanBeSortedWithFocusInSpacer() throws InterruptedException { + + // Firefox behaves badly with focus-related tests - skip it. + if (BrowserUtil.isFirefox(super.getDesiredCapabilities())) { + return; + } + + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + + WebElement inputElement = getEscalator() + .findElement(By.tagName("input")); + inputElement.click(); + scrollVerticallyTo(30); + + // Sleep needed because of all the JS we're doing, and to let + // the DOM reordering to take place. + Thread.sleep(500); + + assertFalse("Error message detected", + $(NotificationElement.class).exists()); + } + + @Test + public void spacersAreInsertedInCorrectDomPosition() { + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + + WebElement tbody = getEscalator().findElement(By.tagName("tbody")); + WebElement spacer = getChild(tbody, 2); + String cssClass = spacer.getAttribute("class"); + assertTrue( + "element index 2 was not a spacer (class=\"" + cssClass + "\")", + cssClass.contains("-spacer")); + } + + @Test + public void spacersAreInCorrectDomPositionAfterScroll() { + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + + scrollVerticallyTo(32); // roughly one row's worth + + WebElement tbody = getEscalator().findElement(By.tagName("tbody")); + WebElement spacer = getChild(tbody, 1); + String cssClass = spacer.getAttribute("class"); + assertTrue( + "element index 1 was not a spacer (class=\"" + cssClass + "\")", + cssClass.contains("-spacer")); + } + + @Test + public void spacerScrolledIntoViewGetsFocus() { + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + tryToTabIntoFocusUpdaterElement(); + assertEquals("input", getFocusedElement().getTagName()); + } + + @Test + public void spacerScrolledOutOfViewDoesNotGetFocus() { + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + tryToTabIntoFocusUpdaterElement(); + assertNotEquals("input", getFocusedElement().getTagName()); + } + + @Test + public void spacerOpenedInViewGetsFocus() { + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + tryToTabIntoFocusUpdaterElement(); + WebElement focusedElement = getFocusedElement(); + assertEquals("input", focusedElement.getTagName()); + } + + @Test + public void spacerOpenedOutOfViewDoesNotGetFocus() { + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + + tryToTabIntoFocusUpdaterElement(); + assertNotEquals("input", getFocusedElement().getTagName()); + } + + @Test + public void spacerOpenedInViewAndScrolledOutAndBackAgainGetsFocus() { + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_1, SET_100PX); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_50); + selectMenuPath(FEATURES, SPACERS, ROW_1, SCROLL_HERE_ANY_0PADDING); + + tryToTabIntoFocusUpdaterElement(); + assertEquals("input", getFocusedElement().getTagName()); + } + + @Test + public void spacerOpenedOutOfViewAndScrolledInAndBackAgainDoesNotGetFocus() { + selectMenuPath(FEATURES, SPACERS, FOCUSABLE_UPDATER); + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, SCROLL_TO, ROW_0); + + tryToTabIntoFocusUpdaterElement(); + assertNotEquals("input", getFocusedElement().getTagName()); + } + + private void tryToTabIntoFocusUpdaterElement() { + ((TestBenchElement) findElement(By.className("gwt-MenuBar"))).focus(); + WebElement focusedElement = getFocusedElement(); + focusedElement.sendKeys(Keys.TAB); + } + + private WebElement getChild(WebElement parent, int childIndex) { + return (WebElement) executeScript( + "return arguments[0].children[" + childIndex + "];", parent); + } + + private static double[] getElementDimensions(WebElement element) { + /* + * we need to parse the style attribute, since using getCssValue gets a + * normalized value that is harder to parse. + */ + String style = element.getAttribute("style"); + + String transform = getTransformFromStyle(style); + if (transform != null) { + return getTranslateValues(transform); + } + + double[] result = new double[] { -1, -1 }; + String left = getLeftFromStyle(style); + if (left != null) { + result[0] = getPixelValue(left); + } + String top = getTopFromStyle(style); + if (top != null) { + result[1] = getPixelValue(top); + } + + if (result[0] != -1 && result[1] != -1) { + return result; + } else { + throw new IllegalArgumentException("Could not parse the position " + + "information from the CSS \"" + style + "\""); + } + } + + private static double getElementTop(WebElement element) { + return getElementDimensions(element)[1]; + } + + private static double getElementLeft(WebElement element) { + return getElementDimensions(element)[0]; + } + + private static String getTransformFromStyle(String style) { + return getFromStyle(TRANSFORM_CSS_PATTERN, style); + } + + private static String getTopFromStyle(String style) { + return getFromStyle(TOP_CSS_PATTERN, style); + } + + private static String getLeftFromStyle(String style) { + return getFromStyle(LEFT_CSS_PATTERN, style); + } + + private static String getFromStyle(Pattern pattern, String style) { + Matcher matcher = pattern.matcher(style); + if (matcher.find()) { + assertEquals("wrong amount of groups matched in " + style, 1, + matcher.groupCount()); + return matcher.group(1); + } else { + return null; + } + } + + /** + * @return {@code [0] == x}, {@code [1] == y} + */ + private static double[] getTranslateValues(String translate) { + Matcher matcher = TRANSLATE_VALUE_PATTERN.matcher(translate); + assertTrue("no matches for " + translate + " against " + + TRANSLATE_VALUE_PATTERN, matcher.find()); + assertEquals("wrong amout of groups matched in " + translate, 2, + matcher.groupCount()); + + return new double[] { Double.parseDouble(matcher.group(1)), + Double.parseDouble(matcher.group(2)) }; + } + + private static double getPixelValue(String top) { + Matcher matcher = PIXEL_VALUE_PATTERN.matcher(top); + assertTrue( + "no matches for \"" + top + "\" against " + PIXEL_VALUE_PATTERN, + matcher.find()); + assertEquals("wrong amount of groups matched in " + top, 1, + matcher.groupCount()); + return Double.parseDouble(matcher.group(1)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java new file mode 100644 index 0000000000..8ab3753603 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/escalator/EscalatorUpdaterUiTest.java @@ -0,0 +1,151 @@ +/* + * 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.basicfeatures.escalator; + +import org.junit.Test; + +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; +import com.vaadin.v7.tests.components.grid.basicfeatures.EscalatorUpdaterUi; + +public class EscalatorUpdaterUiTest extends EscalatorBasicClientFeaturesTest { + @Override + protected Class getUIClass() { + return EscalatorUpdaterUi.class; + } + + @Test + public void testHeaderPaintOrderRowColRowCol() { + boolean addColumnFirst = false; + boolean removeColumnFirst = false; + testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testHeaderPaintOrderRowColColRow() { + boolean addColumnFirst = false; + boolean removeColumnFirst = true; + testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testHeaderPaintOrderColRowColRow() { + boolean addColumnFirst = true; + boolean removeColumnFirst = true; + testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testHeaderPaintOrderColRowRowCol() { + boolean addColumnFirst = true; + boolean removeColumnFirst = false; + testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testBodyPaintOrderRowColRowCol() { + boolean addColumnFirst = false; + boolean removeColumnFirst = false; + testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testBodyPaintOrderRowColColRow() { + boolean addColumnFirst = false; + boolean removeColumnFirst = true; + testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testBodyPaintOrderColRowColRow() { + boolean addColumnFirst = true; + boolean removeColumnFirst = true; + testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testBodyPaintOrderColRowRowCol() { + boolean addColumnFirst = true; + boolean removeColumnFirst = false; + testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testFooterPaintOrderRowColRowCol() { + boolean addColumnFirst = false; + boolean removeColumnFirst = false; + testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testFooterPaintOrderRowColColRow() { + boolean addColumnFirst = false; + boolean removeColumnFirst = true; + testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testFooterPaintOrderColRowColRow() { + boolean addColumnFirst = true; + boolean removeColumnFirst = true; + testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); + } + + @Test + public void testFooterPaintOrderColRowRowCol() { + boolean addColumnFirst = true; + boolean removeColumnFirst = false; + testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst); + } + + private void testPaintOrder(String tableSection, boolean addColumnFirst, + boolean removeColumnFirst) { + openTestURL(); + + if (addColumnFirst) { + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, + ADD_ONE_COLUMN_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, tableSection, + ADD_ONE_ROW_TO_BEGINNING); + } else { + selectMenuPath(COLUMNS_AND_ROWS, tableSection, + ADD_ONE_ROW_TO_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, + ADD_ONE_COLUMN_TO_BEGINNING); + } + + assertLogContainsInOrder("preAttach: elementIsAttached == false", + "postAttach: elementIsAttached == true", + "update: elementIsAttached == true"); + assertLogDoesNotContain("preDetach"); + assertLogDoesNotContain("postDetach"); + + if (removeColumnFirst) { + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, + REMOVE_ONE_COLUMN_FROM_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, tableSection, + REMOVE_ONE_ROW_FROM_BEGINNING); + } else { + selectMenuPath(COLUMNS_AND_ROWS, tableSection, + REMOVE_ONE_ROW_FROM_BEGINNING); + selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, + REMOVE_ONE_COLUMN_FROM_BEGINNING); + } + + assertLogContainsInOrder("preDetach: elementIsAttached == true", + "postDetach: elementIsAttached == false"); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/DisabledGridTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/DisabledGridTest.java new file mode 100644 index 0000000000..25fcc5a424 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/DisabledGridTest.java @@ -0,0 +1,61 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class DisabledGridTest extends GridBasicFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + selectMenuPath("Component", "State", "Enabled"); + } + + @Test + public void testSelection() { + selectMenuPath("Component", "State", "Selection mode", "single"); + + GridRowElement row = getGridElement().getRow(0); + GridCellElement cell = getGridElement().getCell(0, 0); + cell.click(); + assertFalse("disabled row should not be selected", row.isSelected()); + + } + + @Test + public void testEditorOpening() { + selectMenuPath("Component", "Editor", "Enabled"); + + GridRowElement row = getGridElement().getRow(0); + GridCellElement cell = getGridElement().getCell(0, 0); + cell.click(); + assertNull("Editor should not open", getEditor()); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertNull("Editor should not open", getEditor()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java new file mode 100644 index 0000000000..515c7dbdbf --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridCellFocusAdjustmentTest.java @@ -0,0 +1,86 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridCellFocusAdjustmentTest extends GridBasicFeaturesTest { + + @Test + public void testCellFocusWithAddAndRemoveRows() { + openTestURL(); + GridElement grid = getGridElement(); + + grid.getCell(0, 0).click(); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Cell focus was not moved when adding a row", + grid.getCell(1, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add 18 rows"); + assertTrue("Cell focus was not moved when adding multiple rows", + grid.getCell(19, 0).isFocused()); + + for (int i = 18; i <= 0; --i) { + selectMenuPath("Component", "Body rows", "Remove first row"); + assertTrue("Cell focus was not moved when removing a row", + grid.getCell(i, 0).isFocused()); + } + } + + @Test + public void testCellFocusOffsetWhileInDifferentSection() { + openTestURL(); + getGridElement().getCell(0, 0).click(); + new Actions(getDriver()).sendKeys(Keys.UP).perform(); + assertTrue("Header 0,0 should've become focused", + getGridElement().getHeaderCell(0, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Header 0,0 should've remained focused", + getGridElement().getHeaderCell(0, 0).isFocused()); + } + + @Test + public void testCellFocusOffsetWhileInSameSectionAndInsertedAbove() { + openTestURL(); + assertTrue("Body 0,0 should've gotten focus", + getGridElement().getCell(0, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Body 1,0 should've gotten focus", + getGridElement().getCell(1, 0).isFocused()); + } + + @Test + public void testCellFocusOffsetWhileInSameSectionAndInsertedBelow() { + openTestURL(); + assertTrue("Body 0,0 should've gotten focus", + getGridElement().getCell(0, 0).isFocused()); + + selectMenuPath("Component", "Body rows", "Add third row"); + assertTrue("Body 0,0 should've remained focused", + getGridElement().getCell(0, 0).isFocused()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java new file mode 100644 index 0000000000..5d1d99c426 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridCellStyleGeneratorTest.java @@ -0,0 +1,155 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertFalse; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridCellStyleGeneratorTest extends GridBasicFeaturesTest { + @Test + public void testStyleNameGeneratorScrolling() throws Exception { + openTestURL(); + + selectRowStyleNameGenerator( + GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); + + GridRowElement row = getGridElement().getRow(2); + GridCellElement cell = getGridElement().getCell(3, 2); + + Assert.assertTrue(hasCssClass(row, "row2")); + Assert.assertTrue(hasCssClass(cell, "Column_2")); + + // Scroll down and verify that the old elements don't have the + // stylename any more + + // Carefully chosen offset to hit an index % 4 without cell style + row = getGridElement().getRow(352); + cell = getGridElement().getCell(353, 2); + + Assert.assertFalse(hasCssClass(row, "row352")); + Assert.assertFalse(hasCssClass(cell, "Column_2")); + } + + @Test + public void testDisableStyleNameGenerator() throws Exception { + openTestURL(); + + selectRowStyleNameGenerator( + GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); + + // Just verify that change was effective + GridRowElement row2 = getGridElement().getRow(2); + GridCellElement cell3_2 = getGridElement().getCell(3, 2); + + Assert.assertTrue(hasCssClass(row2, "row2")); + Assert.assertTrue(hasCssClass(cell3_2, "Column_2")); + + // Disable the generator and check again + selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_NONE); + + Assert.assertFalse(hasCssClass(row2, "row2")); + Assert.assertFalse(hasCssClass(cell3_2, "Column_2")); + } + + @Test + public void testChangeStyleNameGenerator() throws Exception { + openTestURL(); + + selectRowStyleNameGenerator( + GridBasicFeatures.ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); + + // Just verify that change was effective + GridRowElement row2 = getGridElement().getRow(2); + GridCellElement cell3_2 = getGridElement().getCell(3, 2); + + Assert.assertTrue(hasCssClass(row2, "row2")); + Assert.assertTrue(hasCssClass(cell3_2, "Column_2")); + + // Change the generator and check again + selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NONE); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_PROPERTY_TO_STRING); + + // Old styles removed? + Assert.assertFalse(hasCssClass(row2, "row2")); + Assert.assertFalse(hasCssClass(cell3_2, "Column_2")); + + // New style present? + Assert.assertTrue(hasCssClass(cell3_2, "Column-2")); + } + + @Test + public void testCellStyleGeneratorWithSelectionColumn() { + setDebug(true); + openTestURL(); + selectMenuPath("Component", "State", "Selection mode", "multi"); + + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_SPECIAL); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } + + private void selectRowStyleNameGenerator(String name) { + selectMenuPath("Component", "State", "Row style generator", name); + } + + private void selectCellStyleNameGenerator(String name) { + selectMenuPath("Component", "State", "Cell style generator", name); + } + + @Test + public void testEmptyStringStyleGenerator() { + setDebug(true); + openTestURL(); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_EMPTY); + selectRowStyleNameGenerator( + GridBasicFeatures.ROW_STYLE_GENERATOR_EMPTY); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } + + @Test + public void testNullStringStyleGenerator() { + setDebug(true); + openTestURL(); + selectCellStyleNameGenerator( + GridBasicFeatures.CELL_STYLE_GENERATOR_NULL); + selectRowStyleNameGenerator(GridBasicFeatures.ROW_STYLE_GENERATOR_NULL); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridClearContainerTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridClearContainerTest.java new file mode 100644 index 0000000000..12636c7817 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridClearContainerTest.java @@ -0,0 +1,51 @@ +/* + * 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.basicfeatures.server; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.v7.testbench.customelements.GridElement; + +/** + * Tests that removing and adding rows doesn't cause an infinite loop in the + * browser. + * + * @author Vaadin Ltd + */ +@TestCategory("grid") +public class GridClearContainerTest extends MultiBrowserTest { + + private final String ERRORNOTE = "Unexpected cell contents."; + + @Test + public void clearAndReadd() { + openTestURL(); + ButtonElement button = $(ButtonElement.class) + .caption("Clear and re-add").first(); + GridElement grid = $(GridElement.class).first(); + Assert.assertEquals(ERRORNOTE, "default", grid.getCell(0, 0).getText()); + Assert.assertEquals(ERRORNOTE, "default", grid.getCell(1, 0).getText()); + button.click(); + Assert.assertEquals(ERRORNOTE, "Updated value 1", + grid.getCell(0, 0).getText()); + Assert.assertEquals(ERRORNOTE, "Updated value 2", + grid.getCell(1, 0).getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnMaxWidthTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnMaxWidthTest.java new file mode 100644 index 0000000000..57acfec7b8 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnMaxWidthTest.java @@ -0,0 +1,37 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridColumnMaxWidthTest extends GridBasicFeaturesTest { + + @Test + public void testMaxWidthAffectsColumnWidth() { + setDebug(true); + openTestURL(); + + selectMenuPath("Component", "Columns", + "All columns expanding, Col 0 has max width of 30px"); + + assertEquals("Column 0 did not obey max width of 30px.", 30, + getGridElement().getCell(0, 0).getSize().getWidth()); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java new file mode 100644 index 0000000000..feac52c0d3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnReorderTest.java @@ -0,0 +1,403 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +/** + * Tests that Grid columns can be reordered by user with drag and drop #16643. + * + * @author Vaadin Ltd + */ +public class GridColumnReorderTest extends GridBasicFeaturesTest { + + private static final String[] COLUMN_REORDERING_PATH = { "Component", + "State", "Column Reordering Allowed" }; + private static final String[] COLUMN_REORDER_LISTENER_PATH = { "Component", + "State", "ColumnReorderListener" }; + + @Before + public void setUp() { + setDebug(true); + } + + @Test + public void testColumnReordering_firstColumnDroppedOnThird_dropOnLeftSide() { + // given + openTestURL(); + assertColumnHeaderOrder(0, 1, 2); + toggleColumnReordering(); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + + // then + assertColumnHeaderOrder(1, 0, 2); + } + + @Test + public void testColumnReordering_firstColumnDroppedOnThird_dropOnRightSide() { + // given + openTestURL(); + assertColumnHeaderOrder(0, 1, 2); + toggleColumnReordering(); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(1, 2, 0); + } + + @Test + public void testColumnReordering_reorderingTwiceBackForth_reordered() { + // given + openTestURL(); + selectMenuPath("Component", "Size", "Width", "800px"); + assertColumnHeaderOrder(0, 1, 2, 3, 4); + toggleColumnReordering(); + + // when + dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(2, 0, 1, 3, 4); + + // when + dragAndDropDefaultColumnHeader(1, 3, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(2, 1, 3, 0); + } + + @Test + public void testColumnReordering_notEnabled_noReordering() { + // given + openTestURL(); + assertColumnHeaderOrder(0, 1, 2); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(0, 1, 2); + } + + @Test + public void testColumnReordering_userChangesRevertedByServer_columnsAreUpdated() { + // given + openTestURL(); + assertColumnHeaderOrder(0, 1, 2); + toggleColumnReordering(); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + assertColumnHeaderOrder(1, 0, 2); + moveColumnManuallyLeftByOne(0); + + // then + assertColumnHeaderOrder(0, 1, 2); + } + + @Test + public void testColumnReordering_concurrentUpdatesFromServer_columnOrderFromServerUsed() { + // given + openTestURL(); + assertColumnHeaderOrder(0, 1, 2); + toggleColumnReordering(); + + // when + selectMenuPath(new String[] { "Component", "Internals", + "Update column order without updating client" }); + dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(1, 0, 2); + } + + @Test + public void testColumnReordering_triggersReorderEvent_isUserInitiated() { + // given + openTestURL(); + toggleColumnReordering(); + + // when + toggleColumnReorderListener(); + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + + // then + assertColumnReorderEvent(true); + } + + @Test + public void testColumnReordering_addAndRemoveListener_registerUnRegisterWorks() { + // given + openTestURL(); + toggleColumnReordering(); + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + assertNoColumnReorderEvent(); + + // when + toggleColumnReorderListener(); + dragAndDropDefaultColumnHeader(0, 2, CellSide.RIGHT); + + // then + assertColumnReorderEvent(true); + + // when + toggleColumnReorderListener(); + dragAndDropDefaultColumnHeader(0, 3, CellSide.LEFT); + + // then + assertNoColumnReorderEvent(); + } + + @Test + public void testColumnReorderingEvent_serverSideReorder_triggersReorderEvent() { + openTestURL(); + + // when + toggleColumnReorderListener(); + moveColumnManuallyLeftByOne(3); + + // then + assertColumnReorderEvent(false); + } + + @Test + public void testColumnReorder_draggingFrozenColumns_impossible() { + // given + openTestURL(); + toggleColumnReordering(); + setFrozenColumns(2); + assertColumnHeaderOrder(0, 1, 2, 3); + + // when + dragAndDropDefaultColumnHeader(0, 2, CellSide.LEFT); + + // then + assertColumnHeaderOrder(0, 1, 2, 3); + assertTrue(getGridElement().getHeaderCell(0, 0).isFrozen()); + assertTrue(getGridElement().getHeaderCell(0, 1).isFrozen()); + assertFalse(getGridElement().getHeaderCell(0, 2).isFrozen()); + } + + @Test + public void testColumnReorder_draggingColumnOnTopOfFrozenColumn_columnDroppedRightOfFrozenColumns() { + // given + openTestURL(); + toggleColumnReordering(); + setFrozenColumns(1); + assertColumnHeaderOrder(0, 1, 2, 3); + + // when + dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); + + // then + assertColumnHeaderOrder(0, 2, 1, 3); + } + + @Test + public void testColumnReorder_draggingColumnLeftOfMultiSelectionColumn_columnDroppedRight() { + // given + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "State", "Selection mode", "multi"); + List gridHeaderRowCells = getGridHeaderRowCells(); + assertTrue(gridHeaderRowCells.get(0).getText().equals("")); + assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); + assertColumnHeader("Column 1", gridHeaderRowCells.get(2)); + assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); + + // when + dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); + + // then + gridHeaderRowCells = getGridHeaderRowCells(); + assertTrue(gridHeaderRowCells.get(0).getText().equals("")); + assertColumnHeader("Column 1", gridHeaderRowCells.get(1)); + assertColumnHeader("Column 0", gridHeaderRowCells.get(2)); + assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); + } + + @Test + public void testColumnReorder_multiSelectionAndFrozenColumns_columnDroppedRight() { + // given + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "State", "Selection mode", "multi"); + setFrozenColumns(1); + List gridHeaderRowCells = getGridHeaderRowCells(); + assertTrue(gridHeaderRowCells.get(0).getText().equals("")); + assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); + assertColumnHeader("Column 1", gridHeaderRowCells.get(2)); + assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); + + // when + dragAndDropDefaultColumnHeader(3, 0, CellSide.LEFT); + + // then + gridHeaderRowCells = getGridHeaderRowCells(); + assertTrue(gridHeaderRowCells.get(0).getText().equals("")); + assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); + assertColumnHeader("Column 2", gridHeaderRowCells.get(2)); + assertColumnHeader("Column 1", gridHeaderRowCells.get(3)); + } + + @Test + public void testColumnReordering_multiSelectionColumnNotFrozen_stillCantDropLeftSide() { + // given + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "State", "Selection mode", "multi"); + setFrozenColumns(-1); + List gridHeaderRowCells = getGridHeaderRowCells(); + assertTrue(gridHeaderRowCells.get(0).getText().equals("")); + assertColumnHeader("Column 0", gridHeaderRowCells.get(1)); + assertColumnHeader("Column 1", gridHeaderRowCells.get(2)); + assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); + + // when + dragAndDropDefaultColumnHeader(2, 0, CellSide.LEFT); + + // then + gridHeaderRowCells = getGridHeaderRowCells(); + assertTrue(gridHeaderRowCells.get(0).getText().equals("")); + assertColumnHeader("Column 1", gridHeaderRowCells.get(1)); + assertColumnHeader("Column 0", gridHeaderRowCells.get(2)); + assertColumnHeader("Column 2", gridHeaderRowCells.get(3)); + } + + @Test + public void testColumnReordering_twoHeaderRows_dndReorderingPossibleFromFirstRow() { + // given + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "Header", "Append row"); + assertColumnHeaderOrder(0, 1, 2, 3); + + // when + dragAndDropColumnHeader(0, 0, 2, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(1, 2, 0, 3); + } + + @Test + public void testColumnReordering_twoHeaderRows_dndReorderingPossibleFromSecondRow() { + // given + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "Header", "Append row"); + assertColumnHeaderOrder(0, 1, 2, 3); + + // when + dragAndDropColumnHeader(1, 0, 2, CellSide.RIGHT); + + // then + assertColumnHeaderOrder(1, 2, 0, 3); + } + + @Test + public void testColumnReordering_bigWidth_dragElementPositionCorrect() { + openTestURL(); + toggleColumnReordering(); + selectMenuPath("Component", "Size", "Width", "900px"); + assertColumnHeaderOrder(0, 1, 2, 3); + + GridCellElement draggedHeaderCell = getGridElement().getHeaderCell(0, + 1); + final int xOffset = 500; + new Actions(getDriver()).moveToElement(draggedHeaderCell, 20, 10) + .clickAndHold().moveByOffset(xOffset, 0).build().perform(); + + WebElement floatingDragElement = findElement( + By.className("dragged-column-header")); + + int expectedLeft = draggedHeaderCell.getLocation().getX() + xOffset + 20 + - (floatingDragElement.getSize().getWidth() / 2); + int realLeft = floatingDragElement.getLocation().getX(); + + assertTrue( + "Dragged element location wrong, expected " + expectedLeft + + " was " + realLeft, + Math.abs(expectedLeft - realLeft) < 10); + } + + @Test + public void testDropMarker_sidebarOpenButtonVisible_dropMarkerOnCorrectPosition() { + // using runo since there the sidebar opening button is wider than the + // scroll deco, and because using Valo has some TB issues + openTestURL("theme=runo"); + + selectMenuPath("Component", "Size", "Width", "100%"); + selectMenuPath("Component", "Columns", "All columns hidable"); + toggleColumnReordering(); + scrollGridHorizontallyTo(100000); + + new Actions(getDriver()).clickAndHold(getDefaultColumnHeader(10)) + .moveByOffset(800, 0).build().perform(); + + WebElement dragDropMarker = findElement( + By.className("v-grid-drop-marker")); + WebElement sidebar = findElement(By.className("v-grid-sidebar")); + + int dragDropMarkerX = dragDropMarker.getLocation().getX(); + int sidebarX = sidebar.getLocation().getX(); + assertTrue( + "Drop marker misplaced " + dragDropMarkerX + + " compared to sidebar open button " + sidebarX, + dragDropMarkerX <= sidebarX); + } + + private void toggleColumnReordering() { + selectMenuPath(COLUMN_REORDERING_PATH); + } + + private void toggleColumnReorderListener() { + selectMenuPath(COLUMN_REORDER_LISTENER_PATH); + } + + private void moveColumnManuallyLeftByOne(int index) { + selectMenuPath(new String[] { "Component", "Columns", "Column " + index, + "Move left" }); + } + + private void assertColumnReorderEvent(boolean userOriginated) { + final String logRow = getLogRow(0); + assertTrue(logRow.contains( + "Columns reordered, userOriginated: " + userOriginated)); + } + + private void assertNoColumnReorderEvent() { + final String logRow = getLogRow(0); + assertFalse(logRow.contains("Columns reordered")); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java new file mode 100644 index 0000000000..22bea4f9f5 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnResizeTest.java @@ -0,0 +1,149 @@ +/* + * 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.basicfeatures.server; + +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 org.openqa.selenium.Dimension; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +@TestCategory("grid") +public class GridColumnResizeTest extends GridBasicFeaturesTest { + + @Before + public void before() { + openTestURL(); + } + + @Test + public void testResizeHandlesPresentInDefaultHeader() { + for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { + assertResizable(i, true); + } + } + + @Test + public void testResizeHandlesNotInNonDefaultHeader() { + selectMenuPath("Component", "Header", "Prepend row"); + + for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { + assertResizable(getGridElement().getHeaderCell(0, i), false); + assertResizable(getGridElement().getHeaderCell(1, i), true); + } + } + + @Test + public void testResizeHandlesNotInFooter() { + selectMenuPath("Component", "Footer", "Visible"); + for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { + assertResizable(getGridElement().getFooterCell(0, i), false); + } + } + + @Test + public void testToggleSetResizable() { + selectMenuPath("Component", "Columns", "Column 1", "Resizable"); + + for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { + assertResizable(i, i != 1); + } + + selectMenuPath("Component", "Columns", "Column 1", "Resizable"); + + for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { + assertResizable(i, true); + } + } + + @Test + public void testResizeFirstColumn() { + dragResizeColumn(0, -1, -10); + assertTrue("Log should contain a resize event", + logContainsText("ColumnResizeEvent: isUserOriginated? true")); + } + + @Test + public void testDragHandleStraddlesColumns() { + dragResizeColumn(0, 4, -10); + assertTrue("Log should contain a resize event", + logContainsText("ColumnResizeEvent: isUserOriginated? true")); + } + + @Test + public void testColumnPixelSizesSetOnResize() { + selectMenuPath("Component", "Columns", "All columns auto width"); + dragResizeColumn(0, -1, -10); + for (String msg : getLogs()) { + assertTrue("Log should contain a resize event", + msg.contains("ColumnResizeEvent: isUserOriginated? true")); + } + } + + @Test + public void testResizeWithWidgetHeader() { + selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width", + "250px"); + selectMenuPath("Component", "Columns", "Column 0", "Header Type", + "Widget Header"); + + // IE9 and IE10 sometimes have a 1px gap between resize handle parts, so + // using posX 1px + dragResizeColumn(0, 1, 10); + + assertTrue("Log should contain a resize event", + logContainsText("ColumnResizeEvent: isUserOriginated? true")); + } + + private void dragResizeColumn(int columnIndex, int posX, int offset) { + GridCellElement headerCell = getGridElement().getHeaderCell(0, + columnIndex); + Dimension size = headerCell.getSize(); + new Actions(getDriver()) + .moveToElement(headerCell, size.getWidth() + posX, + size.getHeight() / 2) + .clickAndHold().moveByOffset(offset, 0).release().perform(); + } + + private void assertResizable(int columnIndex, boolean resizable) { + assertResizable(getGridElement().getHeaderCell(0, columnIndex), + resizable); + } + + private void assertResizable(GridCellElement cell, boolean resizable) { + assertEquals("Header resize handle present", resizable, + cell.isElementPresent( + By.cssSelector("div.v-grid-column-resize-handle"))); + } + + @Test + public void testShrinkColumnToZero() { + openTestURL(); + GridCellElement cell = getGridElement().getCell(0, 1); + dragResizeColumn(1, 0, cell.getSize().getWidth()); + + assertGreaterOrEqual("Cell got too small.", cell.getSize().getWidth(), + 10); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java new file mode 100644 index 0000000000..65fe0e7dee --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridColumnVisibilityTest.java @@ -0,0 +1,314 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +@TestCategory("grid") +public class GridColumnVisibilityTest extends GridBasicFeaturesTest { + + private static final String[] TOGGLE_LISTENER = new String[] { "Component", + "State", "ColumnVisibilityChangeListener" }; + private static final String[] TOGGLE_HIDE_COLUMN_0 = new String[] { + "Component", "Columns", "Column 0", "Hidden" }; + + private static final String COLUMN_0_BECAME_HIDDEN_MSG = "Visibility " + + "changed: propertyId: Column 0, isHidden: true"; + private static final String COLUMN_0_BECAME_UNHIDDEN_MSG = "Visibility " + + "changed: propertyId: Column 0, isHidden: false"; + private static final String USER_ORIGINATED_TRUE = "userOriginated: true"; + private static final String USER_ORIGINATED_FALSE = "userOriginated: false"; + + @Before + public void setUp() { + openTestURL(); + } + + @Test + public void columnIsNotShownWhenHidden() { + assertEquals("column 0", + getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); + + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + assertEquals("column 1", + getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); + } + + @Test + public void columnIsShownWhenUnhidden() { + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + assertEquals("column 0", + getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); + } + + @Test + public void registeringListener() { + assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); + selectMenuPath(TOGGLE_LISTENER); + assertFalse(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); + + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); + assertTrue(logContainsText(USER_ORIGINATED_FALSE)); + + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG)); + assertTrue(logContainsText(USER_ORIGINATED_FALSE)); + } + + @Test + public void deregisteringListener() { + selectMenuPath(TOGGLE_LISTENER); + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + + selectMenuPath(TOGGLE_LISTENER); + selectMenuPath(TOGGLE_HIDE_COLUMN_0); + assertFalse(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG)); + } + + @Test + public void testColumnHiding_userOriginated_correctParams() { + selectMenuPath(TOGGLE_LISTENER); + toggleColumnHidable(0); + assertColumnHeaderOrder(0, 1, 2, 3); + + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + getSidebarOpenButton().click(); + + assertColumnHeaderOrder(1, 2, 3); + assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); + assertTrue(logContainsText(USER_ORIGINATED_TRUE)); + + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + getSidebarOpenButton().click(); + + assertColumnHeaderOrder(0, 1, 2, 3); + assertTrue(logContainsText(COLUMN_0_BECAME_UNHIDDEN_MSG)); + assertTrue(logContainsText(USER_ORIGINATED_TRUE)); + + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + getSidebarOpenButton().click(); + + assertColumnHeaderOrder(1, 2, 3); + assertTrue(logContainsText(COLUMN_0_BECAME_HIDDEN_MSG)); + assertTrue(logContainsText(USER_ORIGINATED_TRUE)); + } + + @Test + public void testColumnHiding_whenHidableColumnRemoved_toggleRemoved() { + toggleColumnHidable(0); + toggleColumnHidable(1); + getSidebarOpenButton().click(); + assertNotNull(getColumnHidingToggle(0)); + + addRemoveColumn(0); + + assertNull(getColumnHidingToggle(0)); + } + + @Test + public void testColumnHiding_whenHidableColumnAdded_toggleWithCorrectCaptionAdded() { + selectMenuPath("Component", "Size", "Width", "100%"); + toggleColumnHidable(0); + toggleColumnHidable(1); + toggleColumnHidingToggleCaptionChange(0); + getSidebarOpenButton().click(); + assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText()); + getSidebarOpenButton().click(); + + addRemoveColumn(0); + addRemoveColumn(4); + addRemoveColumn(5); + addRemoveColumn(6); + addRemoveColumn(7); + addRemoveColumn(8); + addRemoveColumn(9); + addRemoveColumn(10); + assertColumnHeaderOrder(1, 2, 3, 11); + + getSidebarOpenButton().click(); + assertNull(getColumnHidingToggle(0)); + getSidebarOpenButton().click(); + + addRemoveColumn(0); + assertColumnHeaderOrder(1, 2, 3, 11, 0); + + getSidebarOpenButton().click(); + assertEquals("Column 0 caption 0", getColumnHidingToggle(0).getText()); + } + + @Test + public void testColumnHidingToggleCaption_settingToggleCaption_updatesToggle() { + toggleColumnHidable(1); + getSidebarOpenButton().click(); + assertEquals("column 1", + getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Column 1", getColumnHidingToggle(1).getText()); + + toggleColumnHidingToggleCaptionChange(1); + + getSidebarOpenButton().click(); + assertEquals("column 1", + getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText()); + + toggleColumnHidingToggleCaptionChange(1); + getSidebarOpenButton().click(); + assertEquals("Column 1 caption 1", getColumnHidingToggle(1).getText()); + } + + @Test + public void testColumnHidingToggleCaption_settingWidgetToHeader_toggleCaptionStays() { + toggleColumnHidable(1); + getSidebarOpenButton().click(); + assertEquals("column 1", + getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Column 1", getColumnHidingToggle(1).getText()); + + selectMenuPath("Component", "Columns", "Column 1", "Header Type", + "Widget Header"); + + getSidebarOpenButton().click(); + assertEquals("Column 1", getColumnHidingToggle(1).getText()); + } + + @Test + public void testColumnHidingToggleCaption_settingColumnHeaderCaption_toggleCaptionIsEqual() { + toggleColumnHidable(1); + + selectMenuPath("Component", "Columns", "Column 1", + "Change header caption"); + + getSidebarOpenButton().click(); + assertEquals("column 1 header 0", + getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Column 1 header 0", getColumnHidingToggle(1).getText()); + } + + @Test + public void testColumnHidingToggleCaption_explicitlySet_toggleCaptionIsNotOverridden() { + toggleColumnHidable(1); + + selectMenuPath("Component", "Columns", "Column 1", + "Change hiding toggle caption"); + selectMenuPath("Component", "Columns", "Column 1", + "Change header caption"); + + getSidebarOpenButton().click(); + assertEquals("column 1 header 0", + getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); + assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText()); + } + + private void toggleColumnHidingToggleCaptionChange(int index) { + selectMenuPath("Component", "Columns", "Column " + index, + "Change hiding toggle caption"); + } + + @Test + public void testFrozenColumnHiding_hiddenColumnMadeFrozen_frozenWhenMadeVisible() { + selectMenuPath("Component", "Size", "Width", "100%"); + toggleColumnHidable(0); + toggleColumnHidable(1); + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + getColumnHidingToggle(1).click(); + + assertColumnHeaderOrder(2, 3, 4, 5); + + setFrozenColumns(2); + verifyColumnNotFrozen(0); + verifyColumnNotFrozen(1); + + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + assertColumnHeaderOrder(0, 2, 3, 4, 5); + verifyColumnFrozen(0); + verifyColumnNotFrozen(1); + + getColumnHidingToggle(1).click(); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5); + verifyColumnFrozen(0); + verifyColumnFrozen(1); + verifyColumnNotFrozen(2); + } + + @Test + public void testFrozenColumnHiding_hiddenFrozenColumnUnfrozen_notFrozenWhenMadeVisible() { + selectMenuPath("Component", "Size", "Width", "100%"); + toggleColumnHidable(0); + toggleColumnHidable(1); + setFrozenColumns(2); + verifyColumnFrozen(0); + verifyColumnFrozen(1); + verifyColumnNotFrozen(2); + verifyColumnNotFrozen(3); + + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + getColumnHidingToggle(1).click(); + assertColumnHeaderOrder(2, 3, 4, 5); + verifyColumnNotFrozen(0); + verifyColumnNotFrozen(1); + + setFrozenColumns(0); + verifyColumnNotFrozen(0); + verifyColumnNotFrozen(1); + + getSidebarOpenButton().click(); + getColumnHidingToggle(0).click(); + assertColumnHeaderOrder(0, 2, 3, 4, 5); + verifyColumnNotFrozen(0); + verifyColumnNotFrozen(1); + + getColumnHidingToggle(1).click(); + assertColumnHeaderOrder(0, 1, 2, 3, 4, 5); + verifyColumnNotFrozen(0); + verifyColumnNotFrozen(1); + verifyColumnNotFrozen(2); + } + + private void verifyColumnFrozen(int index) { + assertTrue(getGridElement().getHeaderCell(0, index).isFrozen()); + } + + private void verifyColumnNotFrozen(int index) { + assertFalse(getGridElement().getHeaderCell(0, index).isFrozen()); + } + + private void toggleColumnHidable(int index) { + selectMenuPath("Component", "Columns", "Column " + index, "Hidable"); + } + + private void addRemoveColumn(int index) { + selectMenuPath("Component", "Columns", "Column " + index, + "Add / Remove"); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java new file mode 100644 index 0000000000..d1225a8b1b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java @@ -0,0 +1,297 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridDetailsServerTest extends GridBasicFeaturesTest { + /** + * The reason to why last item details wasn't selected is that since it will + * exist only after the viewport has been scrolled into view, we wouldn't be + * able to scroll that particular details row into view, making tests + * awkward with two scroll commands back to back. + */ + private static final int ALMOST_LAST_INDEX = 995; + private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = new String[] { + "Component", "Details", "Open " + ALMOST_LAST_INDEX }; + private static final String[] OPEN_FIRST_ITEM_DETAILS = new String[] { + "Component", "Details", "Open firstItemId" }; + private static final String[] TOGGLE_FIRST_ITEM_DETAILS = new String[] { + "Component", "Details", "Toggle firstItemId" }; + private static final String[] DETAILS_GENERATOR_NULL = new String[] { + "Component", "Details", "Generators", "NULL" }; + private static final String[] DETAILS_GENERATOR_WATCHING = new String[] { + "Component", "Details", "Generators", "\"Watching\"" }; + private static final String[] DETAILS_GENERATOR_PERSISTING = new String[] { + "Component", "Details", "Generators", "Persisting" }; + private static final String[] CHANGE_HIERARCHY = new String[] { "Component", + "Details", "Generators", "- Change Component" }; + + @Before + public void setUp() { + openTestURL(); + } + + @Test(expected = NoSuchElementException.class) + public void openWithNoGenerator() { + try { + getGridElement().getDetails(0); + fail("Expected NoSuchElementException"); + } catch (NoSuchElementException ignore) { + // expected + } + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + getGridElement().getDetails(0); + } + + @Test + public void openVisiblePopulatedDetails() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertNotNull("details should've populated", getGridElement() + .getDetails(0).findElement(By.className("v-widget"))); + } + + @Test(expected = NoSuchElementException.class) + public void closeVisiblePopulatedDetails() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + getGridElement().getDetails(0); + } + + @Test + public void openDetailsOutsideOfActiveRange() throws InterruptedException { + getGridElement().scroll(10000); + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + getGridElement().scroll(0); + Thread.sleep(50); + assertNotNull("details should've been opened", + getGridElement().getDetails(0)); + } + + @Test(expected = NoSuchElementException.class) + public void closeDetailsOutsideOfActiveRange() { + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + getGridElement().scroll(10000); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + getGridElement().scroll(0); + getGridElement().getDetails(0); + } + + @Test + public void componentIsVisibleClientSide() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + + TestBenchElement details = getGridElement().getDetails(0); + assertNotNull("No widget detected inside details", + details.findElement(By.className("v-widget"))); + } + + @Test + public void openingDetailsTwice() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // close + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open + + TestBenchElement details = getGridElement().getDetails(0); + assertNotNull("No widget detected inside details", + details.findElement(By.className("v-widget"))); + } + + @Test(expected = NoSuchElementException.class) + public void scrollingDoesNotCreateAFloodOfDetailsRows() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + + // scroll somewhere to hit uncached rows + getGridElement().scrollToRow(101); + + // this should throw + getGridElement().getDetails(100); + } + + @Test + public void openingDetailsOutOfView() { + getGridElement().scrollToRow(500); + + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + + getGridElement().scrollToRow(0); + + // if this fails, it'll fail before the assertNotNull + assertNotNull("unexpected null details row", + getGridElement().getDetails(0)); + } + + @Test + public void togglingAVisibleDetailsRowWithOneRoundtrip() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open + + assertTrue("Unexpected generator content", + getGridElement().getDetails(0).getText().endsWith("(0)")); + selectMenuPath(TOGGLE_FIRST_ITEM_DETAILS); + assertTrue("New component was not displayed in the client", + getGridElement().getDetails(0).getText().endsWith("(1)")); + } + + @Test + public void almostLastItemIdIsRendered() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_ALMOST_LAST_ITEM_DETAILS); + scrollGridVerticallyTo(100000); + + TestBenchElement details = getGridElement() + .getDetails(ALMOST_LAST_INDEX); + assertNotNull(details); + assertTrue("Unexpected details content", + details.getText().endsWith(ALMOST_LAST_INDEX + " (0)")); + } + + @Test + public void persistingChangesWorkInDetails() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertEquals("One", getGridElement().getDetails(0).getText()); + selectMenuPath(CHANGE_HIERARCHY); + assertEquals("Two", getGridElement().getDetails(0).getText()); + } + + @Test + public void persistingChangesWorkInDetailsWhileOutOfView() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertEquals("One", getGridElement().getDetails(0).getText()); + scrollGridVerticallyTo(10000); + selectMenuPath(CHANGE_HIERARCHY); + scrollGridVerticallyTo(0); + assertEquals("Two", getGridElement().getDetails(0).getText()); + } + + @Test + public void persistingChangesWorkInDetailsWhenNotAttached() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertEquals("One", getGridElement().getDetails(0).getText()); + + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertFalse("Details should be detached", + getGridElement().isElementPresent(By.vaadin("#details[0]"))); + + selectMenuPath(CHANGE_HIERARCHY); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + + assertEquals("Two", getGridElement().getDetails(0).getText()); + } + + @Test + public void swappingDetailsGenerators_noDetailsShown() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(DETAILS_GENERATOR_NULL); + assertFalse("Got some errors", $(NotificationElement.class).exists()); + } + + @Test + public void swappingDetailsGenerators_shownDetails() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertTrue("Details should contain 'One' at first", + getGridElement().getDetails(0).getText().contains("One")); + + selectMenuPath(DETAILS_GENERATOR_WATCHING); + assertFalse( + "Details should contain 'Watching' after swapping generator", + getGridElement().getDetails(0).getText().contains("Watching")); + } + + @Test + public void swappingDetailsGenerators_whileDetailsScrolledOut_showNever() { + scrollGridVerticallyTo(1000); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + selectMenuPath(DETAILS_GENERATOR_WATCHING); + assertFalse("Got some errors", $(NotificationElement.class).exists()); + } + + @Test + public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() { + scrollGridVerticallyTo(1000); + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + selectMenuPath(DETAILS_GENERATOR_WATCHING); + scrollGridVerticallyTo(0); + + assertFalse("Got some errors", $(NotificationElement.class).exists()); + assertNotNull("Could not find a details", + getGridElement().getDetails(0)); + } + + @Test + public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + selectMenuPath(DETAILS_GENERATOR_WATCHING); + scrollGridVerticallyTo(1000); + + assertFalse("Got some errors", $(NotificationElement.class).exists()); + assertNotNull("Could not find a details", + getGridElement().getDetails(0)); + } + + @Test + public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + selectMenuPath(DETAILS_GENERATOR_WATCHING); + scrollGridVerticallyTo(1000); + scrollGridVerticallyTo(0); + + assertFalse("Got some errors", $(NotificationElement.class).exists()); + assertNotNull("Could not find a details", + getGridElement().getDetails(0)); + } + + @Test + public void noAssertErrorsOnEmptyDetailsAndScrollDown() { + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + scrollGridVerticallyTo(500); + assertFalse(logContainsText("AssertionError")); + } + + @Test + public void noAssertErrorsOnPopulatedDetailsAndScrollDown() { + selectMenuPath(DETAILS_GENERATOR_WATCHING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + scrollGridVerticallyTo(500); + assertFalse(logContainsText("AssertionError")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java new file mode 100644 index 0000000000..e41ace4a1f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java @@ -0,0 +1,314 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.shared.ui.grid.GridConstants; + +public class GridEditorBufferedTest extends GridEditorTest { + + @Override + @Before + public void setUp() { + super.setUp(); + } + + @Test + public void testKeyboardSave() { + selectMenuPath(EDIT_ITEM_100); + + WebElement textField = getEditorWidgets().get(0); + + textField.click(); + // without this, the click in the middle of the field might not be after + // the old text on some browsers + new Actions(getDriver()).sendKeys(Keys.END).perform(); + + textField.sendKeys(" changed"); + + // Save from keyboard + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertEditorClosed(); + assertEquals("(100, 0) changed", + getGridElement().getCell(100, 0).getText()); + } + + @Test + public void testKeyboardSaveWithInvalidEdition() { + makeInvalidEdition(); + + GridEditorElement editor = getGridElement().getEditor(); + TestBenchElement field = editor.getField(7); + + field.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + assertEditorOpen(); + assertEquals("Column 7: Could not convert value to Integer", + editor.getErrorMessage()); + assertTrue("Field 7 should have been marked with an error after error", + editor.isFieldErrorMarked(7)); + + editor.cancel(); + + selectMenuPath(EDIT_ITEM_100); + assertFalse("Exception should not exist", + isElementPresent(NotificationElement.class)); + assertEquals("There should be no editor error message", null, + getGridElement().getEditor().getErrorMessage()); + } + + @Test + public void testSave() { + selectMenuPath(EDIT_ITEM_100); + + WebElement textField = getEditorWidgets().get(0); + + textField.click(); + // without this, the click in the middle of the field might not be after + // the old text on some browsers + new Actions(getDriver()).sendKeys(Keys.END).perform(); + + textField.sendKeys(" changed"); + + WebElement saveButton = getEditor() + .findElement(By.className("v-grid-editor-save")); + + saveButton.click(); + + assertEquals("(100, 0) changed", + getGridElement().getCell(100, 0).getText()); + } + + @Test + public void testProgrammaticSave() { + selectMenuPath(EDIT_ITEM_100); + + WebElement textField = getEditorWidgets().get(0); + + textField.click(); + // without this, the click in the middle of the field might not be after + // the old text on some browsers + new Actions(getDriver()).sendKeys(Keys.END).perform(); + + textField.sendKeys(" changed"); + + selectMenuPath("Component", "Editor", "Save"); + + assertEquals("(100, 0) changed", + getGridElement().getCell(100, 0).getText()); + } + + @Test + public void testInvalidEdition() { + makeInvalidEdition(); + + GridEditorElement editor = getGridElement().getEditor(); + editor.save(); + + assertEquals("Column 7: Could not convert value to Integer", + editor.getErrorMessage()); + assertTrue("Field 7 should have been marked with an error after error", + editor.isFieldErrorMarked(7)); + editor.cancel(); + + selectMenuPath(EDIT_ITEM_100); + assertFalse("Exception should not exist", + isElementPresent(NotificationElement.class)); + assertEquals("There should be no editor error message", null, + getGridElement().getEditor().getErrorMessage()); + } + + private void makeInvalidEdition() { + selectMenuPath(EDIT_ITEM_5); + assertFalse(logContainsText( + "Exception occured, java.lang.IllegalStateException")); + + GridEditorElement editor = getGridElement().getEditor(); + + assertFalse( + "Field 7 should not have been marked with an error before error", + editor.isFieldErrorMarked(7)); + + WebElement intField = editor.getField(7); + intField.clear(); + intField.sendKeys("banana phone"); + } + + @Test + public void testEditorInDisabledGrid() { + int originalScrollPos = getGridVerticalScrollPos(); + + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + + selectMenuPath("Component", "State", "Enabled"); + assertEditorOpen(); + + GridEditorElement editor = getGridElement().getEditor(); + editor.save(); + assertEditorOpen(); + + editor.cancel(); + assertEditorOpen(); + + selectMenuPath("Component", "State", "Enabled"); + + scrollGridVerticallyTo(100); + assertEquals( + "Grid shouldn't scroll vertically while editing in buffered mode", + originalScrollPos, getGridVerticalScrollPos()); + } + + @Test + public void testCaptionChange() { + selectMenuPath(EDIT_ITEM_5); + assertEquals("Save button caption should've been \"" + + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with", + GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); + assertEquals("Cancel button caption should've been \"" + + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with", + GridConstants.DEFAULT_CANCEL_CAPTION, + getCancelButton().getText()); + + selectMenuPath("Component", "Editor", "Change save caption"); + assertNotEquals( + "Save button caption should've changed while editor is open", + GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText()); + + getCancelButton().click(); + + selectMenuPath("Component", "Editor", "Change cancel caption"); + selectMenuPath(EDIT_ITEM_5); + assertNotEquals( + "Cancel button caption should've changed while editor is closed", + GridConstants.DEFAULT_CANCEL_CAPTION, + getCancelButton().getText()); + } + + @Test(expected = NoSuchElementException.class) + public void testVerticalScrollLocking() { + selectMenuPath(EDIT_ITEM_5); + getGridElement().getCell(200, 0); + } + + @Test + public void testScrollDisabledOnProgrammaticOpen() { + int originalScrollPos = getGridVerticalScrollPos(); + + selectMenuPath(EDIT_ITEM_5); + + scrollGridVerticallyTo(100); + assertEquals( + "Grid shouldn't scroll vertically while editing in buffered mode", + originalScrollPos, getGridVerticalScrollPos()); + } + + @Test + public void testScrollDisabledOnMouseOpen() { + int originalScrollPos = getGridVerticalScrollPos(); + + GridCellElement cell_5_0 = getGridElement().getCell(5, 0); + new Actions(getDriver()).doubleClick(cell_5_0).perform(); + + scrollGridVerticallyTo(100); + assertEquals( + "Grid shouldn't scroll vertically while editing in buffered mode", + originalScrollPos, getGridVerticalScrollPos()); + } + + @Test + public void testScrollDisabledOnKeyboardOpen() { + int originalScrollPos = getGridVerticalScrollPos(); + + GridCellElement cell_5_0 = getGridElement().getCell(5, 0); + cell_5_0.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + scrollGridVerticallyTo(100); + assertEquals( + "Grid shouldn't scroll vertically while editing in buffered mode", + originalScrollPos, getGridVerticalScrollPos()); + } + + @Test + public void testMouseOpeningClosing() { + + getGridElement().getCell(4, 0).doubleClick(); + assertEditorOpen(); + + getCancelButton().click(); + assertEditorClosed(); + + selectMenuPath(TOGGLE_EDIT_ENABLED); + getGridElement().getCell(4, 0).doubleClick(); + assertEditorClosed(); + } + + @Test + public void testMouseOpeningDisabledWhenOpen() { + selectMenuPath(EDIT_ITEM_5); + + getGridElement().getCell(4, 0).doubleClick(); + + assertEquals("Editor should still edit row 5", "(5, 0)", + getEditorWidgets().get(0).getAttribute("value")); + } + + @Test + public void testProgrammaticOpeningDisabledWhenOpen() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + assertEquals("Editor should edit row 5", "(5, 0)", + getEditorWidgets().get(0).getAttribute("value")); + + selectMenuPath(EDIT_ITEM_100); + boolean thrown = logContainsText( + "Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + + assertEditorOpen(); + assertEquals("Editor should still edit row 5", "(5, 0)", + getEditorWidgets().get(0).getAttribute("value")); + } + + @Test + public void testUserSortDisabledWhenOpen() { + selectMenuPath(EDIT_ITEM_5); + + getGridElement().getHeaderCell(0, 0).click(); + + assertEditorOpen(); + assertEquals("(2, 0)", getGridElement().getCell(2, 0).getText()); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorTest.java new file mode 100644 index 0000000000..33c543bb20 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorTest.java @@ -0,0 +1,303 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public abstract class GridEditorTest extends GridBasicFeaturesTest { + + protected static final By BY_EDITOR_CANCEL = By + .className("v-grid-editor-cancel"); + protected static final By BY_EDITOR_SAVE = By + .className("v-grid-editor-save"); + protected static final String[] EDIT_ITEM_5 = new String[] { "Component", + "Editor", "Edit item 5" }; + protected static final String[] EDIT_ITEM_100 = new String[] { "Component", + "Editor", "Edit item 100" }; + protected static final String[] TOGGLE_EDIT_ENABLED = new String[] { + "Component", "Editor", "Enabled" }; + + @Before + public void setUp() { + setDebug(true); + openTestURL(); + selectMenuPath(TOGGLE_EDIT_ENABLED); + } + + @Test + public void testProgrammaticOpeningClosing() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + + selectMenuPath("Component", "Editor", "Cancel edit"); + assertEditorClosed(); + } + + @Test + public void testProgrammaticOpeningWhenDisabled() { + selectMenuPath(TOGGLE_EDIT_ENABLED); + selectMenuPath(EDIT_ITEM_5); + assertEditorClosed(); + boolean thrown = logContainsText( + "Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + } + + @Test + public void testDisablingWhileOpen() { + selectMenuPath(EDIT_ITEM_5); + selectMenuPath(TOGGLE_EDIT_ENABLED); + assertEditorOpen(); + boolean thrown = logContainsText( + "Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + } + + @Test + public void testProgrammaticOpeningWithScroll() { + selectMenuPath(EDIT_ITEM_100); + assertEditorOpen(); + } + + @Test + public void testKeyboardOpeningClosing() { + + getGridElement().getCell(4, 0).click(); + assertEditorClosed(); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertEditorOpen(); + + new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform(); + assertEditorClosed(); + + // Disable Editor + selectMenuPath(TOGGLE_EDIT_ENABLED); + getGridElement().getCell(5, 0).click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertEditorClosed(); + } + + @Test + public void testComponentBinding() { + selectMenuPath(EDIT_ITEM_100); + + List widgets = getEditorWidgets(); + assertEquals("Number of widgets", GridBasicFeatures.EDITABLE_COLUMNS, + widgets.size()); + + assertEquals("(100, 0)", widgets.get(0).getAttribute("value")); + assertEquals("(100, 1)", widgets.get(1).getAttribute("value")); + assertEquals("(100, 2)", widgets.get(2).getAttribute("value")); + assertEquals("100", widgets.get(8).getAttribute("value")); + } + + protected void assertEditorOpen() { + assertEquals("Unexpected number of widgets", + GridBasicFeatures.EDITABLE_COLUMNS, getEditorWidgets().size()); + } + + protected void assertEditorClosed() { + assertNull("Editor is supposed to be closed", getEditor()); + } + + protected List getEditorWidgets() { + assertNotNull("Editor is supposed to be open", getEditor()); + return getEditor().findElements(By.className("v-textfield")); + + } + + @Test + public void testFocusOnMouseOpen() { + + GridCellElement cell = getGridElement().getCell(4, 2); + + cell.doubleClick(); + + WebElement focused = getFocusedElement(); + + assertEquals("", "input", focused.getTagName()); + assertEquals("", cell.getText(), focused.getAttribute("value")); + } + + @Test + public void testFocusOnKeyboardOpen() { + + GridCellElement cell = getGridElement().getCell(4, 2); + + cell.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + WebElement focused = getFocusedElement(); + + assertEquals("", "input", focused.getTagName()); + assertEquals("", cell.getText(), focused.getAttribute("value")); + } + + @Test + public void testFocusOnProgrammaticOpenOnItemClick() { + selectMenuPath("Component", "State", "EditorOpeningItemClickListener"); + + GridCellElement cell = getGridElement().getCell(4, 2); + + cell.click(); + + WebElement focused = getFocusedElement(); + + assertEquals("", "input", focused.getTagName()); + assertEquals("", cell.getText(), focused.getAttribute("value")); + } + + @Test + public void testNoFocusOnProgrammaticOpen() { + + selectMenuPath(EDIT_ITEM_5); + + WebElement focused = getFocusedElement(); + + assertEquals("Focus should remain in the menu", "menu", + focused.getAttribute("id")); + } + + @Test + public void testUneditableColumn() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + + GridEditorElement editor = getGridElement().getEditor(); + assertFalse("Uneditable column should not have an editor widget", + editor.isEditable(3)); + + String classNames = editor + .findElements(By.className("v-grid-editor-cells")).get(1) + .findElements(By.xpath("./div")).get(3).getAttribute("class"); + + assertTrue("Noneditable cell should contain not-editable classname", + classNames.contains("not-editable")); + + assertTrue("Noneditable cell should contain v-grid-cell classname", + classNames.contains("v-grid-cell")); + + assertNoErrorNotifications(); + } + + @Test + public void testNoOpenFromHeaderOrFooter() { + selectMenuPath("Component", "Footer", "Visible"); + + getGridElement().getHeaderCell(0, 0).doubleClick(); + assertEditorClosed(); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertEditorClosed(); + + getGridElement().getFooterCell(0, 0).doubleClick(); + assertEditorClosed(); + + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + assertEditorClosed(); + } + + public void testEditorMoveOnResize() { + selectMenuPath("Component", "Size", "Height", "500px"); + getGridElement().getCell(22, 0).doubleClick(); + assertEditorOpen(); + + GridEditorElement editor = getGridElement().getEditor(); + TestBenchElement tableWrapper = getGridElement().getTableWrapper(); + + int tableWrapperBottom = tableWrapper.getLocation().getY() + + tableWrapper.getSize().getHeight(); + int editorBottom = editor.getLocation().getY() + + editor.getSize().getHeight(); + + assertTrue("Editor should not be initially outside grid", + tableWrapperBottom - editorBottom <= 2); + + selectMenuPath("Component", "Size", "Height", "300px"); + assertEditorOpen(); + + tableWrapperBottom = tableWrapper.getLocation().getY() + + tableWrapper.getSize().getHeight(); + editorBottom = editor.getLocation().getY() + + editor.getSize().getHeight(); + + assertTrue("Editor should not be outside grid after resize", + tableWrapperBottom - editorBottom <= 2); + } + + public void testEditorDoesNotMoveOnResizeIfNotNeeded() { + selectMenuPath("Component", "Size", "Height", "500px"); + + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + + GridEditorElement editor = getGridElement().getEditor(); + + int editorPos = editor.getLocation().getY(); + + selectMenuPath("Component", "Size", "Height", "300px"); + assertEditorOpen(); + + assertTrue("Editor should not have moved due to resize", + editorPos == editor.getLocation().getY()); + } + + @Test + public void testEditorClosedOnSort() { + selectMenuPath(EDIT_ITEM_5); + + selectMenuPath("Component", "State", "Sort by column", "Column 0, ASC"); + + assertEditorClosed(); + } + + @Test + public void testEditorClosedOnFilter() { + selectMenuPath(EDIT_ITEM_5); + + selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\""); + + assertEditorClosed(); + } + + protected WebElement getSaveButton() { + return getDriver().findElement(BY_EDITOR_SAVE); + } + + protected WebElement getCancelButton() { + return getDriver().findElement(BY_EDITOR_CANCEL); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java new file mode 100644 index 0000000000..00ec50aaf8 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java @@ -0,0 +1,282 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; + +public class GridEditorUnbufferedTest extends GridEditorTest { + + private static final String[] TOGGLE_EDITOR_BUFFERED = new String[] { + "Component", "Editor", "Buffered mode" }; + private static final String[] CANCEL_EDIT = new String[] { "Component", + "Editor", "Cancel edit" }; + + @Override + @Before + public void setUp() { + super.setUp(); + selectMenuPath(TOGGLE_EDITOR_BUFFERED); + } + + @Test + public void testEditorShowsNoButtons() { + selectMenuPath(EDIT_ITEM_5); + + assertEditorOpen(); + + assertFalse("Save button should not be visible in unbuffered mode.", + isElementPresent(BY_EDITOR_SAVE)); + + assertFalse("Cancel button should not be visible in unbuffered mode.", + isElementPresent(BY_EDITOR_CANCEL)); + } + + @Test + public void testToggleEditorUnbufferedWhileOpen() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + selectMenuPath(TOGGLE_EDITOR_BUFFERED); + boolean thrown = logContainsText( + "Exception occured, java.lang.IllegalStateException"); + assertTrue("IllegalStateException thrown", thrown); + } + + @Test + public void testEditorMoveWithMouse() { + selectMenuPath(EDIT_ITEM_5); + + assertEditorOpen(); + + String firstFieldValue = getEditorWidgets().get(0) + .getAttribute("value"); + assertEquals("Editor should be at row 5", "(5, 0)", firstFieldValue); + + getGridElement().getCell(10, 0).click(); + firstFieldValue = getEditorWidgets().get(0).getAttribute("value"); + + assertEquals("Editor should be at row 10", "(10, 0)", firstFieldValue); + } + + @Test + public void testEditorMoveWithKeyboard() throws InterruptedException { + selectMenuPath(EDIT_ITEM_100); + + assertEditorOpen(); + + getEditorWidgets().get(0).click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + String firstFieldValue = getEditorWidgets().get(0) + .getAttribute("value"); + assertEquals("Editor should move to row 101", "(101, 0)", + firstFieldValue); + + for (int i = 0; i < 10; i++) { + new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.ENTER) + .keyUp(Keys.SHIFT).perform(); + + firstFieldValue = getEditorWidgets().get(0).getAttribute("value"); + int row = 100 - i; + assertEquals("Editor should move to row " + row, "(" + row + ", 0)", + firstFieldValue); + } + } + + @Test + public void testValidationErrorPreventsMove() throws InterruptedException { + // Because of "out of view" issues, we need to move this for easy access + selectMenuPath("Component", "Columns", "Column 7", "Column 7 Width", + "50px"); + for (int i = 0; i < 6; ++i) { + selectMenuPath("Component", "Columns", "Column 7", "Move left"); + } + + selectMenuPath(EDIT_ITEM_5); + + getEditorWidgets().get(1).click(); + String faultyInt = "not a number"; + getEditorWidgets().get(1).sendKeys(faultyInt); + + getGridElement().getCell(10, 0).click(); + + assertEquals("Editor should not move from row 5", "(5, 0)", + getEditorWidgets().get(0).getAttribute("value")); + + getEditorWidgets().get(1).sendKeys(Keys.chord(Keys.CONTROL, "a")); + getEditorWidgets().get(1).sendKeys("5"); + // FIXME: Needs to trigger one extra validation round-trip for now + getGridElement().sendKeys(Keys.ENTER); + + getGridElement().getCell(10, 0).click(); + + assertEquals("Editor should move to row 10", "(10, 0)", + getEditorWidgets().get(0).getAttribute("value")); + + } + + @Test + public void testErrorMessageWrapperHidden() { + selectMenuPath(EDIT_ITEM_5); + + assertEditorOpen(); + + WebElement editorFooter = getEditor() + .findElement(By.className("v-grid-editor-footer")); + + assertTrue("Editor footer should not be visible when there's no error", + editorFooter.getCssValue("display").equalsIgnoreCase("none")); + } + + @Test + public void testScrollEnabledOnProgrammaticOpen() { + int originalScrollPos = getGridVerticalScrollPos(); + + selectMenuPath(EDIT_ITEM_5); + + scrollGridVerticallyTo(100); + assertGreater( + "Grid should scroll vertically while editing in unbuffered mode", + getGridVerticalScrollPos(), originalScrollPos); + } + + @Test + public void testScrollEnabledOnMouseOpen() { + int originalScrollPos = getGridVerticalScrollPos(); + + GridCellElement cell_5_0 = getGridElement().getCell(5, 0); + new Actions(getDriver()).doubleClick(cell_5_0).perform(); + + scrollGridVerticallyTo(100); + assertGreater( + "Grid should scroll vertically while editing in unbuffered mode", + getGridVerticalScrollPos(), originalScrollPos); + } + + @Test + public void testScrollEnabledOnKeyboardOpen() { + int originalScrollPos = getGridVerticalScrollPos(); + + GridCellElement cell_5_0 = getGridElement().getCell(5, 0); + cell_5_0.click(); + new Actions(getDriver()).sendKeys(Keys.ENTER).perform(); + + scrollGridVerticallyTo(100); + assertGreater( + "Grid should scroll vertically while editing in unbuffered mode", + getGridVerticalScrollPos(), originalScrollPos); + } + + @Test + public void testEditorInDisabledGrid() { + selectMenuPath(EDIT_ITEM_5); + + selectMenuPath("Component", "State", "Enabled"); + assertEditorOpen(); + + assertTrue("Editor text field should be disabled", + null != getEditorWidgets().get(2).getAttribute("disabled")); + + selectMenuPath("Component", "State", "Enabled"); + assertEditorOpen(); + + assertFalse("Editor text field should not be disabled", + null != getEditorWidgets().get(2).getAttribute("disabled")); + } + + @Test + public void testMouseOpeningClosing() { + + getGridElement().getCell(4, 0).doubleClick(); + assertEditorOpen(); + + selectMenuPath(CANCEL_EDIT); + selectMenuPath(TOGGLE_EDIT_ENABLED); + + getGridElement().getCell(4, 0).doubleClick(); + assertEditorClosed(); + } + + @Test + public void testProgrammaticOpeningWhenOpen() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + assertEquals("Editor should edit row 5", "(5, 0)", + getEditorWidgets().get(0).getAttribute("value")); + + selectMenuPath(EDIT_ITEM_100); + assertEditorOpen(); + assertEquals("Editor should edit row 100", "(100, 0)", + getEditorWidgets().get(0).getAttribute("value")); + } + + @Test + public void testExternalValueChangePassesToEditor() { + selectMenuPath(EDIT_ITEM_5); + assertEditorOpen(); + + selectMenuPath("Component", "State", "ReactiveValueChanger"); + + getEditorWidgets().get(0).click(); + getEditorWidgets().get(0).sendKeys("changing value"); + + // Focus another field to cause the value to be sent to the server + getEditorWidgets().get(2).click(); + + assertEquals("Value of Column 2 in the editor was not changed", + "Modified", getEditorWidgets().get(2).getAttribute("value")); + } + + @Test + public void testEditorClosedOnUserSort() { + selectMenuPath(EDIT_ITEM_5); + + getGridElement().getHeaderCell(0, 0).click(); + + assertEditorClosed(); + } + + @Test + public void testEditorSaveOnRowChange() { + // Double click sets the focus programmatically + getGridElement().getCell(5, 2).doubleClick(); + + TestBenchElement editor = getGridElement().getEditor().getField(2); + editor.clear(); + // Click to ensure IE focus... + editor.click(5, 5); + editor.sendKeys("Foo", Keys.ENTER); + + assertEquals("Editor did not move.", "(6, 0)", + getGridElement().getEditor().getField(0).getAttribute("value")); + assertEquals("Editor field value did not update from server.", "(6, 2)", + getGridElement().getEditor().getField(2).getAttribute("value")); + + assertEquals("Edited value was not saved.", "Foo", + getGridElement().getCell(5, 2).getText()); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridFocusTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridFocusTest.java new file mode 100644 index 0000000000..81bb68e153 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridFocusTest.java @@ -0,0 +1,79 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.MenuBarElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +/** + * Test for server-side Grid focus features. + * + * @since + * @author Vaadin Ltd + */ +public class GridFocusTest extends GridBasicFeaturesTest { + + @Before + public void setUp() { + openTestURL(); + } + + @Test + public void testFocusListener() { + selectMenuPath("Component", "Listeners", "Focus listener"); + + getGridElement().click(); + + assertTrue("Focus listener should be invoked", + getLogRow(0).contains("FocusEvent")); + } + + @Test + public void testBlurListener() { + selectMenuPath("Component", "Listeners", "Blur listener"); + + getGridElement().click(); + $(MenuBarElement.class).first().click(); + + assertTrue("Blur listener should be invoked", + getLogRow(0).contains("BlurEvent")); + } + + @Test + public void testProgrammaticFocus() { + selectMenuPath("Component", "State", "Set focus"); + + assertTrue("Grid cell (0, 0) should be focused", + getGridElement().getCell(0, 0).isFocused()); + } + + @Test + public void testTabIndex() { + assertEquals(getGridElement().getAttribute("tabindex"), "0"); + + selectMenuPath("Component", "State", "Tab index", "-1"); + assertEquals(getGridElement().getAttribute("tabindex"), "-1"); + + selectMenuPath("Component", "State", "Tab index", "10"); + assertEquals(getGridElement().getAttribute("tabindex"), "10"); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridItemClickTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridItemClickTest.java new file mode 100644 index 0000000000..3f8a19ae55 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridItemClickTest.java @@ -0,0 +1,58 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridItemClickTest extends GridBasicFeaturesTest { + + @Test + public void testItemClick() { + openTestURL(); + + selectMenuPath("Component", "State", "ItemClickListener"); + + GridCellElement cell = getGridElement().getCell(3, 2); + new Actions(getDriver()).moveToElement(cell).click().perform(); + + assertTrue("No click in log", + logContainsText(itemClickOn(3, 2, false))); + } + + @Test + public void testItemDoubleClick() { + openTestURL(); + + selectMenuPath("Component", "State", "ItemClickListener"); + + GridCellElement cell = getGridElement().getCell(3, 2); + new Actions(getDriver()).moveToElement(cell).doubleClick().perform(); + + assertTrue("No double click in log", + logContainsText(itemClickOn(3, 2, true))); + } + + private String itemClickOn(int row, int column, boolean dblClick) { + return "Item " + (dblClick ? "double " : "") + "click on Column " + + column + ", item " + row; + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java new file mode 100644 index 0000000000..34fcea09fb --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridKeyboardNavigationTest.java @@ -0,0 +1,232 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridKeyboardNavigationTest extends GridBasicFeaturesTest { + + @Test + public void testCellFocusOnClick() { + openTestURL(); + + GridElement grid = getGridElement(); + assertTrue("Body cell 0, 0 is not focused on init.", + grid.getCell(0, 0).isFocused()); + grid.getCell(5, 2).click(); + assertFalse("Body cell 0, 0 was still focused after clicking", + grid.getCell(0, 0).isFocused()); + assertTrue("Body cell 5, 2 is not focused after clicking", + grid.getCell(5, 2).isFocused()); + } + + @Test + public void testCellNotFocusedWhenRendererHandlesEvent() { + openTestURL(); + + GridElement grid = getGridElement(); + assertTrue("Body cell 0, 0 is not focused on init.", + grid.getCell(0, 0).isFocused()); + grid.getHeaderCell(0, 3).click(); + assertFalse("Body cell 0, 0 is focused after click on header.", + grid.getCell(0, 0).isFocused()); + assertTrue("Header cell 0, 3 is not focused after click on header.", + grid.getHeaderCell(0, 3).isFocused()); + } + + @Test + public void testSimpleKeyboardNavigation() { + openTestURL(); + + GridElement grid = getGridElement(); + grid.getCell(0, 0).click(); + + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + assertTrue("Body cell 1, 0 is not focused after keyboard navigation.", + grid.getCell(1, 0).isFocused()); + + new Actions(getDriver()).sendKeys(Keys.ARROW_RIGHT).perform(); + assertTrue("Body cell 1, 1 is not focused after keyboard navigation.", + grid.getCell(1, 1).isFocused()); + + int i; + for (i = 1; i < 40; ++i) { + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + } + + assertFalse("Grid has not scrolled with cell focus", + isElementPresent(By.xpath("//td[text() = '(0, 0)']"))); + assertTrue("Cell focus is not visible", + isElementPresent(By.xpath("//td[text() = '(" + i + ", 0)']"))); + assertTrue("Body cell " + i + ", 1 is not focused", + grid.getCell(i, 1).isFocused()); + } + + @Test + public void testNavigateFromHeaderToBody() { + openTestURL(); + + GridElement grid = getGridElement(); + grid.scrollToRow(300); + new Actions(driver).moveToElement(grid.getHeaderCell(0, 7)).click() + .perform(); + grid.scrollToRow(280); + + assertTrue("Header cell is not focused.", + grid.getHeaderCell(0, 7).isFocused()); + new Actions(getDriver()).sendKeys(Keys.ARROW_DOWN).perform(); + assertTrue("Body cell 280, 7 is not focused", + grid.getCell(280, 7).isFocused()); + } + + @Test + public void testNavigationFromFooterToBody() { + openTestURL(); + + selectMenuPath("Component", "Footer", "Visible"); + + GridElement grid = getGridElement(); + grid.scrollToRow(300); + grid.getFooterCell(0, 2).click(); + + assertTrue("Footer cell does not have focus.", + grid.getFooterCell(0, 2).isFocused()); + new Actions(getDriver()).sendKeys(Keys.ARROW_UP).perform(); + assertTrue("Body cell 300, 2 does not have focus.", + grid.getCell(300, 2).isFocused()); + } + + @Test + public void testNavigateBetweenHeaderAndBodyWithTab() { + openTestURL(); + + GridElement grid = getGridElement(); + grid.getCell(10, 2).click(); + + assertTrue("Body cell 10, 2 does not have focus", + grid.getCell(10, 2).isFocused()); + new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) + .keyUp(Keys.SHIFT).perform(); + assertTrue("Header cell 0, 2 does not have focus", + grid.getHeaderCell(0, 2).isFocused()); + new Actions(getDriver()).sendKeys(Keys.TAB).perform(); + assertTrue("Body cell 10, 2 does not have focus", + grid.getCell(10, 2).isFocused()); + + // Navigate out of the Grid and try to navigate with arrow keys. + new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) + .sendKeys(Keys.TAB).keyUp(Keys.SHIFT).sendKeys(Keys.ARROW_DOWN) + .perform(); + assertTrue("Header cell 0, 2 does not have focus", + grid.getHeaderCell(0, 2).isFocused()); + } + + @Test + public void testNavigateBetweenFooterAndBodyWithTab() { + openTestURL(); + + selectMenuPath("Component", "Footer", "Visible"); + + GridElement grid = getGridElement(); + grid.getCell(10, 2).click(); + + assertTrue("Body cell 10, 2 does not have focus", + grid.getCell(10, 2).isFocused()); + new Actions(getDriver()).sendKeys(Keys.TAB).perform(); + assertTrue("Footer cell 0, 2 does not have focus", + grid.getFooterCell(0, 2).isFocused()); + new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.TAB) + .keyUp(Keys.SHIFT).perform(); + assertTrue("Body cell 10, 2 does not have focus", + grid.getCell(10, 2).isFocused()); + + // Navigate out of the Grid and try to navigate with arrow keys. + new Actions(getDriver()).sendKeys(Keys.TAB).sendKeys(Keys.TAB) + .sendKeys(Keys.ARROW_UP).perform(); + assertTrue("Footer cell 0, 2 does not have focus", + grid.getFooterCell(0, 2).isFocused()); + } + + @Test + public void testHomeEnd() throws Exception { + openTestURL(); + + getGridElement().getCell(100, 2).click(); + + new Actions(getDriver()).sendKeys(Keys.HOME).perform(); + assertTrue("First row is not visible", + getGridElement().getCell(0, 2).isDisplayed()); + + new Actions(getDriver()).sendKeys(Keys.END).perform(); + assertTrue("Last row cell not visible", getGridElement() + .getCell(GridBasicFeatures.ROWS - 1, 2).isDisplayed()); + } + + @Test + public void testPageUpPageDown() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Size", "HeightMode Row"); + + getGridElement().getCell(9, 2).click(); + new Actions(getDriver()).sendKeys(Keys.PAGE_DOWN).perform(); + assertTrue("Row 17 did not become visible", + isElementPresent(By.xpath("//td[text() = '(17, 2)']"))); + + new Actions(getDriver()).sendKeys(Keys.PAGE_DOWN).perform(); + assertTrue("Row 25 did not become visible", + isElementPresent(By.xpath("//td[text() = '(25, 2)']"))); + checkFocusedCell(29, 2, 4); + + getGridElement().getCell(41, 2).click(); + new Actions(getDriver()).sendKeys(Keys.PAGE_UP).perform(); + assertTrue("Row 33 did not become visible", + isElementPresent(By.xpath("//td[text() = '(33, 2)']"))); + + new Actions(getDriver()).sendKeys(Keys.PAGE_UP).perform(); + assertTrue("Row 25 did not become visible", + isElementPresent(By.xpath("//td[text() = '(25, 2)']"))); + checkFocusedCell(21, 2, 4); + } + + private void checkFocusedCell(int row, int column, int rowTolerance) { + WebElement focusedCell = getGridElement() + .findElement(By.className("v-grid-cell-focused")); + String cellContents = focusedCell.getText(); + String[] rowAndCol = cellContents.replaceAll("[()\\s]", "").split(","); + int focusedRow = Integer.parseInt(rowAndCol[0].trim()); + int focusedColumn = Integer.parseInt(rowAndCol[1].trim()); + // rowTolerance is the maximal allowed difference from the expected + // focused row. It is required because scrolling using page up/down + // may not move the position by exactly the visible height of the grid. + assertTrue( + "The wrong cell is focused. Expected (" + row + "," + column + + "), was " + cellContents, + column == focusedColumn + && Math.abs(row - focusedRow) <= rowTolerance); + } +} \ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridMultiSortingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridMultiSortingTest.java new file mode 100644 index 0000000000..a13cdb46c0 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridMultiSortingTest.java @@ -0,0 +1,65 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridMultiSortingTest extends GridBasicFeaturesTest { + + @Override + public List getBrowsersToTest() { + return super.getBrowsersSupportingShiftClick(); + } + + @Test + public void testUserMultiColumnSorting() { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 11", "Column 11 Width", + "Auto"); + + GridCellElement cell = getGridElement().getHeaderCell(0, 11); + new Actions(driver).moveToElement(cell, 20, 10).click().perform(); + new Actions(driver).keyDown(Keys.SHIFT).perform(); + new Actions(driver) + .moveToElement(getGridElement().getHeaderCell(0, 0), 20, 10) + .click().perform(); + new Actions(driver).keyUp(Keys.SHIFT).perform(); + + String prev = getGridElement().getCell(0, 11).getAttribute("innerHTML"); + for (int i = 1; i <= 6; ++i) { + assertEquals("Column 11 should contain same values.", prev, + getGridElement().getCell(i, 11).getAttribute("innerHTML")); + } + + prev = getGridElement().getCell(0, 0).getText(); + for (int i = 1; i <= 6; ++i) { + assertTrue("Grid is not sorted by column 0.", prev + .compareTo(getGridElement().getCell(i, 0).getText()) < 0); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridRowAddRemoveTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridRowAddRemoveTest.java new file mode 100644 index 0000000000..fd56fbf2f2 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridRowAddRemoveTest.java @@ -0,0 +1,51 @@ +/* + * 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.basicfeatures.server; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridRowAddRemoveTest extends GridBasicFeaturesTest { + + @Test + public void addRows_loadAllAtOnce() { + setDebug(true); + openTestURL(); + + selectMenuPath("Settings", "Clear log"); + selectMenuPath("Component", "Body rows", "Remove all rows"); + selectMenuPath("Component", "Body rows", "Add 18 rows"); + + Assert.assertTrue( + "All added rows should be fetched in the same round trip.", + logContainsText("Requested items 0 - 18")); + } + + @Test + public void testAdd18Rows() { + setDebug(true); + openTestURL(); + + selectMenuPath("Settings", "Clear log"); + selectMenuPath("Component", "Body rows", "Add 18 rows"); + + Assert.assertFalse("An error notification is present.", + isElementPresent(NotificationElement.class)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridScrollTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridScrollTest.java new file mode 100644 index 0000000000..d3fefddeea --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridScrollTest.java @@ -0,0 +1,57 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridScrollTest extends GridBasicFeaturesTest { + + @Test + public void testCorrectItemRequestsOnScroll() { + openTestURL(); + + assertTrue("Initial push from server not found", + getLogRow(1).equals("0. Requested items 0 - 40")); + // Client response varies a bit between browsers as different amount of + // rows is cached. + assertTrue("First row request from client not found", + getLogRow(0).startsWith("1. Requested items 0 - ")); + + selectMenuPath("Component", "Size", "HeightMode Row"); + + selectMenuPath("Settings", "Clear log"); + $(GridElement.class).first().scrollToRow(40); + assertEquals("Log row did not contain expected item request", + "0. Requested items 0 - 86", getLogRow(0)); + assertEquals("There should be only one log row", " ", getLogRow(1)); + selectMenuPath("Settings", "Clear log"); + $(GridElement.class).first().scrollToRow(100); + assertEquals("Log row did not contain expected item request", + "0. Requested items 47 - 146", getLogRow(0)); + assertEquals("There should be only one log row", " ", getLogRow(1)); + selectMenuPath("Settings", "Clear log"); + $(GridElement.class).first().scrollToRow(300); + assertEquals("Log row did not contain expected item request", + "0. Requested items 247 - 346", getLogRow(0)); + assertEquals("There should be only one log row", " ", getLogRow(1)); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSelectionTest.java new file mode 100644 index 0000000000..319848fec3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSelectionTest.java @@ -0,0 +1,429 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.GridElement.GridRowElement; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridSelectionTest extends GridBasicFeaturesTest { + + @Test + public void testSelectOnOff() throws Exception { + openTestURL(); + + setSelectionModelMulti(); + + assertFalse("row shouldn't start out as selected", + getRow(0).isSelected()); + toggleFirstRowSelection(); + assertTrue("row should become selected", getRow(0).isSelected()); + toggleFirstRowSelection(); + assertFalse("row shouldn't remain selected", getRow(0).isSelected()); + } + + @Test + public void testSelectOnScrollOffScroll() throws Exception { + openTestURL(); + + setSelectionModelMulti(); + + assertFalse("row shouldn't start out as selected", + getRow(0).isSelected()); + toggleFirstRowSelection(); + assertTrue("row should become selected", getRow(0).isSelected()); + + scrollGridVerticallyTo(10000); // make sure the row is out of cache + scrollGridVerticallyTo(0); // scroll it back into view + + assertTrue("row should still be selected when scrolling " + + "back into view", getRow(0).isSelected()); + } + + @Test + public void testSelectScrollOnScrollOff() throws Exception { + openTestURL(); + + setSelectionModelMulti(); + + assertFalse("row shouldn't start out as selected", + getRow(0).isSelected()); + + scrollGridVerticallyTo(10000); // make sure the row is out of cache + toggleFirstRowSelection(); + + scrollGridVerticallyTo(0); // scroll it back into view + assertTrue("row should still be selected when scrolling " + + "back into view", getRow(0).isSelected()); + + toggleFirstRowSelection(); + assertFalse("row shouldn't remain selected", getRow(0).isSelected()); + } + + @Test + public void testSelectScrollOnOffScroll() throws Exception { + openTestURL(); + + setSelectionModelMulti(); + + assertFalse("row shouldn't start out as selected", + getRow(0).isSelected()); + + scrollGridVerticallyTo(10000); // make sure the row is out of cache + toggleFirstRowSelection(); + toggleFirstRowSelection(); + + scrollGridVerticallyTo(0); // make sure the row is out of cache + assertFalse( + "row shouldn't be selected when scrolling " + "back into view", + getRow(0).isSelected()); + } + + @Test + public void testSingleSelectionUpdatesFromServer() { + openTestURL(); + setSelectionModelSingle(); + + GridElement grid = getGridElement(); + assertFalse("First row was selected from start", + grid.getRow(0).isSelected()); + toggleFirstRowSelection(); + assertTrue("First row was not selected.", getRow(0).isSelected()); + assertTrue("Selection event was not correct", + logContainsText("Added 0, Removed none")); + grid.getCell(5, 0).click(); + assertTrue("Fifth row was not selected.", getRow(5).isSelected()); + assertFalse("First row was still selected.", getRow(0).isSelected()); + assertTrue("Selection event was not correct", + logContainsText("Added 5, Removed 0")); + grid.getCell(0, 6).click(); + assertTrue("Selection event was not correct", + logContainsText("Added 0, Removed 5")); + toggleFirstRowSelection(); + assertTrue("Selection event was not correct", + logContainsText("Added none, Removed 0")); + assertFalse("First row was still selected.", getRow(0).isSelected()); + assertFalse("Fifth row was still selected.", getRow(5).isSelected()); + + grid.scrollToRow(600); + grid.getCell(595, 3).click(); + assertTrue("Row 595 was not selected.", getRow(595).isSelected()); + assertTrue("Selection event was not correct", + logContainsText("Added 595, Removed none")); + toggleFirstRowSelection(); + assertFalse("Row 595 was still selected.", getRow(595).isSelected()); + assertTrue("First row was not selected.", getRow(0).isSelected()); + assertTrue("Selection event was not correct", + logContainsText("Added 0, Removed 595")); + } + + @Test + public void testKeyboardSelection() { + openTestURL(); + setSelectionModelMulti(); + + GridElement grid = getGridElement(); + grid.getCell(3, 1).click(); + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Grid row 3 was not selected with space key.", + grid.getRow(3).isSelected()); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Grid row 3 was not deselected with space key.", + !grid.getRow(3).isSelected()); + + grid.scrollToRow(500); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Grid row 3 was not selected with space key.", + grid.getRow(3).isSelected()); + } + + @Test + public void testKeyboardWithSingleSelection() { + openTestURL(); + setSelectionModelSingle(); + + GridElement grid = getGridElement(); + grid.getCell(3, 1).click(); + + assertTrue("Grid row 3 was not selected with clicking.", + grid.getRow(3).isSelected()); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Grid row 3 was not deselected with space key.", + !grid.getRow(3).isSelected()); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Grid row 3 was not selected with space key.", + grid.getRow(3).isSelected()); + + grid.scrollToRow(500); + + new Actions(getDriver()).sendKeys(Keys.SPACE).perform(); + + assertTrue("Grid row 3 was not deselected with space key.", + !grid.getRow(3).isSelected()); + } + + @Test + public void testSelectAllCheckbox() { + openTestURL(); + + setSelectionModelMulti(); + GridCellElement header = getGridElement().getHeaderCell(0, 0); + + assertTrue("No checkbox", header.isElementPresent(By.tagName("input"))); + header.findElement(By.tagName("input")).click(); + + for (int i = 0; i < GridBasicFeatures.ROWS; i += 100) { + assertTrue("Row " + i + " was not selected.", + getGridElement().getRow(i).isSelected()); + } + + header.findElement(By.tagName("input")).click(); + assertFalse("Row 100 was still selected", + getGridElement().getRow(100).isSelected()); + } + + @Test + public void testSelectAllAndSort() { + openTestURL(); + + setSelectionModelMulti(); + GridCellElement header = getGridElement().getHeaderCell(0, 0); + + header.findElement(By.tagName("input")).click(); + + getGridElement().getHeaderCell(0, 1).click(); + + WebElement selectionBox = getGridElement().getCell(4, 0) + .findElement(By.tagName("input")); + selectionBox.click(); + selectionBox.click(); + + assertFalse("Exception occured on row reselection.", logContainsText( + "Exception occured, java.lang.IllegalStateException: No item id for key 101 found.")); + } + + @Test + public void testSelectAllCheckboxWhenChangingModels() { + openTestURL(); + + GridCellElement header; + header = getGridElement().getHeaderCell(0, 0); + assertFalse( + "Check box shouldn't have been in header for None Selection Model", + header.isElementPresent(By.tagName("input"))); + + setSelectionModelMulti(); + header = getGridElement().getHeaderCell(0, 0); + assertTrue("Multi Selection Model should have select all checkbox", + header.isElementPresent(By.tagName("input"))); + + setSelectionModelSingle(); + header = getGridElement().getHeaderCell(0, 0); + assertFalse( + "Check box shouldn't have been in header for Single Selection Model", + header.isElementPresent(By.tagName("input"))); + + // Single selection model shouldn't have selection column to begin with + assertFalse( + "Selection columnn shouldn't have been in grid for Single Selection Model", + getGridElement().getCell(0, 1) + .isElementPresent(By.tagName("input"))); + + setSelectionModelNone(); + header = getGridElement().getHeaderCell(0, 0); + assertFalse( + "Check box shouldn't have been in header for None Selection Model", + header.isElementPresent(By.tagName("input"))); + + } + + @Test + public void testSelectAllCheckboxWithHeaderOperations() { + openTestURL(); + + setSelectionModelMulti(); + selectMenuPath("Component", "Header", "Prepend row"); + selectMenuPath("Component", "Header", "Append row"); + + GridCellElement header = getGridElement().getHeaderCell(1, 0); + assertTrue("Multi Selection Model should have select all checkbox", + header.isElementPresent(By.tagName("input"))); + + } + + @Test + public void testToggleDeselectAllowed() { + openTestURL(); + + setSelectionModelSingle(); + // Deselect allowed already enabled + + getGridElement().getCell(5, 1).click(); + getGridElement().getCell(5, 1).click(); + assertFalse("Row should be not selected after two clicks", + getRow(5).isSelected()); + + selectMenuPath("Component", "State", "Single select allow deselect"); + getGridElement().getCell(5, 1).click(); + getGridElement().getCell(5, 1).click(); + assertTrue("Row should be selected after two clicks", + getRow(5).isSelected()); + + selectMenuPath("Component", "State", "Single select allow deselect"); + getGridElement().getCell(5, 1).click(); + assertFalse("Row should be not selected after another click", + getRow(5).isSelected()); + + // Also verify that state is updated together with the model + setSelectionModelNone(); + selectMenuPath("Component", "State", "Single select allow deselect"); + setSelectionModelSingle(); + + getGridElement().getCell(5, 1).click(); + getGridElement().getCell(5, 1).click(); + + assertTrue("Row should stay selected after two clicks", + getRow(5).isSelected()); + } + + @Test + public void testChangeSelectionModelUpdatesUI() { + openTestURL(); + + setSelectionModelSingle(); + + getGridElement().getCell(5, 1).click(); + assertTrue("Row should be selected after clicking", + getRow(5).isSelected()); + + setSelectionModelNone(); + assertFalse("Row should not be selected after changing selection model", + getRow(5).isSelected()); + } + + @Test + public void testSelectionCheckBoxesHaveStyleNames() { + openTestURL(); + + setSelectionModelMulti(); + + assertTrue( + "Selection column CheckBox should have the proper style name set", + getGridElement().getCell(0, 0).findElement(By.tagName("span")) + .getAttribute("class") + .contains("v-grid-selection-checkbox")); + + GridCellElement header = getGridElement().getHeaderCell(0, 0); + assertTrue("Select all CheckBox should have the proper style name set", + header.findElement(By.tagName("span")).getAttribute("class") + .contains("v-grid-select-all-checkbox")); + } + + @Test + public void testServerSideSelectTogglesSelectAllCheckBox() { + openTestURL(); + + setSelectionModelMulti(); + GridCellElement header = getGridElement().getHeaderCell(0, 0); + + WebElement selectAll = header.findElement(By.tagName("input")); + + selectMenuPath("Component", "State", "Select all"); + waitUntilCheckBoxValue(selectAll, true); + assertTrue("Select all CheckBox wasn't selected as expected", + selectAll.isSelected()); + + selectMenuPath("Component", "State", "Select none"); + waitUntilCheckBoxValue(selectAll, false); + assertFalse("Select all CheckBox was selected unexpectedly", + selectAll.isSelected()); + + selectMenuPath("Component", "State", "Select all"); + waitUntilCheckBoxValue(selectAll, true); + getGridElement().getCell(5, 0).click(); + waitUntilCheckBoxValue(selectAll, false); + assertFalse("Select all CheckBox was selected unexpectedly", + selectAll.isSelected()); + } + + @Test + public void testRemoveSelectedRow() { + openTestURL(); + + setSelectionModelSingle(); + getGridElement().getCell(0, 0).click(); + + selectMenuPath("Component", "Body rows", "Remove selected rows"); + + assertFalse( + "Unexpected NullPointerException when removing selected rows", + logContainsText( + "Exception occured, java.lang.NullPointerException: null")); + } + + private void waitUntilCheckBoxValue(final WebElement checkBoxElememnt, + final boolean expectedValue) { + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver input) { + return expectedValue ? checkBoxElememnt.isSelected() + : !checkBoxElememnt.isSelected(); + } + }, 5); + } + + private void setSelectionModelMulti() { + selectMenuPath("Component", "State", "Selection mode", "multi"); + } + + private void setSelectionModelSingle() { + selectMenuPath("Component", "State", "Selection mode", "single"); + } + + private void setSelectionModelNone() { + selectMenuPath("Component", "State", "Selection mode", "none"); + } + + private void toggleFirstRowSelection() { + selectMenuPath("Component", "Body rows", "Select first row"); + } + + private GridRowElement getRow(int i) { + return getGridElement().getRow(i); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java new file mode 100644 index 0000000000..a4a0d20352 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSidebarThemeTest.java @@ -0,0 +1,84 @@ +/* + * 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.basicfeatures.server; + +import java.io.IOException; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.remote.DesiredCapabilities; + +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridSidebarFeatures; + +public class GridSidebarThemeTest extends GridBasicFeaturesTest { + + @Test + public void testValo() throws Exception { + runTestSequence("valo"); + } + + @Test + public void testValoDark() throws Exception { + runTestSequence("tests-valo-dark"); + } + + @Override + protected Class getUIClass() { + return GridSidebarFeatures.class; + } + + private void runTestSequence(String theme) throws IOException { + openTestURL("theme=" + theme); + + compareScreen(theme + "-SidebarClosed"); + getSidebarOpenButton().click(); + + compareScreen(theme + "-SidebarOpen"); + + new Actions(getDriver()).moveToElement(getColumnHidingToggle(2), 5, 5) + .perform(); + + compareScreen(theme + "-OnMouseOverNotHiddenToggle"); + + getColumnHidingToggle(2).click(); + getColumnHidingToggle(3).click(); + getColumnHidingToggle(6).click(); + + new Actions(getDriver()).moveToElement(getSidebarOpenButton()) + .perform(); + ; + + compareScreen(theme + "-TogglesTriggered"); + + new Actions(getDriver()).moveToElement(getColumnHidingToggle(2)) + .perform(); + ; + + compareScreen(theme + "-OnMouseOverHiddenToggle"); + + getSidebarOpenButton().click(); + + compareScreen(theme + "-SidebarClosed2"); + } + + @Override + public List getBrowsersToTest() { + // phantom JS looks wrong from the beginning, so not tested + return getBrowsersExcludingPhantomJS(); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSortingTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSortingTest.java new file mode 100644 index 0000000000..5cb6f59021 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridSortingTest.java @@ -0,0 +1,408 @@ +/* + * 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.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridSortingTest extends GridBasicFeaturesTest { + + private static class SortInfo { + public final int sortOrder; + public final SortDirection sortDirection; + + private SortInfo(int sortOrder, SortDirection sortDirection) { + this.sortOrder = sortOrder; + this.sortDirection = sortDirection; + } + } + + private static class SortInfoWithColumn extends SortInfo { + public final int columnIndex; + + private SortInfoWithColumn(int columnIndex, int sortOrder, + SortDirection sortDirection) { + super(sortOrder, sortDirection); + this.columnIndex = columnIndex; + } + } + + private static SortInfo _(int sortOrder, SortDirection sortDirection) { + return new SortInfo(sortOrder, sortDirection); + } + + private static SortInfoWithColumn _(int columnIndex, int sortOrder, + SortDirection sortDirection) { + return new SortInfoWithColumn(columnIndex, sortOrder, sortDirection); + } + + @Test + public void testProgrammaticSorting() throws Exception { + openTestURL(); + + // Sorting by column 9 is sorting by row index that is represented as a + // String. + // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) + sortBy("Column 9, DESC"); + assertLastSortIsUserOriginated(false); + + // Verify that programmatic sorting calls are identified as originating + // from API + assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); + + String row = ""; + for (int i = 0; i < 3; ++i) { + row += "9"; + String expected = "(" + row + ", 0)"; + String cellValue = getGridElement().getCell(i, 0).getText(); + assertEquals( + "Grid is not sorted by Column 9 " + + "using descending direction.", + expected, cellValue); + } + + // Column 10 is random numbers from Random with seed 13334 + sortBy("Column 10, ASC"); + + assertFalse("Column 9 should no longer have the sort-desc stylename", + getGridElement().getHeaderCell(0, 9).getAttribute("class") + .contains("sort-desc")); + + assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); + + for (int i = 0; i < 5; ++i) { + Integer firstRow = Integer + .valueOf(getGridElement().getCell(i + 1, 10).getText()); + Integer secondRow = Integer + .valueOf(getGridElement().getCell(i, 10).getText()); + assertGreater("Grid is not sorted by Column 10 using" + + " ascending direction", firstRow, secondRow); + + } + + // Column 7 is row index as a number. Last three row are original rows + // 2, 1 and 0. + sortBy("Column 7, DESC"); + for (int i = 0; i < 3; ++i) { + String expected = "(" + i + ", 0)"; + String cellContent = getGridElement() + .getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText(); + assertEquals("Grid is not sorted by Column 7 using " + + "descending direction", expected, cellContent); + } + + assertFalse("Column 10 should no longer have the sort-asc stylename", + getGridElement().getHeaderCell(0, 10).getAttribute("class") + .contains("sort-asc")); + + assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); + } + + @Test + public void testMouseSorting() throws Exception { + setDebug(true); + openTestURL(); + + GridElement grid = getGridElement(); + + selectMenuPath("Component", "Columns", "Column 9", "Column 9 Width", + "Auto"); + + // Sorting by column 9 is sorting by row index that is represented as a + // String. + + // Click header twice to sort descending + clickHeader(grid.getHeaderCell(0, 9)); + + assertLastSortIsUserOriginated(true); + + assertColumnsAreSortedAs(_(9, 1, SortDirection.ASCENDING)); + clickHeader(grid.getHeaderCell(0, 9)); + assertColumnsAreSortedAs(_(9, 1, SortDirection.DESCENDING)); + + // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0) + String row = ""; + for (int i = 0; i < 3; ++i) { + row += "9"; + String expected = "(" + row + ", 0)"; + String actual = grid.getCell(i, 0).getText(); + assertEquals("Grid is not sorted by Column 9" + + " using descending direction.", expected, actual); + } + + selectMenuPath("Component", "Columns", "Column 10", "Column 10 Width", + "Auto"); + // Column 10 is random numbers from Random with seed 13334 + // Click header to sort ascending + clickHeader(grid.getHeaderCell(0, 10)); + assertColumnsAreSortedAs(_(10, 1, SortDirection.ASCENDING)); + + for (int i = 0; i < 5; ++i) { + Integer firstRow = Integer + .valueOf(grid.getCell(i + 1, 10).getText()); + Integer secondRow = Integer.valueOf(grid.getCell(i, 10).getText()); + assertGreater( + "Grid is not sorted by Column 10 using ascending direction", + firstRow, secondRow); + + } + + selectMenuPath("Component", "Columns", "Column 7", "Column 7 Width", + "Auto"); + // Column 7 is row index as a number. Last three row are original rows + // 2, 1 and 0. + // Click header twice to sort descending + clickHeader(grid.getHeaderCell(0, 7)); + assertColumnsAreSortedAs(_(7, 1, SortDirection.ASCENDING)); + clickHeader(grid.getHeaderCell(0, 7)); + assertColumnsAreSortedAs(_(7, 1, SortDirection.DESCENDING)); + + for (int i = 0; i < 3; ++i) { + assertEquals( + "Grid is not sorted by Column 7 using descending direction", + "(" + i + ", 0)", + grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0) + .getText()); + } + + } + + private void clickHeader(GridCellElement headerCell) { + new Actions(getDriver()).moveToElement(headerCell, 20, 10).click() + .perform(); + } + + private void sendKey(Keys seq) { + new Actions(getDriver()).sendKeys(seq).perform(); + } + + private void holdKey(Keys key) { + new Actions(getDriver()).keyDown(key).perform(); + } + + private void releaseKey(Keys key) { + new Actions(getDriver()).keyUp(key).perform(); + } + + @Test + public void testKeyboardSortingMultipleHeaders() { + openTestURL(); + selectMenuPath("Component", "Header", "Append row"); + + // Sort according to first column by clicking + getGridElement().getHeaderCell(0, 0).click(); + assertColumnIsSorted(0); + + // Try to sort according to second column by pressing enter on the new + // header + sendKey(Keys.ARROW_RIGHT); + sendKey(Keys.ARROW_DOWN); + sendKey(Keys.ENTER); + + // Should not have sorted + assertColumnIsSorted(0); + + // Sort using default header + sendKey(Keys.ARROW_UP); + sendKey(Keys.ENTER); + + // Should have sorted + assertColumnIsSorted(1); + + } + + @Test + public void testKeyboardSorting() { + openTestURL(); + + /* + * We can't click on the header directly, since it will sort the header + * immediately. We need to focus some other column first, and only then + * navigate there. + */ + getGridElement().getCell(0, 0).click(); + sendKey(Keys.ARROW_UP); + + // Sort ASCENDING on first column + sendKey(Keys.ENTER); + assertLastSortIsUserOriginated(true); + assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING)); + + // Move to next column + sendKey(Keys.RIGHT); + + // Add this column to the existing sorting group + holdKey(Keys.SHIFT); + sendKey(Keys.ENTER); + releaseKey(Keys.SHIFT); + assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), + _(2, SortDirection.ASCENDING)); + + // Move to next column + sendKey(Keys.RIGHT); + + // Add a third column to the sorting group + holdKey(Keys.SHIFT); + sendKey(Keys.ENTER); + releaseKey(Keys.SHIFT); + assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), + _(2, SortDirection.ASCENDING), _(3, SortDirection.ASCENDING)); + + // Move back to the second column + sendKey(Keys.LEFT); + + // Change sort direction of the second column to DESCENDING + holdKey(Keys.SHIFT); + sendKey(Keys.ENTER); + releaseKey(Keys.SHIFT); + assertColumnsAreSortedAs(_(1, SortDirection.ASCENDING), + _(2, SortDirection.DESCENDING), _(3, SortDirection.ASCENDING)); + + // Move back to the third column + sendKey(Keys.RIGHT); + + // Set sorting to third column, ASCENDING + sendKey(Keys.ENTER); + assertColumnsAreSortedAs(_(2, 1, SortDirection.ASCENDING)); + + // Move to the fourth column + sendKey(Keys.RIGHT); + + // Make sure that single-column sorting also works as expected + sendKey(Keys.ENTER); + assertColumnsAreSortedAs(_(3, 1, SortDirection.ASCENDING)); + + } + + private void assertColumnsAreSortedAs(SortInfoWithColumn... sortInfos) { + for (SortInfoWithColumn sortInfo : sortInfos) { + assertSort(sortInfo, sortInfo.columnIndex, + onlyOneColumnIsSorted(sortInfos)); + } + } + + /** + * @param sortDirections + * null if not interested in that index, otherwise a + * direction that the column needs to be sorted as + */ + private void assertColumnsAreSortedAs(SortInfo... sortInfos) { + for (int column = 0; column < sortInfos.length; column++) { + SortInfo sortInfo = sortInfos[column]; + assertSort(sortInfo, column, onlyOneColumnIsSorted(sortInfos)); + } + } + + private void assertSort(SortInfo sortInfo, int column, + boolean onlyOneColumnIsSorted) { + if (sortInfo == null) { + return; + } + + GridCellElement headerCell = getGridElement().getHeaderCell(0, column); + String classValue = headerCell.getAttribute("class"); + + boolean isSortedAscending = sortInfo.sortDirection == SortDirection.ASCENDING + && classValue.contains("sort-asc"); + boolean isSortedDescending = sortInfo.sortDirection == SortDirection.DESCENDING + && classValue.contains("sort-desc"); + + if (isSortedAscending || isSortedDescending) { + String sortOrderAttribute = headerCell.getAttribute("sort-order"); + + if (sortOrderAttribute == null) { + if (!(sortInfo.sortOrder == 1 && onlyOneColumnIsSorted)) { + fail("missing sort-order element attribute from column " + + column); + } + } else { + assertEquals("sort order was not as expected", + String.valueOf(sortInfo.sortOrder), sortOrderAttribute); + } + } else { + fail("column index " + column + " was not sorted as " + + sortInfo.sortDirection + " (class: " + classValue + ")"); + } + } + + private static boolean onlyOneColumnIsSorted(SortInfo[] sortInfos) { + + boolean foundSortedColumn = false; + for (SortInfo sortInfo : sortInfos) { + if (sortInfo == null) { + continue; + } + + if (!foundSortedColumn) { + foundSortedColumn = true; + } else { + // two columns were sorted + return false; + } + } + return foundSortedColumn; + } + + private void sortBy(String column) { + selectMenuPath("Component", "State", "Sort by column", column); + } + + private void assertLastSortIsUserOriginated(boolean isUserOriginated) { + // Find a message in the log + List userOriginatedMessages = getDriver().findElements(By + .xpath("//div[@id='Log']//*[contains(text(),'SortEvent: isUserOriginated')]")); + + Collections.sort(userOriginatedMessages, new Comparator() { + @Override + public int compare(WebElement o1, WebElement o2) { + return o1.getText().compareTo(o2.getText()); + } + }); + + String newestEntry = userOriginatedMessages + .get(userOriginatedMessages.size() - 1).getText(); + + String[] parts = newestEntry.split(" "); + boolean wasUserOriginated = Boolean + .parseBoolean(parts[parts.length - 1]); + if (isUserOriginated) { + assertTrue("expected the sort to be user originated, but wasn't", + wasUserOriginated); + } else { + assertFalse( + "expected the sort not to be user originated, but it was", + wasUserOriginated); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridStaticSectionComponentTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridStaticSectionComponentTest.java new file mode 100644 index 0000000000..ed0b4a7186 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridStaticSectionComponentTest.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.v7.tests.components.grid.basicfeatures.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridStaticSectionComponentTest extends GridBasicFeaturesTest { + + @Test + public void testNativeButtonInHeader() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Columns", "Column 1", "Header Type", + "Widget Header"); + + getGridElement().$(ButtonElement.class).first().click(); + + assertTrue("Button click should be logged", + logContainsText("Button clicked!")); + } + + @Test + public void testNativeButtonInFooter() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Footer", "Visible"); + selectMenuPath("Component", "Footer", "Append row"); + selectMenuPath("Component", "Columns", "Column 1", "Footer Type", + "Widget Footer"); + + getGridElement().$(ButtonElement.class).first().click(); + + assertTrue("Button click should be logged", + logContainsText("Button clicked!")); + } + + @Test + public void testRemoveComponentFromHeader() throws Exception { + openTestURL(); + selectMenuPath("Component", "Columns", "Column 1", "Header Type", + "Widget Header"); + selectMenuPath("Component", "Columns", "Column 1", "Header Type", + "Text Header"); + assertTrue("No notifications should've been shown", + !$(NotificationElement.class).exists()); + assertEquals("Header should've been reverted back to text header", + "text header", + getGridElement().getHeaderCell(0, 1).getText().toLowerCase()); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridStructureTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridStructureTest.java new file mode 100644 index 0000000000..ed84b9d056 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridStructureTest.java @@ -0,0 +1,517 @@ +/* + * 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.basicfeatures.server; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeatures; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class GridStructureTest extends GridBasicFeaturesTest { + + @Test + public void testRemovingAllColumns() { + setDebug(true); + openTestURL(); + for (int i = 0; i < GridBasicFeatures.COLUMNS; ++i) { + selectMenuPath("Component", "Columns", "Column " + i, + "Add / Remove"); + assertFalse(isElementPresent(NotificationElement.class)); + } + + assertEquals("Headers still visible.", 0, + getGridHeaderRowCells().size()); + } + + @Test + public void testRemoveAndAddColumn() { + setDebug(true); + openTestURL(); + + assertEquals("column 0", + getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); + selectMenuPath("Component", "Columns", "Column 0", "Add / Remove"); + assertEquals("column 1", + getGridElement().getHeaderCell(0, 0).getText().toLowerCase()); + selectMenuPath("Component", "Columns", "Column 0", "Add / Remove"); + + // Column 0 is now the last column in Grid. + assertEquals("Unexpected column content", "(0, 0)", + getGridElement().getCell(0, 11).getText()); + } + + @Test + public void testRemovingColumn() throws Exception { + openTestURL(); + + // Column 0 should be visible + List cells = getGridHeaderRowCells(); + assertEquals("column 0", cells.get(0).getText().toLowerCase()); + + // Hide column 0 + selectMenuPath("Component", "Columns", "Column 0", "Add / Remove"); + + // Column 1 should now be the first cell + cells = getGridHeaderRowCells(); + assertEquals("column 1", cells.get(0).getText().toLowerCase()); + } + + @Test + public void testDataLoadingAfterRowRemoval() throws Exception { + openTestURL(); + + // Remove columns 2,3,4 + selectMenuPath("Component", "Columns", "Column 2", "Add / Remove"); + selectMenuPath("Component", "Columns", "Column 3", "Add / Remove"); + selectMenuPath("Component", "Columns", "Column 4", "Add / Remove"); + + // Scroll so new data is lazy loaded + scrollGridVerticallyTo(1000); + + // Let lazy loading do its job + sleep(1000); + + // Check that row is loaded + assertThat(getGridElement().getCell(11, 0).getText(), not("...")); + } + + @Test + public void testFreezingColumn() throws Exception { + openTestURL(); + + // Freeze column 1 + selectMenuPath("Component", "State", "Frozen column count", "1"); + + WebElement cell = getGridElement().getCell(0, 0); + assertTrue(cell.getAttribute("class").contains("frozen")); + + cell = getGridElement().getCell(0, 1); + assertFalse(cell.getAttribute("class").contains("frozen")); + } + + @Test + public void testInitialColumnWidths() throws Exception { + openTestURL(); + + WebElement cell = getGridElement().getCell(0, 0); + assertEquals(100, cell.getSize().getWidth()); + + cell = getGridElement().getCell(0, 1); + assertEquals(150, cell.getSize().getWidth()); + + cell = getGridElement().getCell(0, 2); + assertEquals(200, cell.getSize().getWidth()); + } + + @Test + public void testColumnWidths() throws Exception { + openTestURL(); + + // Default column width is 100px + WebElement cell = getGridElement().getCell(0, 0); + assertEquals(100, cell.getSize().getWidth()); + + // Set first column to be 200px wide + selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width", + "200px"); + + cell = getGridElement().getCell(0, 0); + assertEquals(200, cell.getSize().getWidth()); + + // Set second column to be 150px wide + selectMenuPath("Component", "Columns", "Column 1", "Column 1 Width", + "150px"); + cell = getGridElement().getCell(0, 1); + assertEquals(150, cell.getSize().getWidth()); + + selectMenuPath("Component", "Columns", "Column 0", "Column 0 Width", + "Auto"); + + // since the column 0 was previously 200, it should've shrunk when + // autoresizing. + cell = getGridElement().getCell(0, 0); + assertLessThan("", cell.getSize().getWidth(), 200); + } + + @Test + public void testPrimaryStyleNames() throws Exception { + openTestURL(); + + // v-grid is default primary style namea + assertPrimaryStylename("v-grid"); + + selectMenuPath("Component", "State", "Primary style name", + "v-escalator"); + assertPrimaryStylename("v-escalator"); + + selectMenuPath("Component", "State", "Primary style name", "my-grid"); + assertPrimaryStylename("my-grid"); + + selectMenuPath("Component", "State", "Primary style name", "v-grid"); + assertPrimaryStylename("v-grid"); + } + + /** + * Test that the current view is updated when a server-side container change + * occurs (without scrolling back and forth) + */ + @Test + public void testItemSetChangeEvent() throws Exception { + openTestURL(); + + final org.openqa.selenium.By newRow = By + .xpath("//td[text()='newcell: 0']"); + + assertTrue("Unexpected initial state", !isElementPresent(newRow)); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue("Add row failed", isElementPresent(newRow)); + + selectMenuPath("Component", "Body rows", "Remove first row"); + assertTrue("Remove row failed", !isElementPresent(newRow)); + } + + /** + * Test that the current view is updated when a property's value is reflect + * to the client, when the value is modified server-side. + */ + @Test + public void testPropertyValueChangeEvent() throws Exception { + openTestURL(); + + assertEquals("Unexpected cell initial state", "(0, 0)", + getGridElement().getCell(0, 0).getText()); + + selectMenuPath("Component", "Body rows", + "Modify first row (getItemProperty)"); + assertEquals("(First) modification with getItemProperty failed", + "modified: 0", getGridElement().getCell(0, 0).getText()); + + selectMenuPath("Component", "Body rows", + "Modify first row (getContainerProperty)"); + assertEquals("(Second) modification with getItemProperty failed", + "modified: Column 0", getGridElement().getCell(0, 0).getText()); + } + + @Test + public void testRemovingAllItems() throws Exception { + openTestURL(); + + selectMenuPath("Component", "Body rows", "Remove all rows"); + + assertEquals(0, getGridElement().findElement(By.tagName("tbody")) + .findElements(By.tagName("tr")).size()); + } + + @Test + public void testRemoveFirstRowTwice() { + openTestURL(); + + selectMenuPath("Component", "Body rows", "Remove first row"); + selectMenuPath("Component", "Body rows", "Remove first row"); + + getGridElement().scrollToRow(50); + assertFalse("Listener setup problem occurred.", + logContainsText("AssertionError: Value change listeners")); + } + + @Test + public void testVerticalScrollBarVisibilityWhenEnoughRows() + throws Exception { + openTestURL(); + + assertTrue(verticalScrollbarIsPresent()); + + selectMenuPath("Component", "Body rows", "Remove all rows"); + assertFalse(verticalScrollbarIsPresent()); + + selectMenuPath("Component", "Size", "HeightMode Row"); + selectMenuPath("Component", "Size", "Height by Rows", "2.33 rows"); + selectMenuPath("Component", "Body rows", "Add first row"); + selectMenuPath("Component", "Body rows", "Add first row"); + assertFalse(verticalScrollbarIsPresent()); + + selectMenuPath("Component", "Body rows", "Add first row"); + assertTrue(verticalScrollbarIsPresent()); + } + + @Test + public void testBareItemSetChange() throws Exception { + openTestURL(); + filterSomeAndAssert(); + } + + @Test + public void testBareItemSetChangeRemovingAllRows() throws Exception { + openTestURL(); + selectMenuPath("Component", "Filter", "Impassable filter"); + assertFalse("A notification shouldn't have been displayed", + $(NotificationElement.class).exists()); + assertTrue("No body cells should've been found", getGridElement() + .getBody().findElements(By.tagName("td")).isEmpty()); + } + + @Test + public void testBareItemSetChangeWithMidScroll() throws Exception { + openTestURL(); + getGridElement().scrollToRow(GridBasicFeatures.ROWS / 2); + filterSomeAndAssert(); + } + + @Test + public void testBareItemSetChangeWithBottomScroll() throws Exception { + openTestURL(); + getGridElement().scrollToRow(GridBasicFeatures.ROWS); + filterSomeAndAssert(); + } + + @Test + public void testBareItemSetChangeWithBottomScrollAndSmallViewport() + throws Exception { + openTestURL(); + selectMenuPath("Component", "Size", "HeightMode Row"); + getGridElement().getRow(GridBasicFeatures.ROWS - 1); + // filter + selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\""); + + String text = getGridElement().getCell(10, 0).getText(); + + assertFalse(text.isEmpty()); + } + + private void filterSomeAndAssert() { + selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\""); + boolean foundElements = false; + for (int row = 0; row < 100; row++) { + try { + GridCellElement cell = getGridElement().getCell(row, 1); + foundElements = true; + assertTrue( + "Unexpected cell contents. " + + "Did the ItemSetChange work after all?", + cell.getText().startsWith("(23")); + } catch (NoSuchElementException e) { + assertTrue("No rows were found", foundElements); + return; + } + } + fail("unexpected amount of rows post-filter. Did the ItemSetChange work after all?"); + } + + @Test + public void testRemoveLastColumn() { + setDebug(true); + openTestURL(); + + int col = GridBasicFeatures.COLUMNS; + String columnName = "Column " + (GridBasicFeatures.COLUMNS - 1); + assertTrue(columnName + " was not present in DOM", + isElementPresent(By.xpath("//th[" + col + "]/div[1]"))); + selectMenuPath("Component", "Columns", columnName, "Add / Remove"); + assertFalse(isElementPresent(NotificationElement.class)); + assertFalse(columnName + " was still present in DOM", + isElementPresent(By.xpath("//th[" + col + "]/div[1]"))); + } + + @Test + public void testReverseColumns() { + openTestURL(); + + String[] gridData = new String[GridBasicFeatures.COLUMNS]; + GridElement grid = getGridElement(); + for (int i = 0; i < gridData.length; ++i) { + gridData[i] = grid.getCell(0, i).getAttribute("innerHTML"); + } + + selectMenuPath("Component", "State", "Reverse Grid Columns"); + + // Compare with reversed order + for (int i = 0; i < gridData.length; ++i) { + final int column = gridData.length - 1 - i; + final String newText = grid.getCell(0, column) + .getAttribute("innerHTML"); + assertEquals( + "Grid contained unexpected values. (0, " + column + ")", + gridData[i], newText); + } + } + + @Test + public void testAddingProperty() { + setDebug(true); + openTestURL(); + + assertNotEquals("property value", + getGridElement().getCell(0, 0).getText()); + selectMenuPath("Component", "Properties", "Prepend property"); + assertEquals("property value", + getGridElement().getCell(0, 0).getText()); + } + + @Test + public void testRemovingAddedProperty() { + openTestURL(); + + assertEquals("(0, 0)", getGridElement().getCell(0, 0).getText()); + assertNotEquals("property value", + getGridElement().getCell(0, 0).getText()); + + selectMenuPath("Component", "Properties", "Prepend property"); + selectMenuPath("Component", "Properties", "Prepend property"); + + assertNotEquals("property value", + getGridElement().getCell(0, 0).getText()); + assertEquals("(0, 0)", getGridElement().getCell(0, 0).getText()); + } + + private boolean verticalScrollbarIsPresent() { + return "scroll" + .equals(getGridVerticalScrollbar().getCssValue("overflow-y")); + } + + @Test + public void testAddRowAboveViewport() { + setDebug(true); + openTestURL(); + + GridCellElement cell = getGridElement().getCell(500, 1); + String cellContent = cell.getText(); + selectMenuPath("Component", "Body rows", "Add first row"); + + assertFalse("Error notification was present", + isElementPresent(NotificationElement.class)); + + assertEquals("Grid scrolled unexpectedly", cellContent, cell.getText()); + } + + @Test + public void testRemoveAndAddRowAboveViewport() { + setDebug(true); + openTestURL(); + + GridCellElement cell = getGridElement().getCell(500, 1); + String cellContent = cell.getText(); + selectMenuPath("Component", "Body rows", "Remove first row"); + + assertFalse("Error notification was present after removing row", + isElementPresent(NotificationElement.class)); + + assertEquals("Grid scrolled unexpectedly", cellContent, cell.getText()); + + selectMenuPath("Component", "Body rows", "Add first row"); + + assertFalse("Error notification was present after adding row", + isElementPresent(NotificationElement.class)); + + assertEquals("Grid scrolled unexpectedly", cellContent, cell.getText()); + } + + @Test + public void testScrollAndRemoveAll() { + setDebug(true); + openTestURL(); + + getGridElement().scrollToRow(500); + selectMenuPath("Component", "Body rows", "Remove all rows"); + + assertFalse("Error notification was present after removing all rows", + isElementPresent(NotificationElement.class)); + + assertFalse( + getGridElement().isElementPresent(By.vaadin("#cell[0][0]"))); + } + + private void assertPrimaryStylename(String stylename) { + assertTrue(getGridElement().getAttribute("class").contains(stylename)); + + String tableWrapperStyleName = getGridElement().getTableWrapper() + .getAttribute("class"); + assertTrue(tableWrapperStyleName.contains(stylename + "-tablewrapper")); + + String hscrollStyleName = getGridElement().getHorizontalScroller() + .getAttribute("class"); + assertTrue(hscrollStyleName.contains(stylename + "-scroller")); + assertTrue( + hscrollStyleName.contains(stylename + "-scroller-horizontal")); + + String vscrollStyleName = getGridElement().getVerticalScroller() + .getAttribute("class"); + assertTrue(vscrollStyleName.contains(stylename + "-scroller")); + assertTrue(vscrollStyleName.contains(stylename + "-scroller-vertical")); + } + + @Test + public void testScrollPosDoesNotChangeAfterStateChange() { + openTestURL(); + scrollGridVerticallyTo(1000); + int scrollPos = getGridVerticalScrollPos(); + selectMenuPath("Component", "Editor", "Enabled"); + assertEquals("Scroll position should've not have changed", scrollPos, + getGridVerticalScrollPos()); + } + + @Test + public void testReloadPage() throws InterruptedException { + setDebug(true); + openTestURL(); + + reopenTestURL(); + + // After opening the URL Grid can be stuck in a state where it thinks it + // should wait for something that's not going to happen. + testBench().disableWaitForVaadin(); + + // Wait until page is loaded completely. + int count = 0; + while (!$(GridElement.class).exists()) { + if (count == 100) { + fail("Reloading page failed"); + } + sleep(100); + ++count; + } + + // Wait a bit more for notification to occur. + sleep(1000); + + assertFalse("Exception occurred when reloading page", + isElementPresent(NotificationElement.class)); + } + + @Test + public void testAddThirdRowToGrid() { + openTestURL(); + selectMenuPath("Component", "Body rows", "Add third row"); + assertFalse(logContainsText("Exception occured")); + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java new file mode 100644 index 0000000000..7d7e88f8c1 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/LoadingIndicatorTest.java @@ -0,0 +1,85 @@ +/* + * 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.basicfeatures.server; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.v7.testbench.customelements.GridElement; +import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; + +public class LoadingIndicatorTest extends GridBasicFeaturesTest { + @Test + public void testLoadingIndicator() throws InterruptedException { + setDebug(true); + openTestURL(); + + selectMenuPath("Component", "State", "Container delay", "2000"); + + GridElement gridElement = $(GridElement.class).first(); + + Assert.assertFalse( + "Loading indicator should not be visible before disabling waitForVaadin", + isLoadingIndicatorVisible()); + + testBench().disableWaitForVaadin(); + + // Scroll to a completely new location + gridElement.getCell(200, 1); + + // Wait for loading indicator delay + waitUntil(ExpectedConditions.visibilityOfElementLocated( + By.className("v-loading-indicator"))); + + waitUntilNot(ExpectedConditions.visibilityOfElementLocated( + By.className("v-loading-indicator"))); + + // Scroll so much that more data gets fetched, but not so much that + // missing rows are shown + gridElement.getCell(230, 1); + + // Wait for potentially triggered loading indicator to become visible + Thread.sleep(500); + + Assert.assertFalse( + "Loading indicator should not be visible when fetching rows that are not visible", + isLoadingIndicatorVisible()); + + // Finally verify that there was actually a request going on + waitUntilLogContains("Requested items"); + } + + private void waitUntilLogContains(final String value) { + waitUntil(new ExpectedCondition() { + @Override + public Boolean apply(WebDriver input) { + return getLogRow(0).contains(value); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return "first log row to contain '" + value + "' (was: '" + + getLogRow(0) + "')"; + } + }); + } + +}