Skip to content

Commit

Permalink
DropdownSection (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-alan authored Feb 12, 2024
1 parent bde67e7 commit 4abfd88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static public Locator.XPathLocator buttonGroupWithId(String Id)

static public Locator.XPathLocator buttonGroupWithClass(String cls)
{
return Locator.tagWithClass("div", "dropdown").withChild(Locators.toggleAnchor().withClass(cls));
return Locator.tagWithClass("div", "dropdown").withClass(cls);
}
}

Expand Down
38 changes: 27 additions & 11 deletions src/org/labkey/test/components/react/MultiMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public void doMenuAction(@LoggedParam List<String> pathToAction)
{
expand();

WebElement menuList = getMenuList();

for (int i = 0; i < pathToAction.size(); i++)
{
Assert.assertFalse("Menu item not enabled.", isMenuItemDisabled(pathToAction.get(i)));
Expand All @@ -72,8 +70,8 @@ public void doMenuAction(@LoggedParam List<String> pathToAction)
if (i < pathToAction.size() - 1)
{
// Everything in the pathToAction should contain a sub menu except possibly the last item.
Assert.assertTrue("Item in menu path '" + pathToAction.get(i) + "' does not contain a sub-menu.", menuItem.getAttribute("class").contains("dropdown-submenu"));
if(!Locator.xpath("./i").findElement(menuItem).getAttribute("class").contains("fa-chevron-up"))
Assert.assertTrue("Item in menu path '" + pathToAction.get(i) + "' does not contain a sub-menu.", menuItem.getAttribute("class").contains("dropdown-section-toggle"));
if(!Locator.byClass("fa").findElement(menuItem).getAttribute("class").contains("fa-chevron-up"))
{
// This is a sub-menu item, but click it only if the sub-menu is not expanded.
menuItem.click();
Expand Down Expand Up @@ -156,11 +154,13 @@ private void expandAll()
for (WebElement menuItem : menuItems)
{
menuItem = Locator.xpath("..").findElement(menuItem); // Up a level
Optional<WebElement> expando = Locator.xpath("./i").withClass("fa-chevron-down").findOptionalElement(menuItem);
Optional<WebElement> expando = Locator.byClass("fa-chevron-down").findOptionalElement(menuItem);
if (expando.isPresent())
{
expando.get().click();
Locator.tagWithClass("ul", "well").waitForElement(menuItem, 1_000);
// Note: if we really do need to wait for the items to appear we can probably wait for elements with
// class "dropdown-section__menu-item", we'll want to track how many we already have and check that the
// number has increased, since nothing is nested, everything is siblings.
}
}
}
Expand Down Expand Up @@ -189,15 +189,31 @@ public List<String> getMenuText()
public List<String> getItemsUnderHeading(String heading)
{
expandAll();
boolean headingFound = false;
List<String> items = new ArrayList<>();
List<WebElement> listItems = Locator.tag("li").findElements(this);

for (WebElement item : listItems)
{
String className = item.getAttribute("class");
String text = item.getText().trim();

if (className.contains("dropdown-header") && text.equalsIgnoreCase(heading))
headingFound = true;

WebElement submenu = Locator.byClass("dropdown-header").withText(heading)
.followingSibling("li").withClass("dropdown-submenu").findElement(this);
List<WebElement> menuList = Locator.tagWithAttribute("a", "role", "menuitem").findElements(submenu);
List<String> menuText = getWrapper().getTexts(menuList);
// Once we've found our header we know that all dropdown-section__menu-item elements belong to the heading
// we are interested in
if (headingFound && className.contains("dropdown-section__menu-item"))
items.add(text);

// Once we hit a divider we're done looking at menu items related to the heading, so we can stop iterating
if (headingFound && className.contains("divider"))
break;
}

collapse();

return menuText;
return items;
}

public String getButtonText()
Expand Down

0 comments on commit 4abfd88

Please sign in to comment.