|
20 | 20 | package com.flowingcode.vaadin.addons.chipfield.integration; |
21 | 21 |
|
22 | 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | +import static org.hamcrest.Matchers.isEmptyString; |
23 | 24 | import static org.junit.Assert.assertThrows; |
24 | 25 | import static org.junit.Assert.assertTrue; |
25 | 26 |
|
@@ -337,4 +338,31 @@ public void testFindItemByLabel() { |
337 | 338 | "Additional item was not returned by findItemByLabel", |
338 | 339 | $server.hasItemWithLabel(ADDITIONAL)); |
339 | 340 | } |
| 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 | + |
340 | 368 | } |
0 commit comments