1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.renderkit.renderer;
21
22 import org.apache.myfaces.tobago.component.RendererTypes;
23 import org.apache.myfaces.tobago.component.Tags;
24 import org.apache.myfaces.tobago.component.UILink;
25 import org.apache.myfaces.tobago.component.UISelectBooleanCheckbox;
26 import org.apache.myfaces.tobago.component.UISelectItem;
27 import org.apache.myfaces.tobago.component.UISelectManyCheckbox;
28 import org.apache.myfaces.tobago.component.UISelectOneRadio;
29 import org.apache.myfaces.tobago.component.UISeparator;
30 import org.apache.myfaces.tobago.util.ComponentUtils;
31 import org.junit.Assert;
32 import org.junit.jupiter.api.Test;
33
34 import java.io.IOException;
35
36 public class LinkRendererUnitTest extends RendererTestBase {
37
38 @Test
39 public void booleanInsideLink() throws IOException {
40 final UILink c = (UILink) ComponentUtils.createComponent(
41 facesContext, Tags.link.componentType(), RendererTypes.Link, "id");
42 c.setLabel("dropdown");
43
44 final UISelectBooleanCheckbox s = (UISelectBooleanCheckbox) ComponentUtils.createComponent(
45 facesContext, Tags.selectBooleanCheckbox.componentType(), RendererTypes.SelectBooleanCheckbox, "id");
46 s.setLabel("boolean");
47
48 c.getChildren().add(s);
49
50 c.encodeAll(facesContext);
51
52 Assert.assertEquals(loadHtml("renderer/link/booleanInsideLink.html"), formattedResult());
53 }
54
55 @Test
56 public void link() throws IOException {
57 final UILink c = (UILink) ComponentUtils.createComponent(
58 facesContext, Tags.link.componentType(), RendererTypes.Link, "id");
59 c.setLabel("label");
60 c.setLink("https://www.apache.org/");
61 c.encodeAll(facesContext);
62
63 Assert.assertEquals(loadHtml("renderer/link/link.html"), formattedResult());
64 }
65
66 @Test
67 public void manyInsideLink() throws IOException {
68 final UILink c = (UILink) ComponentUtils.createComponent(
69 facesContext, Tags.link.componentType(), RendererTypes.Link, "id");
70 c.setLabel("dropdown");
71
72 final UISelectManyCheckbox s = (UISelectManyCheckbox) ComponentUtils.createComponent(
73 facesContext, Tags.selectManyCheckbox.componentType(), RendererTypes.SelectManyCheckbox, "many");
74 s.setLabel("many");
75
76 c.getChildren().add(s);
77
78 final UISelectItem i1 = (UISelectItem) ComponentUtils.createComponent(
79 facesContext, Tags.selectItem.componentType(), null, "i1");
80 i1.setItemLabel("Stratocaster");
81 s.getChildren().add(i1);
82 final UISelectItem i2 = (UISelectItem) ComponentUtils.createComponent(
83 facesContext, Tags.selectItem.componentType(), null, "i2");
84 i2.setItemLabel("Telecaster");
85 s.getChildren().add(i2);
86
87 c.encodeAll(facesContext);
88
89 Assert.assertEquals(loadHtml("renderer/link/manyInsideLink.html"), formattedResult());
90 }
91
92 @Test
93 public void radioInsideLink() throws IOException {
94 final UILink c = (UILink) ComponentUtils.createComponent(
95 facesContext, Tags.link.componentType(), RendererTypes.Link, "id");
96 c.setLabel("dropdown");
97
98 final UISelectOneRadio s = (UISelectOneRadio) ComponentUtils.createComponent(
99 facesContext, Tags.selectOneRadio.componentType(), RendererTypes.SelectOneRadio, "radio");
100 s.setLabel("radio");
101
102 c.getChildren().add(s);
103
104 final UISelectItem i1 = (UISelectItem) ComponentUtils.createComponent(
105 facesContext, Tags.selectItem.componentType(), null, "i1");
106 i1.setItemLabel("Stratocaster");
107 s.getChildren().add(i1);
108 final UISelectItem i2 = (UISelectItem) ComponentUtils.createComponent(
109 facesContext, Tags.selectItem.componentType(), null, "i2");
110 i2.setItemLabel("Telecaster");
111 s.getChildren().add(i2);
112
113 c.encodeAll(facesContext);
114
115 Assert.assertEquals(loadHtml("renderer/link/radioInsideLink.html"), formattedResult());
116 }
117
118 @Test
119 public void separatorInsideLink() throws IOException {
120 final UILink c = (UILink) ComponentUtils.createComponent(
121 facesContext, Tags.link.componentType(), RendererTypes.Link, "id");
122 c.setLabel("dropdown");
123
124 final UILink l1 = (UILink) ComponentUtils.createComponent(
125 facesContext, Tags.link.componentType(), RendererTypes.Link, "link1");
126 l1.setLabel("Link 1");
127 l1.setLink("https://www.apache.org/");
128
129 final UISeparator s = (UISeparator) ComponentUtils.createComponent(
130 facesContext, Tags.separator.componentType(), RendererTypes.Separator, "separator");
131
132 final UILink l2 = (UILink) ComponentUtils.createComponent(
133 facesContext, Tags.link.componentType(), RendererTypes.Link, "link2");
134 l2.setLabel("Link 2");
135 l2.setLink("https://www.apache.org/");
136
137 c.getChildren().add(l1);
138 c.getChildren().add(s);
139 c.getChildren().add(l2);
140
141 c.encodeAll(facesContext);
142
143 Assert.assertEquals(loadHtml("renderer/link/separatorInsideLink.html"), formattedResult());
144 }
145
146 }