Skip to content

Commit

Permalink
refactor 'select all/clear all selections' methods out of GridBar, in…
Browse files Browse the repository at this point in the history
…to Grid (#1740)
  • Loading branch information
labkey-chrisj authored Dec 5, 2023
1 parent a82f477 commit 527655b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 81 deletions.
44 changes: 0 additions & 44 deletions src/org/labkey/test/components/ui/grids/GridBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.Assert;
import org.labkey.test.BootstrapLocators;
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;
Expand All @@ -28,7 +27,6 @@
import java.util.List;
import java.util.Map;

import static org.labkey.test.BaseWebDriverTest.WAIT_FOR_JAVASCRIPT;
import static org.labkey.test.WebDriverWrapper.sleep;

/**
Expand Down Expand Up @@ -166,48 +164,6 @@ public QueryGrid clickPrevious()
return _queryGrid;
}

/**
* Click the 'Select All' button in the grid bar.
*
* @return This grid bar.
*/
public GridBar selectAllRows()
{
Locator selectBtn = Locator.xpath("//button[contains(text(), 'Select all')]"); // Select all n
Locator selectedText = Locator.xpath("//span[@class='QueryGrid-right-spacing' and normalize-space(contains(text(), 'selected'))]"); // n of n
Locator allSelected = Locator.xpath("//span[contains(text(), 'All ')]"); // All n selected
WebElement btn = selectBtn.waitForElement(_queryGrid, 5_000);
btn.click();

WebDriverWrapper.waitFor(() -> allSelected.findOptionalElement(this).isPresent() ||
selectBtn.findOptionalElement(this).isEmpty() &&
selectedText.findOptionalElement(this).isPresent() ,
WAIT_FOR_JAVASCRIPT);

return this;
}

/**
* Click the 'Clear All' button in the grid bar.
* @return This grid bar.
*/
public GridBar clearAllSelections()
{
// Clear button can have text values of 'Clear', 'Clear both' or 'Clear all ' so just look for clear.
Locator clearBtn = Locator.xpath("//button[contains(text(), 'Clear')]");

if(clearBtn.findOptionalElement(this).isPresent())
{
WebElement btn = clearBtn.waitForElement(this, 5_000);
btn.click();

WebDriverWrapper.waitFor(() -> clearBtn.findOptionalElement(this).isEmpty(),
WAIT_FOR_JAVASCRIPT);
}

return this;
}

/**
* Click a button on the grid bar with the given text.
* @param buttonCaption Button caption.
Expand Down
49 changes: 12 additions & 37 deletions src/org/labkey/test/components/ui/grids/QueryGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,26 +292,18 @@ public boolean hasSelectAllButton()
*/
public QueryGrid selectAllRows()
{
if (isGridPanel())
WebElement selectAllBtn = elementCache().selectAllBtnLoc.findWhenNeeded(elementCache());
if (selectAllBtn.isDisplayed())
{
WebElement selectAllBtn = elementCache().selectAllBtnLoc.findWhenNeeded(elementCache());
if (selectAllBtn.isDisplayed())
{
doAndWaitForUpdate(selectAllBtn::click);
}
else
{
ReactCheckBox selectAll = selectAllBox();
if (selectAll.isIndeterminate() || !selectAll.isChecked())
{
doAndWaitForUpdate(() -> selectAllOnPage(true, null));
}
}
doAndWaitForUpdate(selectAllBtn::click);
}
else
{
doAndWaitForUpdate(() ->
getGridBar().selectAllRows());
ReactCheckBox selectAll = selectAllBox();
if (selectAll.isIndeterminate() || !selectAll.isChecked())
{
doAndWaitForUpdate(() -> selectAllOnPage(true, null));
}
}

return this;
Expand All @@ -334,22 +326,14 @@ public QueryGrid clearAllSelections()
{
if(hasItemsSelected())
{
if (isGridPanel())
WebElement clearBtn = elementCache().clearBtnLoc.findWhenNeeded(elementCache());
if (clearBtn.isDisplayed())
{
WebElement clearBtn = elementCache().clearBtnLoc.findWhenNeeded(elementCache());
if (clearBtn.isDisplayed())
{
doAndWaitForUpdate(clearBtn::click);
}
else
{
doAndWaitForUpdate(() -> selectAllOnPage(false));
}
doAndWaitForUpdate(clearBtn::click);
}
else
{
doAndWaitForUpdate(() ->
getGridBar().clearAllSelections());
doAndWaitForUpdate(() -> selectAllOnPage(false));
}
}

Expand Down Expand Up @@ -708,15 +692,6 @@ public void closeChart()
elementCache().closeButton.click();
}

/**
* possible this is either a GridPanel, or a QueryGridPanel (QGP is to be deprecated).
* use this to test which one so we can fork behavior until QGP is gone
*/
private boolean isGridPanel()
{
return elementCache().selectionStatusContainerLoc.existsIn(elementCache());
}

@Override
protected ElementCache newElementCache()
{
Expand Down

0 comments on commit 527655b

Please sign in to comment.