summaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtain.java85
-rw-r--r--uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtainTest.java26
2 files changed, 92 insertions, 19 deletions
diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtain.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtain.java
index c182894db4..c7e16440bc 100644
--- a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtain.java
+++ b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtain.java
@@ -15,11 +15,22 @@
*/
package com.vaadin.tests.components.draganddropwrapper;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.event.dd.DragAndDropEvent;
+import com.vaadin.event.dd.DropHandler;
+import com.vaadin.event.dd.acceptcriteria.AcceptAll;
+import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.AbstractField;
import com.vaadin.ui.DragAndDropWrapper;
import com.vaadin.ui.DragAndDropWrapper.DragStartMode;
+import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.TextArea;
+import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
/**
@@ -29,18 +40,80 @@ import com.vaadin.ui.VerticalLayout;
* @since
* @author Vaadin Ltd
*/
-public class DragAndDropFocusObtain extends AbstractTestUI {
+public class DragAndDropFocusObtain extends AbstractTestUIWithLog {
+
+ private FocusListener focusListener = new FocusListener() {
+
+ @Override
+ public void focus(FocusEvent event) {
+ log("Field '" + event.getComponent().getCaption() + "' focused");
+
+ }
+ };
+ private ValueChangeListener listener = new ValueChangeListener() {
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ AbstractField f = (AbstractField) event.getProperty();
+ log("Value of " + f.getCaption() + " changed to " + f.getValue());
+ }
+ };
@Override
protected void setup(VaadinRequest request) {
+ HorizontalLayout hl = new HorizontalLayout();
+ VerticalLayout dndLayout = createLayout();
+ VerticalLayout normalLayout = createLayout();
+ DragAndDropWrapper wrapper = new DragAndDropWrapper(dndLayout);
+ wrapper.setDragStartMode(DragStartMode.COMPONENT);
+ wrapper.setDropHandler(new DropHandler() {
+
+ @Override
+ public AcceptCriterion getAcceptCriterion() {
+ return AcceptAll.get();
+ }
+
+ @Override
+ public void drop(DragAndDropEvent event) {
+ log("Dropped " + event.getTransferable().getSourceComponent()
+ + " on " + event.getTargetDetails().getTarget());
+
+ }
+ });
+ hl.addComponent(wrapper);
+ hl.addComponent(normalLayout);
+ addComponent(hl);
+
+ }
+
+ private VerticalLayout createLayout() {
VerticalLayout dndLayout = new VerticalLayout();
- TextArea area = new TextArea();
+
+ TextArea area = new TextArea("Text area 1");
area.setValue("text");
+ area.addValueChangeListener(listener);
+ area.addFocusListener(focusListener);
dndLayout.addComponent(area);
- DragAndDropWrapper wrapper = new DragAndDropWrapper(dndLayout);
- wrapper.setDragStartMode(DragStartMode.COMPONENT);
- addComponent(wrapper);
+ area = new TextArea("Text area 2");
+ area.setValue("text");
+ area.addValueChangeListener(listener);
+ area.addFocusListener(focusListener);
+ dndLayout.addComponent(area);
+
+ TextField field = new TextField("Text field 1");
+ field.setValue("text");
+ field.addValueChangeListener(listener);
+ field.addFocusListener(focusListener);
+ dndLayout.addComponent(field);
+
+ field = new TextField("Text field 2");
+ field.setValue("text");
+ field.addValueChangeListener(listener);
+ field.addFocusListener(focusListener);
+ dndLayout.addComponent(field);
+
+ return dndLayout;
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtainTest.java b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtainTest.java
index ccb28b7103..7a2abe5efc 100644
--- a/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtainTest.java
+++ b/uitest/src/com/vaadin/tests/components/draganddropwrapper/DragAndDropFocusObtainTest.java
@@ -17,10 +17,8 @@ package com.vaadin.tests.components.draganddropwrapper;
import org.junit.Assert;
import org.junit.Test;
-import org.openqa.selenium.WebElement;
-import org.openqa.selenium.interactions.Actions;
-import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.AbstractTextFieldElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.DragAndDropWrapper;
@@ -36,16 +34,18 @@ public class DragAndDropFocusObtainTest extends MultiBrowserTest {
@Test
public void testTextAreaDndImage() {
openTestURL();
-
- WebElement wrapper = driver.findElement(By.className("v-ddwrapper"));
- Actions actions = new Actions(driver);
- actions.click(wrapper);
- actions.perform();
-
- WebElement focusedElement = driver.findElement(By
- .className("v-textarea-focus"));
- Assert.assertNotNull("Text area did not obtain focus after click",
- focusedElement);
+ int index = 1;
+ for (AbstractTextFieldElement ta : $(AbstractTextFieldElement.class)
+ .all()) {
+ String caption = ta.getCaption();
+ ta.click();
+ Assert.assertEquals(index + ". Field '" + caption + "' focused",
+ getLogRow(0));
+ index++;
+ }
+
+ // Make sure we checked all fields
+ Assert.assertEquals(8 + 1, index);
}