summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2016-09-15 15:00:25 +0300
committerVaadin Code Review <review@vaadin.com>2016-10-05 10:55:26 +0000
commitde717dd92acc66ca3e6f697c0ef37a61d5c1e043 (patch)
tree8e661c0c3b6f207a5f292c6df958ad63b1454e45 /uitest
parent0b8ec18b67e95b7be28277a4e8537090f536695f (diff)
downloadvaadin-framework-de717dd92acc66ca3e6f697c0ef37a61d5c1e043.tar.gz
vaadin-framework-de717dd92acc66ca3e6f697c0ef37a61d5c1e043.zip
Add ItemDataSource for tests
ItemDataSource generates "Item n" strings on the fly. Change-Id: Icc87776b3ad3eaf0a93de6ebcf5bd9f1fcd21757
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java20
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java14
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java10
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java10
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java10
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java12
-rw-r--r--uitest/src/main/java/com/vaadin/tests/util/ItemDataSource.java21
7 files changed, 39 insertions, 58 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java
index 28b791626b..3917ad2ebd 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxEnablesComboBox.java
@@ -1,9 +1,7 @@
package com.vaadin.tests.components.combobox;
-import java.util.ArrayList;
-import java.util.List;
-
import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.ItemDataSource;
import com.vaadin.ui.ComboBox;
public class ComboBoxEnablesComboBox extends TestBase {
@@ -12,25 +10,17 @@ public class ComboBoxEnablesComboBox extends TestBase {
@Override
protected void setup() {
- ComboBox<String> cb = new ComboBox<>("Always enabled");
- populate(cb);
+ ComboBox<String> cb = new ComboBox<>("Always enabled",
+ new ItemDataSource(10));
cb.addValueChangeListener(event -> cb2.setEnabled(true));
- cb2 = new ComboBox<String>("Initially disabled");
+ cb2 = new ComboBox<String>("Initially disabled",
+ new ItemDataSource(10));
cb2.setEnabled(false);
- populate(cb2);
addComponent(cb);
addComponent(cb2);
}
- private void populate(ComboBox<String> cb) {
- List<String> items = new ArrayList<>();
- for (int i = 1; i < 10; i++) {
- items.add("Item " + i);
- }
- cb.setItems(items);
- }
-
@Override
protected String getDescription() {
return "Selecting an item in the first combobox enables the second.";
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java
index d99e1ef681..e34615410b 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxMousewheel.java
@@ -15,11 +15,9 @@
*/
package com.vaadin.tests.components.combobox;
-import java.util.ArrayList;
-import java.util.List;
-
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.util.ItemDataSource;
import com.vaadin.ui.ComboBox;
/**
@@ -33,17 +31,13 @@ public class ComboBoxMousewheel extends AbstractTestUI {
protected void setup(VaadinRequest request) {
addComponent(createComboBox("Paged"));
- ComboBox cb = createComboBox("Unpaged");
+ ComboBox<String> cb = createComboBox("Unpaged");
cb.setPageLength(0);
addComponent(cb);
}
- private ComboBox createComboBox(String caption) {
- List<String> data = new ArrayList<>();
- for (int i = 1; i < 100; i++) {
- data.add("Item " + i);
- }
- ComboBox<String> cb = new ComboBox<>(caption, data);
+ private ComboBox<String> createComboBox(String caption) {
+ ComboBox<String> cb = new ComboBox<>(caption, new ItemDataSource(100));
cb.setId(caption);
return cb;
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java
index e823c32e1d..b4b12bcb5b 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxNavigation.java
@@ -1,9 +1,7 @@
package com.vaadin.tests.components.combobox;
-import java.util.ArrayList;
-import java.util.List;
-
import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.ItemDataSource;
import com.vaadin.ui.ComboBox;
public class ComboBoxNavigation extends TestBase {
@@ -20,11 +18,7 @@ public class ComboBoxNavigation extends TestBase {
@Override
protected void setup() {
- List<String> items = new ArrayList<>();
- for (int i = 1; i < 100; i++) {
- items.add("Item " + i);
- }
- ComboBox cb = new ComboBox(null, items);
+ ComboBox<String> cb = new ComboBox<>(null, new ItemDataSource(100));
addComponent(cb);
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java
index 98b4c8025f..3a0a44e464 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxPopupWhenBodyScrolls.java
@@ -15,11 +15,9 @@
*/
package com.vaadin.tests.components.combobox;
-import java.util.ArrayList;
-import java.util.List;
-
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.util.ItemDataSource;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Label;
@@ -31,11 +29,7 @@ public class ComboBoxPopupWhenBodyScrolls extends AbstractTestUI {
.add("body.v-generated-body { overflow: auto;height:auto;}");
getPage().getStyles().add(
"body.v-generated-body .v-ui.v-scrollable{ overflow: visible;height:auto !important;}");
- List<String> data = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- data.add("Item " + i);
- }
- ComboBox<String> cb = new ComboBox<>(null, data);
+ ComboBox<String> cb = new ComboBox<>(null, new ItemDataSource(10));
Label spacer = new Label("foo");
spacer.setHeight("2000px");
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java
index 5b2e580fc8..d1f8c16562 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboBoxUndefinedWidthAndIcon.java
@@ -1,20 +1,14 @@
package com.vaadin.tests.components.combobox;
-import java.util.ArrayList;
-import java.util.List;
-
import com.vaadin.server.ThemeResource;
import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.ItemDataSource;
import com.vaadin.ui.ComboBox;
public class ComboBoxUndefinedWidthAndIcon extends TestBase {
@Override
protected void setup() {
- List<String> data = new ArrayList<>();
- for (int i = 1; i < 200 + 1; i++) {
- data.add("Item " + i);
- }
- ComboBox<String> cb = new ComboBox<>(null, data);
+ ComboBox<String> cb = new ComboBox<>(null, new ItemDataSource(200));
cb.setItemIconGenerator(
item -> new ThemeResource("../runo/icons/16/users.png"));
diff --git a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java
index 88986fb69a..5513c9eba9 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/combobox/ComboFocusBlurEvents.java
@@ -1,9 +1,7 @@
package com.vaadin.tests.components.combobox;
-import java.util.ArrayList;
-import java.util.List;
-
import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.ItemDataSource;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextField;
import com.vaadin.v7.data.util.ObjectProperty;
@@ -17,12 +15,8 @@ public class ComboFocusBlurEvents extends TestBase {
@Override
protected void setup() {
- List<String> list = new ArrayList<>();
- for (int i = 0; i < 100; i++) {
- list.add("Item " + i);
- }
-
- ComboBox<String> cb = new ComboBox<>("Combobox", list);
+ ComboBox<String> cb = new ComboBox<>("Combobox",
+ new ItemDataSource(100));
cb.setPlaceholder("Enter text");
cb.setDescription("Some Combobox");
addComponent(cb);
diff --git a/uitest/src/main/java/com/vaadin/tests/util/ItemDataSource.java b/uitest/src/main/java/com/vaadin/tests/util/ItemDataSource.java
new file mode 100644
index 0000000000..e7a184f6da
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/util/ItemDataSource.java
@@ -0,0 +1,21 @@
+package com.vaadin.tests.util;
+
+import java.util.stream.IntStream;
+
+import com.vaadin.server.data.BackEndDataSource;
+
+/**
+ * A data source for tests that creates "Item n" strings on the fly.
+ *
+ * @author Vaadin Ltd
+ */
+public class ItemDataSource extends BackEndDataSource<String> {
+
+ public ItemDataSource(int size) {
+ super(q -> IntStream
+ .range(q.getOffset(),
+ Math.max(q.getOffset() + q.getLimit() + 1, size))
+ .mapToObj(i -> "Item " + i), q -> size);
+ }
+
+}