diff --git a/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java b/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java index f21859cec3..ae0030bf46 100644 --- a/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java +++ b/src/org/labkey/test/components/ui/grids/ResponsiveGrid.java @@ -256,7 +256,7 @@ private GridFilterModal initFilterColumn(CharSequence columnIdentifier, Filter.O { filterPanel.selectArrayFilterOperator(operator); } - if (value != null) + if (value != null && !((List) value).isEmpty()) { List values = (List) value; filterPanel.selectValue(values.get(0)); diff --git a/src/org/labkey/test/components/ui/search/FilterFacetedPanel.java b/src/org/labkey/test/components/ui/search/FilterFacetedPanel.java index 1ffbe27f88..cdff449be2 100644 --- a/src/org/labkey/test/components/ui/search/FilterFacetedPanel.java +++ b/src/org/labkey/test/components/ui/search/FilterFacetedPanel.java @@ -13,9 +13,12 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; +import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import static org.labkey.test.WebDriverWrapper.waitFor; import static org.labkey.test.components.html.Input.Input; public class FilterFacetedPanel extends WebDriverComponent @@ -74,9 +77,15 @@ public boolean isChecked(String value) */ public void checkValues(String... values) { + // waitForElement(elementCache().findCheckbox(values[0])); + // waitFor(() -> elementCache().findCheckbox(values[0]).isDisplayed(), 10000); for (String value : values) { - elementCache().findCheckbox(value).check(); + try{ + elementCache().findCheckbox(value).check();} + catch (Exception e){ + elementCache().findCheckbox(value).check(); + } } } diff --git a/src/org/labkey/test/params/FieldDefinition.java b/src/org/labkey/test/params/FieldDefinition.java index 78585ac23e..0336d68b51 100644 --- a/src/org/labkey/test/params/FieldDefinition.java +++ b/src/org/labkey/test/params/FieldDefinition.java @@ -617,7 +617,7 @@ public boolean isMeasureByDefault() ColumnType Sample = new ColumnTypeImpl("Sample", "int", "http://www.labkey.org/exp/xml#sample", new IntLookup( "exp", "Materials")); ColumnType Barcode = new ColumnTypeImpl("Unique ID", "string", "http://www.labkey.org/types#storageUniqueId", null); ColumnType TextChoice = new ColumnTypeImpl("Text Choice", "string", "http://www.labkey.org/types#textChoice", null); - ColumnType MultiValueTextChoice = new ColumnTypeImpl("Text Choice", "string", "http://cpas.fhcrc.org/exp/xml#multiChoice", null); + ColumnType MultiValueTextChoice = new ColumnTypeImpl("Text Choice", "http://cpas.fhcrc.org/exp/xml#multiChoice", null, null); ColumnType SMILES = new ColumnTypeImpl("SMILES", "string", "http://www.labkey.org/exp/xml#smiles", null); ColumnType Calculation = new ColumnTypeImpl("Calculation", null, "http://www.labkey.org/exp/xml#calculated", null); /** diff --git a/src/org/labkey/test/util/TestDataGenerator.java b/src/org/labkey/test/util/TestDataGenerator.java index 3432935859..964c193c76 100644 --- a/src/org/labkey/test/util/TestDataGenerator.java +++ b/src/org/labkey/test/util/TestDataGenerator.java @@ -183,6 +183,14 @@ else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.TextChoice) else entityData.put(key, textChoices.get(textChoiceIndex)); } + else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.MultiValueTextChoice)) + { + FieldDefinition.TextChoiceValidator validator = + (FieldDefinition.TextChoiceValidator) fieldDefinition.getValidators().getFirst(); + List values = shuffleSelect(validator.getValues()); + Collections.sort(values); + entityData.put(key, values); + } } } @@ -491,6 +499,16 @@ public static String randomString(int size) return randomString(size, null); } + public static List randomTextChoice(int size) + { + List textChoices = new ArrayList<>(); + for (int i = 0; i < size; i++) + { + textChoices.add(randomString(randomInt(1, 25))); + } + return textChoices; + } + public static String randomString(int size, @Nullable String exclusion) { return randomString(size, exclusion, CHARSET_STRING); diff --git a/src/org/labkey/test/util/data/TestArrayDataUtils.java b/src/org/labkey/test/util/data/TestArrayDataUtils.java new file mode 100644 index 0000000000..ea71248b59 --- /dev/null +++ b/src/org/labkey/test/util/data/TestArrayDataUtils.java @@ -0,0 +1,105 @@ +package org.labkey.test.util.data; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; +import org.labkey.remoteapi.query.Filter; + +import java.io.IOException; +import java.io.StringReader; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.labkey.test.util.samplemanagement.SMTestUtils.COL_SAMPLE_ID_NAME; +import static org.labkey.test.util.samplemanagement.SMTestUtils.COL_SAMPLE_NAME_NAME; + +public class TestArrayDataUtils +{ + + public static Map getMapWithIdAndMultiChoiceField(List> data) + { + return data.stream() + .collect(Collectors.toMap( + row -> String.valueOf(row.get(COL_SAMPLE_NAME_NAME) != null ? row.get(COL_SAMPLE_NAME_NAME) : row.get(COL_SAMPLE_ID_NAME)), + row -> + { + String complexKey = row.keySet().stream() + .filter(k -> k.contains("Multi Choice")) + .findFirst() + .orElse(""); + return row.get(complexKey); + } + )); + } + + /** + * Filtering Map according to filter and then sorting values in alphabetical order. + * + * @return filtered Map + */ + public static Map> filterMap(Map map, List searchValues, Filter.Operator filterType) + { + return map.entrySet().stream() + .filter(entry -> entry.getValue() instanceof List) + .map(entry -> Map.entry(entry.getKey(), (List) entry.getValue())) + .filter(entry -> isMatch(entry.getValue(), searchValues, filterType)) + .collect(Collectors.toMap( + Map.Entry::getKey, + e -> e.getValue().stream() + .sorted(Comparator + .comparing((String s) -> s.substring(0, 1).toLowerCase()) + .thenComparing(s -> s.substring(0, 1)) + .thenComparing(s -> s)) + .collect(Collectors.toList()), + (e1, e2) -> e1, + LinkedHashMap::new + )); + } + + public static Map prepareMapForCheck(Map> map) + { + return map.entrySet().stream() + .collect(Collectors.toMap( + Map.Entry::getKey, + entry -> String.join(", ", entry.getValue()), + (e1, e2) -> e1, + LinkedHashMap::new + )); + } + + public static Map filterAndPrepareMap(Map map, List searchValues, Filter.Operator filterType) + { + return prepareMapForCheck(filterMap(map, searchValues, filterType)); + } + + public static List parseMultiValueText(String multiValueString) throws IOException + { + CSVFormat format = CSVFormat.RFC4180.builder() + .setIgnoreSurroundingSpaces(true).setTrim(true).get(); + try (CSVParser parser = format.parse(new StringReader(multiValueString))) + { + List records = parser.getRecords(); + if (records.size() != 1) + throw new IllegalArgumentException("Invalid multi-value text string: " + multiValueString); + return records.getFirst().toList(); + } + } + + private static boolean isMatch(List actualValues, List searchValues, Filter.Operator type) + { + return switch (type) + { + case ARRAY_CONTAINS_ALL -> actualValues.containsAll(searchValues); + case ARRAY_CONTAINS_ANY -> searchValues.stream().anyMatch(actualValues::contains); + case ARRAY_CONTAINS_EXACT -> actualValues.size() == searchValues.size() && actualValues.containsAll(searchValues); + case ARRAY_CONTAINS_NONE -> searchValues.stream().noneMatch(actualValues::contains); + case ARRAY_CONTAINS_NOT_EXACT -> !(actualValues.size() == searchValues.size() && actualValues.containsAll(searchValues)); + case ARRAY_ISEMPTY -> actualValues.isEmpty(); + case ARRAY_ISNOTEMPTY -> !actualValues.isEmpty(); + default -> throw new IllegalArgumentException("Invalid filter type " + type); + }; + } +} \ No newline at end of file diff --git a/src/org/labkey/test/util/data/TestDataUtils.java b/src/org/labkey/test/util/data/TestDataUtils.java index 2795dd4916..149ad38817 100644 --- a/src/org/labkey/test/util/data/TestDataUtils.java +++ b/src/org/labkey/test/util/data/TestDataUtils.java @@ -578,19 +578,6 @@ public static List> readRowsFromFile(File file, CSVFormat format) t } } - public static List parseMultiValueText(String multiValueString) throws IOException - { - CSVFormat format = CSVFormat.RFC4180.builder() - .setIgnoreSurroundingSpaces(true).setTrim(true).get(); - try (CSVParser parser = format.parse(new StringReader(multiValueString))) - { - List records = parser.getRecords(); - if (records.size() != 1) - throw new IllegalArgumentException("Invalid multi-value text string: " + multiValueString); - return records.getFirst().toList(); - } - } - public static String stringFromRows(List> rows, CSVFormat format) { StringWriter stringWriter = new StringWriter();