diff options
Diffstat (limited to 'uitest/src/com')
-rw-r--r-- | uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderTest.java | 31 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java | 64 |
2 files changed, 73 insertions, 22 deletions
diff --git a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderTest.java b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderTest.java index 3821428ab2..9396dc05f0 100644 --- a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderTest.java +++ b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderTest.java @@ -29,9 +29,12 @@ import java.util.Random; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; import com.vaadin.shared.data.DataProviderConstants; +import com.vaadin.testbench.elements.AbstractComponentElement; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elementsbase.ServerClass; import com.vaadin.tests.fieldgroup.ComplexPerson; import com.vaadin.tests.tb3.SingleBrowserTest; @@ -40,6 +43,14 @@ import elemental.json.JsonObject; public class DummyDataProviderTest extends SingleBrowserTest { + @ServerClass("com.vaadin.ui.proto.ListBox") + public static class ListBoxElement extends AbstractComponentElement { + + public void selectByText(String text) { + new Select(this).selectByVisibleText(text); + } + } + // Each test uses a set of person objects (generated json) that is supposed // to match the data sent to the client-side. private List<JsonObject> personObjects = new ArrayList<JsonObject>(); @@ -113,10 +124,12 @@ public class DummyDataProviderTest extends SingleBrowserTest { openTestURL(); - $(ButtonElement.class).id("sort").click(); + $(ListBoxElement.class).first().selectByText("sort"); + ButtonElement button = $(ButtonElement.class).first(); + button.click(); // Second sort would show if any keys got destroyed/recreated. - $(ButtonElement.class).id("sort").click(); + button.click(); int size = DummyDataProviderUI.PERSON_COUNT + 1; List<WebElement> labels = findElements(By.className("v-label")); @@ -143,13 +156,16 @@ public class DummyDataProviderTest extends SingleBrowserTest { openTestURL(); - $(ButtonElement.class).id("sort").click(); + $(ListBoxElement.class).first().selectByText("sort"); + ButtonElement button = $(ButtonElement.class).first(); + button.click(); String text = findElements(By.className("v-label")).get(3).getText(); String json = personObjects.get(2).toJson(); assertEquals("Data not sorted", json, text); - $(ButtonElement.class).id("remove").click(); + $(ListBoxElement.class).first().selectByText("remove"); + button.click(); text = findElements(By.className("v-label")).get(3).getText(); json = personObjects.get(3).toJson(); @@ -169,7 +185,9 @@ public class DummyDataProviderTest extends SingleBrowserTest { String text = findElements(By.className("v-label")).get(1).getText(); assertEquals("Initial data did not match", json, text); - $(ButtonElement.class).id("edit").click(); + $(ListBoxElement.class).first().selectByText("edit"); + ButtonElement button = $(ButtonElement.class).first(); + button.click(); persons.get(0).setFirstName("Foo"); createPersonObjects(); @@ -182,7 +200,8 @@ public class DummyDataProviderTest extends SingleBrowserTest { text = findElements(By.className("v-label")).get(1).getText(); assertEquals("Modified data did not match", json, text); - $(ButtonElement.class).id("edit").click(); + $(ListBoxElement.class).first().selectByText("edit"); + button.click(); text = findElements(By.className("v-label")).get(1).getText(); assertEquals("Running edit again shouldn't change anything", json, text); diff --git a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java index 0cd45f1994..984035a5d1 100644 --- a/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java +++ b/uitest/src/com/vaadin/tests/dataprovider/DummyDataProviderUI.java @@ -15,10 +15,12 @@ */ package com.vaadin.tests.dataprovider; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Random; @@ -37,12 +39,27 @@ import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.proto.ListBox; +import com.vaadin.ui.proto.ListBox.NameProvider; import elemental.json.JsonObject; @Widgetset(TestingWidgetSet.NAME) public class DummyDataProviderUI extends AbstractTestUI { + abstract static class MyRunnable implements Runnable, Serializable { + + private final String name; + + public MyRunnable(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + public static class DummyDataComponent extends AbstractComponent { private SimpleDataProvider<ComplexPerson> dataProvider; @@ -99,50 +116,65 @@ public class DummyDataProviderUI extends AbstractTestUI { private Random r = new Random(RANDOM_SEED); private MyDataSource dataSource; private DummyDataComponent dummy; + private ListBox<MyRunnable> listBox; + private List<ComplexPerson> persons; @Override protected void setup(VaadinRequest request) { - dataSource = new MyDataSource(createPersons(PERSON_COUNT, r)); + + persons = createPersons(PERSON_COUNT, r); + dataSource = new MyDataSource(persons); dummy = new DummyDataComponent(dataSource); - Button remove = new Button("Remove third", new ClickListener() { + Collection<MyRunnable> actions = new LinkedHashSet<MyRunnable>(); + actions.add(new MyRunnable("remove") { @Override - public void buttonClick(ClickEvent event) { + public void run() { dataSource.remove(dataSource.getData().get(2)); } }); - Button add = new Button("Add new", new ClickListener() { + actions.add(new MyRunnable("add") { @Override - public void buttonClick(ClickEvent event) { + public void run() { dataSource.save(ComplexPerson.create(r)); } }); - Button sort = new Button("Sort content", new ClickListener() { + actions.add(new MyRunnable("sort") { @Override - public void buttonClick(ClickEvent event) { + public void run() { dataSource.sort(nameComparator); } }); - Button edit = new Button("Edit first", new ClickListener() { + actions.add(new MyRunnable("edit") { @Override - public void buttonClick(ClickEvent event) { - ComplexPerson p = dataSource.iterator().next(); + public void run() { + ComplexPerson p = persons.get(0); p.setFirstName("Foo"); dataSource.save(p); } }); - // Button Ids - remove.setId("remove"); - add.setId("add"); - sort.setId("sort"); - edit.setId("edit"); + listBox = new ListBox<MyRunnable>(actions, + new NameProvider<MyRunnable>() { + + @Override + public String getName(MyRunnable value) { + return value.getName(); + } + }); + + Button execute = new Button("Execute", new ClickListener() { - addComponent(new HorizontalLayout(add, remove, sort, edit)); + @Override + public void buttonClick(ClickEvent event) { + listBox.getSelected().run(); + } + }); + addComponent(new HorizontalLayout(listBox, execute)); addComponent(dummy); } |