summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorelmot <elmot@vaadin.com>2016-09-14 12:13:14 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-19 05:44:39 +0000
commitedd8b9bd16a33fe6be3e5082c953aaf374884070 (patch)
tree30ff2f28aeee9411068a562b03a6e1b9e3e15740
parent05c051717401660a857ee7a314361a1735f376e6 (diff)
downloadvaadin-framework-edd8b9bd16a33fe6be3e5082c953aaf374884070.tar.gz
vaadin-framework-edd8b9bd16a33fe6be3e5082c953aaf374884070.zip
Test and fix a CheckBoxGroup icon provider and item enabled provider
Change-Id: Ia3ed99478d19efc041cc4adaabd856ee69f3531b
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VCheckBoxGroup.java3
-rw-r--r--uitest-common/src/main/java/com/vaadin/testbench/customelements/CheckBoxGroupElement.java25
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/checkbox/CheckBoxGroupTestUI.java11
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupTest.java40
4 files changed, 77 insertions, 2 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VCheckBoxGroup.java b/client/src/main/java/com/vaadin/client/ui/VCheckBoxGroup.java
index 3fde2f6998..c51cb32a2f 100644
--- a/client/src/main/java/com/vaadin/client/ui/VCheckBoxGroup.java
+++ b/client/src/main/java/com/vaadin/client/ui/VCheckBoxGroup.java
@@ -107,7 +107,8 @@ public class VCheckBoxGroup extends Composite implements Field, ClickHandler,
String iconUrl = item
.getString(CheckBoxGroupConstants.JSONKEY_ITEM_ICON);
if (iconUrl != null && iconUrl.length() != 0) {
- checkBox.icon = client.getIcon(iconUrl);
+ Icon icon = client.getIcon(iconUrl);
+ itemHtml = icon.getElement().getString() + itemHtml;
}
checkBox.addStyleName(CLASSNAME_OPTION);
diff --git a/uitest-common/src/main/java/com/vaadin/testbench/customelements/CheckBoxGroupElement.java b/uitest-common/src/main/java/com/vaadin/testbench/customelements/CheckBoxGroupElement.java
index b2dd93a7b0..9b234fa1cd 100644
--- a/uitest-common/src/main/java/com/vaadin/testbench/customelements/CheckBoxGroupElement.java
+++ b/uitest-common/src/main/java/com/vaadin/testbench/customelements/CheckBoxGroupElement.java
@@ -46,6 +46,30 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
return optionTexts;
}
+ public List<String> getOptionsCssClasses() {
+ List<String> optionTexts = new ArrayList<>();
+ List<WebElement> options = findElements(byButtonSpan);
+ for (WebElement option : options) {
+ optionTexts.add(option.getAttribute("class"));
+ }
+ return optionTexts;
+ }
+
+ public List<String> getOptionsIconUrls() {
+ List<String> icons = new ArrayList<>();
+ List<WebElement> options = findElements(byButtonSpan);
+ for (WebElement option : options) {
+ List<WebElement> images = option.findElements(By.tagName("img"));
+ if (images != null && images.size() > 0) {
+ icons.add(images.get(0).getAttribute("src"));
+ } else {
+ icons.add(null);
+ }
+
+ }
+ return icons;
+ }
+
public void selectByText(String text) throws ReadOnlyException {
if (isReadOnly()) {
throw new ReadOnlyException();
@@ -103,4 +127,5 @@ public class CheckBoxGroupElement extends AbstractSelectElement {
"Clear operation is not supported for CheckBoxGroup."
+ " This operation has no effect on the element.");
}
+
}
diff --git a/uitest/src/main/java/com/vaadin/tests/components/checkbox/CheckBoxGroupTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/checkbox/CheckBoxGroupTestUI.java
index fef23f56d3..e8af72bfa6 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/checkbox/CheckBoxGroupTestUI.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/checkbox/CheckBoxGroupTestUI.java
@@ -37,6 +37,17 @@ public class CheckBoxGroupTestUI
return (Class) CheckBoxGroup.class;
}
+
+ @Override
+ protected CheckBoxGroup<Object> constructComponent() {
+ CheckBoxGroup<Object> checkBoxGroup = super.constructComponent();
+ checkBoxGroup.setItemIconProvider(
+ item -> "Item 2".equals(item) ? ICON_16_HELP_PNG_CACHEABLE :
+ null);
+ checkBoxGroup.setItemEnabledProvider(item -> !"Item 10".equals(item));
+ return checkBoxGroup;
+ }
+
@Override
protected void createActions() {
super.createActions();
diff --git a/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupTest.java b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupTest.java
index 9a8f631594..087ab55b6c 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupTest.java
@@ -1,6 +1,6 @@
/*
* 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
@@ -26,6 +26,16 @@ import org.junit.Test;
import com.vaadin.testbench.customelements.CheckBoxGroupElement;
import com.vaadin.tests.components.checkbox.CheckBoxGroupTestUI;
import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* Test for CheckBoxGroup
@@ -113,4 +123,32 @@ public class CheckBoxGroupTest extends MultiBrowserTest {
}
assertEquals("Number of items", count, i);
}
+
+ @Test
+ public void testDisabled() {
+ List<String> optionsCssClasses = getSelect().getOptionsCssClasses();
+ for (int i = 0; i < optionsCssClasses.size(); i++) {
+ String cssClassList = optionsCssClasses.get(i);
+ if (i == 10) {
+ assertTrue("10th item should be disabled",
+ cssClassList.toLowerCase().contains("disabled"));
+ } else {
+ assertFalse("Only 10th item should be disabled",
+ cssClassList.toLowerCase().contains("disabled"));
+ }
+ }
+ }
+
+ @Test
+ public void testIconUrl() {
+ List<String> optionsIcons = getSelect().getOptionsIconUrls();
+ for (int i = 0; i < optionsIcons.size(); i++) {
+ String icon = optionsIcons.get(i);
+ if (i == 2) {
+ assertNotNull("2nd item should have icon", icon);
+ } else {
+ assertNull("Only 2nd item should have icon", icon);
+ }
+ }
+ }
}