diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2018-12-13 16:59:35 +0200 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2018-12-13 16:59:35 +0200 |
commit | 891bb534de30ed39e463af88f67e7f5bbf94e3f1 (patch) | |
tree | 105e552080f3905eacf16dc8a57f2e37ae67134c /uitest | |
parent | f60d431c7cbf0689f74c5ba230681c4ab5171463 (diff) | |
download | vaadin-framework-891bb534de30ed39e463af88f67e7f5bbf94e3f1.tar.gz vaadin-framework-891bb534de30ed39e463af88f67e7f5bbf94e3f1.zip |
Apply missing v-readonly style to CheckBoxGroup, when component is readOnly (#11370)
Setting read-only state to CheckBoxGroup should disable adding clicking effect. Missing v-readonly style is added to every CheckBox in the component, if it's set to read-only.
Fixes: https://github.com/vaadin/framework/issues/11113
* Add file missed from initial commit
* Verifying that option is enabled
Some of the options might be disabled on there own. Verify that option is not disabled, before removing disabled styles.
* Add missing test file
Diffstat (limited to 'uitest')
2 files changed, 76 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupReadOnly.java b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupReadOnly.java new file mode 100644 index 0000000000..8c0caf3ac3 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupReadOnly.java @@ -0,0 +1,30 @@ +package com.vaadin.tests.components.checkboxgroup; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBoxGroup; +import com.vaadin.ui.Button; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class CheckBoxGroupReadOnly extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + CheckBoxGroup<Integer> cbg = new CheckBoxGroup<>(); + cbg.setId("cbg"); + cbg.setItems(1, 2, 3, 4); + cbg.setReadOnly(true); + addComponent(cbg); + + Button changeReadOnly = new Button("Change Read-Only", e -> { + cbg.setReadOnly(!cbg.isReadOnly()); + }); + changeReadOnly.setId("changeReadOnly"); + Button changeEnabled = new Button("Change Enabled", e -> { + cbg.setEnabled(!cbg.isEnabled()); + }); + changeEnabled.setId("changeEnabled"); + addComponent(changeReadOnly); + addComponent(changeEnabled); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupReadOnlyTest.java b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupReadOnlyTest.java new file mode 100644 index 0000000000..ad0fb4fbac --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupReadOnlyTest.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.components.checkboxgroup; + +import com.vaadin.testbench.elements.CheckBoxGroupElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; + +public class CheckBoxGroupReadOnlyTest extends MultiBrowserTest { + + @Test + public void itemsAreReadOnly() { + openTestURL(); + // Initially components are read-only + assertTrue(getSelect().isReadOnly()); + assertEquals(4, findReadOnlyCheckboxes().size()); + // Should not contain v-readonly + findElement(By.id("changeReadOnly")).click(); + assertEquals(0, findReadOnlyCheckboxes().size()); + + // Should not contain v-readonly + findElement(By.id("changeEnabled")).click(); + assertEquals(0, findReadOnlyCheckboxes().size()); + + // make read-only + findElement(By.id("changeReadOnly")).click(); + // enable + findElement(By.id("changeEnabled")).click(); + // Should contain v-readonly + assertEquals(4, findReadOnlyCheckboxes().size()); + } + + protected CheckBoxGroupElement getSelect() { + return $(CheckBoxGroupElement.class).first(); + } + + private List<WebElement> findReadOnlyCheckboxes() { + return findElement(By.id("cbg")) + .findElements(By.cssSelector("span.v-readonly.v-checkbox")); + } +} |