Skip to content

Commit 5338702

Browse files
committed
test: implement integration tests
1 parent 38ff94c commit 5338702

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/test/java/com/flowingcode/vaadin/addons/chipfield/integration/IntegrationView.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,24 @@ private void testCallable(boolean arg) {
2525
}
2626
}
2727

28+
@ClientCallable
29+
private void allowAdditionalItems(boolean value) {
30+
field.setAllowAdditionalItems(value);
31+
}
32+
33+
@ClientCallable
34+
private void setFieldReadOnly(boolean value) {
35+
field.setReadOnly(value);
36+
}
37+
38+
@ClientCallable
39+
private void setFieldEnabled(boolean value) {
40+
field.setEnabled(value);
41+
}
42+
43+
@ClientCallable
44+
private void setValue(String... items) {
45+
field.setValue(Arrays.asList(items));
46+
}
47+
2848
}

src/test/java/com/flowingcode/vaadin/addons/chipfield/integration/ViewIT.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
import static org.junit.Assert.assertThrows;
55

66
import java.util.Arrays;
7+
import java.util.Collection;
78

9+
import org.hamcrest.Matcher;
810
import org.hamcrest.Matchers;
911
import org.junit.Test;
12+
import org.openqa.selenium.Keys;
1013

1114
public 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

Comments
 (0)