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 #2106

Closed
wants to merge 16 commits into from
Closed
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
171 changes: 112 additions & 59 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,12 +1290,14 @@ 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())
Expand All @@ -1317,53 +1306,65 @@ public DomainFieldRow setDateTimeFormatDate(String dateFormat)
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("<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,10 +1381,26 @@ 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 DomainFieldRow setDateFormat(String dateFormat)
public boolean isDateFormatEnabled()
{
return elementCache().dateFormatSelect.isInteractive();
}

public DomainFieldRow setDateFormat(DATE_FORMAT dateFormat)
{
expand();
if (isDateInherited())
Expand All @@ -1406,10 +1423,26 @@ 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())
Expand All @@ -1418,6 +1451,16 @@ public DomainFieldRow setTimeFormat(String timeFormat)
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 +1566,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.TimeoutException;
Expand Down Expand Up @@ -124,7 +126,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(" ");
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