From 69f66c8b28119da604836bde502e2220a35216e3 Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Wed, 3 Jun 2015 22:06:42 +0300 Subject: Do not send value change to server for non-immediate CheckBox (#18102) Change-Id: I60a58af72d7166869d8bdc8930e16440e02d2ac5 --- .../components/checkbox/CheckBoxImmediate.java | 62 ++++++++++++++++++++++ .../components/checkbox/CheckBoxImmediateTest.java | 53 ++++++++++++++++++ .../components/checkbox/CheckBoxRpcCount.java | 10 ++++ 3 files changed, 125 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediate.java create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxImmediateTest.java (limited to 'uitest/src') 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); } -- cgit v1.2.3