7
7
import com .vaadin .flow .component .orderedlayout .testbench .VerticalLayoutElement ;
8
8
import com .vaadin .testbench .TestBenchElement ;
9
9
import org .junit .Assert ;
10
+ import org .junit .Before ;
10
11
import org .junit .Test ;
11
12
import org .openqa .selenium .By ;
12
13
import org .openqa .selenium .NoSuchElementException ;
19
20
20
21
public class ToggleButtonGroupIT extends AbstractViewTest {
21
22
23
+ @ Before
24
+ public void setup () throws Exception {
25
+ super .setup ();
26
+ waitForElementPresent (By .ById .id ("group120" ));
27
+ }
28
+
22
29
@ Test
23
30
public void group_withLabelAddedToView_groupIsRendered_labelIsRendered () {
24
31
CustomFieldElement group10 = $ (CustomFieldElement .class ).id ("group10" );
@@ -33,6 +40,8 @@ public void registeredValueChangeListener_IsCalledAccordingly() {
33
40
LabelElement selectedValueLabel = $ (LabelElement .class ).id ("group10-selected-value" );
34
41
Assert .assertEquals ("" , selectedValueLabel .getText ());
35
42
43
+ CustomFieldElement group10 = $ (CustomFieldElement .class ).id ("group10" );
44
+ group10 .scrollIntoView ();
36
45
List <WebElement > groupButtons = getGroupButtons ("group10" );
37
46
38
47
WebElement pastaButton = groupButtons .get (0 );
@@ -59,6 +68,8 @@ public void registeredValueChangeListener_IsCalledAccordingly() {
59
68
@ Test
60
69
public void toggleableGroup_clearsSelection_whenSelectedOptionReClicked () {
61
70
LabelElement selectedValueLabel = $ (LabelElement .class ).id ("group15-selected-value" );
71
+ CustomFieldElement group15 = $ (CustomFieldElement .class ).id ("group15" );
72
+ group15 .scrollIntoView ();
62
73
63
74
WebElement burgerButton = getGroupButtons ("group15" ).get (2 );
64
75
burgerButton .click ();
@@ -81,6 +92,8 @@ public void toggleableGroup_clearsSelection_whenSelectedOptionReClicked() {
81
92
@ Test
82
93
public void notToggleableGroup_doesNotClearSelection_whenSelectedOptionReClicked () {
83
94
LabelElement selectedValueLabel = $ (LabelElement .class ).id ("group10-selected-value" );
95
+ CustomFieldElement group10 = $ (CustomFieldElement .class ).id ("group10" );
96
+ group10 .scrollIntoView ();
84
97
85
98
WebElement burgerButton = getGroupButtons ("group10" ).get (2 );
86
99
burgerButton .click ();
@@ -100,6 +113,8 @@ public void notToggleableGroup_doesNotClearSelection_whenSelectedOptionReClicked
100
113
public void notToggleableGroup_valueCanBeCleared_Programmatically () {
101
114
LabelElement selectedValueLabel = $ (LabelElement .class ).id ("group10-selected-value" );
102
115
Assert .assertEquals ("" , selectedValueLabel .getText ());
116
+ CustomFieldElement group10 = $ (CustomFieldElement .class ).id ("group10" );
117
+ group10 .scrollIntoView ();
103
118
104
119
WebElement pastaButton = getGroupButtons ("group10" ).get (0 );
105
120
pastaButton .click ();
@@ -116,7 +131,7 @@ public void notToggleableGroup_valueCanBeCleared_Programmatically() {
116
131
}
117
132
118
133
@ Test
119
- public void widthFullGroup_hasWith100PercentStyle () {
134
+ public void widthFullGroup_hasWidth100PercentStyle () {
120
135
CustomFieldElement group20 = $ (CustomFieldElement .class ).id ("group20" );
121
136
Assert .assertTrue (group20 .getAttribute ("style" ).contains ("width: 100%" ));
122
137
@@ -129,6 +144,7 @@ public void widthFullGroup_hasWith100PercentStyle() {
129
144
@ Test
130
145
public void group_withTooltip_tooltipOverlayIsShownWhenFocused () {
131
146
CustomFieldElement group20 = $ (CustomFieldElement .class ).id ("group20" );
147
+ group20 .scrollIntoView ();
132
148
hoverOn (group20 );
133
149
Assert .assertTrue ("Tooltip for group with id 'group20' should be visible." , isTooltipVisibleFor (group20 ));
134
150
}
@@ -192,6 +208,8 @@ public void group_withItemTooltipTextGenerator_showsCorrespondentTooltips() {
192
208
193
209
@ Test
194
210
public void group_withEnabledSetToFalse_hasAllButtonsDisabled () {
211
+ CustomFieldElement group60 = $ (CustomFieldElement .class ).id ("group60" );
212
+ group60 .scrollIntoView ();
195
213
List <WebElement > buttons = getGroupButtons ("group60" );
196
214
buttons .forEach (button -> Assert .assertFalse (isButtonEnabled (button )));
197
215
}
@@ -266,6 +284,26 @@ public void group_withVerticalOrientation_rendersItemsInVerticalLayout() {
266
284
() -> group100 .findElement (By .tagName ("vaadin-horizontal-layout" )));
267
285
}
268
286
287
+ // https://github.com/taefi/toggle-button-group/issues/8
288
+ @ Test
289
+ public void customizingGroupAfterSetValue_theStylesRemainInTact () {
290
+ List <WebElement > buttons = getGroupButtons ("group120" );
291
+ // customization after setting the value should not affect the selected item's style:
292
+ Assert .assertEquals ("primary" , buttons .get (1 ).getAttribute ("theme" ));
293
+ // customizing using setItemTooltipTextGenerator still works:
294
+ hoverOn (buttons .get (0 ));
295
+ Assert .assertEquals ("Answer is yes" ,
296
+ getTooltipFor (buttons .get (0 ))
297
+ .map (TestBenchElement ::getText )
298
+ .orElse ("" ));
299
+
300
+ hoverOn (buttons .get (1 ));
301
+ Assert .assertEquals ("Answer is no" ,
302
+ getTooltipFor (buttons .get (1 ))
303
+ .map (TestBenchElement ::getText )
304
+ .orElse ("" ));
305
+ }
306
+
269
307
private List <WebElement > getGroupButtons (String groupId ) {
270
308
CustomFieldElement group = $ (CustomFieldElement .class ).id (groupId );
271
309
return group .getWrappedElement ().findElements (By .tagName ("vaadin-button" ));
0 commit comments