Skip to content

Commit ecbdfc3

Browse files
committed
test: add integration tests for #37
1 parent 3de4752 commit ecbdfc3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public void click(int index) {
4545
TestBenchElement chip = $("paper-chip").get(index);
4646
executeScript("arguments[0].root.querySelector('.chip').click()", chip);
4747
}
48+
49+
public String getInputValue() {
50+
return (String) executeScript("return arguments[0].$.paperInput.value", this);
51+
}
52+
4853
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.flowingcode.vaadin.addons.chipfield.integration;
2121

2222
import static org.hamcrest.MatcherAssert.assertThat;
23+
import static org.hamcrest.Matchers.isEmptyString;
2324
import static org.junit.Assert.assertThrows;
2425
import static org.junit.Assert.assertTrue;
2526

@@ -337,4 +338,31 @@ public void testFindItemByLabel() {
337338
"Additional item was not returned by findItemByLabel",
338339
$server.hasItemWithLabel(ADDITIONAL));
339340
}
341+
342+
/**
343+
* Test selection of existing item by pressing Enter when no newItemHandler is configured
344+
*
345+
* @See https://github.com/FlowingCode/ChipFieldAddon/issues/37
346+
*/
347+
@Test
348+
public void testEnterSelectsValueWithNoHandler() {
349+
chipfield.sendKeys(LOREM, Keys.ENTER);
350+
assertThat(chipfield.getInputValue(), isEmptyString());
351+
assertThat(chipfield.getValue(), isEqualTo(LOREM));
352+
assertThat($server.getValue(), isEqualTo(LOREM));
353+
}
354+
355+
/**
356+
* Test that pressing Enter doesn't clear the value when no newItemHandler is configured
357+
*
358+
* @See https://github.com/FlowingCode/ChipFieldAddon/issues/37
359+
*/
360+
@Test
361+
public void testEnterPreservesValueWhenNoHandler() {
362+
chipfield.sendKeys(ADDITIONAL, Keys.ENTER);
363+
assertThat(chipfield.getInputValue(), Matchers.equalTo(ADDITIONAL));
364+
assertThat(chipfield.getValue(), Matchers.empty());
365+
assertThat($server.getValue(), Matchers.empty());
366+
}
367+
340368
}

0 commit comments

Comments
 (0)