summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGeneration.java45
-rw-r--r--uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html19
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGenerationTest.java65
3 files changed, 129 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGeneration.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGeneration.java
new file mode 100644
index 0000000000..8d386cf823
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGeneration.java
@@ -0,0 +1,45 @@
+package com.vaadin.tests.components.nativeselect;
+
+import com.vaadin.annotations.DesignRoot;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.ItemCaptionGenerator;
+import com.vaadin.ui.NativeSelect;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.declarative.Design;
+
+public class NativeSelectCaptionGeneration extends UI {
+
+ @DesignRoot
+ public static class TestComponent extends VerticalLayout {
+
+ HorizontalLayout buttons;
+ NativeSelect<String> nativeSelect;
+
+ public TestComponent() {
+ Design.read(this);
+
+ // Store the declarative with to string fallback
+ ItemCaptionGenerator<String> declarative = nativeSelect
+ .getItemCaptionGenerator();
+
+ buttons.addComponents(
+ new Button("toString",
+ e -> nativeSelect
+ .setItemCaptionGenerator(String::toString)),
+ new Button("Only number",
+ e -> nativeSelect.setItemCaptionGenerator(
+ str -> str.substring(7))),
+ new Button("Declarative", e -> nativeSelect
+ .setItemCaptionGenerator(declarative)));
+ }
+ }
+
+ @Override
+ protected void init(VaadinRequest request) {
+ setContent(new TestComponent());
+ }
+
+}
diff --git a/uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html b/uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html
new file mode 100644
index 0000000000..f4228bf60f
--- /dev/null
+++ b/uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="UTF-8" name="design-properties" content="{&quot;RULERS_VISIBLE&quot;:true,&quot;GUIDELINES_VISIBLE&quot;:false,&quot;SNAP_TO_OBJECTS&quot;:true,&quot;SNAP_TO_GRID&quot;:true,&quot;SNAPPING_DISTANCE&quot;:10,&quot;JAVA_SOURCES_ROOT&quot;:&quot;src/main/java&quot;,&quot;THEME&quot;:&quot;reindeer-tests&quot;}">
+ <meta charset="UTF-8" name="vaadin-version" content="7.7.0">
+ </head>
+ <body>
+ <vaadin-vertical-layout>
+ <vaadin-horizontal-layout _id="buttons" width-full></vaadin-horizontal-layout>
+ <vaadin-native-select _id="nativeSelect">
+ <option item="Option 1">Foo</option>
+ <option item="Option 2">Bar</option>
+ <option item="Option 3">Baz</option>
+ <option item="Option 4">Spam</option>
+ <option item="Option 5">Eggs</option>
+ </vaadin-native-select>
+ </vaadin-vertical-layout>
+ </body>
+</html> \ No newline at end of file
diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGenerationTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGenerationTest.java
new file mode 100644
index 0000000000..445c11e889
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectCaptionGenerationTest.java
@@ -0,0 +1,65 @@
+package com.vaadin.tests.components.nativeselect;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.customelements.NativeSelectElement;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class NativeSelectCaptionGenerationTest extends SingleBrowserTest {
+
+ private static final String[] value = new String[] { "Foo", "Bar", "Baz",
+ "Spam", "Eggs" };
+
+ @Test
+ public void testDefaultDeclarativeCaptions() {
+ openTestURL();
+ List<TestBenchElement> options = $(NativeSelectElement.class).first()
+ .getOptions();
+ for (int i = 0; i < options.size(); ++i) {
+ Assert.assertEquals("Captions don't match.", value[i],
+ options.get(i).getText());
+ }
+ }
+
+ @Test
+ public void testToStringCaptions() {
+ openTestURL();
+ $(ButtonElement.class).caption("toString").first().click();
+ List<TestBenchElement> options = $(NativeSelectElement.class).first()
+ .getOptions();
+ for (int i = 0; i < options.size(); ++i) {
+ Assert.assertEquals("Captions don't match.", "Option " + (i + 1),
+ options.get(i).getText());
+ }
+ }
+
+ @Test
+ public void testNumberOnlyCaptions() {
+ openTestURL();
+ $(ButtonElement.class).caption("Only number").first().click();
+ List<TestBenchElement> options = $(NativeSelectElement.class).first()
+ .getOptions();
+ for (int i = 0; i < options.size(); ++i) {
+ Assert.assertEquals("Captions don't match.", "" + (i + 1),
+ options.get(i).getText());
+ }
+ }
+
+ @Test
+ public void testChangeGeneratorToStringAndBackToDeclarative() {
+ openTestURL();
+ $(ButtonElement.class).caption("toString").first().click();
+ $(ButtonElement.class).caption("Declarative").first().click();
+ List<TestBenchElement> options = $(NativeSelectElement.class).first()
+ .getOptions();
+ for (int i = 0; i < options.size(); ++i) {
+ Assert.assertEquals("Captions don't match.", value[i],
+ options.get(i).getText());
+ }
+ }
+}