summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/combobox
diff options
context:
space:
mode:
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>2014-12-11 13:50:51 +0300
committerVaadin Code Review <review@vaadin.com>2015-01-15 14:28:44 +0000
commit77bcd2fdd38839eae422ba0928e42d23e6b2bc96 (patch)
tree566cd7621fff7f77246cd3aa8573a45308919eda /uitest/src/com/vaadin/tests/components/combobox
parent8212377595295b2f997733b24ae731d144ebe2bf (diff)
downloadvaadin-framework-77bcd2fdd38839eae422ba0928e42d23e6b2bc96.tar.gz
vaadin-framework-77bcd2fdd38839eae422ba0928e42d23e6b2bc96.zip
ComboBox: programmatic value reset breaks dropdown (#13217)
Change-Id: I6f749ab0788324d24e1e7451183ec9f0ff8ed5ba
Diffstat (limited to 'uitest/src/com/vaadin/tests/components/combobox')
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java87
-rw-r--r--uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java166
2 files changed, 253 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java
new file mode 100644
index 0000000000..b6b284c5c5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValue.java
@@ -0,0 +1,87 @@
+package com.vaadin.tests.components.combobox;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.VerticalLayout;
+
+public class ComboBoxResetValue extends AbstractTestUI {
+
+ protected static final String EMPTY_VALUE = "Empty value";
+ protected static final String NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithSetNullSelectionItemId";
+ protected static final String NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID = "nullSelectionAllowedWithoutNullSelectionItemId";
+ protected static final String NULL_SELECTION_NOT_ALLOWED = "nullSelectionNotAllowed";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final ComboBox cbNullSelectionAllowedWithSetNullSelectionItemId = getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId();
+ final ComboBox cbNullSelectionAllowedWithoutNullSelectionItemId = getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId();
+ final ComboBox cbNullSelectionNotAllowed = getComboBoxWithNullSelectionNotAllowed();
+
+ Button b = new Button("Reset");
+ b.setImmediate(true);
+ b.addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ cbNullSelectionAllowedWithSetNullSelectionItemId.setValue(null);
+ cbNullSelectionAllowedWithoutNullSelectionItemId.setValue(null);
+ cbNullSelectionNotAllowed.setValue(null);
+ }
+ });
+ addComponents(new HorizontalLayout(new VerticalLayout(
+ cbNullSelectionAllowedWithSetNullSelectionItemId,
+ cbNullSelectionAllowedWithoutNullSelectionItemId,
+ cbNullSelectionNotAllowed), b));
+ }
+
+ protected ComboBox getComboBoxWithNullSelectionAllowedWithSetNullSelectionItemId() {
+ ComboBox cb = new ComboBox();
+ cb.setId(NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID);
+ cb.setImmediate(true);
+ cb.setNullSelectionAllowed(true);
+
+ cb.addItem(EMPTY_VALUE);
+ cb.setNullSelectionItemId(EMPTY_VALUE);
+
+ cb.addItem(1);
+ cb.select(1);
+ return cb;
+ }
+
+ protected ComboBox getComboBoxWithNullSelectionAllowedWithoutNullSelectionItemId() {
+ ComboBox cb = new ComboBox();
+ cb.setId(NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID);
+ cb.setImmediate(true);
+ cb.setNullSelectionAllowed(true);
+
+ cb.addItem(1);
+ cb.select(1);
+ return cb;
+ }
+
+ protected ComboBox getComboBoxWithNullSelectionNotAllowed() {
+ ComboBox cb = new ComboBox();
+ cb.setId(NULL_SELECTION_NOT_ALLOWED);
+ cb.setImmediate(true);
+ cb.setNullSelectionAllowed(false);
+
+ cb.addItem(1);
+ cb.select(1);
+ return cb;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 13217;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Tests that reseting (setValue(null), select(null)) of combobox works correctly (removes/updates old selection, also correctly works with filtering)";
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java
new file mode 100644
index 0000000000..3021cb6e1a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxResetValueTest.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2000-2014 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.combobox;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebDriverException;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.ComboBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class ComboBoxResetValueTest extends MultiBrowserTest {
+
+ static final String FILTER_STRING = "filter";
+
+ @Test
+ public void testNullSelectionAllowedAndSetNullSelectionItemId() {
+ openTestURL();
+
+ ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class)
+ .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID);
+ clickResetButton();
+
+ openPopup(comboBoxWebElement);
+
+ assertEquals("There should be selected: "
+ + ComboBoxResetValue.EMPTY_VALUE,
+ ComboBoxResetValue.EMPTY_VALUE, getSelectedInPopupValue());
+ }
+
+ @Test
+ public void testFilterNullSelectionAllowedAndSetNullSelectionItemId() {
+ openTestURL();
+
+ ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class)
+ .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITH_SET_NULL_SELECTION_ITEM_ID);
+ clickResetButton();
+ printFilterAndRemoveIt(getComboBoxInput(comboBoxWebElement));
+
+ assertEquals("There should be " + ComboBoxResetValue.EMPTY_VALUE,
+ ComboBoxResetValue.EMPTY_VALUE,
+ getComboBoxValue(comboBoxWebElement));
+ }
+
+ @Test
+ public void testNullSelectionAllowedWithoutNullSelectionItemId() {
+ openTestURL();
+
+ ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class)
+ .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID);
+ clickResetButton();
+
+ openPopup(comboBoxWebElement);
+
+ // not sure about expected result here.. Should be first empty string
+ // selected or not after reseting..
+ assertEquals("There should be no selection", null,
+ getSelectedInPopupValue());
+ }
+
+ @Test
+ public void testFilterNullSelectionAllowedWithoutNullSelectionItemId() {
+ openTestURL();
+
+ ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class)
+ .id(ComboBoxResetValue.NULL_SELECTION_ALLOWED_WITHOUT_NULL_SELECTION_ITEM_ID);
+ clickResetButton();
+ printFilterAndRemoveIt(getComboBoxInput(comboBoxWebElement));
+
+ assertEquals("There should be empty value", "",
+ getComboBoxValue(comboBoxWebElement));
+ }
+
+ @Test
+ public void testNullSelectionNotAllowed() {
+ openTestURL();
+
+ ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class).id(
+ ComboBoxResetValue.NULL_SELECTION_NOT_ALLOWED);
+ clickResetButton();
+
+ openPopup(comboBoxWebElement);
+
+ assertEquals("There should be no selection", null,
+ getSelectedInPopupValue());
+ }
+
+ @Test
+ public void testFilterNullSelectionNotAllowed() {
+ openTestURL();
+
+ ComboBoxElement comboBoxWebElement = $(ComboBoxElement.class).id(
+ ComboBoxResetValue.NULL_SELECTION_NOT_ALLOWED);
+ clickResetButton();
+ printFilterAndRemoveIt(getComboBoxInput(comboBoxWebElement));
+
+ assertEquals("There should be empty value", "",
+ getComboBoxValue(comboBoxWebElement));
+ }
+
+ private void openPopup(ComboBoxElement comboBox) {
+ if (!isElementPresent(By.vaadin("#popup"))) {
+ comboBox.openPopup();
+ }
+ }
+
+ private String getSelectedInPopupValue() {
+ try {
+ WebElement selectedSpan = driver.findElement(By
+ .cssSelector(".gwt-MenuItem-selected span"));
+ return selectedSpan.getText();
+ } catch (NoSuchElementException e) {
+ return null;
+ } catch (WebDriverException e) {
+ if (e.getMessage() != null
+ && e.getMessage().contains("Unable to find element")) {
+ return null;
+ }
+ throw e;
+ }
+ }
+
+ private void clickResetButton() {
+ ButtonElement resetButton = $(ButtonElement.class).first();
+ // workaround because of IE10 that doesn't always respond to click
+ resetButton.focus();
+ resetButton.sendKeys(Keys.ENTER);
+ }
+
+ private void printFilterAndRemoveIt(WebElement target) {
+ Actions actions = new Actions(getDriver());
+ actions.click(target).perform();
+ actions.sendKeys(Keys.chord(Keys.CONTROL, "a")).perform(); // Select all
+ actions.sendKeys(FILTER_STRING);
+ actions.sendKeys(Keys.ENTER).sendKeys(Keys.ESCAPE).sendKeys(Keys.TAB); // hack
+ actions.perform();
+ }
+
+ private String getComboBoxValue(ComboBoxElement comboBox) {
+ return getComboBoxInput(comboBox).getAttribute("value");
+ }
+
+ private WebElement getComboBoxInput(ComboBoxElement comboBox) {
+ return comboBox.findElement(By.tagName("input"));
+ }
+}