summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMehdi Javan <32511762+mehdi-vaadin@users.noreply.github.com>2018-07-20 10:57:03 +0300
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-07-20 10:57:03 +0300
commita0893716d770b459f2e9d1dfb862f1893442f53d (patch)
tree2cb36a82bc6cce5011ff0b640a0d6ca52f0fe780
parentde42456db1d81d84388583dd1ad0d3ac85c298ba (diff)
downloadvaadin-framework-a0893716d770b459f2e9d1dfb862f1893442f53d.tar.gz
vaadin-framework-a0893716d770b459f2e9d1dfb862f1893442f53d.zip
Fix Grid Editor closing and disabling at same time (#11078)
Fixes #10688
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java12
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorEnableDisable.java68
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEnableDisableTest.java113
3 files changed, 192 insertions, 1 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
index 76a79693ca..05aa8fe392 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/EditorConnector.java
@@ -197,7 +197,17 @@ public class EditorConnector extends AbstractExtensionConnector {
@OnStateChange("enabled")
void updateEnabled() {
- getParent().getWidget().getEditor().setEnabled(getState().enabled);
+ boolean enabled = getState().enabled;
+
+ Scheduler.ScheduledCommand setEnabledCommand = () -> {
+ getParent().getWidget().getEditor().setEnabled(enabled);
+ };
+
+ if (!enabled) {
+ Scheduler.get().scheduleFinally(setEnabledCommand);
+ } else {
+ setEnabledCommand.execute();
+ }
}
@OnStateChange("saveCaption")
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorEnableDisable.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorEnableDisable.java
new file mode 100644
index 0000000000..ecaae430dc
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorEnableDisable.java
@@ -0,0 +1,68 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.data.Binder;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.TextField;
+
+public class GridEditorEnableDisable extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Grid<Person> grid = new Grid<>();
+ Person person1 = new Person();
+ person1.setFirstName("Foo");
+
+ Person person2 = new Person();
+ person2.setFirstName("Bar");
+
+ grid.setItems(person1, person2);
+ Grid.Column<Person, String> column = grid
+ .addColumn(Person::getFirstName);
+
+ Binder<Person> binder = grid.getEditor().getBinder();
+ grid.getEditor().setEnabled(true);
+
+ TextField field = new TextField();
+ Binder.Binding<Person, String> binding = binder.bind(field,
+ Person::getFirstName, Person::setFirstName);
+ column.setEditorBinding(binding);
+
+ addComponent(grid);
+
+ final Button disableButton = new Button("Disable");
+ disableButton.addClickListener((event) -> {
+ grid.getEditor().setEnabled(false);
+ });
+
+ addComponent(disableButton);
+
+ final Button cancelAndDisableButton = new Button("Cancel & Disable");
+ cancelAndDisableButton.addClickListener((event) -> {
+ if (grid.getEditor().isOpen())
+ grid.getEditor().cancel();
+ grid.getEditor().setEnabled(false);
+ });
+
+ addComponent(cancelAndDisableButton);
+
+ final Button enableButton = new Button("Enable");
+ enableButton.addClickListener((event) -> {
+ grid.getEditor().setEnabled(true);
+ });
+
+ addComponent(enableButton);
+
+ final Button enableAndEditRowButton = new Button("Enable & Edit Row");
+ enableAndEditRowButton.addClickListener((event) -> {
+ grid.getEditor().setEnabled(true);
+ grid.getEditor().editRow(0);
+ });
+
+ addComponent(enableAndEditRowButton);
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEnableDisableTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEnableDisableTest.java
new file mode 100644
index 0000000000..cf37db957c
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorEnableDisableTest.java
@@ -0,0 +1,113 @@
+package com.vaadin.tests.components.grid;
+
+import com.vaadin.testbench.annotations.RunLocally;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.GridElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.testbench.parallel.Browser;
+import com.vaadin.testbench.parallel.TestCategory;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.interactions.Actions;
+
+import static org.junit.Assert.assertTrue;
+
+@TestCategory("grid")
+public class GridEditorEnableDisableTest extends SingleBrowserTest {
+ @Override
+ public void setup() throws Exception {
+ super.setup();
+
+ openTestURL();
+ }
+
+ @Test
+ public void testEnabledEditor() {
+ GridElement grid = $(GridElement.class).first();
+ grid.getCell(0, 0).doubleClick();
+
+ assertTrue("Editor must work when it is enabled!",
+ isElementPresent(TextFieldElement.class));
+ }
+
+ @Test
+ public void testDisabledEditor() {
+ GridElement grid = $(GridElement.class).first();
+ ButtonElement disableButton = $(ButtonElement.class).caption("Disable")
+ .first();
+
+ disableButton.click();
+ grid.getCell(0, 0).doubleClick();
+
+ assertTrue("Editor must not work when it is disabled!",
+ !isElementPresent(TextFieldElement.class));
+ }
+
+ @Test
+ public void testCancelAndDisableEditorWhenEditing() {
+ GridElement grid = $(GridElement.class).first();
+ ButtonElement cancelAndDisableButton = $(ButtonElement.class)
+ .caption("Cancel & Disable").first();
+
+ grid.getCell(0, 0).doubleClick();
+ cancelAndDisableButton.click();
+
+ assertTrue("Editing must be canceled after calling cancel method!",
+ !isElementPresent(TextFieldElement.class));
+
+ grid.getCell(0, 0).doubleClick();
+ assertTrue("Editor must not work when it is disabled!",
+ !isElementPresent(TextFieldElement.class));
+ }
+
+ @Test
+ public void testDisableEditorAfterCancelEditing() {
+ GridElement grid = $(GridElement.class).first();
+ ButtonElement disableButton = $(ButtonElement.class).caption("Disable")
+ .first();
+
+ grid.getCell(0, 0).doubleClick();
+ new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
+
+ assertTrue("Editing must be canceled after pressing Escape key!",
+ !isElementPresent(TextFieldElement.class));
+
+ disableButton.click();
+ grid.getCell(0, 0).doubleClick();
+
+ assertTrue("Editor must not work when it is disabled!",
+ !isElementPresent(TextFieldElement.class));
+ }
+
+ @Test
+ public void testReenableEditorAfterCancelEditing() {
+ GridElement grid = $(GridElement.class).first();
+ ButtonElement cancelAndDisableButton = $(ButtonElement.class)
+ .caption("Cancel & Disable").first();
+ ButtonElement enableButton = $(ButtonElement.class).caption("Enable")
+ .first();
+
+ grid.getCell(0, 0).doubleClick();
+ cancelAndDisableButton.click();
+ enableButton.click();
+ grid.getCell(0, 0).doubleClick();
+
+ assertTrue("Editor must work after re-enabling!",
+ isElementPresent(TextFieldElement.class));
+ }
+
+ @Test
+ public void testEnableAndEditRow() {
+ ButtonElement disableButton = $(ButtonElement.class).caption("Disable")
+ .first();
+ ButtonElement enableAndEditRowButton = $(ButtonElement.class)
+ .caption("Enable & Edit Row").first();
+
+ disableButton.click();
+ enableAndEditRowButton.click();
+
+ assertTrue("Editor must be open after calling editRow method!",
+ isElementPresent(TextFieldElement.class));
+ }
+}