diff options
author | Artur Signell <artur@vaadin.com> | 2015-04-24 16:51:22 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-05-05 06:59:34 +0000 |
commit | 8b93cba4dec9cc04adc8776d116042755d18fe1e (patch) | |
tree | 687e8fa240fc2bd83e0a7bbb2de8bb4314084773 /uitest/src/com/vaadin/tests/components/datefield | |
parent | 3c5824fad9f22a3091d2bcb52122959c513d14f7 (diff) | |
download | vaadin-framework-8b93cba4dec9cc04adc8776d116042755d18fe1e.tar.gz vaadin-framework-8b93cba4dec9cc04adc8776d116042755d18fe1e.zip |
Fix enabled handling for DateField and PopupDateField (#17620)
Change-Id: I3e38bb5c03453b6c1ad5c9bb717241297a779f73
Diffstat (limited to 'uitest/src/com/vaadin/tests/components/datefield')
2 files changed, 174 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java new file mode 100644 index 0000000000..2c5e9e251b --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParent.java @@ -0,0 +1,76 @@ +package com.vaadin.tests.components.datefield; + +import java.util.Date; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.DateField; +import com.vaadin.ui.PopupDateField; +import com.vaadin.ui.VerticalLayout; + +public class DateFieldWhenChangingValueAndEnablingParent extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final VerticalLayout main = new VerticalLayout(); + final VerticalLayout sub = new VerticalLayout(); + final CheckBox chk = new CheckBox("Parent layout enabled"); + + main.setMargin(true); + setContent(main); + + final DateField df1 = createDateField(true); + final DateField df2 = createDateField(false); + final PopupDateField pdf1 = createPopupDateField(true, true); + final PopupDateField pdf2 = createPopupDateField(true, false); + final PopupDateField pdf3 = createPopupDateField(false, true); + final PopupDateField pdf4 = createPopupDateField(false, false); + + sub.addComponent(df1); + sub.addComponent(df2); + sub.addComponent(pdf1); + sub.addComponent(pdf2); + sub.addComponent(pdf3); + sub.addComponent(pdf4); + sub.setEnabled(false); + main.addComponent(chk); + main.addComponent(sub); + + chk.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + df1.setValue(new Date()); + df2.setValue(new Date()); + pdf1.setValue(new Date()); + pdf2.setValue(new Date()); + pdf3.setValue(new Date()); + pdf4.setValue(new Date()); + sub.setEnabled(chk.getValue()); + } + }); + } + + private DateField createDateField(boolean enabled) { + DateField df = new DateField("DateField, " + + (enabled ? "enabled" : "disabled")); + df.setEnabled(enabled); + df.setId("DATEFIELD_" + (enabled ? "ENABLED" : "DISABLED")); + return df; + } + + private PopupDateField createPopupDateField(boolean enabled, + boolean textInputEnabled) { + PopupDateField df = new PopupDateField("PopupDateField, " + + (enabled ? "enabled" : "disabled") + ", text input " + + (textInputEnabled ? "enabled" : "disabled")); + df.setEnabled(enabled); + df.setTextFieldEnabled(textInputEnabled); + df.setId("DATEFIELD_" + (enabled ? "ENABLED" : "DISABLED") + "_" + + (textInputEnabled ? "ENABLED" : "DISABLED")); + return df; + } +} diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParentTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParentTest.java new file mode 100644 index 0000000000..23f6d6f5a6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldWhenChangingValueAndEnablingParentTest.java @@ -0,0 +1,98 @@ +/* + * 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.datefield; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.DateFieldElement; +import com.vaadin.testbench.elements.PopupDateFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class DateFieldWhenChangingValueAndEnablingParentTest extends + SingleBrowserTest { + + @Test + public void ensureCorrectStateAfterEnabling() { + openTestURL(); + $(CheckBoxElement.class).first().click(); + + assertState($(DateFieldElement.class).id("DATEFIELD_ENABLED"), true, + true); + assertState($(DateFieldElement.class).id("DATEFIELD_DISABLED"), false, + false); + + assertState( + $(PopupDateFieldElement.class).id("DATEFIELD_ENABLED_ENABLED"), + true, true); + assertState( + $(PopupDateFieldElement.class).id("DATEFIELD_ENABLED_DISABLED"), + true, false); + + // disabling widget should always disable input + assertState( + $(PopupDateFieldElement.class).id("DATEFIELD_DISABLED_ENABLED"), + false, false); + assertState( + $(PopupDateFieldElement.class) + .id("DATEFIELD_DISABLED_DISABLED"), false, false); + + } + + /** + * @since + * @param id + * @param widgetEnabled + * @param textInputEnabled + */ + private void assertState(DateFieldElement id, boolean widgetEnabled, + boolean textInputEnabled) { + assertDateFieldEnabled(id, widgetEnabled); + assertTextInputEnabled(id, textInputEnabled); + + } + + private void assertDateFieldEnabled(DateFieldElement id, + boolean assertEnabled) { + boolean hasClass = hasCssClass(id, "v-disabled"); + boolean fieldEnabled = !hasClass; + if (assertEnabled) { + Assert.assertTrue("Field " + id.getAttribute("id") + + " should be enabled", fieldEnabled); + } else { + Assert.assertFalse("Field " + id.getAttribute("id") + + " should be disabled", fieldEnabled); + } + + } + + private void assertTextInputEnabled(DateFieldElement id, boolean enabled) { + String disabledAttr = id.findElement(By.xpath("./input")).getAttribute( + "disabled"); + boolean textinputEnabled = (disabledAttr == null); + + if (enabled) { + Assert.assertTrue("Field " + id.getAttribute("id") + + " text field should be enabled", textinputEnabled); + } else { + Assert.assertFalse("Field " + id.getAttribute("id") + + " text field should be disabled", textinputEnabled); + } + + } +} |