summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Stucki <jeremy@myelin.ch>2018-11-02 11:51:23 +0100
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2018-11-02 12:51:23 +0200
commit09207941a982b825dbd429b71c7e89712a3da8f2 (patch)
treee3e99d9e97d07629608ca3335e854bc7172b7486
parent4d053a9c1ce1ef0ac63769867c4f89f74a99de26 (diff)
downloadvaadin-framework-09207941a982b825dbd429b71c7e89712a3da8f2.tar.gz
vaadin-framework-09207941a982b825dbd429b71c7e89712a3da8f2.zip
Make value changes in color picker user originated (#11252)
* Make value changes in color picker user originated This is not a programmatically initiated event, so it should have the 'userOriginated' property set to 'true'. - Added test to verify that indeed event is user originated after the change
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractColorPicker.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChange.java38
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChangeTest.java32
3 files changed, 72 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
index be359cc2ff..cf4c8c8b74 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
@@ -464,8 +464,8 @@ public abstract class AbstractColorPicker extends AbstractField<Color> {
window.addCloseListener(
event -> getState().popupVisible = false);
window.addValueChangeListener(event -> {
- setValue(event.getValue());
- rpc.changeColor(event.getValue().getCSS());
+ window.setValue(color);
+ setValue(event.getValue(), true);
});
window.getHistory().setValue(color);
window.setPositionX(positionX);
diff --git a/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChange.java b/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChange.java
new file mode 100644
index 0000000000..4aeeeb1897
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChange.java
@@ -0,0 +1,38 @@
+package com.vaadin.tests.components.colorpicker;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.colorpicker.Color;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractColorPicker;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ColorPicker;
+import com.vaadin.ui.Label;
+
+public class ColorPickerUserColorChange extends AbstractTestUI {
+
+ public static final String value = "User originated: ";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ AbstractColorPicker colorpicker = new ColorPicker("ColorPicker",
+ Color.GREEN);
+ Label isUserOriginated = new Label(value);
+ isUserOriginated.setId("labelValue");
+ colorpicker.setPosition(250, 0);
+ colorpicker.setId("clp");
+ colorpicker.setRGBVisibility(true);
+ colorpicker.setHSVVisibility(true);
+ colorpicker.setTextfieldVisibility(true);
+ colorpicker.setSwatchesVisibility(true);
+ colorpicker.addValueChangeListener(event -> {
+ isUserOriginated.setValue(value + event.isUserOriginated());
+ });
+ addComponent(isUserOriginated);
+ addComponent(colorpicker);
+ Button changeColor = new Button("Change Color", e -> {
+ colorpicker.setValue(Color.YELLOW);
+ });
+ changeColor.setId("changeColor");
+ addComponent(changeColor);
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChangeTest.java b/uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChangeTest.java
new file mode 100644
index 0000000000..3fc4cb4e08
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/colorpicker/ColorPickerUserColorChangeTest.java
@@ -0,0 +1,32 @@
+package com.vaadin.tests.components.colorpicker;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import static org.junit.Assert.assertEquals;
+
+public class ColorPickerUserColorChangeTest extends MultiBrowserTest {
+
+ @Test
+ public void testUserOriginatedTrue() {
+ openTestURL();
+ // Open colorPicker
+ findElement(By.className("v-button-v-colorpicker ")).click();
+ sleep(100);
+ // click somewhere inside the gradient layer
+ findElement(By.className("v-colorpicker-gradient-clicklayer")).click();
+ // confirm selection by clicking "OK" button
+ findElements(By.className("v-button")).stream()
+ .filter(el -> el.getText().equals("OK")).findFirst().get()
+ .click();
+
+ WebElement label = findElement(By.id("labelValue"));
+ assertEquals(true, label.getText().endsWith("true"));
+
+ findElement(By.id("changeColor")).click();
+ assertEquals(false, label.getText().endsWith("true"));
+ assertEquals(true, label.getText().endsWith("false"));
+ }
+}