diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2019-04-10 16:17:18 +0300 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2019-04-10 16:17:18 +0300 |
commit | 258450a82b61b1582905978433b8ed23575924b8 (patch) | |
tree | a410f391ff9889e475a88b94bad4c7e24c73d49f /uitest | |
parent | 7392bf241f115a9a338e047187be1b1d1ddfaed6 (diff) | |
download | vaadin-framework-258450a82b61b1582905978433b8ed23575924b8.tar.gz vaadin-framework-258450a82b61b1582905978433b8ed23575924b8.zip |
Clicking on slider makes handler move (#11519)
* Clicking on slider makes handler move
Fixes #1496
* Introducing control over clicking behaviour
- User will have to enable process of the click event on handle calling `slider.setEnableClickHandler(true);`
- Clean-up the handler logic in VSlider.java
- Renaming the property to `updateValueOnClick`
- Added JavaDocs
- Fixing tests
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/slider/SliderHandleBaseClick.java | 38 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/slider/SliderHandleBaseClickTest.java | 59 |
2 files changed, 97 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/slider/SliderHandleBaseClick.java b/uitest/src/main/java/com/vaadin/tests/components/slider/SliderHandleBaseClick.java new file mode 100644 index 0000000000..837f22056a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/slider/SliderHandleBaseClick.java @@ -0,0 +1,38 @@ +package com.vaadin.tests.components.slider; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Slider; +import com.vaadin.ui.Button; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class SliderHandleBaseClick extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Slider slider = new Slider(); + slider.setWidth(500, Unit.PIXELS); + slider.setMin(0); + slider.setMax(10); + slider.setValue(3.0); + slider.setUpdateValueOnClick(true); + addComponent(slider); + Button toggleHandling = new Button("Apply/remove click action", e -> { + slider.setUpdateValueOnClick(!slider.isUpdateValueOnClick()); + }); + toggleHandling.setId("toggleHandling"); + addComponent(toggleHandling); + } + + @Override + protected String getTestDescription() { + return "Slider should update its value, when clicked on the base"; + } + + @Override + protected Integer getTicketNumber() { + return 1496; + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/slider/SliderHandleBaseClickTest.java b/uitest/src/test/java/com/vaadin/tests/components/slider/SliderHandleBaseClickTest.java new file mode 100644 index 0000000000..8de82a590f --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/slider/SliderHandleBaseClickTest.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.slider; + +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import static org.junit.Assert.assertEquals; + +public class SliderHandleBaseClickTest extends MultiBrowserTest { + private WebElement base; + private int offsetStep; + + @Before + public void setUp() throws Exception { + super.setup(); + openTestURL(); + base = findElement(By.className("v-slider-base")); + offsetStep = base.getSize().getWidth() / 10; + } + + @Test + public void testHandlerHasMoved() { + // dragAndDropBy function starts calculating click position from the + // middle of the component . + // So the click will always be at the position (center + offsetStep)px + + // Will move by one from the middle + new Actions(driver).dragAndDropBy(base, offsetStep, 0).perform(); + sleep(100); + assertEquals("The Slider value should be 6 after moving by one offset", + 6, getSliderValue(), 0); + // Will move by two from the middle, in this case from 5 + new Actions(driver).dragAndDropBy(base, offsetStep * 2, 0).perform(); + sleep(100); + assertEquals("The Slider value should be 7 after moving by two offsets", + 7, getSliderValue(), 0); + } + + private double getSliderValue() { + return Double.valueOf( + findElement(By.className("v-slider-feedback")).getText()); + } + + @Test + public void testHandlerNotMoved() { + // Disable click event handling + findElement(By.id("toggleHandling")).click(); + new Actions(driver).dragAndDropBy(base, offsetStep, 0).perform(); + sleep(100); + assertEquals(String.format( + "Slider value should not have changed. Expected 3.0 , but was %f", + getSliderValue()), 3.0,getSliderValue(), 0.0); + // Enable click event handling + findElement(By.id("toggleHandling")).click(); + } +} |