Skip to content
Merged
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
80 changes: 61 additions & 19 deletions src/org/labkey/test/tests/component/EditableGridTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.labkey.test.tests.component;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.labkey.remoteapi.CommandException;
import org.labkey.remoteapi.Connection;
import org.labkey.remoteapi.SimplePostCommand;
import org.labkey.remoteapi.query.InsertRowsCommand;
import org.labkey.test.BaseWebDriverTest;
import org.labkey.test.Locator;
Expand All @@ -21,7 +23,7 @@
import org.labkey.test.params.experiment.SampleTypeDefinition;
import org.labkey.test.params.list.IntListDefinition;
import org.labkey.test.params.list.ListDefinition;
import org.labkey.test.util.TextUtils;
import org.labkey.test.util.EscapeUtil;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -165,6 +167,41 @@ private void doSetup() throws Exception
.setFields(
ALL_FIELDS.stream().map(FieldInfo::getFieldDefinition).toList())
.create(connection, getProjectName());

for (String sampleType : List.of(EXTRAPOLATING_SAMPLE_TYPE, FILLING_SAMPLE_TYPE, PASTING_SAMPLE_TYPE, ALL_TYPE_SAMPLE_TYPE))
{
// Hide columns from editable grid so that test columns are in view
String metadataXml = """
<tables xmlns="http://labkey.org/data/xml">
<table tableName="%s" tableDbType="NOT_IN_DB">
<columns>
<column columnName="Name">
<shownInInsertView>false</shownInInsertView>
</column>
<column columnName="Alias">
<shownInInsertView>false</shownInInsertView>
</column>
<column columnName="MaterialExpDate">
<shownInInsertView>false</shownInInsertView>
</column>
<column columnName="Flag">
<shownInInsertView>false</shownInInsertView>
</column>
<column columnName="SampleState">
<shownInInsertView>false</shownInInsertView>
</column>
</columns>
</table>
</tables>
""".formatted(EscapeUtil.getMarkupEscapedValue(sampleType));

SimplePostCommand postCommand = new SimplePostCommand("query", "saveSourceQuery");
postCommand.setJsonObject(new JSONObject());
postCommand.getJsonObject().put("ff_metadataText", metadataXml);
postCommand.getJsonObject().put("schemaName", "samples");
postCommand.getJsonObject().put("queryName", sampleType);
postCommand.execute(connection, getProjectName());
}
}

@Test
Expand Down Expand Up @@ -429,15 +466,12 @@ public void testShiftClick()
Locator boxes = Locator.tag("tr").child("td")
.child(Locator.tagWithAttribute("input", "type", "checkbox"));
var checkBoxes = boxes.findElements(testGrid);
scrollIntoView(checkBoxes.get(0), true); // bring as much of the grid into view as possible
scrollIntoView(checkBoxes.get(2), false);
checkBoxes.get(2).click();

new Actions(getDriver())
.click(checkBoxes.get(2))
.keyDown(Keys.SHIFT)
.click(checkBoxes.get(5))
.click(checkBoxes.get(7))
.keyUp(Keys.SHIFT)
.perform();
shiftClickCheckbox(checkBoxes.get(5));

shiftClickCheckbox(checkBoxes.get(7));

// make sure 2-7 are still selected
for (int i=2; i<7; i++)
Expand All @@ -457,11 +491,8 @@ public void testShiftClick()
checkBoxes = boxes.findElements(testGrid);

// verify shift-select to another row does not select the range from the now-removed row
new Actions(getDriver())
.keyDown(Keys.SHIFT)
.click(checkBoxes.get(7))
.keyUp(Keys.SHIFT)
.perform();

shiftClickCheckbox(checkBoxes.get(7));

for (int i=2; i<6; i++)
{
Expand All @@ -471,6 +502,16 @@ public void testShiftClick()
checker().screenShotIfNewError("unexpected_selection_range");
}

private void shiftClickCheckbox(WebElement el)
{
scrollIntoView(el, false);
new Actions(getDriver())
.keyDown(Keys.SHIFT)
.click(el)
.keyUp(Keys.SHIFT)
.perform();
}

@Test
public void testExpandedPaste()
{
Expand All @@ -481,6 +522,7 @@ public void testExpandedPaste()
EditableGrid testGrid = goToEditableGrid(PASTING_SAMPLE_TYPE);
testGrid.addRows(5);

scrollIntoView(testGrid.getCell(3, PASTE_4), false); // Get target area into view
log("Test wide");
testGrid.selectCellRange(testGrid.getCell(0, PASTE_1), testGrid.getCell(1, PASTE_4));
actionPaste(null, rowsToString(clipRows));
Expand Down Expand Up @@ -1000,10 +1042,10 @@ public void testShiftArrowSelectHorizontal()
.verifyEquals("There should be no grid cells already selected. Fatal error.",
0, editableGrid.getSelectedCells().size());

int startColumn = editableGrid.getColumnIndex(PASTE_1);
int startColumn = editableGrid.getColumnIndex(PASTE_3);

int gridRow = 4;
WebElement startCell = editableGrid.getCell(gridRow, PASTE_1);
WebElement startCell = editableGrid.getCell(gridRow, PASTE_3);
startCell.click();

log("Select a few horizontal cells the the left in the grid.");
Expand Down Expand Up @@ -1100,10 +1142,10 @@ public void testShiftArrowSelectHorizontal()
checker().verifyEquals("Hitting <tab> should have removed the selection.",
0, editableGrid.getSelectedCells().size());

WebElement endCell = Locator.tag("div").findWhenNeeded(editableGrid.getCell(gridRow, PASTE_2));
WebElement endCell = Locator.tag("div").findWhenNeeded(editableGrid.getCell(gridRow, PASTE_4));

checker().verifyTrue(String.format("The expected cell on row %d and column %s is not selected after hitting <tab>.",
gridRow, PASTE_2),
gridRow, PASTE_4),
Objects.requireNonNullElse(endCell.getAttribute("class"), "").toLowerCase().contains("cell-selected"));

checker().screenShotIfNewError("TAB_ERROR");
Expand Down Expand Up @@ -1138,7 +1180,7 @@ public void testShiftArrowSelect2D()
0, editableGrid.getSelectedCells().size());

List<String> columns = editableGrid.getColumnLabels();
int startColumn = columns.indexOf("Description");
int startColumn = 4;

int startRow = 5;
WebElement startCell = editableGrid.getCell(startRow, columns.get(startColumn));
Expand Down