Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test non-standard date and time formats #2127

Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
76039f9
Consolidate helpers that interact with Date, Time and DateTime fields.
labkey-danield Oct 23, 2024
334dbf3
Re-enable ProjectSettingsTest.testInjection.
labkey-danield Oct 23, 2024
dfa1194
Fix error in DomainFieldRow.setFormat
labkey-danield Oct 23, 2024
4f5f6bf
Change the none time format to have a format value of "<none>".
labkey-danield Oct 23, 2024
539011f
Use variable and remove reference to string value.
labkey-danield Oct 24, 2024
220418c
Merge branch 'develop' into fb_testNonStandardDateAndTimeFormats
labkey-danield Oct 24, 2024
e668d50
Merge branch 'develop' into fb_testNonStandardDateAndTimeFormats
labkey-danield Oct 25, 2024
d51174c
Testing non-standard formats in list and projects.
labkey-danield Oct 25, 2024
59970f4
Added test for Data Sets.
labkey-danield Oct 26, 2024
ed46e30
Merge branch 'develop' into fb_testNonStandardDateAndTimeFormats
labkey-danield Oct 28, 2024
3b98f94
Add comments and descriptions doe each test.
labkey-danield Oct 28, 2024
313b0d2
Merge branch 'develop' into fb_testNonStandardDateAndTimeFormats
labkey-danield Oct 29, 2024
c174c26
Adding tests for child folder and site settings.
labkey-danield Oct 29, 2024
6efad7d
Merge branch 'develop' into fb_testNonStandardDateAndTimeFormats
labkey-danield Oct 30, 2024
2e955ec
Add test for site and subfolder settings.
labkey-danield Oct 31, 2024
cb2181e
Cleaning up code and comments.
labkey-danield Oct 31, 2024
3019f76
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 5, 2024
f9a5685
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 7, 2024
16e0a2c
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 8, 2024
03e6116
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 11, 2024
07a1c32
Validate using 'Date', 'Time' and 'DateTime' as format values.
labkey-danield Nov 12, 2024
83a18d5
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 12, 2024
03f730a
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 19, 2024
3670157
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 22, 2024
6163394
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Nov 26, 2024
8123c4c
Merge branch 'release24.11-SNAPSHOT' into 24.11_fb_testNonStandardDat…
labkey-danield Dec 2, 2024
121f8b0
Some minor clean up.
labkey-danield Dec 3, 2024
32bf6ab
In DomainFormPanel.editField fix how a DateTime format is parsed.
labkey-danield Dec 3, 2024
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
212 changes: 150 additions & 62 deletions src/org/labkey/test/components/domain/DomainFieldRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
import org.labkey.test.components.html.SelectWrapper;
import org.labkey.test.components.react.FilteringReactSelect;
import org.labkey.test.components.ui.ontology.ConceptPickerDialog;
import org.labkey.test.pages.core.admin.BaseSettingsPage.DATE_FORMAT;
import org.labkey.test.pages.core.admin.BaseSettingsPage.TIME_FORMAT;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.util.LabKeyExpectedConditions;
import org.openqa.selenium.ElementNotInteractableException;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -146,12 +147,8 @@ public DomainFieldRow setType(FieldDefinition.ColumnType columnType, boolean con
public ModalDialog setTypeWithDialog(FieldDefinition.ColumnType columnType)
{
elementCache().fieldTypeSelectInput.selectByVisibleText(columnType.getLabel());

ModalDialog confirmDialog = new ModalDialog.ModalDialogFinder(getDriver())
return new ModalDialog.ModalDialogFinder(getDriver())
.withTitle("Confirm Data Type Change").timeout(1000).waitFor();

return confirmDialog;

}

public boolean getRequiredField()
Expand Down Expand Up @@ -412,29 +409,19 @@ public DomainFieldRow setFormat(String formatString, @Nullable String dataType)
{
expand();

if (!StringUtils.isEmpty(dataType))

if (FieldDefinition.ColumnType.DateAndTime.getRangeURI().equals(dataType) ||
FieldDefinition.ColumnType.Date.getRangeURI().equals(dataType) ||
(FieldDefinition.ColumnType.Time.getRangeURI().equals(dataType)))
{
if (FieldDefinition.ColumnType.DateAndTime.getRangeURI().equals(dataType))
{
setDateTimeFormat(formatString);
return this;
}
if (FieldDefinition.ColumnType.Date.getRangeURI().equals(dataType))
{
setDateFormat(formatString);
return this;
}
if (FieldDefinition.ColumnType.Time.getRangeURI().equals(dataType))
{
setTimeFormat(formatString);
return this;
}
throw new UnsupportedOperationException("Setting the format for Date, Time or DateTime fields not supported in this method.");
}
if(elementCache().formatInput.getComponentElement().isDisplayed())

if (elementCache().formatInput.getComponentElement().isDisplayed())
{
elementCache().formatInput.setValue(formatString);
}
else if(elementCache().charScaleInput.getComponentElement().isDisplayed())
else if (elementCache().charScaleInput.getComponentElement().isDisplayed())
{
// Formatting of Boolean types use the scale input.
elementCache().charScaleInput.setValue(formatString);
Expand Down Expand Up @@ -1303,67 +1290,93 @@ public boolean isDateTimeInherited()
return elementCache().dateTimeInheritedCheckbox.get();
}

public String getDateTimeFormatDate()
public DomainFieldRow setDateTimeFormat(DATE_FORMAT date, TIME_FORMAT time)
{
return getFormatWithoutExample(elementCache().dateTimeFormatDateSelect.getValue());
setDateTimeFormat(date);
setDateTimeFormat(time);
return this;
}

public DomainFieldRow setDateTimeFormatDate(String dateFormat)
public DomainFieldRow setDateTimeFormat(DATE_FORMAT dateFormat)
{
expand();
if (isDateTimeInherited())
setDateTimeInherited(false);
elementCache().dateTimeFormatDateSelect.typeAheadSelect(dateFormat + " (");

String txt;

if (dateFormat.equals(DATE_FORMAT.DATETIME))
{
txt = dateFormat.toString();
}
else
{
txt = dateFormat + " (";
}

elementCache().dateTimeFormatDateSelect.typeAheadSelect(txt);
return this;
}

public DomainFieldRow setDateTimeFormatTime(String timeFormat)
public DomainFieldRow setDateTimeFormat(TIME_FORMAT timeFormat)
{
expand();
if (isDateTimeInherited())
setDateTimeInherited(false);
elementCache().dateTimeFormatTimeSelect.typeAheadSelect(timeFormat + " (");
elementCache().dateTimeFormatTimeSelect.typeAheadSelect(TIME_FORMAT.none.equals(timeFormat) ? timeFormat.toString() : timeFormat + " (");
return this;
}

public String getDateTimeFormatTime()
public String getDateTimeFormatDate()
{
return getFormatWithoutExample(elementCache().dateTimeFormatTimeSelect.getValue());
String formatValue;

if(elementCache().dateTimeFormatDateSelect.isInteractive())
{
formatValue = getFormatWithoutExample(elementCache().dateTimeFormatDateSelect.getValue());
}
else
{
formatValue = getFormatWithoutExample(elementCache().disabledDateTimeDateFormat.getText());
}

return formatValue;
}

public String getDateTimeFormat()
public boolean isDateTimeFormatDateEnabled()
{
String date = getDateTimeFormatDate();
String time = getDateTimeFormatTime();
if ("<none>".equals(time))
time = null;
if (StringUtils.isEmpty(time))
return date;

return date + " " + time;
return elementCache().dateTimeFormatDateSelect.isInteractive();
}

public DomainFieldRow setDateTimeFormat(String dateTime)
public String getDateTimeFormatTime()
{
expand();
if (isDateTimeInherited())
setDateTimeInherited(false);
String formatValue;

if(elementCache().dateTimeFormatTimeSelect.isInteractive())
{
formatValue = getFormatWithoutExample(elementCache().dateTimeFormatTimeSelect.getValue());
}
else
{
formatValue = getFormatWithoutExample(elementCache().disabledDateTimeTimeFormat.getText());
}

String[] parts = dateTime.split("\\s+", 2);
if (parts.length == 2)
return setDateTimeFormat(parts[0], parts[1]);
return setDateTimeFormat(parts[0], "<none>");
return formatValue;
}

public DomainFieldRow setDateTimeFormat(String date, String time)
public boolean isDateTimeFormatTimeEnabled()
{
expand();
if (isDateTimeInherited())
setDateTimeInherited(false);
return elementCache().dateTimeFormatTimeSelect.isInteractive();
}

elementCache().dateTimeFormatDateSelect.typeAheadSelect(date + " (");
elementCache().dateTimeFormatTimeSelect.typeAheadSelect("<none>".equals(time) ? time : time + " (");
return this;
public String getDateTimeFormat()
{
String date = getDateTimeFormatDate();
String time = getDateTimeFormatTime();
if (TIME_FORMAT.none.toString().equals(time) || StringUtils.isEmpty(time))
return date;

return date + " " + time;
}

public DomainFieldRow setDateInherited(boolean check)
Expand All @@ -1380,15 +1393,42 @@ public boolean isDateInherited()

public String getDateFormat()
{
return getFormatWithoutExample(elementCache().dateFormatSelect.getValue());
String formatValue;

if(elementCache().dateFormatSelect.isInteractive())
{
formatValue = getFormatWithoutExample(elementCache().dateFormatSelect.getValue());
}
else
{
formatValue = getFormatWithoutExample(elementCache().disabledDateFormat.getText());
}

return formatValue;
}

public boolean isDateFormatEnabled()
{
return elementCache().dateFormatSelect.isInteractive();
}

public DomainFieldRow setDateFormat(String dateFormat)
public DomainFieldRow setDateFormat(DATE_FORMAT dateFormat)
{
expand();
if (isDateInherited())
setDateInherited(false);
elementCache().dateFormatSelect.typeAheadSelect(dateFormat + " (");

String txt;
if (dateFormat.equals(DATE_FORMAT.DATE))
{
txt = dateFormat.toString();
}
else
{
txt = dateFormat + " (";
}
elementCache().dateFormatSelect.typeAheadSelect(txt);

return this;
}

Expand All @@ -1406,18 +1446,56 @@ public boolean isTimeInherited()

public String getTimeFormat()
{
return getFormatWithoutExample(elementCache().timeFormatSelect.getValue());
String formatValue;

if(elementCache().timeFormatSelect.isInteractive())
{
formatValue = getFormatWithoutExample(elementCache().timeFormatSelect.getValue());
}
else
{
formatValue = getFormatWithoutExample(elementCache().disabledTimeFormat.getText());
}

return formatValue;
}

public DomainFieldRow setTimeFormat(String timeFormat)
public boolean isTimeFormatEnabled()
{
return elementCache().timeFormatSelect.isInteractive();
}

public DomainFieldRow setTimeFormat(TIME_FORMAT timeFormat)
{
expand();
if (isTimeInherited())
setTimeInherited(false);
elementCache().timeFormatSelect.typeAheadSelect(timeFormat + " (");

String txt;

if (timeFormat.equals(TIME_FORMAT.TIME))
{
txt = timeFormat.toString();
}
else
{
txt = timeFormat + " (";
}

elementCache().timeFormatSelect.typeAheadSelect(txt);
return this;
}

public boolean hasDomainWarningIcon()
{
return elementCache().domainWarningIcon.isDisplayed();
}

public WebElement getDomainWarningIcon()
{
return elementCache().domainWarningIcon;
}

public static class DomainFieldRowFinder extends WebDriverComponentFinder<DomainFieldRow, DomainFieldRowFinder>
{
private final Locator.XPathLocator _baseLocator = Locator.tagWithClassContaining("div", "domain-field-row").withoutClass("domain-floating-hdr");
Expand Down Expand Up @@ -1523,15 +1601,25 @@ protected class ElementCache extends WebDriverComponent.ElementCache
public final FilteringReactSelect dateTimeFormatDateSelect = FilteringReactSelect.finder(getDriver())
.withNamedInput("domainpropertiesrow-format_datedateTime")
.refindWhenNeeded(this);
public final WebElement disabledDateTimeDateFormat = Locator.tagWithAttributeContaining("div", "id", "domainpropertiesrow-format_datedateTime")
.descendant("div[contains(@class,'select-input__single-value--is-disabled')]").findWhenNeeded(this);
public final FilteringReactSelect dateTimeFormatTimeSelect = FilteringReactSelect.finder(getDriver())
.withNamedInput("domainpropertiesrow-format_timedateTime")
.refindWhenNeeded(this);
public final WebElement disabledDateTimeTimeFormat = Locator.tagWithAttributeContaining("div", "id", "domainpropertiesrow-format_timedateTime")
.descendant("div[contains(@class,'select-input__single-value--is-disabled')]").findWhenNeeded(this);
public final FilteringReactSelect dateFormatSelect = FilteringReactSelect.finder(getDriver())
.withNamedInput("domainpropertiesrow-format_datedate")
.refindWhenNeeded(this);
public final WebElement disabledDateFormat = Locator.tagWithAttributeContaining("div", "id", "domainpropertiesrow-format_datedate")
.descendant("div[contains(@class,'select-input__single-value--is-disabled')]").findWhenNeeded(this);
public final FilteringReactSelect timeFormatSelect = FilteringReactSelect.finder(getDriver())
.withNamedInput("domainpropertiesrow-format_timetime")
.refindWhenNeeded(this);
public final WebElement disabledTimeFormat = Locator.tagWithAttributeContaining("div", "id", "domainpropertiesrow-format_timetime")
.descendant("div[contains(@class,'select-input__single-value--is-disabled')]").findWhenNeeded(this);
public final WebElement domainWarningIcon = Locator.tagWithClass("span", "domain-warning-icon")
.findWhenNeeded(this);

// lookup field options
public final Select lookupContainerSelect = SelectWrapper.Select(Locator.name("domainpropertiesrow-lookupContainer"))
Expand Down
33 changes: 32 additions & 1 deletion src/org/labkey/test/components/domain/DomainFormPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.labkey.test.components.html.Checkbox;
import org.labkey.test.components.react.ToggleButton;
import org.labkey.test.components.ui.grids.ResponsiveGrid;
import org.labkey.test.pages.core.admin.BaseSettingsPage.DATE_FORMAT;
import org.labkey.test.pages.core.admin.BaseSettingsPage.TIME_FORMAT;
import org.labkey.test.params.FieldDefinition;
import org.labkey.test.selenium.WebElementWrapper;
import org.openqa.selenium.NoSuchElementException;
Expand Down Expand Up @@ -125,7 +127,36 @@ private DomainFormPanel editField(DomainFieldRow fieldRow, FieldDefinition field
if (fieldDefinition.getLabel() != null)
fieldRow.setLabel(fieldDefinition.getLabel());
if (fieldDefinition.getFormat() != null)
fieldRow.setFormat(fieldDefinition.getFormat(), fieldDefinition.getRangeURI());
{
if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.Date))
{
fieldRow.setDateFormat(DATE_FORMAT.get(fieldDefinition.getFormat()));
}
else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.Time))
{
fieldRow.setTimeFormat(TIME_FORMAT.get(fieldDefinition.getFormat()));
}
else if (fieldDefinition.getType().equals(FieldDefinition.ColumnType.DateAndTime))
{
String format = fieldDefinition.getFormat().trim();

int index = format.indexOf(" ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works with MMMM dd yyyy date time format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right.
I have changed the code to this:

                String format = fieldDefinition.getFormat().trim();
                int index = format.lastIndexOf(" ");

                if (format.substring(index + 1).contains(":"))
                {
                    fieldRow.setDateTimeFormat(
                            DATE_FORMAT.get(format.substring(0, index)),
                            TIME_FORMAT.get(format.substring(index + 1)));

If the "last part" of the format string contains a ':' the it has a time value. If it doesn't then it is a date only format.

if (index > 0)
{
fieldRow.setDateTimeFormat(
DATE_FORMAT.get(format.substring(0, index)),
TIME_FORMAT.get(format.substring(index + 1)));
}
else
{
fieldRow.setDateTimeFormat(DATE_FORMAT.get(format));
}
}
else
{
fieldRow.setFormat(fieldDefinition.getFormat(), fieldDefinition.getRangeURI());
}
}
if (fieldDefinition.getScale() != null)
fieldRow.setCharCount(fieldDefinition.getScale());
if (fieldDefinition.getURL() != null)
Expand Down
Loading