Skip to content

Commit

Permalink
Navigation Menus: don't use DropdownButton (#1824)
Browse files Browse the repository at this point in the history
* Update AppsMenu to account for DOM changes
* Update ProductMenu to account for DOM changes
* Update ServerNotificationsMenu to account for DOM changes
  • Loading branch information
labkey-alan authored Feb 14, 2024
1 parent ee5de5c commit 1f86123
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/org/labkey/test/components/ui/navigation/NavBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public String getUserAvatarSource()
*/
public ServerNotificationMenu getNotificationMenu()
{
return ServerNotificationMenu.finder(getDriver()).find(this);
return elementCache().notificationsMenu;
}

public ProductMenu getProductMenu()
Expand Down Expand Up @@ -121,5 +121,6 @@ protected abstract class ElementCache extends Component<ElementCache>.ElementCac
public Input searchBox = Input.Input(Locator.tagWithClass("input", "navbar__search-input"), getDriver()).findWhenNeeded(this);
public MultiMenu searchMenu = new MultiMenu.MultiMenuFinder(getDriver()).withButtonClass("navbar__find-and-search-button").findWhenNeeded(this);
public final ProductMenu productMenu = ProductMenu.finder(getDriver()).timeout(1000).findWhenNeeded(this);
public final ServerNotificationMenu notificationsMenu = ServerNotificationMenu.finder(getDriver()).timeout(1000).findWhenNeeded(this);
}
}
68 changes: 45 additions & 23 deletions src/org/labkey/test/components/ui/navigation/ProductMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import org.labkey.test.BootstrapLocators;
import org.labkey.test.Locator;
import org.labkey.test.components.react.BaseBootstrapMenu;
import org.labkey.test.components.react.MultiMenu;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.Component;
import org.labkey.test.components.WebDriverComponent;
import org.labkey.test.util.TestLogger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -19,23 +20,37 @@
import java.util.Map;
import java.util.stream.Collectors;

public class ProductMenu extends BaseBootstrapMenu
public class ProductMenu extends WebDriverComponent<ProductMenu.ElementCache>
{
private final WebElement _componentElement;
private final WebDriver _driver;

protected ProductMenu(WebElement element, WebDriver driver)
{
super(element, driver);
_componentElement = element;
_driver = driver;
}

public static SimpleWebDriverComponentFinder<ProductMenu> finder(WebDriver driver)
{
return new MultiMenu.MultiMenuFinder(driver).withButtonId("product-menu").wrap(ProductMenu::new);
return new SimpleWebDriverComponentFinder<>(driver, rootLocator, ProductMenu::new);
}

@Override
protected WebDriver getDriver()
{
return _driver;
}

@Override
public WebElement getComponentElement()
{
return _componentElement;
}

protected boolean isExpanded()
{
boolean ariaExpanded = super.isExpanded();
boolean ariaExpanded = "true".equals(elementCache().toggle.getAttribute("aria-expanded"));
boolean menuContentDisplayed = elementCache().menuContent.isDisplayed();
TestLogger.debug(String.format("Product menu expansion state: aria-expanded is %b, menuContentDisplayed is %b.",
ariaExpanded, menuContentDisplayed));
Expand All @@ -44,6 +59,23 @@ protected boolean isExpanded()
ExpectedConditions.invisibilityOfAllElements(BootstrapLocators.loadingSpinner.findElements(this)).apply(getDriver());
}

public void expand()
{
if (!isExpanded())
{
elementCache().toggle.click();
WebDriverWrapper.waitFor(this::isExpanded, "AppsMenu did not expand as expected", WebDriverWrapper.WAIT_FOR_JAVASCRIPT);
}
}

public void collapse()
{
if (isExpanded())
{
elementCache().toggle.click();
}
}

public List<String> getMenuSectionHeaders()
{
expand();
Expand Down Expand Up @@ -138,38 +170,28 @@ public int getAdministrationIconCount()

public String getButtonTitle()
{
WebElement buttonTitle = Locator.tagWithId("button", "product-menu")
.child(Locator.tagWithClass("div", "title")).findElement(this);
WebElement buttonTitle = elementCache().toggle.findElement(Locator.byClass("title"));
return buttonTitle.getText();
}

public String getButtonSubtitle()
{
WebElement buttonSubtitle = Locator.tagWithId("button", "product-menu")
.child(Locator.tagWithClass("div", "subtitle")).findElement(this);
WebElement buttonSubtitle = elementCache().toggle.findElement(Locator.byClass("subtitle"));
return buttonSubtitle.getText();
}

@Override
protected Locator getToggleLocator()
{
return Locator.tagWithId("button", "product-menu");
}

@Override
protected ElementCache elementCache()
{
return (ElementCache) super.elementCache();
}

@Override
protected ElementCache newElementCache()
{
return new ElementCache();
}

protected class ElementCache extends BaseBootstrapMenu.ElementCache
static Locator rootLocator = Locator.byClass("product-menu");

protected class ElementCache extends Component<?>.ElementCache
{
private final WebElement rootElement = rootLocator.findElement(getDriver());
private final WebElement toggle = Locator.byClass("product-menu-button").findElement(rootElement);
private final WebElement menuContent = Locator.tagWithClass("div", "product-menu-content").refindWhenNeeded(this);
private final WebElement sectionContent = Locator.tagWithClass("div", "sections-content").refindWhenNeeded(menuContent);

Expand Down
91 changes: 74 additions & 17 deletions src/org/labkey/test/components/ui/navigation/apps/AppsMenu.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,66 @@
package org.labkey.test.components.ui.navigation.apps;

import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.Component;
import org.labkey.test.components.WebDriverComponent;
import org.labkey.test.components.html.BootstrapMenu;
import org.labkey.test.components.react.BaseBootstrapMenu;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.Optional;

/**
* Wraps the expand/collapse toggle piece of the Apps menu in Biologics and SampleManager.
* In LKS views, LKAppsMenu is the analog of this component
*/
public class AppsMenu extends BaseBootstrapMenu
public class AppsMenu extends WebDriverComponent<AppsMenu.ElementCache>
{
private final WebElement _componentElement;
private final WebDriver _driver;

protected AppsMenu(WebElement element, WebDriver driver)
{
super(element, driver);
_componentElement = element;
_driver = driver;
}

@Override
protected WebDriver getDriver()
{
return _driver;
}

@Override
public WebElement getComponentElement()
{
return _componentElement;
}

protected boolean isExpanded()
{
return "true".equals(elementCache().toggle.getAttribute("aria-expanded"));
}

protected boolean isLoaded()
{
return elementCache().getList().isPresent();
}

public void expand()
{
if (!isExpanded())
{
elementCache().toggle.click();
WebDriverWrapper.waitFor(this::isLoaded, "AppsMenu did not expand as expected", WebDriverWrapper.WAIT_FOR_JAVASCRIPT);
}
}

public void collapse()
{
if (isExpanded())
{
elementCache().toggle.click();
}
}

/**
Expand All @@ -26,6 +70,7 @@ protected AppsMenu(WebElement element, WebDriver driver)
public ProductsNavContainer showProductsPanel()
{
expand();

return new ProductsNavContainer.ProductNavContainerFinder(getDriver()).withTitle("Applications")
.waitFor();
}
Expand All @@ -43,26 +88,38 @@ public void navigateTo(ProductsNavContainer.Product product, String node)
.clickItem(node);
}

public void navigateToLabKey(String project)
{
showProductsPanel()
.clickLabkey()
.clickProject(project);
}

public static Locator rootLocator = Locator.XPathLocator.union(
Locator.byClass("product-navigation-menu"), // Bio/FM/SM
Locator.id("headerProductDropdown")); // LKS

@Override
protected Locator getToggleLocator()
protected AppsMenu.ElementCache newElementCache()
{
return BootstrapMenu.Locators.dropdownToggle();
return new AppsMenu.ElementCache();
}

protected class ElementCache extends Component<?>.ElementCache
{
public final WebElement rootElement = rootLocator.findWhenNeeded(getDriver());

private final Locator _toggleLocator = Locator.XPathLocator.union(
Locator.byClass("navbar-menu-button"), // Bio/FM/SM
Locator.byClass("dropdown-toggle") // LKS
);
public final WebElement toggle = _toggleLocator.findWhenNeeded(rootElement);

public Optional<WebElement> getList()
{
return Locator.byClass("product-navigation-listing").findOptionalElement(rootElement);
}
}

public static class AppsMenuFinder extends WebDriverComponent.WebDriverComponentFinder<AppsMenu, AppsMenuFinder>
{
private Locator _locator = Locator.XPathLocator.union(
Locator.id("product-navigation-button").parent(), //lksm/bio
Locator.id("headerProductDropdown")); //lks
private final Locator _locator = Locator.XPathLocator.union(
Locator.byClass("product-navigation-menu"), // Bio/FM/SM
Locator.id("headerProductDropdown") // LKS
);

public AppsMenuFinder(WebDriver driver)
{
Expand All @@ -72,7 +129,7 @@ public AppsMenuFinder(WebDriver driver)
@Override
protected Locator locator()
{
return _locator;
return AppsMenu.rootLocator;
}

@Override
Expand Down
Loading

0 comments on commit 1f86123

Please sign in to comment.