summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2017-01-27 15:44:03 +0200
committerGitHub <noreply@github.com>2017-01-27 15:44:03 +0200
commit9ef479303bb514622ef90d95b94d912780c1812d (patch)
treefd6929a4b396cb6b1ff290ded4e129cd60415d60 /uitest
parent5616216306a138b3437d188e4b2df8253590abf5 (diff)
downloadvaadin-framework-9ef479303bb514622ef90d95b94d912780c1812d.tar.gz
vaadin-framework-9ef479303bb514622ef90d95b94d912780c1812d.zip
Introduce empty selection functionality for NativeSelect. (#8336)
* Introduce empty selection functionality for NativeSelect. Fixes vaadin/framework8-issues#545
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelection.java50
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java7
-rw-r--r--uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html2
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelectionTest.java71
4 files changed, 129 insertions, 1 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelection.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelection.java
new file mode 100644
index 0000000000..2d222490f6
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelection.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.nativeselect;
+
+import java.util.stream.IntStream;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.NativeSelect;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class NativeSelectEmptySelection extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ NativeSelect<String> select = new NativeSelect<>();
+ select.setItems(IntStream.range(1, 50)
+ .mapToObj(index -> String.valueOf(index)));
+ select.setEmptySelectionCaption("empty");
+ addComponent(select);
+
+ Button update = new Button("Update Empty Caption to 'updated'",
+ event -> select.setEmptySelectionCaption("updated"));
+
+ Button disallow = new Button("Disallow empty selection item",
+ event -> select.setEmptySelectionAllowed(false));
+
+ Button enable = new Button("Allow empty selection item",
+ event -> select.setEmptySelectionAllowed(true));
+ addComponents(update, disallow, enable);
+ }
+
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java
index 1a28fd41fb..34b78089bb 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/nativeselect/NativeSelects.java
@@ -11,4 +11,11 @@ public class NativeSelects
protected Class<NativeSelect<Object>> getTestClass() {
return (Class) NativeSelect.class;
}
+
+ @Override
+ protected NativeSelect<Object> constructComponent() {
+ NativeSelect<Object> component = super.constructComponent();
+ component.setEmptySelectionAllowed(false);
+ return component;
+ }
}
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
index f4228bf60f..17adb460e4 100644
--- a/uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html
+++ b/uitest/src/main/resources/com/vaadin/tests/components/nativeselect/TestComponent.html
@@ -7,7 +7,7 @@
<body>
<vaadin-vertical-layout>
<vaadin-horizontal-layout _id="buttons" width-full></vaadin-horizontal-layout>
- <vaadin-native-select _id="nativeSelect">
+ <vaadin-native-select _id="nativeSelect" empty-selection-allowed="false">
<option item="Option 1">Foo</option>
<option item="Option 2">Bar</option>
<option item="Option 3">Baz</option>
diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelectionTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelectionTest.java
new file mode 100644
index 0000000000..102b504605
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectEmptySelectionTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.nativeselect;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.NativeSelectElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * @author Vaadin Ltd
+ *
+ */
+public class NativeSelectEmptySelectionTest extends MultiBrowserTest {
+
+ @Test
+ public void checkEmptySelection() {
+ openTestURL();
+
+ checkOptions("empty");
+
+ // change the caption
+ $(ButtonElement.class).first().click();
+ checkOptions("updated");
+
+ // disable empty caption
+ $(ButtonElement.class).get(1).click();
+ checkOptions(null);
+
+ // enable back
+ $(ButtonElement.class).get(2).click();
+ checkOptions("updated");
+ }
+
+ private void checkOptions(String emptyCaption) {
+ NativeSelectElement select = $(NativeSelectElement.class).first();
+ Set<String> originalOptions = IntStream.range(1, 50)
+ .mapToObj(index -> String.valueOf(index))
+ .collect(Collectors.toSet());
+ Set<String> options = select.getOptions().stream()
+ .map(TestBenchElement::getText).collect(Collectors.toSet());
+ if (emptyCaption == null) {
+ Assert.assertEquals(49, options.size());
+ Assert.assertTrue(options.containsAll(originalOptions));
+ } else {
+ options.contains(emptyCaption);
+ Assert.assertEquals(50, options.size());
+ Assert.assertTrue(options.containsAll(originalOptions));
+ }
+ }
+}