44import static org .junit .Assert .assertThrows ;
55
66import java .util .Arrays ;
7+ import java .util .Collection ;
78
9+ import org .hamcrest .Matcher ;
810import org .hamcrest .Matchers ;
911import org .junit .Test ;
12+ import org .openqa .selenium .Keys ;
1013
1114public class ViewIT extends AbstractChipfieldTest {
1215
16+ private static final String LOREM = "Lorem" ;
17+ private static final String IPSUM = "Ipsum" ;
18+ private static final String ADDITIONAL = "Additional" ;
19+
1320 @ Test
1421 public void testUpgradedToCustomElement () {
1522 ChipFieldElement chipfield = $ (ChipFieldElement .class ).first ();
@@ -28,10 +35,63 @@ public void testCallableFailure() {
2835 assertThrows (RuntimeException .class , () -> call ("testCallable" , false ));
2936 }
3037
38+ private Matcher <Collection <String >> isEqualTo (String ... values ) {
39+ return Matchers .equalTo (Arrays .asList (values ));
40+ }
41+
3142 @ Test
3243 public void testCallableFailure2 () {
3344 // test that the callable mechanism detect failures
3445 assertThrows (RuntimeException .class , () -> call ("testCallable" ));
3546 }
3647
48+ @ Test
49+ public void testSelectByText () {
50+ chipfield .selectByText (LOREM );
51+ assertThat (chipfield .getValue (), isEqualTo (LOREM ));
52+
53+ chipfield .selectByText (IPSUM );
54+ assertThat (chipfield .getValue (), isEqualTo (LOREM , IPSUM ));
55+
56+ chipfield .sendKeys (Keys .BACK_SPACE );
57+ assertThat (chipfield .getValue (), isEqualTo (LOREM ));
58+
59+ chipfield .sendKeys (Keys .BACK_SPACE );
60+ assertThat (chipfield .getValue (), Matchers .empty ());
61+ }
62+
63+
64+ @ Test
65+ public void testAdditionalItemEnabled () {
66+ call ("allowAdditionalItems" , true );
67+
68+ chipfield .sendKeys (ADDITIONAL , Keys .ENTER );
69+ assertThat (chipfield .getValue (), isEqualTo (ADDITIONAL ));
70+
71+ chipfield .sendKeys (LOREM , Keys .ENTER );
72+ assertThat (chipfield .getValue (), isEqualTo (ADDITIONAL , LOREM ));
73+ }
74+
75+ @ Test
76+ public void testAdditionalItemDisabled () {
77+ chipfield .sendKeys ("Additional" , Keys .ENTER );
78+ assertThat (chipfield .getValue (), Matchers .empty ());
79+ }
80+
81+ @ Test
82+ public void testReadOnly () {
83+
84+ chipfield .selectByText (LOREM );
85+ assertThat (chipfield .getValue (), isEqualTo (LOREM ));
86+
87+
88+ chipfield .sendKeys (Keys .BACK_SPACE );
89+ assertThat (chipfield .getValue (), isEqualTo (LOREM ));
90+
91+
92+ chipfield .sendKeys (ADDITIONAL , Keys .ENTER );
93+ assertThat (chipfield .getValue (), isEqualTo (LOREM ));
94+ }
95+
96+
3797}
0 commit comments