From be2c4684cd43547c2785831a8b0aeda63ccbaebe Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 2 Feb 2017 12:50:09 +0200 Subject: Grid tests migration. Next round. (#8412) * Grid tests migration. Next round. Fixes #8373 --- .../grid/GridExtensionCommunication.java | 84 ++++++++++ .../components/grid/GridGeneratedProperties.java | 168 +++++++++++++++++++ .../grid/GridHeaderFooterComponents.java | 125 ++++++++++++++ .../components/grid/GridHeaderFormatChange.java | 128 ++++++++++++++ .../client/grid/GridClickExtensionConnector.java | 65 ++++++++ .../v7/grid/GridClickExtensionConnector.java | 67 -------- .../v7/tests/components/grid/GridEditorUI.java | 53 ------ .../grid/GridExtensionCommunication.java | 69 -------- .../tests/components/grid/GridFastAsyncUpdate.java | 5 + .../components/grid/GridGeneratedProperties.java | 165 ------------------- .../grid/GridHeaderFooterComponents.java | 133 --------------- .../components/grid/GridHeaderFormatChange.java | 183 --------------------- .../tests/components/grid/GridEditorUITest.java | 96 +++++++++++ .../grid/GridExtensionCommunicationTest.java | 47 ++++++ .../grid/GridGeneratedPropertiesTest.java | 90 ++++++++++ .../grid/GridHeaderFooterComponentsTest.java | 138 ++++++++++++++++ .../grid/GridHeaderFormatChangeTest.java | 151 +++++++++++++++++ .../v7/tests/components/grid/GridEditorUITest.java | 96 ----------- .../grid/GridExtensionCommunicationTest.java | 47 ------ .../grid/GridGeneratedPropertiesTest.java | 90 ---------- .../grid/GridHeaderFooterComponentsTest.java | 138 ---------------- .../grid/GridHeaderFormatChangeTest.java | 151 ----------------- 22 files changed, 1097 insertions(+), 1192 deletions(-) create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridExtensionCommunication.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridGeneratedProperties.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java create mode 100644 uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFormatChange.java create mode 100644 uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClickExtensionConnector.java delete mode 100644 uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/grid/GridClickExtensionConnector.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorUI.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunication.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridGeneratedProperties.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponents.java delete mode 100644 uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChange.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorUITest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridExtensionCommunicationTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridGeneratedPropertiesTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java create mode 100644 uitest/src/test/java/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorUITest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridExtensionCommunicationTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridGeneratedPropertiesTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponentsTest.java delete mode 100644 uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridHeaderFormatChangeTest.java 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 new file mode 100644 index 0000000000..27427f01fe --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridExtensionCommunication.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.tests.components.grid; + +import java.util.stream.IntStream; + +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.data.bean.Person; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.client.grid.GridClickExtensionConnector; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.AbstractGridExtension; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; + +import elemental.json.JsonObject; + +@Widgetset(TestingWidgetSet.NAME) +public class GridExtensionCommunication extends AbstractTestUIWithLog { + + public class GridClickExtension extends AbstractGridExtension { + + public GridClickExtension(Grid grid) { + extend(grid); + registerRpc(new GridClickExtensionConnector.GridClickServerRpc() { + + @Override + public void click(String row, String column, + MouseEventDetails click) { + Person person = getData(row); + Column col = grid.getColumns() + .get(Integer.parseInt(column)); + + log("Click on Person " + person.getFirstName() + " " + + person.getLastName() + " on column " + + col.getId()); + log("MouseEventDetails: " + click.getButtonName() + " (" + + click.getClientX() + ", " + click.getClientY() + + ")"); + } + }); + } + + @Override + public void generateData(Person item, JsonObject jsonObject) { + } + + } + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(); + grid.addColumn(Person::getFirstName).setId("first").setCaption("first"); + grid.addColumn(Person::getLastName).setId("second") + .setCaption("second"); + grid.setItems(IntStream.range(1, 51).mapToObj(this::createPerson)); + grid.setSelectionMode(SelectionMode.NONE); + new GridClickExtension(grid); + addComponent(grid); + } + + private Person createPerson(int index) { + Person person = new Person(); + person.setFirstName("first name " + index); + person.setLastName("last name " + index); + return person; + } +} 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 new file mode 100644 index 0000000000..8c33692f2c --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridGeneratedProperties.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.tests.components.grid; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.tests.components.AbstractReindeerTestUI; +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.sort.Sort; +import com.vaadin.v7.data.sort.SortOrder; +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; + +/** + * Smoke tests for v7 generated properties in Grid + */ +public class GridGeneratedProperties extends AbstractReindeerTestUI { + + 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 new file mode 100644 index 0000000000..cdaf3fed81 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java @@ -0,0 +1,125 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.grid; + +import java.util.stream.IntStream; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.TextField; +import com.vaadin.ui.components.grid.FooterCell; +import com.vaadin.ui.components.grid.FooterRow; +import com.vaadin.ui.components.grid.HeaderCell; +import com.vaadin.ui.components.grid.HeaderRow; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridHeaderFooterComponents extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid<>(); + grid.setWidth("800px"); + grid.addColumn(Person::getFirstName).setId("action"); + grid.addColumn(Person::getLastName).setId("string"); + grid.addColumn(Person::getAge, new NumberRenderer()).setId("int"); + grid.addColumn(Person::getSalaryDouble, new NumberRenderer()) + .setId("double"); + + grid.setItems(IntStream.range(0, 5).mapToObj(this::createPerson)); + + final HeaderRow defaultRow = grid.getDefaultHeaderRow(); + final HeaderRow toggleVisibilityRow = grid.appendHeaderRow(); + final HeaderRow filterRow = grid.appendHeaderRow(); + + final FooterRow footerRow = grid.appendFooterRow(); + final FooterRow toggleVisibilityFooterRow = grid.addFooterRowAt(0); + final FooterRow filterFooterRow = grid.addFooterRowAt(0); + + // Set up a filter for all columns + + for (Column column : grid.getColumns()) { + final HeaderCell headerCell = filterRow.getCell(column); + final FooterCell footerCell = filterFooterRow.getCell(column); + + headerCell.setComponent(createTextField(column.getId())); + footerCell.setComponent(createTextField(column.getId())); + + toggleVisibilityRow.getCell(column.getId()) + .setComponent(new Button("Toggle field", event -> { + Component c = headerCell.getComponent(); + c.setVisible(!c.isVisible()); + })); + toggleVisibilityFooterRow.getCell(column.getId()) + .setComponent(new Button("Toggle field", 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", event -> grid.removeHeaderRow(row))); + + } + + private void addRemoveFooterRow(final Grid grid, + final FooterRow row) { + row.getCell("action").setComponent( + new Button("Remove row", event -> grid.removeFooterRow(row))); + } + + private Person createPerson(int i) { + Person person = new Person(); + person.setFirstName(""); + person.setLastName("Hello world"); + person.setAge(13); + person.setSalaryDouble(5.2d); + return person; + } + + private TextField createTextField(final Object pid) { + TextField filterField = new TextField(); + filterField.setWidth("8em"); + 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 new file mode 100644 index 0000000000..d5b9919f4f --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridHeaderFormatChange.java @@ -0,0 +1,128 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF 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.SelectionModel; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.data.bean.Address; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.components.grid.HeaderRow; + +public class GridHeaderFormatChange extends AbstractReindeerTestUI { + + private static final long serialVersionUID = -2787771187365766027L; + + private HeaderRow row; + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(); + grid.setWidth("600px"); + + grid.addColumn(Person::getFirstName).setId("firstName"); + grid.addColumn(Person::getLastName).setId("lastName"); + grid.addColumn(person -> person.getAddress().getStreetAddress()) + .setId("streetAddress"); + grid.addColumn(person -> person.getAddress().getPostalCode()) + .setId("zip"); + grid.addColumn(person -> person.getAddress().getCity()).setId("city"); + grid.setSelectionMode(SelectionMode.SINGLE); + addComponent(grid); + + grid.setItems(createPerson()); + + Button showHide = new Button("Hide firstName", event -> { + Column column = grid.getColumn("firstName"); + if (grid.getColumn("firstName") != null) { + grid.removeColumn(column); + event.getButton().setCaption("Show firstName"); + } else { + grid.addColumn(Person::getFirstName).setId("firstName"); + grid.setColumnOrder(grid.getColumn("firstName"), + grid.getColumn("lastName"), + grid.getColumn("streetAddress"), grid.getColumn("zip"), + grid.getColumn("city")); + + event.getButton().setCaption("Hide firstName"); + } + }); + showHide.setId("show_hide"); + + Button selectionMode = new Button("Set multiselect", 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", event -> { + if (row == null) { + row = grid.prependHeaderRow(); + if (grid.getColumn("firstName") != null) { + row.join( + grid.getDefaultHeaderRow() + .getCell(grid.getColumn("firstName")), + grid.getDefaultHeaderRow() + .getCell(grid.getColumn("lastName"))) + .setText("Full Name"); + } + row.join( + grid.getDefaultHeaderRow() + .getCell(grid.getColumn("streetAddress")), + grid.getDefaultHeaderRow() + .getCell(grid.getColumn("zip")), + grid.getDefaultHeaderRow() + .getCell(grid.getColumn("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; + } + + private Person createPerson() { + Person person = new Person(); + person.setFirstName("Rudolph"); + person.setLastName("Reindeer"); + person.setAddress(new Address()); + + person.getAddress().setStreetAddress("Ruukinkatu 2-4"); + person.getAddress().setPostalCode(20540); + person.getAddress().setCity("Turku"); + return person; + } +} 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 new file mode 100644 index 0000000000..70f26ba0d9 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/GridClickExtensionConnector.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.tests.widgetset.client.grid; + +import com.vaadin.client.MouseEventDetailsBuilder; +import com.vaadin.client.ServerConnector; +import com.vaadin.client.connectors.grid.GridConnector; +import com.vaadin.client.extensions.AbstractExtensionConnector; +import com.vaadin.client.widget.grid.CellReference; +import com.vaadin.client.widget.grid.events.GridClickEvent; +import com.vaadin.client.widgets.Grid; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.data.DataCommunicatorConstants; +import com.vaadin.shared.ui.Connect; +import com.vaadin.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(this::handleClick); + } + + @Override + public GridConnector getParent() { + return (GridConnector) super.getParent(); + } + + private void handleClick(GridClickEvent event) { + CellReference cellRef = event.getTargetCell(); + + // Gather needed information. + JsonObject row = (JsonObject) cellRef.getRow(); + String rowKey = row.getString(DataCommunicatorConstants.KEY); + String columnId = getParent().getColumnId(cellRef.getColumn()); + MouseEventDetails clickDetails = MouseEventDetailsBuilder + .buildMouseEventDetails(event.getNativeEvent()); + + getRpcProxy(GridClickServerRpc.class).click(rowKey, columnId, + clickDetails); + } +} 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 deleted file mode 100644 index bc2fe71074..0000000000 --- a/uitest/src/main/java/com/vaadin/tests/widgetset/client/v7/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.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/v7/tests/components/grid/GridEditorUI.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorUI.java deleted file mode 100644 index 614e5c3144..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -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 AbstractReindeerTestUI { - - @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 deleted file mode 100644 index 8ee87b1dc1..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/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.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 index 54ddbddf59..c7fc46bfd0 100644 --- 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 @@ -22,6 +22,11 @@ import com.vaadin.v7.ui.Grid.SelectionMode; @Push @SuppressWarnings("serial") +/** + * + * Uses scrollToEnd() method in Grid. Should be migrated once it's available. + * + */ public class GridFastAsyncUpdate extends AbstractTestUI { private final Runnable addRowsTask = new Runnable() { 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 deleted file mode 100644 index bf340fad4b..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/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.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.data.sort.SortDirection; -import com.vaadin.tests.components.AbstractReindeerTestUI; -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.sort.Sort; -import com.vaadin.v7.data.sort.SortOrder; -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 AbstractReindeerTestUI { - - 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 deleted file mode 100644 index 2bc596c3aa..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridHeaderFooterComponents.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2000-2016 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.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; - -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.setWidth("8em"); - 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 deleted file mode 100644 index 8e6d326e24..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/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.v7.tests.components.grid; - -import java.io.Serializable; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.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 AbstractReindeerTestUI { - - 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/test/java/com/vaadin/tests/components/grid/GridEditorUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorUITest.java new file mode 100644 index 0000000000..0b213ec972 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/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.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; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.PasswordFieldElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@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 new file mode 100644 index 0000000000..f86d6b8ec5 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/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.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridExtensionCommunicationTest extends SingleBrowserTest { + + @Test + public void testMouseClickIsSentToExtension() { + openTestURL(); + + GridCellElement cell = $(GridElement.class).first().getCell(0, 1); + cell.click(5, 5); + + int expectedX = cell.getLocation().getX() + 5; + int expectedY = cell.getLocation().getY() + 5; + + assertEquals( + "1. Click on Person first name 1 last name 1 on column second", + 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 new file mode 100644 index 0000000000..df89f217f3 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/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.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; +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; + +@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 new file mode 100644 index 0000000000..f6f1ff05d5 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/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.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; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +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 new file mode 100644 index 0000000000..ef69679d98 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/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.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.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@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/GridEditorUITest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorUITest.java deleted file mode 100644 index dfaf5222a6..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/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.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; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.elements.NotificationElement; -import com.vaadin.testbench.elements.PasswordFieldElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@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 deleted file mode 100644 index deec323b22..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/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.v7.tests.components.grid; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.SingleBrowserTest; - -@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 deleted file mode 100644 index 6238a04467..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/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.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; -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; - -@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 deleted file mode 100644 index b8afd17c49..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/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.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.GridElement; -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; - -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 deleted file mode 100644 index 5018a2433e..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/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.v7.tests.components.grid; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.By; - -import com.vaadin.testbench.elements.GridElement; -import com.vaadin.testbench.elements.ButtonElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@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(); - } -} -- cgit v1.2.3