From 5e33b383fdf31f2ea15603f3a30bcb1e3c22d081 Mon Sep 17 00:00:00 2001 From: Anastasia Smirnova Date: Thu, 18 Oct 2018 15:28:23 +0300 Subject: Display the caption of the Empty selection in NativeSelect (#11191) * Fixes #10937 - Previously if selected value is null, then index is set to -1; in current implementation if value is null and emptySelection is allowed then set the index to 0. (The position for the empty selection) - Also, if changing the allowEmptySelection on the fly, ensure, that either index is to-reset to -1 by setting the selected value to null on the client-side (the value before was null) or preserve the value(value was different than empty). * Change the test case Since in this pr the behaviour of the NS is changed, therefore old test need to be adjusted. Change: setting null as value will select empty selection. Before that nothing would be selected and value will be cleared. Behaviour change in PR: Allow selecting null as value --- .../nativeselect/NativeSelectSetNullTest.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java (limited to 'uitest/src/test') diff --git a/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java new file mode 100644 index 0000000000..90afe9f463 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/nativeselect/NativeSelectSetNullTest.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.nativeselect; + +import com.vaadin.testbench.elements.NativeSelectElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import static junit.framework.TestCase.assertEquals; + +public class NativeSelectSetNullTest extends MultiBrowserTest { + + @Before + public void setUp() { + openTestURL(); + } + + @Test + public void testCaptionSelected() { + getButtonOnId("setNull"); + assertEquals(NativeSelectSetNull.EMPTY_SELECTION_TEXT, + getSelect().getValue()); + } + + @Test + public void changeSelectedValue() { + getButtonOnId("changeSelect").click(); + assertEquals(3, Integer.valueOf(getSelect().getValue()).intValue()); + } + + @Test + public void clearSelection() { + getButtonOnId("clear").click(); + assertEquals(NativeSelectSetNull.EMPTY_SELECTION_TEXT, + getSelect().getValue()); + } + + @Test + public void valuePreservedAfterAllowEmptySelectionChanged() { + getSelect().setValue("2"); + getButtonOnId("disable").click(); + assertEquals(2, Integer.valueOf(getSelect().getValue()).intValue()); + + getButtonOnId("disable").click(); + getButtonOnId("setNull").click(); + assertEquals(NativeSelectSetNull.EMPTY_SELECTION_TEXT, + getSelect().getValue()); + + } + + protected NativeSelectElement getSelect() { + return $(NativeSelectElement.class).first(); + } + + protected WebElement getButtonOnId(String id) { + return findElement(By.id(id)); + } +} -- cgit v1.2.3