Skip to content

Commit 2343ca6

Browse files
awaters1bartmoc
authored andcommitted
Added in a test case for whether the deselect X/cross is visible/hidden
when an option is selected/not-selected
1 parent 041307e commit 2343ca6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

integration-test/src/test/java/ChosenIT.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
public abstract class ChosenIT {
6767
private static final String ROOT = "http://localhost:" + System.getProperty("testPort");
6868
private static final int TIME_OUT_IN_SECONDS = 20;
69+
private static final String CHOSEN_XPATH = "//div[@id='chozen_container__0_chzn']";
6970

7071
protected final WebDriver webDriver = new ChromeDriver();
7172

@@ -106,6 +107,22 @@ public void allowSingleDeselect() {
106107

107108
// Then
108109
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();
109126
}
110127

111128
/**
@@ -414,6 +431,28 @@ public String apply(WebElement element) {
414431
});
415432
}
416433

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+
417456
protected boolean isMobileChosenComponent() {
418457
List<WebElement> multiContainer = webDriver.findElements(
419458
By.className("com-arcbees-chosen-client-resources-ChosenCss-chzn-mobile-container"));

0 commit comments

Comments
 (0)