Skip to content
Merged
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
39 changes: 23 additions & 16 deletions src/org/labkey/test/params/FieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.labkey.test.params.FieldDefinition.ColumnType;
import org.labkey.test.util.CachingSupplier;
import org.labkey.test.util.EscapeUtil;
import org.labkey.test.util.TestDataGenerator;
import org.labkey.test.util.TextUtils;

import java.util.Objects;
import java.util.function.Consumer;
Expand All @@ -17,22 +19,25 @@
public class FieldInfo implements CharSequence, WrapsFieldKey
{
private final FieldKey _fieldKey;
private final String _label;
private final String _rawLabel;
private final ColumnType _columnType;
private final Consumer<FieldDefinition> _fieldDefinitionMutator;
private String _namePart; // used for random field generation to track the name part used
private final String _namePart; // used for random field generation to track the name part used
private final CachingSupplier<String> _label = new CachingSupplier<>(() -> Objects.requireNonNullElseGet(getRawLabel(), () -> FieldDefinition.labelFromName(getName())));
private final CachingSupplier<String> _uiLabel = new CachingSupplier<>(() -> TextUtils.normalizeSpace(getLabel()));

private FieldInfo(FieldKey fieldKey, String label, ColumnType columnType, Consumer<FieldDefinition> fieldDefinitionMutator)
private FieldInfo(FieldKey fieldKey, String label, ColumnType columnType, Consumer<FieldDefinition> fieldDefinitionMutator, String namePart)
{
_fieldKey = fieldKey;
_label = label;
_rawLabel = label;
_columnType = Objects.requireNonNullElse(columnType, ColumnType.String);
_fieldDefinitionMutator = fieldDefinitionMutator;
_namePart = namePart;
}

public FieldInfo(String name, String label, ColumnType columnType)
{
this(FieldKey.fromParts(name.trim()), label, columnType, null);
this(FieldKey.fromParts(name.trim()), label, columnType, null, name);
}

public FieldInfo(String name, String label)
Expand All @@ -55,9 +60,7 @@ public FieldInfo(String name)
*/
public static FieldInfo random(String namePart, ColumnType columnType)
{
FieldInfo field = new FieldInfo(TestDataGenerator.randomFieldName(namePart), columnType);
field.setNamePart(namePart);
return field;
return new FieldInfo(FieldKey.fromParts(TestDataGenerator.randomFieldName(namePart)), null, columnType, null, namePart);
}

/**
Expand All @@ -82,19 +85,28 @@ public FieldInfo customizeFieldDefinition(Consumer<FieldDefinition> fieldDefinit
{
throw new IllegalArgumentException("FieldDefinition customizer should not modify field label");
}
return new FieldInfo(_fieldKey, _label, _columnType, fieldDefinitionMutator);
return new FieldInfo(_fieldKey, _rawLabel, _columnType, fieldDefinitionMutator, _namePart);
}

@Contract(pure = true)
protected String getRawLabel()
{
return _label;
return _rawLabel;
}

@Contract(pure = true)
public String getLabel()
{
return Objects.requireNonNullElseGet(getRawLabel(), () -> FieldDefinition.labelFromName(_fieldKey.getName()));
return _label.get();
}

/**
* Get field label as it appears when rendered in browser
*/
@Contract(pure = true)
public String getUiLabel()
{
return _uiLabel.get();
}

@Override
Expand Down Expand Up @@ -175,11 +187,6 @@ private FieldDefinition getFieldDefinition(ColumnType columnType)
return fieldDefinition;
}

private void setNamePart(String namePart)
{
_namePart = namePart;
}

@Override
public int length()
{
Expand Down
7 changes: 4 additions & 3 deletions src/org/labkey/test/tests/component/EditableGridTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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.openqa.selenium.Dimension;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -1341,11 +1342,11 @@ public void testInputCellValidation()
log("Input empty string for required field should trigger cell warning.");
testGrid.setCellValue(1, REQ_STR_FIELD, " ");
checker().verifyEquals("Cell warning status not as expected at row " + 1 + " for col " + REQ_STR_FIELD.getLabel(), true, testGrid.hasCellError(1, REQ_STR_FIELD));
checker().verifyEquals("Cell warning msg not as expected at row " + 1 + " for col " + REQ_STR_FIELD.getLabel(), REQ_STR_FIELD.getLabel() + " is required.", testGrid.getCellPopoverText(1, REQ_STR_FIELD));
checker().verifyEquals("Cell warning msg not as expected at row " + 1 + " for col " + REQ_STR_FIELD.getLabel(), REQ_STR_FIELD.getUiLabel() + " is required.", testGrid.getCellPopoverText(1, REQ_STR_FIELD));
mouseOver(testGrid.getCell(0, "Row")); // dismiss warning popup
testGrid.setCellValue(1, REQ_INT_FIELD, " ");
checker().verifyEquals("Cell warning status not as expected at row " + 1 + " for col " + REQ_INT_FIELD.getLabel(), true, testGrid.hasCellError(1, REQ_INT_FIELD));
checker().verifyEquals("Cell warning msg not as expected at row " + 1 + " for col " + REQ_INT_FIELD.getLabel(), REQ_INT_FIELD.getLabel() + " is required.", testGrid.getCellPopoverText(1, REQ_INT_FIELD));
checker().verifyEquals("Cell warning msg not as expected at row " + 1 + " for col " + REQ_INT_FIELD.getLabel(), REQ_INT_FIELD.getUiLabel() + " is required.", testGrid.getCellPopoverText(1, REQ_INT_FIELD));

log("Correct values should remove cell warning, keep entering wrong values should update warning");
mouseOver(testGrid.getCell(0, "Row")); // dismiss warning popup
Expand Down Expand Up @@ -1496,7 +1497,7 @@ private void verifyCellWarning(EditableGrid testGrid, List<String> expectedWarni

checker().verifyEquals("Cell warning status not as expected at row " + rowId + " for col " + field.getLabel(), !StringUtils.isEmpty(expectedWarning), testGrid.hasCellError(rowId, field));
if (!StringUtils.isEmpty(expectedWarning))
checker().verifyEquals("Cell warning msg not as expected at row " + rowId + " for col " + field.getLabel(), expectedWarning, testGrid.getCellPopoverText(rowId, field));
checker().verifyEquals("Cell warning msg not as expected at row " + rowId + " for col " + field.getLabel(), TextUtils.normalizeSpace(expectedWarning), testGrid.getCellPopoverText(rowId, field));
}
}

Expand Down
22 changes: 16 additions & 6 deletions src/org/labkey/test/tests/list/ListLookupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.labkey.test.params.FieldDefinition.labelFromName;
import static org.labkey.test.util.TextUtils.normalizeSpace;

// Issue 52098, Issue 49422
@Category({Daily.class, Data.class, Hosting.class})
Expand Down Expand Up @@ -122,7 +124,8 @@ public void testWithoutValidatorOrAlternateKeys() throws IOException, CommandExc
String error = importDataPage
.setText(bulkData)
.submitExpectingError();
checker().withScreenshot().verifyEquals("Error message for invalid primary key not as expected", "Could not convert value 'noneSuch' (String) for Integer field '" + lookFromLookupFieldName + "'", error);
checker().withScreenshot().verifyEquals("Error message for invalid primary key not as expected",
"Could not convert value 'noneSuch' (String) for Integer field '" + normalizeSpace(lookFromLookupFieldName) + "'", error);
}

@Test
Expand Down Expand Up @@ -168,7 +171,8 @@ public void testWithoutValidatorWithAlternateKeys() throws IOException, CommandE
.setText(bulkData)
.setImportLookupByAlternateKey(true)
.submitExpectingError();
checker().withScreenshot().verifyEquals("Error message after supplying invalid alternate key not as expected", "Value 'NotAValue' not found for field " + lookFromLookupFieldName + " in the current context.", error);
checker().withScreenshot().verifyEquals("Error message after supplying invalid alternate key not as expected",
"Value 'NotAValue' not found for field " + normalizeSpace(lookFromLookupFieldName) + " in the current context.", error);
}

@Test
Expand Down Expand Up @@ -196,13 +200,16 @@ public void testWithLookupValidatorWithoutAlternateKeys() throws IOException, Co
String error = importDataPage
.setText(tsvFromColumn(List.of(lookFromLookupFieldName, "1000")))
.submitExpectingError();
checker().withScreenshot().verifyEquals("Error message for invalid primary key value not as expected", "Value '1000' was not present in lookup target 'lists." + lookToListName + "' for field '" + FieldDefinition.labelFromName(lookFromLookupFieldName) + "'", error);
checker().withScreenshot().verifyEquals("Error message for invalid primary key value not as expected",
"Value '1000' was not present in lookup target 'lists." + normalizeSpace(lookToListName)
+ "' for field '" + normalizeSpace(labelFromName(lookFromLookupFieldName)) + "'", error);

log("With lookup validation on, import data and provide an invalid primary key of type string.");
error = importDataPage
.setText(tsvFromColumn(List.of(lookFromLookupFieldName, "Look")))
.submitExpectingError();
checker().withScreenshot().verifyEquals("Error message for invalid primary key type not as expected", "Could not convert value 'Look' (String) for Integer field '" + lookFromLookupFieldName + "'", error);
checker().withScreenshot().verifyEquals("Error message for invalid primary key type not as expected",
"Could not convert value 'Look' (String) for Integer field '" + normalizeSpace(lookFromLookupFieldName) + "'", error);
}

@Test
Expand Down Expand Up @@ -246,14 +253,17 @@ public void testWithLookupValidatorAndAlternateKeys() throws IOException, Comman
.setText(bulkData)
.setImportLookupByAlternateKey(true)
.submitExpectingError();
checker().withScreenshot().verifyEquals("Error message for invalid string alternate key not as expected", "Value 'Invalid' not found for field " + lookFromLookupFieldName + " in the current context.", error);
checker().withScreenshot().verifyEquals("Error message for invalid string alternate key not as expected",
"Value 'Invalid' not found for field " + normalizeSpace(lookFromLookupFieldName) + " in the current context.", error);

bulkData = tsvFromColumn(List.of(lookFromLookupFieldName, "1234"));
error = importDataPage
.setText(bulkData)
.setImportLookupByAlternateKey(true)
.submitExpectingError();
checker().withScreenshot().verifyEquals("Error message for invalid number-like alternate key not as expected", "Value '1234' was not present in lookup target 'lists." + lookToListName + "' for field '" + FieldDefinition.labelFromName(lookFromLookupFieldName) + "'", error);
checker().withScreenshot().verifyEquals("Error message for invalid number-like alternate key not as expected",
"Value '1234' was not present in lookup target 'lists." + normalizeSpace(lookToListName)
+ "' for field '" + normalizeSpace(labelFromName(lookFromLookupFieldName)) + "'", error);

}

Expand Down
5 changes: 4 additions & 1 deletion src/org/labkey/test/util/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ private TextUtils() {}
*/
public static String normalizeSpace(String value)
{
return NS_PATTERN.matcher(value).replaceAll(" ").trim();
if (value == null)
return value;
else
return NS_PATTERN.matcher(value).replaceAll(" ").trim();
}

public static List<String> normalizeSpace(List<String> values)
Expand Down