diff options
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")); + } +} |