Skip to content

Commit

Permalink
ServerNotificationMenu: Fix to account for new DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-alan committed Feb 13, 2024
1 parent 5cf2047 commit d9a9ee4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.react.BaseBootstrapMenu;
import org.labkey.test.components.react.MultiMenu;
import org.labkey.test.components.Component;
import org.labkey.test.components.WebDriverComponent;
import org.labkey.test.components.ui.pipeline.ImportsPage;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
Expand All @@ -13,17 +13,32 @@
/**
* This covers a couple of components under component/notifications. Mostly ServerNotifications.tsx and ServerActivityList.tsx
*/
public class ServerNotificationMenu extends BaseBootstrapMenu
public class ServerNotificationMenu extends WebDriverComponent<ServerNotificationMenu.ElementCache>
{
private final WebElement _componentElement;
private final WebDriver _driver;

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

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

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

public static SimpleWebDriverComponentFinder<ServerNotificationMenu> finder(WebDriver driver)
{
return new MultiMenu.MultiMenuFinder(driver).withButtonId("server-notifications-button").wrap(ServerNotificationMenu::new);
return new SimpleWebDriverComponentFinder<>(driver, rootLocator, ServerNotificationMenu::new);
}

/**
Expand Down Expand Up @@ -105,6 +120,31 @@ public boolean isMarkAllVisible()
return elementCache().markAll().isDisplayed();
}

protected boolean isExpanded()
{
boolean ariaExpanded = "true".equals(elementCache().toggle.getAttribute("aria-expanded"));
boolean menuContentDisplayed = elementCache().menuContent.isDisplayed();

return ariaExpanded && menuContentDisplayed;
}

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();
}
}

/**
* Click the 'Mark all as read' link. This will cause the list to refresh, any references you have to a
* {@link ServerNotificationItem} will need to be reacquired.
Expand Down Expand Up @@ -136,11 +176,11 @@ private WebElement waitForNotificationList()

// Wait for the listing container to show up. The listing container is in the open menu, scope the search to that.
Locator notificationsContainerLocator = Locator.tagWithClass("div", "server-notifications-listing-container");
WebDriverWrapper.waitFor(()-> notificationsContainerLocator.refindWhenNeeded(elementCache().findOpenMenu()).isDisplayed(),
WebDriverWrapper.waitFor(()-> notificationsContainerLocator.refindWhenNeeded(elementCache().menuContent).isDisplayed(),
"List container did not render.", 500);

// Find again (lambda requires a final reference to the component).
WebElement listContainer = notificationsContainerLocator.refindWhenNeeded(elementCache().findOpenMenu());
WebElement listContainer = notificationsContainerLocator.refindWhenNeeded(elementCache().menuContent);

// It may be a moment before any notifications show up.
WebDriverWrapper.waitFor(()-> Locator.tagWithClass("ul", "server-notifications-listing")
Expand All @@ -158,7 +198,7 @@ private WebElement waitForNotificationList()

// Find the container again, don't return listContainer WebElement previously found. If the list was slow to
// update with the most recent notification the old reference will be stale.
return notificationsContainerLocator.waitForElement(elementCache().findOpenMenu(), 1_000);
return notificationsContainerLocator.waitForElement(elementCache().menuContent, 1_000);
}

/**
Expand Down Expand Up @@ -208,26 +248,18 @@ public String getNoNotificationsMessage()
}

@Override
protected Locator getToggleLocator()
protected ServerNotificationMenu.ElementCache newElementCache()
{
return Locator.tagWithId("button", "server-notifications-button");
return new ElementCache();
}

@Override
protected ElementCache elementCache()
{
return (ElementCache) super.elementCache();
}
public static final Locator rootLocator = Locator.byClass("server-notifications");

@Override
protected ElementCache newElementCache()
protected class ElementCache extends Component<?>.ElementCache
{
return new ElementCache();
}
public final WebElement menuContent = Locator.byClass("navbar-menu__content").refindWhenNeeded(this);

protected class ElementCache extends BaseBootstrapMenu.ElementCache
{
public final Locator notificationList = Locator.tagWithClass("ul", "server-notifications-listing");
public final WebElement toggle = Locator.byClass("navbar-menu-button").findWhenNeeded(this);

public final WebElement statusIcon()
{
Expand All @@ -236,14 +268,14 @@ public final WebElement statusIcon()

public final WebElement noNotificationsElement()
{
return Locator.tagWithClass("div", "server-notifications-footer").refindWhenNeeded(elementCache().findOpenMenu());
return Locator.tagWithClass("div", "server-notifications-footer").refindWhenNeeded(elementCache().menuContent);
}

public final WebElement markAll()
{
return Locator.tagWithClass("h3", "navbar-menu-header")
.child(Locator.tagWithClass("div", "server-notifications-link"))
.refindWhenNeeded(elementCache().findOpenMenu());
.refindWhenNeeded(elementCache().menuContent);
}

public final WebElement viewAllLink = Locator.tagWithText("div", "View all activity").refindWhenNeeded(this);
Expand Down

0 comments on commit d9a9ee4

Please sign in to comment.