Skip to content

Commit

Permalink
Date-only and Time-only Tests for Assays
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-danield committed Mar 5, 2024
1 parent b1f28a9 commit 20b2f7d
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 235 deletions.
Binary file modified data/GPAT/trial01.xls
Binary file not shown.
Binary file modified data/GPAT/trial01a.xlsx
Binary file not shown.
404 changes: 202 additions & 202 deletions data/GPAT/trial02.tsv

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions src/org/labkey/test/tests/GpatAssayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.labkey.test.components.domain.DomainFormPanel;
import org.labkey.test.pages.ReactAssayDesignerPage;
import org.labkey.test.pages.assay.AssayBeginPage;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.util.DataRegionTable;
import org.labkey.test.util.LogMethod;
import org.labkey.test.util.LoggedParam;
Expand All @@ -54,8 +55,6 @@ public class GpatAssayTest extends BaseWebDriverTest
private static final File GPAT_ASSAY_XLSX = TestFileUtils.getSampleData("GPAT/trial01a.xlsx");
private static final File GPAT_ASSAY_TSV = TestFileUtils.getSampleData("GPAT/trial02.tsv");
private static final File GPAT_ASSAY_FNA_1 = TestFileUtils.getSampleData("GPAT/trial03.fna");
private static final File GPAT_ASSAY_FNA_2 = TestFileUtils.getSampleData("GPAT/trial04.fna");
private static final File GPAT_ASSAY_FNA_3 = TestFileUtils.getSampleData("GPAT/trial05.fna");
private static final String ASSAY_NAME_XLS = "XLS Assay " + TRICKY_CHARACTERS;
private static final String ASSAY_NAME_XLSX = "XLSX Assay";
private static final String ASSAY_NAME_TSV = "TSV Assay";
Expand Down Expand Up @@ -99,7 +98,7 @@ public void doCleanup(boolean afterTest) throws TestTimeoutException
public void testSteps()
{
ReactAssayDesignerPage assayDesignerPage = startCreateGpatAssay(GPAT_ASSAY_XLS, ASSAY_NAME_XLS);
DomainFormPanel results = setAssayResultsProperties(assayDesignerPage, 10);
DomainFormPanel results = setAssayResultsProperties(assayDesignerPage, 12);
results.removeField("Role");
assayDesignerPage.clickFinish();
clickButton("Next", defaultWaitForPage);
Expand Down Expand Up @@ -128,7 +127,7 @@ public void testSteps()

log("Import XLSX GPAT assay");
assayDesignerPage = startCreateGpatAssay(GPAT_ASSAY_XLSX, ASSAY_NAME_XLSX);
setAssayResultsProperties(assayDesignerPage, 9);
setAssayResultsProperties(assayDesignerPage, 11);
assayDesignerPage.clickFinish();
if (isElementPresent(Locator.tagContainingText("p", "The files listed below have been created by another run")))
clickButton("OK", defaultWaitForPage);
Expand All @@ -150,6 +149,16 @@ public void testSteps()
.setLabel("Result")
.setImportAliases("Score")
.setRequiredField(true);

// Set the date-only field type.
results.getField("DateOnly")
.setType(FieldDefinition.ColumnType.Date, false);

// Using a tsv abd the data-pipeline to define the results fields sets the time-only field to a type of Text.
// A field of type Text cannot be converted to a Time type. The only way around this is to remove the field and
// add it back as a time-only type.
results.removeField("TimeOnly", false);
results.addField(new FieldDefinition("TimeOnly", FieldDefinition.ColumnType.Time));
assayDesignerPage.clickFinish();

clickButton("Next", defaultWaitForPage);
Expand All @@ -175,6 +184,14 @@ private DomainFormPanel setAssayResultsProperties(ReactAssayDesignerPage assayDe
results.getFieldCountMessage());
results.getField("Score").setRequiredField(true);
results.getField("Primary").setMissingValuesEnabled(true);

// Set the date-only and time-only result fields to the proper type.
if(results.fieldNames().contains("DateOnly") && results.fieldNames().contains("TimeOnly"))
{
results.getField("DateOnly").setType(FieldDefinition.ColumnType.Date, false);
results.getField("TimeOnly").setType(FieldDefinition.ColumnType.Time, false);
}

return results;
}

Expand Down
107 changes: 80 additions & 27 deletions src/org/labkey/test/tests/ParsingPatternForDateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,24 @@
import org.labkey.test.util.StudyHelper;
import org.labkey.test.util.TestDataGenerator;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Category({Daily.class})
public class ParsingPatternForDateTest extends BaseWebDriverTest
{
private static final String TEST_LIST = "Input Format List";

private static final String LIST_SCHEMA = "lists";
private static final String TEST_PARSING = "Additional Parsing Format List";
private static final String TEST_MODE = "Date Parsing Mode List";

private static final String COL_NAME = "name";
private static final String COL_DATETIME = "dateTimeCol";
Expand Down Expand Up @@ -101,64 +108,112 @@ public List<String> getAssociatedModules()
@Test
public void testSiteAdditionalParsingPatternDateAndTime() throws IOException, CommandException
{
createList();
createList(TEST_PARSING);
log("Setting the additional parsing patterns for the site.");
testParsingPatternsList(true);
}

@Test
public void testProjectAdditionalParsingPatternDateAndTime() throws IOException, CommandException
{
createList();
createList(TEST_PARSING);
log("Set the additional parsing patterns for the project.");
testParsingPatternsList(false);
}

private void createList() throws IOException, CommandException
@Test
public void testNonUSDateParsingMode() throws IOException, CommandException
{
createList(TEST_MODE);

String dateTimePattern = "ddMMMyyyy:HH:mm:ss";
String datePattern = "mm/dd/yy";
String timePattern = "hh:mm a";

log("Use 'Non-U.S. date parsing (DMY)'.");
setSiteAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern, false);
// setProjectAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern);

String bulkData;
bulkData = String.format("%s\t%s\t%s\t%s\n", COL_NAME, COL_DATETIME, COL_DATE, COL_TIME)
+ "A\t23/12/24 14:45\t23/12/24\t14:45\n"
+ "B\t19/11/99 9:32:06.001\t19/11/99\t9:32:06.001\n"
+ "C\t2/3/1972 10:45 pm\t2/3/1972\t10:45 pm\n"
+ "D\t3-2-05 00:00\t3-2-05\t00:00\n"
+ "E\t19July1999 19:32:06\t19/7/99\t19:32:06\n";

List<String> expectedDateTimeCol = List.of("2024-12-23 14:45", "1999-11-19 09:32", "1972-03-02 22:45", "2005-02-03 00:00", "1999-07-19 19:32");
List<String> expectedDateCol = List.of("2024-12-23", "1999-11-19", "1972-03-02", "2005-02-03", "1999-07-19");
List<String> expectedTimeCol = List.of("14:45:00", "09:32:06", "22:45:00", "00:00:00", "19:32:06");

goToProjectHome();
clickAndWait(Locator.linkWithText(TEST_MODE));
DataRegionTable listTable = new DataRegionTable("query", getDriver());
listTable.clickImportBulkData()
.setText(bulkData);
clickButton("Submit");

goToProjectHome();
clickAndWait(Locator.linkWithText(TEST_MODE));
listTable = new DataRegionTable("query", getDriver());

checker().verifyEquals("Values in " + COL_DATETIME + " are not as expected.",
expectedDateTimeCol, listTable.getColumnDataAsText(COL_DATETIME));

checker().verifyEquals("Values in " + COL_DATE + " are not as expected.",
expectedDateCol, listTable.getColumnDataAsText(COL_DATE));

checker().verifyEquals("Values in " + COL_TIME + " are not as expected.",
expectedTimeCol, listTable.getColumnDataAsText(COL_TIME));

}

private void createList(String listName) throws IOException, CommandException
{
// Delete the list if it already exists.
goToProjectHome();
if(goToManageLists().getGrid().getListNames().contains(TEST_LIST))
if(goToManageLists().getGrid().getListNames().contains(listName))
{
_listHelper.goToList(TEST_LIST);
_listHelper.goToList(listName);
_listHelper.deleteList();
}

TestDataGenerator dgen = new IntListDefinition(TEST_LIST, "id")
new IntListDefinition(listName, "id")
.setFields(List.of(
new FieldDefinition(COL_NAME, FieldDefinition.ColumnType.String),
new FieldDefinition(COL_DATETIME, FieldDefinition.ColumnType.DateAndTime),
new FieldDefinition(COL_DATE, FieldDefinition.ColumnType.Date),
new FieldDefinition(COL_TIME, FieldDefinition.ColumnType.Time)))
.create(createDefaultConnection(), getProjectName());

// Prepopulate the list with one item.
dgen.addCustomRow(Map.of(COL_NAME, "First", COL_DATETIME, "05/10/2020", "date", "02/05/2024", "time", "16:43:32"));
dgen.insertRows(createDefaultConnection(), dgen.getRows());
}

private void testParsingPatternsList(boolean changeSiteSettings)
private void testParsingPatternsList(boolean changeSiteSettings) throws IOException, CommandException
{

// Pre-populate the list with one item that will be updated.
TestDataGenerator dataGenerator = new TestDataGenerator(LIST_SCHEMA, TEST_PARSING, getProjectName());
dataGenerator.addCustomRow(Map.of(COL_NAME, "First", COL_DATETIME, "05/10/2020", COL_DATE, "02/05/2024", COL_TIME, "16:43:32"));
dataGenerator.insertRows(createDefaultConnection(), dataGenerator.getRows());

String dateTimePattern = "ddMMMyyyy:HH:mm:ss";
String datePattern = "mm/dd/yy";
String timePattern = "hh:mm a";

if(changeSiteSettings)
{
setSiteAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern);
setSiteAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern, true);
}
else
{
goToProjectHome();
setProjectAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern);
}

List<Map<String, String>> expectedTableValues = new ArrayList<>();

log("Update a row with values in the additional parsing format.");
goToProjectHome();
clickAndWait(Locator.linkWithText(TEST_LIST));
clickAndWait(Locator.linkWithText(TEST_PARSING));
DataRegionTable listTable = new DataRegionTable("query", getDriver());
listTable.clickEditRow(0);

Expand Down Expand Up @@ -199,22 +254,18 @@ private void testParsingPatternsList(boolean changeSiteSettings)

log("Bulk import with values in additional parsing patterns.");
listTable.clearAllFilters();
listTable.clickImportBulkData();
click(Locator.tagContainingText("h3", "Upload file"));

log("Import a xlsx file where date & time values are numbers.");
setFormElement(Locator.tagWithName("input", "file"), TestFileUtils.getSampleData("DateParsing/BulkImportDateParsing.xlsx"));
listTable.clickImportBulkData()
.setFile(TestFileUtils.getSampleData("DateParsing/BulkImportDateParsing.xlsx"));
clickButton("Submit");

listTable.clickImportBulkData();
click(Locator.tagContainingText("h3", "Upload file"));

log("Import a xlsx file where date & time values are text.");
setFormElement(Locator.tagWithName("input", "file"), TestFileUtils.getSampleData("DateParsing/BulkImportDateParsing_Text.xlsx"));
listTable.clickImportBulkData()
.setFile(TestFileUtils.getSampleData("DateParsing/BulkImportDateParsing_Text.xlsx"));
clickButton("Submit");

goToProjectHome();
clickAndWait(Locator.linkWithText(TEST_LIST));
clickAndWait(Locator.linkWithText(TEST_PARSING));
listTable = new DataRegionTable("query", getDriver());

expectedTableValues.add(Map.of(
Expand Down Expand Up @@ -277,11 +328,10 @@ private void testParsingPatternsPipelineJobs(boolean changeSiteSettings)

if(changeSiteSettings)
{
setSiteAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern);
setSiteAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern, true);
}
else
{
goToProjectHome();
setProjectAdditionalParsingPatterns(dateTimePattern, datePattern, timePattern);
}

Expand All @@ -305,15 +355,18 @@ private void testParsingPatternsPipelineJobs(boolean changeSiteSettings)
, table.getColumnDataAsText(COL_TIME));
}

private void setSiteAdditionalParsingPatterns(String dateTimePattern, String datePattern, String timePattern)
private void setSiteAdditionalParsingPatterns(String dateTimePattern, String datePattern, String timePattern, boolean useUSMode)
{
LookAndFeelSettingsPage lookAndFeelSettingsPage = LookAndFeelSettingsPage.beginAt(this);

lookAndFeelSettingsPage.setDateParsingMode(useUSMode);

setAdditionalParsingPatterns(lookAndFeelSettingsPage, dateTimePattern, datePattern, timePattern);
}

private void setProjectAdditionalParsingPatterns(String dateTimePattern, String datePattern, String timePattern)
{
ProjectSettingsPage projectSettingsPage = ProjectSettingsPage.beginAt(this);
ProjectSettingsPage projectSettingsPage = ProjectSettingsPage.beginAt(this, getProjectName());
setAdditionalParsingPatterns(projectSettingsPage, dateTimePattern, datePattern, timePattern);
}

Expand Down
6 changes: 4 additions & 2 deletions src/org/labkey/test/tests/list/ListDateAndTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,12 @@ else if(date.equals(dateUseTimeOnly))
log("Sort the time-only field in ascending order.");
expectedKeyColOrder = new ArrayList<>();
expectedKeyColOrder.add("3"); // 2024-01-01 00:00:00
expectedKeyColOrder.add("2"); // (some future date) 14:23:54
expectedKeyColOrder.add("1"); // 1950-10-12 08:00:01
expectedKeyColOrder.add("7"); // 1995-03-03 09:10:10
expectedKeyColOrder.add("4"); // 1992-03-03 10:10:10
expectedKeyColOrder.add("5"); // 1992-03-03 10:10:10
expectedKeyColOrder.add("6"); // 1992-03-03 10:11:34
expectedKeyColOrder.add("2"); // (some future date) 14:23:54
expectedKeyColOrder.add("11"); // (empty) 14:59:25
expectedKeyColOrder.add("9"); // 2002-09-15 17:45:20
expectedKeyColOrder.add("8"); // 2024-02-29 18:32:00
Expand All @@ -567,12 +567,12 @@ else if(date.equals(dateUseTimeOnly))
expectedKeyColOrder.add("8");
expectedKeyColOrder.add("9");
expectedKeyColOrder.add("11");
expectedKeyColOrder.add("2");
expectedKeyColOrder.add("6");
expectedKeyColOrder.add("4");
expectedKeyColOrder.add("5");
expectedKeyColOrder.add("7");
expectedKeyColOrder.add("1");
expectedKeyColOrder.add("2");
expectedKeyColOrder.add("3");

table.setSort(timeCol, SortDirection.DESC);
Expand Down Expand Up @@ -823,6 +823,7 @@ else if(date.equals(dateUseTimeOnlyKey11))
log(String.format("Filter the time-only field greater than '%s'.", filterValue01));

expectedKeyCol = new ArrayList<>();
expectedKeyCol.add("2"); // (some future date) 14:23:54
expectedKeyCol.add("8"); // 2024-02-29 18:32:00
expectedKeyCol.add("9"); // 2002-09-15 17:45:20
expectedKeyCol.add("11"); // (empty) 14:59:25
Expand All @@ -848,6 +849,7 @@ else if(date.equals(dateUseTimeOnlyKey11))
filterValue01, filterValue02));

expectedKeyCol = new ArrayList<>();
expectedKeyCol.add("2"); // (some future date) 14:23:54
expectedKeyCol.add("4"); // 1992-03-03 10:10:10
expectedKeyCol.add("5"); // 1992-03-03 10:10:10
expectedKeyCol.add("6"); // 1992-03-03 10:11:34
Expand Down

0 comments on commit 20b2f7d

Please sign in to comment.