diff options
author | Teppo Kurki <teppo.kurki@vaadin.com> | 2015-06-03 22:06:42 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-06-04 11:34:57 +0000 |
commit | 69f66c8b28119da604836bde502e2220a35216e3 (patch) | |
tree | 4d4287b3cc7e27d0e43b13133a9035671300b452 /uitest/src | |
parent | 3954d200f0d1236738cdcd147d5b07540d812bba (diff) | |
download | vaadin-framework-69f66c8b28119da604836bde502e2220a35216e3.tar.gz vaadin-framework-69f66c8b28119da604836bde502e2220a35216e3.zip |
Do not send value change to server for non-immediate CheckBox (#18102)
Change-Id: I60a58af72d7166869d8bdc8930e16440e02d2ac5
Diffstat (limited to 'uitest/src')
3 files changed, 125 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java new file mode 100644 index 0000000000..fec753d5af --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java @@ -0,0 +1,62 @@ +/* + * 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.checkbox; + +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.Label; + +public class CheckBoxImmediate extends AbstractTestUI { + private int count = 0; + + @Override + protected void setup(VaadinRequest request) { + final Label status = new Label("Events received: " + count); + status.setId("count"); + addComponent(status); + + CheckBox cb = new CheckBox("Non-immediate"); + ValueChangeListener listener = new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + count++; + status.setValue("Events received: " + count); + } + }; + cb.addValueChangeListener(listener); + cb.setImmediate(false); + addComponent(cb); + + cb = new CheckBox("Immediate"); + cb.addValueChangeListener(listener); + cb.setImmediate(true); + addComponent(cb); + } + + @Override + protected String getTestDescription() { + return "Test for verifying that a non-immediate CheckBox does not send value change to server immediately."; + } + + @Override + protected Integer getTicketNumber() { + return 18102; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java new file mode 100644 index 0000000000..826b43b9cc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java @@ -0,0 +1,53 @@ +/* + * 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.checkbox; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class CheckBoxImmediateTest extends MultiBrowserTest { + + @Test + public void testNonImmediateCheckBox() { + openTestURL(); + + CheckBoxElement checkBoxElement = $(CheckBoxElement.class).first(); + WebElement inputElem = checkBoxElement.findElement(By.tagName("input")); + final WebElement countElem = $(LabelElement.class).id("count"); + + inputElem.click(); + assertEquals("Events received: 0", countElem.getText()); + } + + @Test + public void testImmediateCheckBox() { + openTestURL(); + + CheckBoxElement checkBoxElement = $(CheckBoxElement.class).get(1); + WebElement inputElem = checkBoxElement.findElement(By.tagName("input")); + final WebElement countElem = $(LabelElement.class).id("count"); + + inputElem.click(); + assertEquals("Events received: 1", countElem.getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRpcCount.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRpcCount.java index bd44e8a074..f909f97996 100644 --- a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRpcCount.java +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRpcCount.java @@ -15,6 +15,8 @@ */ package com.vaadin.tests.components.checkbox; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc; @@ -46,6 +48,14 @@ public class CheckBoxRpcCount extends AbstractTestUI { }); } }; + cb.addValueChangeListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + // Adding an empty ValueChangeListener just to ensure that + // immediate mode is set to true + } + }); addComponent(cb); } |