From 329a24756347cdaf49441fcd9c8e96255fdb732e Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Thu, 8 Jan 2015 15:39:23 +0200 Subject: Fix Grid editor hanging on exception in commit (#15536) This patch adds a minimal editor subpart support. Change-Id: I36a81cb432f71821715cb60338a07a289bdae18d --- .../com/vaadin/testbench/elements/GridElement.java | 51 +++++++++++++++++++++- .../grid/basicfeatures/server/GridEditorTest.java | 21 +++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) (limited to 'uitest') diff --git a/uitest/src/com/vaadin/testbench/elements/GridElement.java b/uitest/src/com/vaadin/testbench/elements/GridElement.java index 254acbfa2a..0c94c1dd88 100644 --- a/uitest/src/com/vaadin/testbench/elements/GridElement.java +++ b/uitest/src/com/vaadin/testbench/elements/GridElement.java @@ -62,6 +62,51 @@ public class GridElement extends AbstractComponentElement { } } + public static class GridEditorElement extends AbstractElement { + + private GridElement grid; + + private GridEditorElement setGrid(GridElement grid) { + this.grid = grid; + return this; + } + + /** + * Gets the editor field for column in given index. + * + * @param colIndex + * column index + * @return the editor field for given location + */ + public TestBenchElement getField(int colIndex) { + return grid.getSubPart("#editor[" + colIndex + "]"); + } + + /** + * Saves the fields of this editor. + *

+ * Note: that this closes the editor making this element + * useless. + */ + public void save() { + getField(0); + List buttons = findElements(By.xpath("./button")); + buttons.get(0).click(); + } + + /** + * Cancels this editor. + *

+ * Note: that this closes the editor making this element + * useless. + */ + public void cancel() { + getField(0); + List buttons = findElements(By.xpath("./button")); + buttons.get(1).click(); + } + } + /** * Scrolls Grid element so that wanted row is displayed * @@ -262,6 +307,11 @@ public class GridElement extends AbstractComponentElement { return rootElements.get(2); } + public GridEditorElement getEditor() { + return getSubPart("#editor").wrap(GridEditorElement.class) + .setGrid(this); + } + /** * Helper function to get Grid subparts wrapped correctly * @@ -272,5 +322,4 @@ public class GridElement extends AbstractComponentElement { private TestBenchElement getSubPart(String subPartSelector) { return (TestBenchElement) findElement(By.vaadin(subPartSelector)); } - } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java index faa7744ff8..35b2fc24fe 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java @@ -16,6 +16,7 @@ package com.vaadin.tests.components.grid.basicfeatures.server; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -30,6 +31,8 @@ import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; +import com.vaadin.testbench.elements.GridElement.GridEditorElement; +import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; @@ -37,6 +40,7 @@ public class GridEditorTest extends GridBasicFeaturesTest { @Before public void setUp() { + setDebug(true); openTestURL(); selectMenuPath("Component", "Editor", "Enabled"); } @@ -165,4 +169,21 @@ public class GridEditorTest extends GridBasicFeaturesTest { return getEditor().findElements(By.className("v-textfield")); } + + @Test + public void testInvalidEdition() { + selectMenuPath("Component", "Editor", "Edit item 5"); + assertFalse(logContainsText("Exception occured, java.lang.IllegalStateException")); + GridEditorElement editor = getGridElement().getEditor(); + WebElement intField = editor.getField(7); + intField.clear(); + intField.sendKeys("banana phone"); + editor.save(); + assertTrue( + "No exception on invalid value.", + logContainsText("Exception occured, com.vaadin.data.fieldgroup.FieldGroup$CommitExceptionCommit failed")); + selectMenuPath("Component", "Editor", "Edit item 100"); + assertFalse("Exception should not exist", + isElementPresent(NotificationElement.class)); + } } -- cgit v1.2.3