Skip to content

Commit

Permalink
await and verify paste contents in the grid
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-chrisj committed Feb 22, 2024
1 parent de100fe commit 4f32942
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/org/labkey/test/components/ui/grids/EditableGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.TimeZone;
import java.util.stream.Collectors;

import static org.awaitility.Awaitility.await;
import static org.labkey.test.BaseWebDriverTest.WAIT_FOR_JAVASCRIPT;
import static org.labkey.test.WebDriverWrapper.waitFor;
import static org.labkey.test.util.TestLogger.log;
Expand Down Expand Up @@ -574,15 +575,22 @@ public List<String> getFilteredDropdownListForCell(int row, String columnName, @
return lookupSelect.getOptions();
}


public EditableGrid pasteFromCell(int row, String columnName, String pasteText)
{
return pasteFromCell(row, columnName, pasteText, true);
}

/**
* Pastes delimited text to the grid, from a single target. The component is clever enough to target
* text into cells based on text delimiters; thus we can paste a square of data into the grid.
* @param row index of the target cell
* @param columnName column of the target cell
* @param pasteText tab-delimited or csv or excel data
* @param validate whether to await/confirm the presence of pasted text before resuming
* @return A Reference to this editableGrid object.
*/
public EditableGrid pasteFromCell(int row, String columnName, String pasteText)
public EditableGrid pasteFromCell(int row, String columnName, String pasteText, boolean validate)
{
int initialRowCount = getRowCount();
WebElement gridCell = getCell(row, columnName);
Expand All @@ -595,9 +603,28 @@ public EditableGrid pasteFromCell(int row, String columnName, String pasteText)
// ... or for a second and a half
WebDriverWrapper.waitFor(()-> (getRowCount() > initialRowCount || !indexValue.equals(gridCell.getText())) &&
isInSelection(gridCell), 1500);
if (validate)
waitForPasteContent(pasteText);

return this;
}

public void waitForPasteContent(String pasteContent)
{
var contentParts = pasteContent.replace("\n", "\t").split("\t");
await().atMost(Duration.ofSeconds(2))
.untilAsserted(()-> Assertions.assertThat(getSelectionCellTexts())
.contains(contentParts));
}

// captures the texts of any cells currently in selection
public List<String> getSelectionCellTexts()
{
var cells = Locator.tagWithClass("div", "cellular-display")
.withAttributeContaining("class","cell-selection").findElements(this);
return getWrapper().getTexts(cells);
}

/**
* Pastes a single value into as many cells as are selected, or supports pasting a square shaped blob of data
* of the same shape as the prescribed selection. If a single value is supplied, that value will be put into
Expand Down

0 comments on commit 4f32942

Please sign in to comment.