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