|
66 | 66 | public abstract class ChosenIT { |
67 | 67 | private static final String ROOT = "http://localhost:" + System.getProperty("testPort"); |
68 | 68 | private static final int TIME_OUT_IN_SECONDS = 20; |
| 69 | + private static final String CHOSEN_XPATH = "//div[@id='chozen_container__0_chzn']"; |
69 | 70 |
|
70 | 71 | protected final WebDriver webDriver = new ChromeDriver(); |
71 | 72 |
|
@@ -106,6 +107,22 @@ public void allowSingleDeselect() { |
106 | 107 |
|
107 | 108 | // Then |
108 | 109 | assertThat(getSelectedOptionText()).isEqualTo(AllowSingleDeselect.PLACEHOLDER); |
| 110 | + assertThat(getChosen().findElements(By.tagName("abbr"))).isEmpty(); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Goal: ensure allowSingleDeselect shows the X/cross when there is a value. |
| 115 | + */ |
| 116 | + @Test |
| 117 | + public void allowSingleDeselect_visibleOnSelection() { |
| 118 | + // Given |
| 119 | + loadTestCase(new AllowSingleDeselect()); |
| 120 | + |
| 121 | + // When |
| 122 | + clickOption(CADILLAC, RENDERER); |
| 123 | + |
| 124 | + // Then |
| 125 | + assertThat(getChosen().findElements(By.tagName("abbr"))).isNotEmpty(); |
109 | 126 | } |
110 | 127 |
|
111 | 128 | /** |
@@ -414,6 +431,28 @@ public String apply(WebElement element) { |
414 | 431 | }); |
415 | 432 | } |
416 | 433 |
|
| 434 | + private WebElement getChosen() { |
| 435 | + return webDriverWait().until(presenceOfElementLocated(By.xpath(CHOSEN_XPATH))); |
| 436 | + } |
| 437 | + |
| 438 | + private List<WebElement> getSelectedOptions() { |
| 439 | + String xpath = CHOSEN_XPATH + "//span"; |
| 440 | + |
| 441 | + List<WebElement> options = webDriverWait().until(presenceOfAllElementsLocatedBy(By.xpath(xpath))); |
| 442 | + return Lists.transform(options, new Function<WebElement, WebElement>() { |
| 443 | + @Override |
| 444 | + public WebElement apply(WebElement element) { |
| 445 | + return element; |
| 446 | + } |
| 447 | + }); |
| 448 | + } |
| 449 | + |
| 450 | + private WebElement getSelectedOption() { |
| 451 | + List<WebElement> selectedOption = getSelectedOptions(); |
| 452 | + |
| 453 | + return selectedOption.isEmpty() ? null : selectedOption.get(0); |
| 454 | + } |
| 455 | + |
417 | 456 | protected boolean isMobileChosenComponent() { |
418 | 457 | List<WebElement> multiContainer = webDriver.findElements( |
419 | 458 | By.className("com-arcbees-chosen-client-resources-ChosenCss-chzn-mobile-container")); |
|
0 commit comments