Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/org/labkey/test/components/ui/Pager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.labkey.test.components.ui;

import org.labkey.test.Locator;
import org.labkey.test.WebDriverWrapper;
import org.labkey.test.components.Component;
import org.labkey.test.components.UpdatingComponent;
import org.labkey.test.components.WebDriverComponent;
Expand Down Expand Up @@ -67,6 +68,68 @@ public MultiMenu getDropDownMenu()
return elementCache().jumpToDropdown;
}

/**
* The "Last Page" jump is always present; it is disabled only when already on the last page of an exact count.
* While the count is capped it stays enabled and lands on the true last row (resolving the exact count first).
* @return true if the pager's "Last Page" jump is present and enabled
*/
public boolean isLastPageAvailable()
{
if (!isLastPageOptionPresent())
return false;

MultiMenu menu = elementCache().jumpToDropdown;
try
{
return !menu.isMenuItemDisabled("Last Page");
}
finally
{
menu.collapse();
}
}

/**
* Unlike {@link #isLastPageAvailable()}, this ignores whether the item is enabled; a present-but-disabled
* "Last Page" (i.e. already on the last page) still counts as present.
* @return true if the pager's jump menu contains a "Last Page" item
*/
public boolean isLastPageOptionPresent()
{
return elementCache().jumpToDropdown.getMenuText().contains("Last Page");
}

// The "Count All Rows" jump appears only while the row count is capped; it computes the exact total on demand.
private static final String COUNT_ALL_ROWS_OPTION = "Count All Rows";

/**
* @return true if the pager's jump menu offers the "Count All Rows" action, i.e. the row count is currently capped
*/
public boolean isCountAllRowsAvailable()
{
MultiMenu menu = elementCache().jumpToDropdown;
try
{
return menu.getMenuText().contains(COUNT_ALL_ROWS_OPTION);
}
finally
{
menu.collapse();
}
}

public Pager countAllRows()
{
// Count All Rows re-fires only the total count; rows aren't reloaded, so there's no grid update to wait on.
// Wait for the exact total to render: the summary shows "... of N" (no capped "+"). The total is briefly hidden
// behind a spinner while counting, so require the " of " to be back before checking that the "+" is gone.
elementCache().jumpToDropdown.clickSubMenu(false, COUNT_ALL_ROWS_OPTION);
WebDriverWrapper.waitFor(() -> summary().contains(" of ") && !summary().contains("+"),
"Exact count did not load", 30_000);

return this;
}

public int getCurrentPage() // only works on GridPanel
{
return Integer.parseInt(elementCache().currentPageButton.getText());
Expand Down
5 changes: 5 additions & 0 deletions src/org/labkey/test/components/ui/grids/GridBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public boolean isOnLastPage()
return !pager().isNextEnabled();
}

public boolean canJumpToLastPage()
{
return pager().isLastPageAvailable();
}

/**
* clicks the 'next' button on the pager associated with this grid and waits for the grid to update
*/
Expand Down
9 changes: 9 additions & 0 deletions src/org/labkey/test/components/ui/grids/QueryGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ public int getRecordCount()
return getGridBar().getRecordCount();
}

/**
* The "Last Page" jump is hidden when the total row count is capped, because the true last page is unknown.
* @return true if the grid can jump to its last page
*/
public boolean canJumpToLastPage()
{
return getGridBar().canJumpToLastPage();
}

public QueryGrid waitForRecordCount(int expectedCount)
{
return waitForRecordCount(expectedCount, WAIT_FOR_JAVASCRIPT);
Expand Down
Loading