2 * Copyright 2000-2014 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.server.component.abstractselect;
18 import org.junit.Before;
19 import org.junit.Test;
21 import com.vaadin.server.ThemeResource;
22 import com.vaadin.tests.design.DeclarativeTestBase;
23 import com.vaadin.ui.OptionGroup;
25 public class OptionGroupDeclarativeTests extends
26 DeclarativeTestBase<OptionGroup> {
28 private OptionGroup og;
32 og = new OptionGroup();
36 public void testBasicSyntax() {
38 String expected = "<vaadin-option-group />";
39 testReadWrite(expected);
44 public void testOptionSyntax() {
46 og.addItems("foo", "bar", "baz", "bang");
50 "<vaadin-option-group>"
51 + "<option>foo</option>"
52 + "<option>bar</option>"
53 + "<option>baz</option>"
54 + "<option>bang</option>"
55 + "</vaadin-option-group>";
58 testReadWrite(expected);
63 public void testDisabledOptionSyntax() {
65 og.addItems("foo", "bar", "baz", "bang");
66 og.setItemEnabled("baz", false);
70 "<vaadin-option-group>"
71 + "<option>foo</option>"
72 + "<option>bar</option>"
73 + "<option disabled>baz</option>"
74 + "<option>bang</option>"
75 + "</vaadin-option-group>";
78 testReadWrite(expected);
83 public void testIconSyntax() {
85 og.addItems("foo", "bar", "baz", "bang");
86 og.setItemIcon("bar", new ThemeResource("foobar.png"));
90 "<vaadin-option-group>"
91 + "<option>foo</option>"
92 + "<option icon='theme://foobar.png'>bar</option>"
93 + "<option>baz</option>"
94 + "<option>bang</option>"
95 + "</vaadin-option-group>";
98 testReadWrite(expected);
103 public void testHTMLCaption() {
105 og.addItems("foo", "bar", "baz", "bang");
107 og.setHtmlContentAllowed(true);
109 og.setItemCaption("foo", "<b>True</b>");
110 og.setItemCaption("bar", "<font color='red'>False</font>");
114 "<vaadin-option-group html-content-allowed>"
115 + "<option item-id=\"foo\"><b>True</b></option>"
116 + "<option item-id=\"bar\"><font color='red'>False</font></option>"
117 + "<option>baz</option>"
118 + "<option>bang</option>"
119 + "</vaadin-option-group>";
122 testReadWrite(expected);
126 public void testPlaintextCaption() {
128 og.addItems("foo", "bar", "baz", "bang");
130 og.setItemCaption("foo", "<b>True</b>");
131 og.setItemCaption("bar", "<font color=\"red\">False</font>");
135 "<vaadin-option-group>"
136 + "<option item-id=\"foo\"><b>True</b></option>"
137 + "<option item-id=\"bar\"><font color=\"red\">False</font></option>"
138 + "<option>baz</option>"
139 + "<option>bang</option>"
140 + "</vaadin-option-group>";
143 testReadWrite(expected);
146 private void testReadWrite(String design) {
147 testWrite(design, og, true);
148 testRead(design, og);
152 public OptionGroup testRead(String design, OptionGroup expected) {
154 OptionGroup read = super.testRead(design, expected);
155 testWrite(design, read, true);