summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorAnna Koskinen <Ansku@users.noreply.github.com>2018-03-21 15:54:26 +0200
committerIlia Motornyi <elmot@vaadin.com>2018-03-21 15:54:26 +0200
commit1187cf22f06df587b2a1ec1068be88e2b70c888d (patch)
tree9712c2700de577ec195e1b159aaf51dd27ee65bc /uitest
parent940a1ef584c82e343474863408771ff091044bdc (diff)
downloadvaadin-framework-1187cf22f06df587b2a1ec1068be88e2b70c888d.tar.gz
vaadin-framework-1187cf22f06df587b2a1ec1068be88e2b70c888d.zip
Grid editor open (#10674)
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridEditRow.java97
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridEditRowTest.java116
2 files changed, 213 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditRow.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditRow.java
new file mode 100644
index 0000000000..bd24f53380
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditRow.java
@@ -0,0 +1,97 @@
+package com.vaadin.tests.components.grid;
+
+import java.util.ArrayList;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.provider.ListDataProvider;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.TextField;
+
+@Widgetset("com.vaadin.DefaultWidgetSet")
+public class GridEditRow extends AbstractTestUI {
+
+ private ArrayList<TestBean> items = new ArrayList<>();
+ private TestBean bean = null;
+ private int counter = 0;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ Grid<TestBean> grid = new Grid<TestBean>(TestBean.class);
+ grid.setDataProvider(new ListDataProvider<>(items));
+ grid.setWidth("100%");
+ grid.setHeight("400px");
+ grid.getEditor().setEnabled(true);
+ grid.getColumn("name").setEditorComponent(new TextField());
+ grid.getColumn("value").setEditorComponent(new TextField());
+
+ getLayout().addComponent(new Button("Add", event -> {
+ bean = new TestBean();
+ items.add(bean);
+ grid.getDataProvider().refreshAll();
+ }));
+ getLayout().addComponent(new Button("Add, Select & Edit", event -> {
+ bean = new TestBean();
+ items.add(bean);
+ grid.getDataProvider().refreshAll();
+ grid.select(bean);
+ int row = ((ArrayList<TestBean>) ((ListDataProvider<TestBean>) grid
+ .getDataProvider()).getItems()).indexOf(bean);
+ grid.getEditor().editRow(row);
+ }));
+ getLayout().addComponent(new Button("Edit", event -> {
+ int row = ((ArrayList<TestBean>) ((ListDataProvider<TestBean>) grid
+ .getDataProvider()).getItems()).indexOf(bean);
+ grid.getEditor().editRow(row);
+ }));
+ getLayout().addComponent(new Button("Select & Edit", event -> {
+ grid.select(bean);
+ int row = ((ArrayList<TestBean>) ((ListDataProvider<TestBean>) grid
+ .getDataProvider()).getItems()).indexOf(bean);
+ grid.getEditor().editRow(row);
+ }));
+
+ getLayout().addComponent(grid);
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 10558;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Calling editRow shouldn't cause any other rows to be emptied.";
+ }
+
+ public class TestBean {
+ private String name = "name" + counter;
+ private String value = "value" + counter;
+
+ public TestBean() {
+ ++counter;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String inName) {
+ name = inName;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String inValue) {
+ value = inValue;
+ }
+
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditRowTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditRowTest.java
new file mode 100644
index 0000000000..d84a09782b
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditRowTest.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.tests.components.grid;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+
+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.GridEditorElement;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Tests for ensuring that the furthest away visible rows don't get emptied when
+ * editRow is called, and that the editor doesn't open beyond the lower border
+ * of the Grid.
+ *
+ */
+@TestCategory("grid")
+public class GridEditRowTest extends MultiBrowserTest {
+
+ private GridElement grid;
+ private ButtonElement addButton;
+ private ButtonElement editButton;
+
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+ openTestURL();
+ grid = $(GridElement.class).first();
+ addButton = $(ButtonElement.class).caption("Add").first();
+ editButton = $(ButtonElement.class).caption("Edit").first();
+ }
+
+ public void addRows(int count) {
+ for (int i = 0; i < count; ++i) {
+ addButton.click();
+ }
+ }
+
+ public void editLastRow() {
+ editButton.click();
+ }
+
+ private void assertRowContents(int rowIndex) {
+ assertThat(grid.getCell(rowIndex, 0).getText(), is("name" + rowIndex));
+ }
+
+ private void assertEditorWithinGrid() {
+ GridEditorElement editor = grid.getEditor();
+ assertThat(editor.getLocation().y + editor.getSize().height,
+ not(greaterThan(grid.getLocation().y + grid.getSize().height)));
+ }
+
+ @Test
+ public void testEditWhenAllRowsVisible() {
+ addRows(7);
+
+ assertRowContents(0);
+
+ editLastRow();
+
+ assertRowContents(0);
+
+ waitForElementVisible(By.className("v-grid-editor"));
+
+ assertEditorWithinGrid();
+ }
+
+ @Test
+ public void testEditWhenSomeRowsNotVisible() {
+ addRows(11);
+
+ assertRowContents(3);
+
+ editLastRow();
+
+ waitForElementVisible(By.className("v-grid-editor"));
+
+ assertRowContents(3);
+ assertEditorWithinGrid();
+ }
+
+ @Test
+ public void testEditWhenSomeRowsOutsideOfCache() {
+ addRows(100);
+
+ assertRowContents(91);
+
+ editLastRow();
+
+ waitForElementVisible(By.className("v-grid-editor"));
+
+ assertRowContents(91);
+ assertEditorWithinGrid();
+ }
+}