aboutsummaryrefslogtreecommitdiffstats
path: root/server/tests/src
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-12-17 16:12:49 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-17 20:55:24 +0000
commit311f5a0a26d78eac19ce07373f37799cbb5e20f0 (patch)
tree5e5ced217427cc3631bd04fcd74361418cc4cd70 /server/tests/src
parent87c559026ae0b756f0406f71ba8ea305cef4fb7e (diff)
downloadvaadin-framework-311f5a0a26d78eac19ce07373f37799cbb5e20f0.tar.gz
vaadin-framework-311f5a0a26d78eac19ce07373f37799cbb5e20f0.zip
Declarative support for CheckBox (#7749)
Change-Id: Ia0608cd0827ab09d9b30993738acd45317778e55
Diffstat (limited to 'server/tests/src')
-rw-r--r--server/tests/src/com/vaadin/tests/design/all-components.html3
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java67
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java57
3 files changed, 127 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/design/all-components.html b/server/tests/src/com/vaadin/tests/design/all-components.html
index 683fafcf05..0f16ea9363 100644
--- a/server/tests/src/com/vaadin/tests/design/all-components.html
+++ b/server/tests/src/com/vaadin/tests/design/all-components.html
@@ -102,6 +102,9 @@
<v-label>Hello world!</v-label>
<v-label>This is <b><u>Rich</u></b> content!</v-label>
<v-label plain-text>This is only <b>text</b> and will contain visible tags</v-label>
+
+ <!-- checkbox -->
+ <v-check-box checked/>
</v-vertical-layout>
</body>
</html>
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java
new file mode 100644
index 0000000000..529dd911e9
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java
@@ -0,0 +1,67 @@
+/*
+ * 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.server.component.checkbox;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Test;
+
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ *
+ * Test cases for reading the contents of a Checkbox from a design.
+ *
+ */
+public class TestReadDesign extends TestCase {
+
+ private DesignContext ctx;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctx = new DesignContext();
+ }
+
+ @Test
+ public void testChecked() {
+ Element e = createElement(true);
+ CheckBox box = (CheckBox) ctx.createChild(e);
+ assertEquals("The checkbox must be checked", Boolean.TRUE,
+ box.getValue());
+ }
+
+ @Test
+ public void testUnchecked() {
+ Element e = createElement(false);
+ CheckBox box = (CheckBox) ctx.createChild(e);
+ assertEquals("The checkbox must be unchecked", Boolean.FALSE,
+ box.getValue());
+ }
+
+ private Element createElement(boolean checked) {
+ Attributes attributes = new Attributes();
+ if (checked) {
+ attributes.put("checked", "");
+ }
+ Element node = new Element(Tag.valueOf("v-check-box"), "", attributes);
+ return node;
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java
new file mode 100644
index 0000000000..d187371db6
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java
@@ -0,0 +1,57 @@
+/*
+ * 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.server.component.checkbox;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Element;
+import org.junit.Test;
+
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Tests generating html tree nodes corresponding to the contents of a Checkbox
+ */
+public class TestWriteDesign extends TestCase {
+
+ private DesignContext ctx;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctx = new DesignContext();
+ }
+
+ @Test
+ public void testChecked() {
+ CheckBox box = new CheckBox();
+ box.setValue(true);
+ Element e = ctx.createElement(box);
+ assertTrue("element must have checked attribute", e.hasAttr("checked"));
+ assertTrue("the checked attribute must be true", e.attr("checked")
+ .equals("true") || e.attr("checked").equals(""));
+ }
+
+ @Test
+ public void testUnchecked() {
+ CheckBox box = new CheckBox();
+ box.setValue(false);
+ Element e = ctx.createElement(box);
+ assertFalse("the element must not have checked attribute",
+ e.hasAttr("checked"));
+ }
+} \ No newline at end of file