]> source.dussan.org Git - vaadin-framework.git/blob
509e46c278081fc46398eba571b9c0f8ab8f167c
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2014 Vaadin Ltd.
3  * 
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
6  * the License at
7  * 
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * 
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
14  * the License.
15  */
16 package com.vaadin.tests.server.component.abstractselect;
17
18 import org.junit.Before;
19 import org.junit.Test;
20
21 import com.vaadin.server.ThemeResource;
22 import com.vaadin.tests.design.DeclarativeTestBase;
23 import com.vaadin.ui.OptionGroup;
24
25 public class OptionGroupDeclarativeTests extends
26         DeclarativeTestBase<OptionGroup> {
27
28     private OptionGroup og;
29
30     @Before
31     public void init() {
32         og = new OptionGroup();
33     }
34
35     @Test
36     public void testBasicSyntax() {
37
38         String expected = "<vaadin-option-group />";
39         testReadWrite(expected);
40
41     }
42
43     @Test
44     public void testOptionSyntax() {
45
46         og.addItems("foo", "bar", "baz", "bang");
47
48         //@formatter:off
49         String expected = 
50                 "<vaadin-option-group>"
51                 + "<option>foo</option>"
52                 + "<option>bar</option>"
53                 + "<option>baz</option>"
54                 + "<option>bang</option>"
55                 + "</vaadin-option-group>";
56         //@formatter:on
57
58         testReadWrite(expected);
59
60     }
61
62     @Test
63     public void testDisabledOptionSyntax() {
64
65         og.addItems("foo", "bar", "baz", "bang");
66         og.setItemEnabled("baz", false);
67
68         //@formatter:off
69         String expected = 
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>";
76         //@formatter:on
77
78         testReadWrite(expected);
79
80     }
81
82     @Test
83     public void testIconSyntax() {
84
85         og.addItems("foo", "bar", "baz", "bang");
86         og.setItemIcon("bar", new ThemeResource("foobar.png"));
87
88         //@formatter:off
89         String expected = 
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>";
96         //@formatter:on
97
98         testReadWrite(expected);
99
100     }
101
102     @Test
103     public void testHTMLCaption() {
104
105         og.addItems("foo", "bar", "baz", "bang");
106
107         og.setHtmlContentAllowed(true);
108
109         og.setItemCaption("foo", "<b>True</b>");
110         og.setItemCaption("bar", "<font color='red'>False</font>");
111
112         //@formatter:off
113         String expected = 
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>";
120         //@formatter:on
121
122         testReadWrite(expected);
123     }
124
125     @Test
126     public void testPlaintextCaption() {
127
128         og.addItems("foo", "bar", "baz", "bang");
129
130         og.setItemCaption("foo", "<b>True</b>");
131         og.setItemCaption("bar", "<font color=\"red\">False</font>");
132
133         //@formatter:off
134         String expected =
135                 "<vaadin-option-group>"
136                 + "<option item-id=\"foo\">&lt;b&gt;True&lt;/b&gt;</option>"
137                 + "<option item-id=\"bar\">&lt;font color=\"red\"&gt;False&lt;/font&gt;</option>"
138                 + "<option>baz</option>"
139                 + "<option>bang</option>"
140                 + "</vaadin-option-group>";
141         //@formatter:on
142
143         testReadWrite(expected);
144     }
145
146     private void testReadWrite(String design) {
147         testWrite(design, og, true);
148         testRead(design, og);
149     }
150
151     @Override
152     public OptionGroup testRead(String design, OptionGroup expected) {
153
154         OptionGroup read = super.testRead(design, expected);
155         testWrite(design, read, true);
156
157         return read;
158     }
159
160 }