summaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-11-17 17:05:28 +0200
committerVaadin Code Review <review@vaadin.com>2016-11-25 13:13:00 +0000
commitd37b2d430eca6b0eeacb48626c0bbfb33d1502de (patch)
treea73527e2b0eef2e902572908c1c6a22d44a2ab27 /uitest/src
parentd63c1f9014e0a49e5250edd41bd5c7542901c267 (diff)
downloadvaadin-framework-d37b2d430eca6b0eeacb48626c0bbfb33d1502de.tar.gz
vaadin-framework-d37b2d430eca6b0eeacb48626c0bbfb33d1502de.zip
Reintroduce Grid Editor using Binder
This patch restores the bean type to BinderValidationStatusHandler Change-Id: I9ace77a492c4823c15591fb1426e9bd216895fb0
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java109
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java10
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java290
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java238
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorUnbufferedTest.java246
5 files changed, 866 insertions, 27 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
index f5f02bbf60..8917ce0241 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java
@@ -1,6 +1,21 @@
package com.vaadin.tests.components.grid.basics;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Widgetset;
+import com.vaadin.data.Binder;
+import com.vaadin.data.util.converter.StringToIntegerConverter;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.Registration;
import com.vaadin.shared.ui.grid.HeightMode;
@@ -19,6 +34,7 @@ import com.vaadin.ui.MenuBar.MenuItem;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.StyleGenerator;
+import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.components.grid.SingleSelectionModel;
import com.vaadin.ui.renderers.DateRenderer;
@@ -26,19 +42,8 @@ import com.vaadin.ui.renderers.HtmlRenderer;
import com.vaadin.ui.renderers.NumberRenderer;
import com.vaadin.ui.renderers.ProgressBarRenderer;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Consumer;
-import java.util.stream.Stream;
-
@Widgetset("com.vaadin.DefaultWidgetSet")
+@Theme("tests-valo-disabled-animations")
public class GridBasics extends AbstractTestUIWithLog {
public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4";
@@ -52,9 +57,9 @@ public class GridBasics extends AbstractTestUIWithLog {
public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string";
public static final String CELL_STYLE_GENERATOR_NULL = "Null";
- public static final String[] COLUMN_CAPTIONS = {"Column 0", "Column 1",
+ public static final String[] COLUMN_CAPTIONS = { "Column 0", "Column 1",
"Column 2", "Row Number", "Date", "HTML String", "Big Random",
- "Small Random"};
+ "Small Random" };
private final Command toggleReorderListenerCommand = new Command() {
private Registration registration = null;
@@ -144,7 +149,6 @@ public class GridBasics extends AbstractTestUIWithLog {
private List<DataObject> data;
private int watchingCount = 0;
private PersistingDetailsGenerator persistingDetails;
- private List<Column<DataObject, ?>> initialColumnOrder;
public GridBasics() {
generators.put("NULL", null);
@@ -169,24 +173,47 @@ public class GridBasics extends AbstractTestUIWithLog {
// Create grid
grid = new Grid<>();
grid.setItems(data);
-
- grid.addColumn(dataObj -> "(" + dataObj.getRowNumber() + ", 0)")
- .setCaption(COLUMN_CAPTIONS[0]);
+ grid.setSizeFull();
+
+ Binder<DataObject> binder = grid.getEditor().getBinder();
+
+ TextField html = new TextField();
+ TextField smallRandom = new TextField();
+ TextField coordinates = new TextField();
+ TextField rowNumber = new TextField();
+
+ binder.bind(html, DataObject::getHtmlString, DataObject::setHtmlString);
+ binder.forField(smallRandom)
+ .withConverter(new StringToIntegerConverter(
+ "Could not convert value to Integer"))
+ .withValidator(i -> i >= 0 && i < 5,
+ "Small random needs to be in range [0..5)")
+ .bind(DataObject::getSmallRandom, DataObject::setSmallRandom);
+ binder.bind(coordinates, DataObject::getCoordinates,
+ DataObject::setCoordinates);
+ binder.forField(rowNumber)
+ .withConverter(new StringToIntegerConverter(
+ "Could not convert value to Integer"))
+ .bind(DataObject::getRowNumber, DataObject::setRowNumber);
+
+ grid.addColumn(DataObject::getCoordinates)
+ .setCaption(COLUMN_CAPTIONS[0]).setEditorComponent(coordinates);
grid.addColumn(dataObj -> "(" + dataObj.getRowNumber() + ", 1)")
.setCaption(COLUMN_CAPTIONS[1]);
grid.addColumn(dataObj -> "(" + dataObj.getRowNumber() + ", 2)")
.setCaption(COLUMN_CAPTIONS[2]);
grid.addColumn(DataObject::getRowNumber, new NumberRenderer())
- .setCaption(COLUMN_CAPTIONS[3]);
+ .setCaption(COLUMN_CAPTIONS[3]).setEditorComponent(rowNumber);
grid.addColumn(DataObject::getDate, new DateRenderer())
.setCaption(COLUMN_CAPTIONS[4]);
grid.addColumn(DataObject::getHtmlString, new HtmlRenderer())
- .setCaption(COLUMN_CAPTIONS[5]);
+ .setCaption(COLUMN_CAPTIONS[5]).setEditorComponent(html);
grid.addColumn(DataObject::getBigRandom, new NumberRenderer())
.setCaption(COLUMN_CAPTIONS[6]);
grid.addColumn(data -> data.getSmallRandom() / 5d,
- new ProgressBarRenderer()).setCaption(COLUMN_CAPTIONS[7]);
+ new ProgressBarRenderer()).setCaption(COLUMN_CAPTIONS[7])
+ .setEditorComponent(smallRandom);
((SingleSelectionModel<DataObject>) grid.getSelectionModel())
.addSelectionChangeListener(
@@ -199,6 +226,9 @@ public class GridBasics extends AbstractTestUIWithLog {
private Component createMenu() {
MenuBar menu = new MenuBar();
+ menu.setErrorHandler(error -> log("Exception occured, "
+ + error.getThrowable().getClass().getName() + ": "
+ + error.getThrowable().getMessage()));
MenuItem componentMenu = menu.addItem("Component", null);
createStateMenu(componentMenu.addItem("State", null));
createSizeMenu(componentMenu.addItem("Size", null));
@@ -207,6 +237,7 @@ public class GridBasics extends AbstractTestUIWithLog {
createHeaderMenu(componentMenu.addItem("Header", null));
createFooterMenu(componentMenu.addItem("Footer", null));
createColumnsMenu(componentMenu.addItem("Columns", null));
+ createEditorMenu(componentMenu.addItem("Editor", null));
return menu;
}
@@ -274,9 +305,8 @@ public class GridBasics extends AbstractTestUIWithLog {
selectedItem -> col
.setHidden(selectedItem.isChecked()))
.setCheckable(true);
- columnMenu
- .addItem("Remove",
- selectedItem -> grid.removeColumn(col));
+ columnMenu.addItem("Remove",
+ selectedItem -> grid.removeColumn(col));
}
}
@@ -353,6 +383,11 @@ public class GridBasics extends AbstractTestUIWithLog {
.addItem("Column Reordering", selectedItem -> grid
.setColumnReorderingAllowed(selectedItem.isChecked()))
.setCheckable(true);
+
+ MenuItem enableItem = stateMenu.addItem("Enabled",
+ e -> grid.setEnabled(e.isChecked()));
+ enableItem.setCheckable(true);
+ enableItem.setChecked(true);
}
private void createRowStyleMenu(MenuItem rowStyleMenu) {
@@ -401,7 +436,7 @@ public class GridBasics extends AbstractTestUIWithLog {
}
private <T> void addGridMethodMenu(MenuItem parent, String name, T value,
- Consumer<T> method) {
+ Consumer<T> method) {
parent.addItem(name, menuItem -> method.accept(value));
}
@@ -453,7 +488,8 @@ public class GridBasics extends AbstractTestUIWithLog {
});
}
- private void mergeHeaderСells(int rowIndex, String jointCellText, int... columnIndexes) {
+ private void mergeHeaderСells(int rowIndex, String jointCellText,
+ int... columnIndexes) {
HeaderRow headerRow = grid.getHeaderRow(rowIndex);
List<Column<DataObject, ?>> columns = grid.getColumns();
Set<Grid.HeaderCell> toMerge = new HashSet<>();
@@ -522,8 +558,27 @@ public class GridBasics extends AbstractTestUIWithLog {
});
}
+ private void createEditorMenu(MenuItem editorMenu) {
+ editorMenu
+ .addItem("Enabled",
+ i -> grid.getEditor().setEnabled(i.isChecked()))
+ .setCheckable(true);
+ MenuItem bufferedMode = editorMenu.addItem("Buffered mode",
+ i -> grid.getEditor().setBuffered(i.isChecked()));
+ bufferedMode.setCheckable(true);
+ bufferedMode.setChecked(true);
+
+ editorMenu.addItem("Save", i -> grid.getEditor().save());
+ editorMenu.addItem("Cancel edit", i -> grid.getEditor().cancel());
+
+ editorMenu.addItem("Change save caption",
+ e -> grid.getEditor().setSaveCaption("ǝʌɐS"));
+ editorMenu.addItem("Change cancel caption",
+ e -> grid.getEditor().setCancelCaption("ʃǝɔuɐↃ"));
+
+ }
+
private void openOrCloseDetails(DataObject dataObj) {
grid.setDetailsVisible(dataObj, !grid.isDetailsVisible(dataObj));
}
-
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java
index c128ba2634..55098eb768 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridBasicsTest.java
@@ -16,6 +16,7 @@ import org.openqa.selenium.remote.DesiredCapabilities;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.customelements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.elements.GridElement.GridEditorElement;
import com.vaadin.testbench.parallel.Browser;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest.CellSide;
@@ -204,4 +205,13 @@ public abstract class GridBasicsTest extends MultiBrowserTest {
return null;
}
+ protected GridEditorElement getEditor() {
+ return getGridElement().getEditor();
+ }
+
+ protected int getGridVerticalScrollPos() {
+ return ((Number) executeScript("return arguments[0].scrollTop",
+ getGridVerticalScrollbar())).intValue();
+ }
+
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java
new file mode 100644
index 0000000000..17411c5a77
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorBufferedTest.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF 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.basics;
+
+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.shared.ui.grid.GridConstants;
+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;
+
+public class GridEditorBufferedTest extends GridEditorTest {
+
+ @Override
+ @Before
+ public void setUp() {
+ super.setUp();
+ }
+
+ @Test
+ public void testKeyboardSave() {
+ editRow(100);
+
+ WebElement textField = getEditor().getField(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(
+ GridBasics.COLUMN_CAPTIONS[7]
+ + ": Could not convert value to Integer",
+ editor.getErrorMessage());
+ assertTrue("Field 7 should have been marked with an error after error",
+ isEditorCellErrorMarked(7));
+
+ editor.cancel();
+
+ editRow(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() {
+ editRow(100);
+
+ WebElement textField = getEditor().getField(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() {
+ editRow(100);
+
+ WebElement textField = getEditor().getField(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(
+ GridBasics.COLUMN_CAPTIONS[7]
+ + ": Could not convert value to Integer",
+ editor.getErrorMessage());
+ assertTrue("Field 7 should have been marked with an error after error",
+ isEditorCellErrorMarked(7));
+ editor.cancel();
+
+ editRow(100);
+ assertFalse("Exception should not exist",
+ isElementPresent(NotificationElement.class));
+ assertEquals("There should be no editor error message", null,
+ getGridElement().getEditor().getErrorMessage());
+ }
+
+ private void makeInvalidEdition() {
+ editRow(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");
+ editor.getField(5).click();
+ }
+
+ @Test
+ public void testEditorInDisabledGrid() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ editRow(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() {
+ editRow(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");
+ editRow(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() {
+ editRow(5);
+ getGridElement().getCell(200, 0);
+ }
+
+ @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() {
+ editRow(5);
+
+ getGridElement().getCell(2, 0).doubleClick();
+
+ assertEquals("Editor should still edit row 5", "(5, 0)",
+ getEditor().getField(0).getAttribute("value"));
+ }
+
+ @Test
+ public void testUserSortDisabledWhenOpen() {
+ editRow(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/basics/GridEditorTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java
new file mode 100644
index 0000000000..fdf1b9bba9
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorTest.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF 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.basics;
+
+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.Ignore;
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.elements.GridElement.GridEditorElement;
+
+public abstract class GridEditorTest extends GridBasicsTest {
+
+ protected static final org.openqa.selenium.By BY_EDITOR_CANCEL = By
+ .className("v-grid-editor-cancel");
+ protected static final org.openqa.selenium.By BY_EDITOR_SAVE = By
+ .className("v-grid-editor-save");
+ protected static final String[] TOGGLE_EDIT_ENABLED = new String[] {
+ "Component", "Editor", "Enabled" };
+
+ @Override
+ @Before
+ public void setUp() {
+ setDebug(true);
+ openTestURL();
+ selectMenuPath(TOGGLE_EDIT_ENABLED);
+ }
+
+ @Test
+ public void testProgrammaticClosing() {
+ editRow(5);
+ assertEditorOpen();
+
+ selectMenuPath("Component", "Editor", "Cancel edit");
+ assertEditorClosed();
+ }
+
+ @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();
+ }
+
+ protected void assertEditorOpen() {
+ assertTrue("Editor is supposed to be open",
+ getGridElement().isElementPresent(By.vaadin("#editor")));
+ }
+
+ protected void assertEditorClosed() {
+ assertFalse("Editor is supposed to be closed",
+ getGridElement().isElementPresent(By.vaadin("#editor")));
+ }
+
+ @Test
+ public void testFocusOnMouseOpen() {
+
+ GridCellElement cell = getGridElement().getCell(4, 0);
+
+ cell.doubleClick();
+
+ WebElement focused = getFocusedElement();
+
+ assertEquals("", "input", focused.getTagName());
+ assertEquals("", cell.getText(), focused.getAttribute("value"));
+ }
+
+ @Test
+ public void testFocusOnKeyboardOpen() {
+
+ GridCellElement cell = getGridElement().getCell(4, 0);
+
+ 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 testUneditableColumn() {
+ editRow(5);
+ assertEditorOpen();
+
+ GridEditorElement editor = getGridElement().getEditor();
+ assertFalse("Uneditable column should not have an editor widget",
+ editor.isEditable(2));
+
+ String classNames = editor
+ .findElements(By.className("v-grid-editor-cells")).get(1)
+ .findElements(By.xpath("./div")).get(2).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", "Append footer row");
+
+ 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");
+
+ editRow(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());
+ }
+
+ @Ignore("Needs programmatic sorting")
+ @Test
+ public void testEditorClosedOnSort() {
+ editRow(5);
+
+ selectMenuPath("Component", "State", "Sort by column", "Column 0, ASC");
+
+ assertEditorClosed();
+ }
+
+ @Ignore("Needs programmatic filtering")
+ @Test
+ public void testEditorClosedOnFilter() {
+ editRow(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);
+ }
+
+ protected void editRow(int rowIndex) {
+ getGridElement().getCell(rowIndex, 0).doubleClick();
+ assertEditorOpen();
+ }
+
+ protected boolean isEditorCellErrorMarked(int colIndex) {
+ WebElement editorCell = getGridElement().getEditor()
+ .findElement(By.xpath("./div/div[" + (colIndex + 1) + "]"));
+ return editorCell.getAttribute("class").contains("error");
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorUnbufferedTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorUnbufferedTest.java
new file mode 100644
index 0000000000..aac69d90f5
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/basics/GridEditorUnbufferedTest.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF 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.basics;
+
+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.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;
+
+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() {
+ editRow(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() {
+ editRow(5);
+ assertEditorOpen();
+ selectMenuPath(TOGGLE_EDITOR_BUFFERED);
+ boolean thrown = logContainsText(
+ "Exception occured, java.lang.IllegalStateException");
+ assertTrue("IllegalStateException was not thrown", thrown);
+ }
+
+ @Test
+ public void testEditorMoveWithMouse() {
+ editRow(5);
+
+ assertEditorOpen();
+
+ String firstFieldValue = getEditor().getField(0).getAttribute("value");
+ assertEquals("Editor should be at row 5", "(5, 0)", firstFieldValue);
+
+ getGridElement().getCell(6, 0).click();
+ firstFieldValue = getEditor().getField(0).getAttribute("value");
+
+ assertEquals("Editor should be at row 6", "(6, 0)", firstFieldValue);
+ }
+
+ @Test
+ public void testEditorMoveWithKeyboard() throws InterruptedException {
+ editRow(100);
+
+ getEditor().getField(0).click();
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+ String firstFieldValue = getEditor().getField(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 = getEditor().getField(0).getAttribute("value");
+ int row = 100 - i;
+ assertEquals("Editor should move to row " + row, "(" + row + ", 0)",
+ firstFieldValue);
+ }
+ }
+
+ @Test
+ public void testValidationErrorPreventsMove() throws InterruptedException {
+ editRow(5);
+
+ getEditor().getField(7).click();
+ String faultyInt = "not a number";
+ getEditor().getField(7).sendKeys(faultyInt);
+
+ getGridElement().getCell(6, 7).click();
+
+ assertEquals("Editor should not move from row 5", "(5, 0)",
+ getEditor().getField(0).getAttribute("value"));
+
+ getEditor().getField(7).sendKeys(Keys.chord(Keys.CONTROL, "a"));
+ getEditor().getField(7).sendKeys("4");
+
+ getGridElement().getCell(7, 0).click();
+
+ assertEquals("Editor should move to row 7", "(7, 0)",
+ getEditor().getField(0).getAttribute("value"));
+
+ }
+
+ @Test
+ public void testErrorMessageWrapperHidden() {
+ editRow(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 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() {
+ editRow(5);
+
+ selectMenuPath("Component", "State", "Enabled");
+ assertEditorOpen();
+
+ assertTrue("Editor text field should be disabled",
+ null != getEditor().getField(0).getAttribute("disabled"));
+
+ selectMenuPath("Component", "State", "Enabled");
+ assertEditorOpen();
+
+ assertFalse("Editor text field should not be disabled",
+ null != getEditor().getField(0).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();
+ }
+
+ @Ignore("Needs refresh item functionality")
+ @Test
+ public void testExternalValueChangePassesToEditor() {
+ editRow(5);
+ assertEditorOpen();
+
+ selectMenuPath("Component", "State", "ReactiveValueChanger");
+
+ getEditor().getField(0).click();
+ getEditor().getField(0).sendKeys("changing value");
+
+ // Focus another field to cause the value to be sent to the server
+ getEditor().getField(3).click();
+
+ assertEquals("Value of Column 2 in the editor was not changed",
+ "Modified", getEditor().getField(5).getAttribute("value"));
+ }
+
+ @Test
+ public void testEditorClosedOnUserSort() {
+ editRow(5);
+
+ getGridElement().getHeaderCell(0, 0).click();
+
+ assertEditorClosed();
+ }
+
+ @Test
+ public void testEditorSaveOnRowChange() {
+ // Double click sets the focus programmatically
+ getGridElement().getCell(5, 0).doubleClick();
+
+ TestBenchElement editor = getGridElement().getEditor().getField(0);
+ 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",
+ getGridElement().getEditor().getField(3).getAttribute("value"));
+
+ assertEquals("Edited value was not saved.", "Foo",
+ getGridElement().getCell(5, 0).getText());
+ }
+} \ No newline at end of file