diff options
author | Artur Signell <artur@vaadin.com> | 2014-09-24 19:20:43 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-09-30 12:39:03 +0000 |
commit | 34934d1055d2451a3633d4380648ce661da17ce7 (patch) | |
tree | 9dfdb3d39bd7beabde441eb7389c566e55a0e855 /uitest | |
parent | afbf79cfecbea444b3276e7ef7c83719364be025 (diff) | |
download | vaadin-framework-34934d1055d2451a3633d4380648ce661da17ce7.tar.gz vaadin-framework-34934d1055d2451a3633d4380648ce661da17ce7.zip |
String <-> Enum converter which produces a human readable string (#14756)
Change-Id: I3a825f52a43daea3172ced23bc510118376e76cb
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java | 50 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java | 57 |
2 files changed, 107 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java b/uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java new file mode 100644 index 0000000000..67b3b84688 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/EnumTextField.java @@ -0,0 +1,50 @@ +/* + * 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.textfield; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.TextField; + +public class EnumTextField extends AbstractTestUIWithLog { + + public enum MyEnum { + FIRST_VALUE, VALUE, THE_LAST_VALUE; + } + + @Override + protected void setup(VaadinRequest request) { + final TextField tf = new TextField(); + tf.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + if (tf.isValid()) { + log(tf.getValue() + " (valid)"); + } else { + log(tf.getValue() + " (INVALID)"); + } + } + }); + + tf.setPropertyDataSource(new ObjectProperty<Enum>(MyEnum.FIRST_VALUE)); + addComponent(tf); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java b/uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java new file mode 100644 index 0000000000..113acee3a2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textfield/EnumTextFieldTest.java @@ -0,0 +1,57 @@ +/* + * 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.textfield; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class EnumTextFieldTest extends SingleBrowserTest { + @Test + public void validValues() { + openTestURL(); + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys("Value"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("3. Value (valid)", getLogRow(0)); + + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys("VaLuE"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("5. Value (valid)", getLogRow(0)); + + $(TextFieldElement.class).first().clear(); + $(TextFieldElement.class).first().sendKeys("The last value"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("7. The last value (valid)", getLogRow(0)); + + } + + @Test + public void invalidValue() { + openTestURL(); + $(TextFieldElement.class).first().clear(); + Assert.assertEquals("2. (INVALID)", getLogRow(0)); + + $(TextFieldElement.class).first().sendKeys("bar"); + $(TextFieldElement.class).first().sendKeys(Keys.TAB); + Assert.assertEquals("3. bar (INVALID)", getLogRow(0)); + + } +} |