Skip to content

Commit 7df39a3

Browse files
committed
BaseReactSelect: support for "Add New"
1 parent cb2d092 commit 7df39a3

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/org/labkey/test/components/react/BaseReactSelect.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,39 @@ public String getName()
422422
return elementCache().input.getAttribute("name");
423423
}
424424

425+
/**
426+
* Determines whether the "Add New" menu footer is present at the bottom of the select's menu area. This item is
427+
* rendered only when the underlying schema/query is registered and configured to support adding new values.
428+
*
429+
* @return true if the "Add New" menu item is visible, otherwise false
430+
*/
431+
public boolean isAddNewVisible()
432+
{
433+
open();
434+
WebElement addNew = Locators.addEntitiesFooter.findElementOrNull(getComponentElement());
435+
return addNew != null && addNew.isDisplayed();
436+
}
437+
438+
/**
439+
* Clicks the "Add New" menu item at the bottom of the select's menu area. The menu is opened first if it is not
440+
* already expanded. This intentionally returns void: the resulting UI varies by schema/query, so the caller is
441+
* responsible for constructing and interacting with whatever the click produces.
442+
*/
443+
public void clickAddNew()
444+
{
445+
open();
446+
WebElement addNew = Locators.addEntitiesFooter.waitForElement(getComponentElement(), WAIT_FOR_JAVASCRIPT);
447+
try
448+
{
449+
addNew.click();
450+
}
451+
catch (WebDriverException wde) // handle the "another element would receive the click" situation
452+
{
453+
getWrapper().scrollIntoView(addNew);
454+
getWrapper().fireEvent(addNew, WebDriverWrapper.SeleniumEvent.click);
455+
}
456+
}
457+
425458
protected T scrollIntoView()
426459
{
427460
try
@@ -515,6 +548,7 @@ private Locators()
515548
}
516549

517550
public static final Locator.XPathLocator option = Locator.tagWithClass("div", "select-input__option");
551+
public static final Locator.XPathLocator addEntitiesFooter = Locator.tagWithClass("div", "add-entities-footer");
518552
public static final Locator placeholder = Locator.tagWithClass("div", "select-input__placeholder");
519553
public static final Locator clear = Locator.tagWithClass("div","select-input__clear-indicator");
520554
public static final Locator arrow = Locator.tagWithClass("div","select-input__dropdown-indicator");

0 commit comments

Comments
 (0)