Browse Source

Clean up DateField UI tests.

Fixes vaadin/framework8-issues#584
tags/8.0.0.beta2
Denis 7 years ago
parent
commit
7b6c97bd4b
38 changed files with 236 additions and 2533 deletions
  1. 6
    5
      uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormat.java
  2. 0
    206
      uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java
  3. 4
    11
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldChangeResolution.java
  4. 0
    151
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldEmptyValid.java
  5. 0
    71
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldExtendedRange.java
  6. 0
    50
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldLocale.java
  7. 15
    21
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupClosingOnDetach.java
  8. 0
    66
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java
  9. 0
    43
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPrimaryStyleNames.java
  10. 0
    135
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRangeValidation.java
  11. 0
    223
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRanges.java
  12. 2
    9
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldReadOnly.java
  13. 0
    38
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTextEnabled.java
  14. 0
    93
      uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldUnparsableDate.java
  15. 0
    34
      uitest/src/main/java/com/vaadin/tests/components/datefield/DatePopupStyleName.java
  16. 0
    46
      uitest/src/main/java/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java
  17. 0
    45
      uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledDateFieldWidth.java
  18. 0
    86
      uitest/src/main/java/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java
  19. 0
    66
      uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldIsValid.java
  20. 0
    262
      uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldRanges.java
  21. 0
    145
      uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldTest.java
  22. 0
    13
      uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyInlineDateFieldTest.java
  23. 0
    53
      uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyPopupDateFieldTest.java
  24. 0
    79
      uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java
  25. 0
    51
      uitest/src/main/java/com/vaadin/tests/components/datefield/LowResolution.java
  26. 0
    34
      uitest/src/main/java/com/vaadin/tests/components/datefield/NarrowPopupDateFieldInTable.java
  27. 0
    89
      uitest/src/main/java/com/vaadin/tests/components/datefield/RequiredInvalidDateField.java
  28. 0
    34
      uitest/src/main/java/com/vaadin/tests/components/datefield/TestDatefieldYear.java
  29. 0
    77
      uitest/src/main/java/com/vaadin/tests/components/datefield/ValueThroughProperty.java
  30. 0
    47
      uitest/src/main/java/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java
  31. 53
    0
      uitest/src/main/java/com/vaadin/tests/smoke/DateFieldSmoke.java
  32. 0
    99
      uitest/src/main/java/com/vaadin/v7/tests/components/datefield/DateFieldDiscardValue.java
  33. 39
    0
      uitest/src/test/java/com/vaadin/tests/components/datefield/CustomDateFormatTest.java
  34. 1
    1
      uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldTestTest.java
  35. 37
    0
      uitest/src/test/java/com/vaadin/tests/components/datefield/InlineDateFieldTestTest.java
  36. 0
    65
      uitest/src/test/java/com/vaadin/tests/components/datefield/LegacyDateFieldIsValidTest.java
  37. 79
    0
      uitest/src/test/java/com/vaadin/tests/smoke/DateFieldSmokeTest.java
  38. 0
    85
      uitest/src/test/java/com/vaadin/v7/tests/components/datefield/DateFieldDiscardValueTest.java

+ 6
- 5
uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormat.java View File

@@ -3,22 +3,23 @@ package com.vaadin.tests.components.datefield;
import java.time.LocalDate;
import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;

public class CustomDateFormat extends TestBase {
public class CustomDateFormat extends AbstractTestUI {

@Override
protected void setup() {
protected void setup(VaadinRequest request) {
Locale locale = new Locale("fi", "FI");
AbstractDateField df = new TestDateField();
df.setResolution(Resolution.DAY);
df.setLocale(locale);
df.setWidth("300px");

String pattern = "d. MMMM'ta 'yyyy 'klo";
String pattern = "d. MMMM'ta 'yyyy 'klo'";
df.setDateFormat(pattern);

df.setValue(LocalDate.of(2010, 1, 1));
@@ -28,7 +29,7 @@ public class CustomDateFormat extends TestBase {
}

@Override
protected String getDescription() {
protected String getTestDescription() {
return "Month name should be visible in text box if format pattern includes it";
}


+ 0
- 206
uitest/src/main/java/com/vaadin/tests/components/datefield/CustomDateFormats.java View File

@@ -1,206 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.ui.NativeSelect;

public class CustomDateFormats extends TestBase {

private static final Object CAPTION = "C";

private Component customFormats = null;

@Override
protected void setup() {
final NativeSelect s = new NativeSelect("Locale");
s.setImmediate(true);
s.setNullSelectionAllowed(false);
s.addContainerProperty(CAPTION, String.class, "");
addLocale(Locale.FRANCE, s);
addLocale(Locale.CHINESE, s);
addLocale(Locale.US, s);
addLocale(Locale.UK, s);
addLocale(new Locale("fi", "FI"), s);

s.addListener(new Property.ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {
setDateFieldLocale((Locale) s.getValue());
}
});
addComponent(s);
s.setValue(Locale.FRANCE);
}

private void addLocale(Locale locale, NativeSelect s) {
Item i = s.addItem(locale);
i.getItemProperty(CAPTION).setValue(locale.toString());

}

protected void setDateFieldLocale(Locale value) {
Component n = getCustomFormats(value);
if (customFormats == null) {
addComponent(n);
} else {
replaceComponent(customFormats, n);
}
customFormats = n;

}

private GridLayout getCustomFormats(Locale locale) {
GridLayout gridLayout = createGridLayout();
usedDebugIds.clear();
addDateFields(gridLayout, locale);

return gridLayout;
}

private GridLayout createGridLayout() {
GridLayout gridLayout = new GridLayout(4, 4);
gridLayout.setMargin(true);
gridLayout.addComponent(new Label("FORMAT"));
gridLayout.addComponent(new Label("DATEFIELD"));
gridLayout.addComponent(new Label("SERVER SIDE VALUE"));
gridLayout.addComponent(new Label("EXPECTED"));

return gridLayout;
}

private void addDateFields(GridLayout gridLayout, Locale locale) {
addDateField(gridLayout, "d M yyyy", locale);
addDateField(gridLayout, "d MM yyyy", locale);
addDateField(gridLayout, "d MMM yyyy", locale);
addDateField(gridLayout, "d MMMM yyyy", locale);

addDateField(gridLayout, "dd M yyyy", locale);
addDateField(gridLayout, "ddd M yyyy", locale);

addDateField(gridLayout, "d M y", locale, "d M yyyy");
addDateField(gridLayout, "d M yy", locale);
addDateField(gridLayout, "d M yyy", locale, "d M yyyy");
addDateField(gridLayout, "d M yyyy", locale);

addDateField(gridLayout, getDatePattern(locale, DateFormat.FULL),
locale);
addDateField(gridLayout, getDatePattern(locale, DateFormat.LONG),
locale);
addDateField(gridLayout, getDatePattern(locale, DateFormat.MEDIUM),
locale);
addDateField(gridLayout, getDatePattern(locale, DateFormat.SHORT),
locale);
addDateField(gridLayout, "EEE d MMMM yyyy", locale);

}

private String getDatePattern(Locale locale, int dateStyle) {
DateFormat dateFormat = DateFormat.getDateInstance(dateStyle, locale);

if (dateFormat instanceof SimpleDateFormat) {
String pattern = ((SimpleDateFormat) dateFormat).toPattern();
return pattern;
}
return null;

}

public class Data {

private Label label;
private String pattern;

public Data(Label label, String pattern) {
this.label = label;
this.pattern = pattern;
}

}

private Set<String> usedDebugIds = new HashSet<>();

private void addDateField(GridLayout gridLayout, String pattern,
Locale locale, String expectedDateFormat) {
Label serversideValueLabel = new Label();

AbstractDateField df = new TestDateField();
df.setResolution(Resolution.DAY);
df.setLocale(locale);
df.setWidth("300px");
df.setDateFormat(pattern);
String debugId = pattern.replace('/', 'X');
// only certain characters are allowed in debug IDs
debugId = debugId.replaceAll("[^-a-zA-Z .'_]", "X");
while (usedDebugIds.contains(debugId)) {
debugId = debugId + "-";
}
df.setId(debugId);
usedDebugIds.add(debugId);

df.setData(new Data(serversideValueLabel, pattern));
df.setValue(LocalDate.of(2010, 2, 1));
df.addValueChangeListener(event -> updateServerSideLabel(
(AbstractDateField) event.getComponent()));

Label patternLabel = new Label(pattern);
patternLabel.setWidth(null);
DateTimeFormatter expDateFormat = DateTimeFormatter
.ofPattern(expectedDateFormat, locale);

Label expectedLabel = new Label(expDateFormat.format(df.getValue()));
if (!pattern.equals(expectedDateFormat)) {
expectedLabel
.setValue(expectedLabel.getValue() + " (differs from JDK)");
}
expectedLabel.setWidth(null);

gridLayout.addComponent(patternLabel);
gridLayout.addComponent(df);
gridLayout.addComponent(serversideValueLabel);
gridLayout.addComponent(expectedLabel);

updateServerSideLabel(df);
}

private void updateServerSideLabel(AbstractDateField df) {
Data data = (Data) df.getData();
String pattern = data.pattern;
Locale locale = df.getLocale();
SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);

String newValue = formatter.format(df.getValue());
data.label.setValue(newValue);
}

private void addDateField(GridLayout gridLayout, String pattern,
Locale locale) {
addDateField(gridLayout, pattern, locale, pattern);
}

@Override
protected String getDescription() {
return "Test that DateField renders custom date formats the same way as SimpleDateFormat formats them";
}

@Override
protected Integer getTicketNumber() {
return 5465;
}
}

+ 4
- 11
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldChangeResolution.java View File

@@ -20,8 +20,6 @@ import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.DateField;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
@@ -45,15 +43,10 @@ public class DateFieldChangeResolution extends AbstractReindeerTestUI {
addComponent(hlayout);
for (final Resolution value : Resolution.values()) {
String resolutionString = value.toString().toLowerCase();
Button b = new Button(resolutionString);
b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
dateField.setResolution(value);
}
});
b.setId(BUTTON_BASE_ID + resolutionString);
hlayout.addComponent(b);
Button button = new Button(resolutionString);
button.addClickListener(event -> dateField.setResolution(value));
button.setId(BUTTON_BASE_ID + resolutionString);
hlayout.addComponent(button);
}

}

+ 0
- 151
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldEmptyValid.java View File

@@ -1,151 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.data.util.ObjectProperty;
import com.vaadin.v7.shared.ui.datefield.Resolution;
import com.vaadin.v7.ui.PopupDateField;

@SuppressWarnings("serial")
public class DateFieldEmptyValid extends TestBase {

private Log log;

private MyDateField df;

private SimpleDateFormat formatter = new SimpleDateFormat(
"MMMM d, yyyy hh:mm:ss aaa", Locale.US);

public class MyDateField extends PopupDateField {
@Override
public boolean isEmpty() {
return super.isEmpty();
}

}

@Override
protected void setup() {
addComponent(new Label("<br/><br/>", ContentMode.HTML));
log = new Log(8);
addComponent(log);
df = new MyDateField();
df.setId("DateField");
df.setRequired(true);
df.setLocale(new Locale("fi", "FI"));
df.setValue(new Date(100000000000L));
df.setImmediate(true);
df.setResolution(Resolution.DAY);
df.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
log.log("Value changeEvent");
checkEmpty();
}
});
addComponent(df);
checkEmpty();
Button b = new Button("Clear date");
b.setId("clear");
b.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
log.log("Clearing date aka setValue(null)");
df.setValue(null);
}
});
addComponent(b);

b = new Button("Set date to 4.5.1990");
b.setId("set4.5.1990");
b.addClickListener(new ClickListener() {

@Override
@SuppressWarnings("deprecation")
public void buttonClick(ClickEvent event) {
log.log("Setting new value to datefield (4.5.1990)");
df.setValue(new Date(1990 - 1900, 5 - 1, 4));
}
});
addComponent(b);

b = new Button("Set date to 5.6.2000 using a property data source");
b.addClickListener(new ClickListener() {

@Override
@SuppressWarnings("deprecation")
public void buttonClick(ClickEvent event) {
log.log("Setting new object property (5.6.2000) to datefield");
ObjectProperty<Date> dfProp = new ObjectProperty<>(
new Date(2000 - 1900, 6 - 1, 5), Date.class);
df.setPropertyDataSource(dfProp);
}
});
b.setId("set-by-ds");
addComponent(b);

b = new Button(
"Set date to 27.8.2005 by changing a new property data source from null, ds attached before value setting.");
b.setId("set-via-ds");
b.addClickListener(new ClickListener() {

@Override
@SuppressWarnings("deprecation")
public void buttonClick(ClickEvent event) {
log.log("Setting object property (with value null) to datefield and set value of property to 27.8.2005");
ObjectProperty<Date> dfProp = new ObjectProperty<>(null,
Date.class);
df.setPropertyDataSource(dfProp);
dfProp.setValue(new Date(2005 - 1900, 8 - 1, 27));
}
});
addComponent(b);

b = new Button("Check value");
b.setId("check-value");
b.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
log.log("Checking state");
checkEmpty();
}
});
addComponent(b);
}

private void checkEmpty() {
Object value = df.getValue();
if (value instanceof Date) {
value = formatter.format(df.getValue());
}

log.log("DateField value is now " + value);
// log.log("DateField value is now " + df.getValue());
log.log("isEmpty: " + df.isEmpty() + ", isValid: " + df.isValid());
}

@Override
protected String getDescription() {
return "Tests the isEmpty() and isValid() functionality of a DateField. The field is required and has no other validators."
+ "IsEmpty() should return true when the field is truly empty i.e. contains no text, no matter how the field has been made empty. If the field contains any text, isEmpty() should return false."
+ "IsValid() should in this case return true if the field is not empty and vice versa.";
}

@Override
protected Integer getTicketNumber() {
return 5277;
}

}

+ 0
- 71
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldExtendedRange.java View File

@@ -1,71 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Locale;
import java.util.stream.Stream;

import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.DateField;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.InlineDateField;

@SuppressWarnings("serial")
public class DateFieldExtendedRange extends TestBase {

@Override
protected void setup() {
GridLayout layout = new GridLayout(2, 3);
layout.setWidth("600px");
layout.setSpacing(true);

final AbstractDateField[] fields = new AbstractDateField[6];

Locale fi = new Locale("fi", "FI");
Locale us = new Locale("en", "US");

fields[0] = makeDateField(true, fi, "Finnish locale");
fields[1] = makeDateField(false, fi, "Finnish locale");

fields[2] = makeDateField(true, us, "US English locale");
fields[3] = makeDateField(false, us, "US English locale");

fields[4] = makeDateField(true, fi, "Finnish locale with week numbers");
fields[4].setShowISOWeekNumbers(true);
fields[5] = makeDateField(false, fi,
"Finnish locale with week numbers");
fields[5].setShowISOWeekNumbers(true);

for (AbstractDateField f : fields) {
layout.addComponent(f);
}

addComponent(layout);

addComponent(new Button("Change date", event -> Stream.of(fields)
.forEach(field -> field.setValue(LocalDate.of(2010, 2, 16)))));
}

@Override
protected String getDescription() {
return "Show a few days of the preceding and following months in the datefield popup";
}

@Override
protected Integer getTicketNumber() {
return 6718;
}

private AbstractDateField makeDateField(boolean isPopup, Locale locale,
String caption) {
AbstractDateField df = isPopup ? new DateField()
: new InlineDateField();
df.setResolution(Resolution.DAY);
df.setValue(LocalDate.of(2011, 1, 1));
df.setLocale(locale);
df.setCaption(caption);
return df;
}
}

+ 0
- 50
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldLocale.java View File

@@ -1,50 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Locale;

import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class DateFieldLocale extends TestBase {

@Override
public void setup() {
final AbstractDateField dateField = new TestDateField("DateField");
dateField.setLocale(new Locale("fi", "FI"));
dateField.setCaption(dateField.getLocale().toString());
dateField.setValue(LocalDate.of(2013, 7, 27));
dateField.setResolution(Resolution.DAY);

addComponent(new Button("Change locale", new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
if (dateField.getLocale().getCountry().equalsIgnoreCase("fi")) {
dateField.setLocale(new Locale("zh", "CN"));
} else {
dateField.setLocale(new Locale("fi", "FI"));
}
dateField.setCaption(dateField.getLocale().toString());
}
}));

addComponent(dateField);
}

@Override
protected String getDescription() {
return "Click change locale to switch between Finnish and Chinese locale for the DateField. The date string should be updated in addition to the caption.";
}

@Override
protected Integer getTicketNumber() {
return 3935;
}

}

+ 15
- 21
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupClosingOnDetach.java View File

@@ -18,8 +18,6 @@ package com.vaadin.tests.components.datefield;
import java.util.Timer;
import java.util.TimerTask;

import com.vaadin.event.LayoutEvents.LayoutClickEvent;
import com.vaadin.event.LayoutEvents.LayoutClickListener;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.tests.components.TestDateField;
@@ -33,26 +31,22 @@ public class DateFieldPopupClosingOnDetach extends AbstractReindeerTestUI {
getUI().setPollInterval(500);

final AbstractDateField df = new TestDateField();
getLayout().addLayoutClickListener(new LayoutClickListener() {
getLayout().addLayoutClickListener(event -> {
// Use a background Thread to remove the DateField 1 second
// after being clicked.
TimerTask removeTask = new TimerTask() {

@Override
public void layoutClick(LayoutClickEvent event) {
// Use a background Thread to remove the DateField 1 second
// after being clicked.
TimerTask removeTask = new TimerTask() {

@Override
public void run() {
getUI().access(new Runnable() {
@Override
public void run() {
removeComponent(df);
}
});
}
};
new Timer(true).schedule(removeTask, 1000);
}
@Override
public void run() {
getUI().access(new Runnable() {
@Override
public void run() {
removeComponent(df);
}
});
}
};
new Timer(true).schedule(removeTask, 1000);
});

addComponent(df);

+ 0
- 66
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPopupOffScreen.java View File

@@ -1,66 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Locale;

import com.vaadin.tests.components.AbstractTestCase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.LegacyWindow;

public class DateFieldPopupOffScreen extends AbstractTestCase {

@Override
protected String getDescription() {
return "Test for the popup position from a DateField. The popup should always be on-screen even if the DateField is close the the edge of the browser.";
}

@Override
protected Integer getTicketNumber() {
return 3639;
}

@Override
public void init() {
LegacyWindow mainWindow = new LegacyWindow(getClass().getName());

GridLayout mainLayout = new GridLayout(3, 3);
mainLayout.setSizeFull();

AbstractDateField df;

df = createDateField();
mainLayout.addComponent(df, 2, 0);
mainLayout.setComponentAlignment(df, Alignment.TOP_RIGHT);

df = createDateField();
mainLayout.addComponent(df, 2, 1);
mainLayout.setComponentAlignment(df, Alignment.MIDDLE_RIGHT);

df = createDateField();
mainLayout.addComponent(df, 2, 2);
mainLayout.setComponentAlignment(df, Alignment.BOTTOM_RIGHT);

df = createDateField();
mainLayout.addComponent(df, 0, 2);
mainLayout.setComponentAlignment(df, Alignment.BOTTOM_LEFT);

df = createDateField();
mainLayout.addComponent(df, 1, 2);
mainLayout.setComponentAlignment(df, Alignment.BOTTOM_CENTER);

mainWindow.setContent(mainLayout);
setMainWindow(mainWindow);
}

private AbstractDateField createDateField() {
AbstractDateField df = new TestDateField();
df.setLocale(new Locale("fi"));
df.setDescription(
"This is a long, multiline tooltip.<br/>It should always be on screen so it can be read.");
df.setValue(LocalDate.of(2000, 1, 1));
return df;
}
}

+ 0
- 43
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldPrimaryStyleNames.java View File

@@ -1,43 +0,0 @@
package com.vaadin.tests.components.datefield;

import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.InlineDateField;

public class DateFieldPrimaryStyleNames extends TestBase {

@Override
protected void setup() {
final AbstractDateField df = new TestDateField();
df.setPrimaryStyleName("my-datefield");
addComponent(df);

final InlineDateField idf = new InlineDateField();
idf.setPrimaryStyleName("my-inline-datefield");
addComponent(idf);

addComponent(
new Button("Set primary stylename", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
df.setPrimaryStyleName("my-second-datefield");
idf.setPrimaryStyleName("my-second-inline-datefield");
}
}));

}

@Override
protected String getDescription() {
return "Datefield should work with primary stylenames both initially and dynamically";
}

@Override
protected Integer getTicketNumber() {
return 9903;
}

}

+ 0
- 135
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRangeValidation.java View File

@@ -1,135 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.util.Date;
import java.util.Locale;

import com.vaadin.data.HasValue;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.CheckBoxWithPropertyDataSource;
import com.vaadin.ui.CheckBox;
import com.vaadin.v7.data.util.BeanItem;
import com.vaadin.v7.data.validator.RangeValidator;
import com.vaadin.v7.ui.PopupDateField;

public class DateFieldRangeValidation extends TestBase {

public class Range {
private Date from, to;
private boolean fromInclusive = true;
private boolean toInclusive = true;

public boolean isFromInclusive() {
return fromInclusive;
}

public void setFromInclusive(boolean fromInclusive) {
this.fromInclusive = fromInclusive;
}

public boolean isToInclusive() {
return toInclusive;
}

public void setToInclusive(boolean toInclusive) {
this.toInclusive = toInclusive;
}

public Date getFrom() {
return from;
}

public void setFrom(Date from) {
this.from = from;
}

public Date getTo() {
return to;
}

public void setTo(Date to) {
this.to = to;
}

}

private Range range = new Range();

private PopupDateField actualDateField;
private HasValue.ValueChangeListener<Boolean> refreshField = event -> actualDateField
.markAsDirty();

@Override
protected void setup() {
BeanItem<Range> bi = new BeanItem<>(range);
range.setFrom(new Date(2011 - 1900, 12 - 1, 4));
range.setTo(new Date(2011 - 1900, 12 - 1, 15));

PopupDateField fromField = createDateField();
fromField.setPropertyDataSource(bi.getItemProperty("from"));
CheckBox fromInclusive = new CheckBoxWithPropertyDataSource(
"From inclusive", bi.getItemProperty("fromInclusive"));
CheckBox toInclusive = new CheckBoxWithPropertyDataSource(
"To inclusive", bi.getItemProperty("toInclusive"));
fromInclusive.addValueChangeListener(refreshField);
toInclusive.addValueChangeListener(refreshField);

PopupDateField toField = createDateField();
toField.setPropertyDataSource(bi.getItemProperty("to"));

actualDateField = createDateField();
actualDateField.setValue(new Date(2011 - 1900, 12 - 1, 1));
actualDateField.addValidator(
new RangeValidator<Date>("", Date.class, null, null) {
@Override
public boolean isMinValueIncluded() {
return range.isFromInclusive();
}

@Override
public boolean isMaxValueIncluded() {
return range.isToInclusive();
}

@Override
public Date getMaxValue() {
return range.getTo();
}

@Override
public Date getMinValue() {
return range.getFrom();
}

@Override
public String getErrorMessage() {
return "Date must be in range " + getMinValue() + " - "
+ getMaxValue();
}
});
addComponent(fromField);
addComponent(fromInclusive);
addComponent(toField);
addComponent(toInclusive);
addComponent(actualDateField);
}

private PopupDateField createDateField() {
PopupDateField df = new PopupDateField();
df.setLocale(new Locale("en", "US"));
df.setBuffered(false);
df.setImmediate(true);
return df;
}

@Override
protected String getDescription() {
return "Tests the DateField range validator. The first field sets the minimum date, the second the maximum. Checkboxes control if the selected date is ok or not.";
}

@Override
protected Integer getTicketNumber() {
// TODO Auto-generated method stub
return null;
}

}

+ 0
- 223
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldRanges.java View File

@@ -1,223 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.ui.NativeSelect;

public class DateFieldRanges extends AbstractReindeerTestUI {

@Override
protected Integer getTicketNumber() {
return 6241;
}

private Label label = new Label();
private NativeSelect resoSelect = new NativeSelect("Resolution");
private AbstractDateField fromRange = new TestDateField("Range start");
private AbstractDateField toRange = new TestDateField("Range end");
private AbstractDateField valueDF = new TestDateField("Value");
private Button recreate = new Button("Recreate static datefields");
private Button clearRangeButton = new Button("Clear range");

private GridLayout currentStaticContainer;

private AbstractDateField inlineDynamicDateField;
private AbstractDateField dynamicDateField;

private Calendar createCalendar() {
Calendar c = Calendar.getInstance();
c.set(2013, 3, 26, 6, 1, 12);
return c;
}

private Date newDate() {
return createCalendar().getTime();
}

private void initializeControlFields() {
resoSelect.addItem(Resolution.DAY);
resoSelect.addItem(Resolution.MONTH);
resoSelect.addItem(Resolution.YEAR);
resoSelect.setImmediate(true);
resoSelect.setValue(Resolution.DAY);
resoSelect.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {

Resolution r = (Resolution) resoSelect.getValue();
inlineDynamicDateField.setResolution(r);
dynamicDateField.setResolution(r);

}
});

fromRange.setValue(null);
fromRange.addValueChangeListener(event -> {
inlineDynamicDateField.setRangeStart(fromRange.getValue());
dynamicDateField.setRangeStart(fromRange.getValue());
});

toRange.setValue(null);
toRange.addValueChangeListener(event -> {
inlineDynamicDateField.setRangeEnd(toRange.getValue());
dynamicDateField.setRangeEnd(toRange.getValue());
});

valueDF.setValue(null);
valueDF.addValueChangeListener(event -> {
inlineDynamicDateField.setValue(valueDF.getValue());
dynamicDateField.setValue(valueDF.getValue());
});

recreate.addClickListener(new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
GridLayout newContainer = createStaticFields();
replaceComponent(currentStaticContainer, newContainer);
currentStaticContainer = newContainer;
}
});

clearRangeButton.addClickListener(new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
fromRange.setValue(null);
toRange.setValue(null);
}
});

Calendar startCal = createCalendar();
Calendar endCal = createCalendar();
endCal.add(Calendar.DATE, 30);

dynamicDateField = createDateField(startCal.getTime(), endCal.getTime(),
null, Resolution.DAY, false);
inlineDynamicDateField = createDateField(startCal.getTime(),
endCal.getTime(), null, Resolution.DAY, true);

resoSelect.setId("resoSelect");
fromRange.setId("fromRange");
toRange.setId("toRange");
valueDF.setId("valueDF");
recreate.setId("recreate");
clearRangeButton.setId("clearRangeButton");
dynamicDateField.setId("dynamicDateField");
inlineDynamicDateField.setId("inlineDynamicDateField");

}

@Override
protected void setup(VaadinRequest request) {
setLocale(new Locale("en", "US"));
getLayout().setWidth(100, Unit.PERCENTAGE);
getLayout().setHeight(null);
getLayout().setMargin(new MarginInfo(true, false, false, false));
getLayout().setSpacing(true);

initializeControlFields();

GridLayout gl = new GridLayout(2, 2);
gl.setSpacing(true);

gl.addComponent(dynamicDateField);
gl.addComponent(inlineDynamicDateField);

HorizontalLayout hl = new HorizontalLayout();
hl.setSpacing(true);
hl.addComponent(resoSelect);
hl.addComponent(fromRange);
hl.addComponent(toRange);
hl.addComponent(valueDF);
hl.addComponent(recreate);
hl.addComponent(clearRangeButton);
addComponent(hl);
addComponent(new Label("Dynamic DateFields"));
addComponent(gl);
currentStaticContainer = createStaticFields();
addComponent(new Label("Static DateFields"));
addComponent(currentStaticContainer);

addComponent(label);

}

private GridLayout createStaticFields() {
Calendar startCal = createCalendar();
Calendar endCal = createCalendar();
endCal.add(Calendar.DATE, 30);
GridLayout gl = new GridLayout(2, 2);
gl.setSpacing(true);
AbstractDateField df = createDateField(startCal.getTime(),
endCal.getTime(), null, Resolution.DAY, false);
gl.addComponent(df);
AbstractDateField inline = createDateField(startCal.getTime(),
endCal.getTime(), null, Resolution.DAY, true);
gl.addComponent(inline);
inline.setId("staticInline");
VerticalLayout vl = new VerticalLayout();

return gl;
}

private AbstractDateField createDateField(Date rangeStart, Date rangeEnd,
Date value, Resolution resolution, boolean inline) {

AbstractDateField df = null;

if (inline) {
df = new InlineDateField();
} else {
df = new TestDateField();
}

final AbstractDateField gg = df;
updateValuesForDateField(df);

df.addValueChangeListener(event -> {
label.setValue((gg.getValue() == null ? "Nothing"
: gg.getValue().toString()) + " selected. isValid: "
+ (gg.getErrorMessage() != null));
});
return df;
}

@Override
protected String getTestDescription() {
return "Not defined yet";

}

private void updateValuesForDateField(AbstractDateField df) {
LocalDate fromVal = fromRange.getValue();
LocalDate toVal = toRange.getValue();
LocalDate value = valueDF.getValue();
Resolution r = (Resolution) resoSelect.getValue();

df.setValue(value);
df.setResolution(r);
df.setRangeStart(fromVal);
df.setRangeEnd(toVal);
}

}

+ 2
- 9
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldReadOnly.java View File

@@ -8,8 +8,6 @@ import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class DateFieldReadOnly extends AbstractReindeerTestUI {

@@ -40,13 +38,8 @@ public class DateFieldReadOnly extends AbstractReindeerTestUI {
addComponent(timeField);

Button b = new Button("Switch read-only");
b.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
timeField.setReadOnly(!timeField.isReadOnly());
}
});
b.addClickListener(
event -> timeField.setReadOnly(!timeField.isReadOnly()));

addComponent(b);
}

+ 0
- 38
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldTextEnabled.java View File

@@ -1,38 +0,0 @@
package com.vaadin.tests.components.datefield;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.DateField;

public class DateFieldTextEnabled extends TestBase {

private static final String ENABLED = "DateField text box enabled";
private static final String DISABLED = "DateField text box disabled";

@Override
public void setup() {
final DateField field = new DateField();
final CheckBox box = new CheckBox(ENABLED, true);
box.addValueChangeListener(event -> {
field.setTextFieldEnabled(event.getValue());
if (field.isTextFieldEnabled()) {
box.setCaption(ENABLED);
} else {
box.setCaption(DISABLED);
}
});
addComponent(box);
addComponent(field);
}

@Override
protected String getDescription() {
return "tests whether or not enabling text field in the component works";
}

@Override
protected Integer getTicketNumber() {
return 6790;
}

}

+ 0
- 93
uitest/src/main/java/com/vaadin/tests/components/datefield/DateFieldUnparsableDate.java View File

@@ -1,93 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;

import com.vaadin.data.Result;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.v7.data.util.converter.Converter;

public class DateFieldUnparsableDate extends TestBase {

public class MyDateField extends AbstractDateField {
LocalDate oldDate = null;

public MyDateField(String caption) {
super(caption);
addValueChangeListener(event -> oldDate = getValue());
}

@Override
protected Result<LocalDate> handleUnparsableDateString(
String dateString) throws Converter.ConversionException {
return Result.ok(oldDate);
}
}

public class MyDateField2 extends AbstractDateField {
public MyDateField2(String caption) {
super(caption);
}

@Override
protected Result<LocalDate> handleUnparsableDateString(
String dateString) throws Converter.ConversionException {
return Result.ok(null);
}
}

public class MyDateField3 extends AbstractDateField {
public MyDateField3(String caption) {
super(caption);
}

@Override
protected Result<LocalDate> handleUnparsableDateString(
String dateString) throws Converter.ConversionException {
return Result.error("You should not enter invalid dates!");
}
}

public class MyDateField4 extends AbstractDateField {
public MyDateField4(String caption) {
super(caption);
}

@Override
protected Result<LocalDate> handleUnparsableDateString(
String dateString) throws Converter.ConversionException {
if (dateString != null && dateString.equals("today")) {
return Result.ok(LocalDate.now());
}
return Result.error("You should not enter invalid dates!");
}
}

@Override
protected void setup() {
MyDateField df = new MyDateField(
"Returns the old value for invalid dates");
addComponent(df);

MyDateField2 df2 = new MyDateField2("Returns empty for invalid dates");
addComponent(df2);

MyDateField3 df3 = new MyDateField3(
"Throws an exception for invalid dates");
addComponent(df3);

MyDateField4 df4 = new MyDateField4("Can convert 'today'");
addComponent(df4);

}

@Override
protected String getDescription() {
return "DateFields in various configurations (according to caption). All handle unparsable dates differently";
}

@Override
protected Integer getTicketNumber() {
return 4236;
}
}

+ 0
- 34
uitest/src/main/java/com/vaadin/tests/components/datefield/DatePopupStyleName.java View File

@@ -1,34 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;

import com.vaadin.server.UserError;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;

public class DatePopupStyleName extends TestBase {
@Override
public void setup() {
setTheme("reindeer-tests");

final AbstractDateField df = new TestDateField();
df.setValue(LocalDate.of(1970, 1, 15));
df.setWidth("200px");
df.setRequiredIndicatorVisible(true);
df.setComponentError(new UserError("abc"));
df.addStyleName("popup-style");
addComponent(df);
}

@Override
protected String getDescription() {
return "The DateField is given a style name 'test', but that style isn't applied on the calendar popup element.";
}

@Override
protected Integer getTicketNumber() {
return 8083;
}

}

+ 0
- 46
uitest/src/main/java/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java View File

@@ -1,46 +0,0 @@
package com.vaadin.tests.components.datefield;

import com.vaadin.tests.components.TestBase;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.validator.NullValidator;
import com.vaadin.v7.ui.DateField;

@SuppressWarnings("serial")
public class DefaultHandleUnparsableDateField extends TestBase {

@Override
protected void setup() {
final DateField date = new DateField("Default DateField");
date.setImmediate(true);
addComponent(date);
date.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if (date.isValid()) {
getMainWindow()
.showNotification(date.getValue().toString());
}

}
});

final DateField validated = new DateField(
"Validated Default DateField");
validated.setImmediate(true);
validated.addValidator(
new NullValidator("Validator: Date is NULL", false));
addComponent(validated);
}

@Override
protected String getDescription() {
return "By default the DateField should handle an unparsable date field without throwing an exception";
}

@Override
protected Integer getTicketNumber() {
return 4311;
}

}

+ 0
- 45
uitest/src/main/java/com/vaadin/tests/components/datefield/DisabledDateFieldWidth.java View File

@@ -1,45 +0,0 @@
package com.vaadin.tests.components.datefield;

import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.GridLayout;

public class DisabledDateFieldWidth extends TestBase {
@Override
public void setup() {

final AbstractDateField dateField1 = new TestDateField("DateField");
dateField1.setResolution(Resolution.YEAR);
dateField1.setEnabled(false);

Button button = new Button("Repaint datefield",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
dateField1.markAsDirty();
}
});

GridLayout gl = new GridLayout(3, 1);
gl.addComponent(dateField1);
gl.addComponent(button);

addComponent(gl);
}

@Override
protected String getDescription() {
// TODO Auto-generated method stub
return null;
}

@Override
protected Integer getTicketNumber() {
// TODO Auto-generated method stub
return null;
}
}

+ 0
- 86
uitest/src/main/java/com/vaadin/tests/components/datefield/DynamicallyChangeDateRange.java View File

@@ -1,86 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.DateField;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.VerticalLayout;

/**
* Main UI class
*/
@SuppressWarnings("serial")
public class DynamicallyChangeDateRange extends AbstractReindeerTestUI {

@Override
protected void setup(VaadinRequest request) {
setLocale(Locale.ENGLISH);
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);

final DateField df = new DateField();
df.setValue(LocalDate.of(2012, 5, 12));
setRange(df, 5);
layout.addComponent(df);

final InlineDateField df2 = new InlineDateField();
df2.setValue(LocalDate.of(2012, 11, 16));

setRange(df2, 5);
// layout.addComponent(df2);

Button button1 = new Button("Set Range Now+/-5d");
button1.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
setRange(df, 5);
setRange(df2, 5);
}
});
layout.addComponent(button1);

Button button2 = new Button("Set Range Now+/-10d");
button2.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
setRange(df, 10);
setRange(df2, 10);
}
});
layout.addComponent(button2);
}

private void setRange(AbstractDateField df, int days) {
df.setRangeStart(df.getValue().minusDays(days));
df.setRangeEnd(df.getValue().plusDays(days));

}

/*
* (non-Javadoc)
*
* @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
*/
@Override
protected String getTestDescription() {
return "Verifies that the allowed date range can be updated dynamically";
}

/*
* (non-Javadoc)
*
* @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
*/
@Override
protected Integer getTicketNumber() {
return 11940;
}

}

+ 0
- 66
uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldIsValid.java View File

@@ -1,66 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.ui.DateField;

public class LegacyDateFieldIsValid extends AbstractTestUIWithLog {

@Override
protected String getTestDescription() {
return "A dateField with invalid text should return false in isValid both when "
+ "handling ValueChange event and after value is changed.";
}

@Override
protected Integer getTicketNumber() {
return 14487;
}

private String pattern = "dd/MM/yy";
private SimpleDateFormat format = new SimpleDateFormat(pattern);

@Override
protected void setup(VaadinRequest request) {
final DateField dateField = new DateField("Insert Date: ");
dateField.setImmediate(true);
dateField.setDateFormat(pattern);

dateField.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
log("valueChange: value: " + format(dateField.getValue())
+ ", is valid: " + dateField.isValid());
}
});
addComponent(dateField);
addButton("check dateField", new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
log("buttonClick: value: " + format(dateField.getValue())
+ ", is valid: " + dateField.isValid());
}
});
}

/**
* @since
* @param value
* @return
*/
protected String format(Date value) {
if (value != null) {
return format.format(value);
} else {
return null;
}
}
}

+ 0
- 262
uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldRanges.java View File

@@ -1,262 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.shared.ui.datefield.Resolution;
import com.vaadin.v7.ui.DateField;
import com.vaadin.v7.ui.InlineDateField;
import com.vaadin.v7.ui.NativeSelect;

public class LegacyDateFieldRanges extends AbstractReindeerTestUI {

@Override
protected Integer getTicketNumber() {
return 6241;
}

private Label label = new Label();
private NativeSelect resoSelect = new NativeSelect("Resolution");
private DateField fromRange = new DateField("Range start");
private DateField toRange = new DateField("Range end");
private DateField valueDF = new DateField("Value");
private CheckBox immediateCB = new CheckBox("Immediate");
private Button recreate = new Button("Recreate static datefields");
private Button clearRangeButton = new Button("Clear range");

private GridLayout currentStaticContainer;

private DateField inlineDynamicDateField;
private DateField dynamicDateField;

private Calendar createCalendar() {
Calendar c = Calendar.getInstance();
c.set(2013, 3, 26, 6, 1, 12);
return c;
}

private Date newDate() {
return createCalendar().getTime();
}

private void initializeControlFields() {
resoSelect.addItem(Resolution.MINUTE);
resoSelect.addItem(Resolution.SECOND);
resoSelect.addItem(Resolution.HOUR);
resoSelect.addItem(Resolution.DAY);
resoSelect.addItem(Resolution.MONTH);
resoSelect.addItem(Resolution.YEAR);
resoSelect.setImmediate(true);
resoSelect.setValue(Resolution.DAY);
resoSelect.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {

Resolution r = (Resolution) resoSelect.getValue();
inlineDynamicDateField.setResolution(r);
dynamicDateField.setResolution(r);

}
});

fromRange.setValue(null);
fromRange.setImmediate(true);
fromRange.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {

inlineDynamicDateField.setRangeStart(fromRange.getValue());
dynamicDateField.setRangeStart(fromRange.getValue());

}
});

toRange.setValue(null);
toRange.setImmediate(true);
toRange.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {

inlineDynamicDateField.setRangeEnd(toRange.getValue());
dynamicDateField.setRangeEnd(toRange.getValue());

}
});

valueDF.setValue(null);
valueDF.setImmediate(true);
valueDF.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {

inlineDynamicDateField.setValue(valueDF.getValue());
dynamicDateField.setValue(valueDF.getValue());

}
});

immediateCB.setValue(true);
immediateCB.addValueChangeListener(event -> {
inlineDynamicDateField.setImmediate(immediateCB.getValue());
dynamicDateField.setImmediate(immediateCB.getValue());
});

recreate.addClickListener(new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
GridLayout newContainer = createStaticFields();
replaceComponent(currentStaticContainer, newContainer);
currentStaticContainer = newContainer;
}
});

clearRangeButton.addClickListener(new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
fromRange.setValue(null);
toRange.setValue(null);
}
});

Calendar startCal = createCalendar();
Calendar endCal = createCalendar();
endCal.add(Calendar.DATE, 30);

dynamicDateField = createDateField(startCal.getTime(), endCal.getTime(),
null, Resolution.DAY, false);
inlineDynamicDateField = createDateField(startCal.getTime(),
endCal.getTime(), null, Resolution.DAY, true);

resoSelect.setId("resoSelect");
fromRange.setId("fromRange");
toRange.setId("toRange");
valueDF.setId("valueDF");
immediateCB.setId("immediateCB");
recreate.setId("recreate");
clearRangeButton.setId("clearRangeButton");
dynamicDateField.setId("dynamicDateField");
inlineDynamicDateField.setId("inlineDynamicDateField");

}

@Override
protected void setup(VaadinRequest request) {
setLocale(new Locale("en", "US"));
getLayout().setWidth(100, Unit.PERCENTAGE);
getLayout().setHeight(null);
getLayout().setMargin(new MarginInfo(true, false, false, false));
getLayout().setSpacing(true);

initializeControlFields();

GridLayout gl = new GridLayout(2, 2);
gl.setSpacing(true);

gl.addComponent(dynamicDateField);
gl.addComponent(inlineDynamicDateField);

HorizontalLayout hl = new HorizontalLayout();
hl.setSpacing(true);
hl.addComponent(resoSelect);
hl.addComponent(fromRange);
hl.addComponent(toRange);
hl.addComponent(valueDF);
hl.addComponent(immediateCB);
hl.addComponent(recreate);
hl.addComponent(clearRangeButton);
addComponent(hl);
addComponent(new Label("Dynamic DateFields"));
addComponent(gl);
currentStaticContainer = createStaticFields();
addComponent(new Label("Static DateFields"));
addComponent(currentStaticContainer);

addComponent(label);

}

private GridLayout createStaticFields() {
Calendar startCal = createCalendar();
Calendar endCal = createCalendar();
endCal.add(Calendar.DATE, 30);
GridLayout gl = new GridLayout(2, 2);
gl.setSpacing(true);
DateField df = createDateField(startCal.getTime(), endCal.getTime(),
null, Resolution.DAY, false);
gl.addComponent(df);
DateField inline = createDateField(startCal.getTime(), endCal.getTime(),
null, Resolution.DAY, true);
gl.addComponent(inline);
inline.setId("staticInline");
VerticalLayout vl = new VerticalLayout();

return gl;
}

private DateField createDateField(Date rangeStart, Date rangeEnd,
Date value, Resolution resolution, boolean inline) {

DateField df = null;

if (inline) {
df = new InlineDateField();
} else {
df = new DateField();
}

final DateField gg = df;
updateValuesForDateField(df);

df.addValueChangeListener(new ValueChangeListener() {

@Override
public void valueChange(ValueChangeEvent event) {
label.setValue((gg.getValue() == null ? "Nothing"
: gg.getValue().toString()) + " selected. isValid: "
+ gg.isValid());
}
});
return df;
}

@Override
protected String getTestDescription() {
return "Not defined yet";

}

private void updateValuesForDateField(DateField df) {
Date fromVal = fromRange.getValue();
Date toVal = toRange.getValue();
Date value = valueDF.getValue();
Resolution r = (Resolution) resoSelect.getValue();
boolean immediate = immediateCB.getValue();

df.setValue(value);
df.setResolution(r);
df.setRangeStart(fromVal);
df.setRangeEnd(toVal);
df.setImmediate(immediate);

}

}

+ 0
- 145
uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyDateFieldTest.java View File

@@ -1,145 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Locale;

import com.vaadin.tests.components.abstractfield.LegacyAbstractFieldTest;
import com.vaadin.v7.shared.ui.datefield.Resolution;
import com.vaadin.v7.ui.DateField;

public class LegacyDateFieldTest<T extends DateField>
extends LegacyAbstractFieldTest<T> {

@SuppressWarnings("unchecked")
@Override
protected Class<T> getTestClass() {
return (Class<T>) DateField.class;
}

private Command<T, Date> setValue = new Command<T, Date>() {

@Override
public void execute(T c, Date value, Object data) {
c.setValue(value);
}
};

@Override
protected void createActions() {
super.createActions();
createResolutionSelectAction(CATEGORY_FEATURES);
createBooleanAction("Lenient", CATEGORY_FEATURES, false,
lenientCommand);
createBooleanAction("Show week numbers", CATEGORY_FEATURES, false,
weekNumberCommand);
createDateFormatSelectAction(CATEGORY_FEATURES);
createSetValueAction(CATEGORY_FEATURES);

}

private void createSetValueAction(String category) {
LinkedHashMap<String, Date> options = new LinkedHashMap<>();
options.put("(null)", null);
options.put("(current time)", new Date());
Calendar c = Calendar.getInstance(new Locale("fi", "FI"));
c.clear();
c.set(2010, 12 - 1, 12, 12, 0, 0);
c.set(Calendar.MILLISECOND, 0);
options.put("2010-12-12 12:00:00.000", c.getTime());
c.clear();
c.set(2000, 1 - 1, 2, 3, 4, 5);
c.set(Calendar.MILLISECOND, 6);
options.put("2000-01-02 03:04:05.006", c.getTime());
createMultiClickAction("Set value", category, options, setValue, null);
}

private void createDateFormatSelectAction(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<>();

options.put("-", null);
options.put("d M yyyy", "d M yyyy");
options.put("d MM yyyy", "d MM yyyy");
options.put("d MMM yyyy", "d MMM yyyy");
options.put("d MMMM yyyy", "d MMMM yyyy");
options.put("dd M yyyy", "dd M yyyy");
options.put("ddd M yyyy", "ddd M yyyy");
options.put("d M y", "d M y");
options.put("d M yy", "d M yy");
options.put("d M yyy", "d M yyy");
options.put("d M yyyy", "d M yyyy");
options.put("d M 'custom text' yyyy", "d M 'custom text' yyyy");
options.put("'day:'d', month:'M', year: 'yyyy",
"'day:'d', month:'M', year: 'yyyy");
options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.LONG),
getDatePattern(new Locale("fi", "FI"), DateFormat.LONG));
options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.MEDIUM),
getDatePattern(new Locale("fi", "FI"), DateFormat.MEDIUM));
options.put(getDatePattern(new Locale("fi", "FI"), DateFormat.SHORT),
getDatePattern(new Locale("fi", "FI"), DateFormat.SHORT));

createSelectAction("Date format", category, options, "-",
dateFormatCommand);

}

private String getDatePattern(Locale locale, int dateStyle) {
DateFormat dateFormat = DateFormat.getDateInstance(dateStyle, locale);

if (dateFormat instanceof SimpleDateFormat) {
String pattern = ((SimpleDateFormat) dateFormat).toPattern();
return pattern;
}
return null;

}

private void createResolutionSelectAction(String category) {
LinkedHashMap<String, Resolution> options = new LinkedHashMap<>();
options.put("Year", Resolution.YEAR);
options.put("Month", Resolution.MONTH);
options.put("Day", Resolution.DAY);
options.put("Hour", Resolution.HOUR);
options.put("Min", Resolution.MINUTE);
options.put("Sec", Resolution.SECOND);

createSelectAction("Resolution", category, options, "Year",
resolutionCommand);
}

private Command<T, Resolution> resolutionCommand = new Command<T, Resolution>() {

@Override
public void execute(T c, Resolution value, Object data) {
c.setResolution(value);

}
};
private Command<T, Boolean> lenientCommand = new Command<T, Boolean>() {

@Override
public void execute(T c, Boolean value, Object data) {
c.setLenient(false);

}
};
private Command<T, Boolean> weekNumberCommand = new Command<T, Boolean>() {

@Override
public void execute(T c, Boolean value, Object data) {
c.setShowISOWeekNumbers(value);

}
};
private Command<T, String> dateFormatCommand = new Command<T, String>() {

@Override
public void execute(T c, String value, Object data) {
c.setDateFormat(value);
}
};

}

+ 0
- 13
uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyInlineDateFieldTest.java View File

@@ -1,13 +0,0 @@
package com.vaadin.tests.components.datefield;

import com.vaadin.v7.ui.InlineDateField;

public class LegacyInlineDateFieldTest
extends LegacyDateFieldTest<InlineDateField> {

@Override
protected Class<InlineDateField> getTestClass() {
return InlineDateField.class;
}

}

+ 0
- 53
uitest/src/main/java/com/vaadin/tests/components/datefield/LegacyPopupDateFieldTest.java View File

@@ -1,53 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.util.LinkedHashMap;

import com.vaadin.v7.ui.PopupDateField;

public class LegacyPopupDateFieldTest
extends LegacyDateFieldTest<PopupDateField> {

@Override
protected Class<PopupDateField> getTestClass() {
return PopupDateField.class;
}

@Override
protected void createActions() {
super.createActions();

createInputPromptSelectAction(CATEGORY_FEATURES);
createTextEnabledAction(CATEGORY_FEATURES);
}

private void createInputPromptSelectAction(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<>();
options.put("<none>", null);
options.put("Please enter date", "Please enter date");
options.put("åäöÅÄÖ", "åäöÅÄÖ");

createSelectAction("Input prompt", category, options, "<none>",
new Command<PopupDateField, String>() {

@Override
public void execute(PopupDateField c, String value,
Object data) {
c.setInputPrompt(value);

}
});
}

private void createTextEnabledAction(String category) {
this.createBooleanAction("Text field enabled", category, true,
new Command<PopupDateField, Boolean>() {

@Override
public void execute(PopupDateField c, Boolean value,
Object data) {
c.setTextFieldEnabled(value);
}

});
}
}

+ 0
- 79
uitest/src/main/java/com/vaadin/tests/components/datefield/LenientMode.java View File

@@ -1,79 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Locale;

import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.data.HasValue.ValueChangeListener;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;

public class LenientMode extends TestBase
implements ValueChangeListener<LocalDate> {

private static final long serialVersionUID = -9064553409580072387L;

@Override
protected String getDescription() {
return "In lenien mode DateField should accept date input from user like '32/12/09'. In normal mode, an exception should be thrown. ";
}

@Override
protected Integer getTicketNumber() {
return 3175;
}

@Override
protected void setup() {

LocalDate d = LocalDate.of(2009, 12, 31);

AbstractDateField df = new TestDateField("Lenient ");
df.setLocale(new Locale("fi"));
df.setResolution(Resolution.DAY);
df.setLenient(true);
df.setValue(d);

AbstractDateField df2 = new TestDateField("Normal ");
df2.setLocale(new Locale("fi"));
df2.setResolution(Resolution.DAY);
// df2.setLenient(false);
df2.setValue(null);
df2.setValue(d);

addComponent(df);
addComponent(df2);

df.addValueChangeListener(this);
df2.addValueChangeListener(this);

df = new TestDateField("Lenient with time");
df.setLocale(new Locale("fi"));
df.setLenient(true);
df.setValue(d);

df2 = new TestDateField("Normal with time");
df2.setLocale(new Locale("fi"));
// df2.setLenient(false);
df2.setValue(null);
df2.setValue(d);

addComponent(df);
addComponent(df2);

df.addValueChangeListener(this);
df2.addValueChangeListener(this);

addComponent(new Button("Visit server"));

}

@Override
public void valueChange(ValueChangeEvent<LocalDate> event) {
getMainWindow().showNotification("New value" + event.getValue());
}

}

+ 0
- 51
uitest/src/main/java/com/vaadin/tests/components/datefield/LowResolution.java View File

@@ -1,51 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;

import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.DateField;
import com.vaadin.ui.InlineDateField;

@SuppressWarnings("serial")
public class LowResolution extends TestBase {

@Override
protected void setup() {
final DateField dateField = new DateField();
dateField.setValue(LocalDate.now());
dateField.setResolution(Resolution.MONTH);
dateField.addValueChangeListener(event -> getMainWindow()
.showNotification("Date now" + event.getValue()));
getLayout().addComponent(dateField);

final DateField dateField3 = new DateField();
// dateField.setValue(new java.util.Date());
dateField3.setResolution(Resolution.YEAR);
dateField3.addValueChangeListener(event -> getMainWindow()
.showNotification("Date now" + event.getValue()));
getLayout().addComponent(dateField3);

final InlineDateField dateField2 = new InlineDateField();
dateField2.setValue(LocalDate.now());
dateField2.setResolution(Resolution.MONTH);
dateField2.addValueChangeListener(event -> getMainWindow()
.showNotification("Date now" + event.getValue()));
getLayout().addComponent(dateField2);

getLayout().addComponent(new Button("sync"));

}

@Override
protected String getDescription() {
return "Date field should work and update its value to the server.";
}

@Override
protected Integer getTicketNumber() {
return 5567;
}

}

+ 0
- 34
uitest/src/main/java/com/vaadin/tests/components/datefield/NarrowPopupDateFieldInTable.java View File

@@ -1,34 +0,0 @@
package com.vaadin.tests.components.datefield;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Component;
import com.vaadin.ui.DateField;
import com.vaadin.v7.ui.Table;

public class NarrowPopupDateFieldInTable extends TestBase {

private final Object DATE = "Date";

@Override
public void setup() {
DateField df = new DateField();
df.setWidth("100%");

Table t = new Table();
t.setWidth("100px");
t.addContainerProperty(DATE, Component.class, null);
t.addItem(new Object[] { df }, "1");
addComponent(t);
}

@Override
protected String getDescription() {
return "Simple test to ensure a narrow PopupDateField can be used in a Table.";
}

@Override
protected Integer getTicketNumber() {
return 6166;
}

}

+ 0
- 89
uitest/src/main/java/com/vaadin/tests/components/datefield/RequiredInvalidDateField.java View File

@@ -1,89 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.util.Date;
import java.util.Locale;

import com.vaadin.tests.components.TestBase;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.Validator;
import com.vaadin.v7.data.util.ObjectProperty;
import com.vaadin.v7.data.validator.AbstractValidator;
import com.vaadin.v7.ui.DateField;

public class RequiredInvalidDateField extends TestBase {

@SuppressWarnings("deprecation")
@Override
protected void setup() {
// StringLengthValidator textValidator = new StringLengthValidator(
// "String length must be 2-4");
// textValidator.setMinLength(2);
// textValidator.setMaxLength(4);
//
// // not required
// TextField tf1 = new TextField();
// tf1.addValidator(textValidator);
// tf1.setImmediate(true);
// addComponent(tf1);
//
// // required
// TextField tf2 = new TextField();
// tf2.addValidator(textValidator);
// tf2.setRequired(true);
// tf2.setImmediate(true);
// addComponent(tf2);

Date date = new Date(2011 - 1900, 9 - 1, 1);

Validator dateValidator = new AbstractValidator<Date>(
"Day of month must be an even number") {

@Override
protected boolean isValidValue(Date value) {
if (value == null) {
return true;
}

return (value.getDate() % 2 == 0);
}

@Override
public Class getType() {
return Date.class;
}
};

// not required
Property<Date> dateProperty1 = new ObjectProperty<>(date);
DateField dateField1 = new DateField("Not required", dateProperty1);
dateField1.setLocale(new Locale("fi", "FI"));
dateField1.setResolution(DateField.RESOLUTION_DAY);
dateField1.setId("_DF1");
dateField1.setImmediate(true);
dateField1.addValidator(dateValidator);
addComponent(dateField1);

// required
Property<Date> dateProperty2 = new ObjectProperty<>(date);
DateField dateField2 = new DateField("Required", dateProperty2);
dateField2.setLocale(new Locale("fi", "FI"));
dateField2.setResolution(DateField.RESOLUTION_DAY);
dateField2.setId("_DF2");
dateField2.setRequired(true);
dateField2.setImmediate(true);
dateField2.addValidator(dateValidator);
addComponent(dateField2);
}

@Override
protected String getDescription() {
return "Error indicator should be shown for a DateField with an "
+ "invalid value, also when the field is required";
}

@Override
protected Integer getTicketNumber() {
return 6770;
}

}

+ 0
- 34
uitest/src/main/java/com/vaadin/tests/components/datefield/TestDatefieldYear.java View File

@@ -1,34 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;
import java.util.Locale;

import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;

public class TestDatefieldYear extends TestBase {

@Override
protected String getDescription() {
return "A popup with resolution year or month should update the textfield when browsing. The value displayed in the textfield should always be the same as the popup shows.";
}

@Override
protected Integer getTicketNumber() {
return 2813;
}

@Override
protected void setup() {
@SuppressWarnings("deprecation")
AbstractDateField df = new TestDateField("Year",
LocalDate.of(2009, 4, 1));
df.setLocale(new Locale("en", "US"));
df.setResolution(Resolution.YEAR);
df.setResolution(Resolution.MONTH);
addComponent(df);

}
}

+ 0
- 77
uitest/src/main/java/com/vaadin/tests/components/datefield/ValueThroughProperty.java View File

@@ -1,77 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.v7.data.Property;
import com.vaadin.v7.data.util.ObjectProperty;
import com.vaadin.v7.shared.ui.label.ContentMode;
import com.vaadin.v7.ui.DateField;
import com.vaadin.v7.ui.Label;
import com.vaadin.v7.ui.PopupDateField;

public class ValueThroughProperty extends TestBase {
private final Property<Date> dateProperty = new ObjectProperty<>(null,
Date.class);

@Override
protected void setup() {
addComponent(new Label(
"Try to input an invalid value to the DateField, for example \"asdf\".<br />"
+ "Then try to set DateField's value using the first button. It sets the value "
+ "correctly (as we can see from the Label) but the client-side is not updated.<br/>"
+ "Using second button updates value correctly on the client-side too.",
ContentMode.XML));

final PopupDateField df = new PopupDateField(dateProperty);
df.setLocale(new Locale("en", "US"));
df.setImmediate(true);
df.setResolution(DateField.RESOLUTION_DAY);
addComponent(df);

Label valueLabel = new Label(df.getPropertyDataSource());
valueLabel.setCaption("DateField's value");
addComponent(valueLabel);

final Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2010);
cal.set(Calendar.MONTH, 11);
cal.set(Calendar.DAY_OF_MONTH, 14);
Button setDateButton1 = new Button(
"Set value to 12/14/10 using property", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
dateProperty.setValue(cal.getTime());
}

});
addComponent(setDateButton1);

Button setDateButton2 = new Button(
"Set value to 12/14/10 using setValue", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
df.setValue(cal.getTime());
}

});
addComponent(setDateButton2);
}

@Override
protected String getDescription() {
return "Setting a value through a property should update the"
+ " client-side even if it contains an invalid value.";
}

@Override
protected Integer getTicketNumber() {
return 5810;
}

}

+ 0
- 47
uitest/src/main/java/com/vaadin/tests/components/datefield/WidthRecalculationOnEnableStateChange.java View File

@@ -1,47 +0,0 @@
package com.vaadin.tests.components.datefield;

import java.time.LocalDate;

import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;

public class WidthRecalculationOnEnableStateChange extends TestBase {
@Override
public void setup() {
setTheme("reindeer-tests");

final AbstractDateField df = new TestDateField();
df.setValue(LocalDate.of(1970, 1, 15));
df.setWidth("200px");
df.addStyleName("enabled-readonly-styled");
addComponent(df);
addComponent(new Button("Toggle disabled for date field",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
df.setEnabled(!df.isEnabled());
}
}));
addComponent(new Button("Toggle read only for date field",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
df.setReadOnly(!df.isReadOnly());
}
}));
}

@Override
protected String getDescription() {
return "Setting the disabled state doesn't recalculate the input element width. Setting the read-only state instead recalculates the width. In both cases, the popup button is hidden using CSS.<br><br>The DateField is also given a style name 'test', but that style isn't applied on the calendar popup element.";
}

@Override
protected Integer getTicketNumber() {
return 8085;
}

}

+ 53
- 0
uitest/src/main/java/com/vaadin/tests/smoke/DateFieldSmoke.java View File

@@ -0,0 +1,53 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.smoke;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Locale;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.v7.ui.InlineDateField;
import com.vaadin.v7.ui.PopupDateField;

/**
* @author Vaadin Ltd
*
*/
public class DateFieldSmoke extends AbstractTestUIWithLog {

private static final SimpleDateFormat FORMAT = new SimpleDateFormat(
"yyyy.MM.dd", Locale.ENGLISH);

@Override
protected void setup(VaadinRequest request) {
InlineDateField inline = new InlineDateField();
PopupDateField popup = new PopupDateField();

int year = 2016 - 1900;
popup.setValue(new Date(year, 11, 28));
inline.setValue(new Date(year, 11, 29));

popup.addValueChangeListener(event -> log(
"Popup value is : " + FORMAT.format(popup.getValue())));
inline.addValueChangeListener(event -> log(
"Inline value is : " + FORMAT.format(inline.getValue())));

addComponents(inline, popup);
}

}

+ 0
- 99
uitest/src/main/java/com/vaadin/v7/tests/components/datefield/DateFieldDiscardValue.java View File

@@ -1,99 +0,0 @@
package com.vaadin.v7.tests.components.datefield;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractReindeerTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.v7.data.util.ObjectProperty;
import com.vaadin.v7.ui.DateField;

/**
* Test to demonstrate how discarding of field value works with various valid
* and invalid data sources. Previously (Ticket #8069) the case where the
* content of the datasource was null was not handled correctly. This value is a
* valid data source value for the field, but discard did not actually discard
* the value or remove error markers in this cases.
*
* @author Vaadin Ltd
*
*/
public class DateFieldDiscardValue extends AbstractReindeerTestUI {

public static final String PROP_NONULL = "A field with a valid date in the data source property";
public static final String PROP_NULL_VALUE = "A field with a null value in the data source property";
public static final String PROP_NULL = "A field with a null datasource property";

@Override
protected void setup(VaadinRequest request) {
String dateFormat = "dd/MM/yy";

final DateField df = new DateField(PROP_NONULL);
df.setDateFormat(dateFormat);
df.setBuffered(true);
Date date = null;
try {
date = new SimpleDateFormat(dateFormat).parse("25/07/16");
} catch (ParseException e1) {
// This cannot happen
}
ObjectProperty<Date> prop = new ObjectProperty<>(date, Date.class);
df.setPropertyDataSource(prop);
Button button = new Button("Discard 1");
button.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
df.discard();
}

});
VerticalLayout layout = new VerticalLayout();
HorizontalLayout hLayout = new HorizontalLayout(df, button);
layout.addComponent(hLayout);

final DateField df1 = new DateField(PROP_NULL_VALUE);
df1.setDateFormat(dateFormat);
df1.setBuffered(true);

prop = new ObjectProperty<>(null, Date.class);
df1.setPropertyDataSource(prop);
button = new Button("Discard 2");
button.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
df1.discard();
}

});
hLayout = new HorizontalLayout(df1, button);
layout.addComponent(hLayout);

final DateField df2 = new DateField(PROP_NULL);
df2.setDateFormat(dateFormat);
df2.setBuffered(true);
df2.setPropertyDataSource(null);
button = new Button("Discard 3");
button.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
df2.discard();
}

});
hLayout = new HorizontalLayout(df2, button);
layout.addComponent(hLayout);

setContent(layout);

}

}

+ 39
- 0
uitest/src/test/java/com/vaadin/tests/components/datefield/CustomDateFormatTest.java View File

@@ -0,0 +1,39 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.datefield;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.vaadin.testbench.By;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
* @author Vaadin Ltd
*
*/
public class CustomDateFormatTest extends MultiBrowserTest {

@Test
public void checkCustomDateFormat() {
openTestURL();

String text = findElement(By.tagName("input")).getAttribute("value");
assertEquals("1. tammikuuta 2010 klo", text);
}

}

uitest/src/test/java/com/vaadin/tests/components/datefield/LegacyDateFieldTestTest.java → uitest/src/test/java/com/vaadin/tests/components/datefield/DateFieldTestTest.java View File

@@ -25,7 +25,7 @@ import org.openqa.selenium.interactions.Actions;
import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class LegacyDateFieldTestTest extends MultiBrowserTest {
public class DateFieldTestTest extends MultiBrowserTest {

@Test
public void testMakingRequired() throws InterruptedException {

+ 37
- 0
uitest/src/test/java/com/vaadin/tests/components/datefield/InlineDateFieldTestTest.java View File

@@ -0,0 +1,37 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.datefield;

import org.junit.Test;

import com.google.gwt.editor.client.Editor.Ignore;

/**
* Reuse tests from super DateFieldTestTest class.
*
* @author Vaadin Ltd
*
*/
public class InlineDateFieldTestTest extends DateFieldTestTest {

@Override
@Test
@Ignore
public void testValueAfterOpeningPopupInRequiredField()
throws InterruptedException {
// no popup for inline date field
}
}

+ 0
- 65
uitest/src/test/java/com/vaadin/tests/components/datefield/LegacyDateFieldIsValidTest.java View File

@@ -1,65 +0,0 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.datefield;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.By;
import com.vaadin.testbench.customelements.DateFieldElement;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
* @author Vaadin Ltd
*/
public class LegacyDateFieldIsValidTest extends MultiBrowserTest {

@Test
public void testInvalidText() throws Exception {
openTestURL();

waitForElementVisible(By.id("Log"));
waitForElementVisible(By.className("v-datefield"));
WebElement dateTextbox = $(DateFieldElement.class).first()
.findElement(By.className("v-textfield"));
ButtonElement button = $(ButtonElement.class).first();

dateTextbox.sendKeys("01/01/01", Keys.TAB);
assertLogText("1. valueChange: value: 01/01/01, is valid: true");
button.click();
assertLogText("2. buttonClick: value: 01/01/01, is valid: true");

dateTextbox.sendKeys("lala", Keys.TAB);
assertLogText("3. valueChange: value: null, is valid: false");
button.click();
assertLogText("4. buttonClick: value: null, is valid: false");

dateTextbox.clear();
dateTextbox.sendKeys("02/02/02", Keys.TAB);
assertLogText("5. valueChange: value: 02/02/02, is valid: true");
button.click();
assertLogText("6. buttonClick: value: 02/02/02, is valid: true");
}

private void assertLogText(String expected) throws Exception {
String text = findElement(By.vaadin("PID_SLog_row_0")).getText();
Assert.assertTrue("Expected '" + expected + "' found '" + text + "'",
text.equals(expected));
}
}

+ 79
- 0
uitest/src/test/java/com/vaadin/tests/smoke/DateFieldSmokeTest.java View File

@@ -0,0 +1,79 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.smoke;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

import com.vaadin.testbench.elements.InlineDateFieldElement;
import com.vaadin.testbench.elements.PopupDateFieldElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

/**
* @author Vaadin Ltd
*
*/
public class DateFieldSmokeTest extends MultiBrowserTest {

@Test
public void dateFieldsSmokeTest() {
openTestURL();

PopupDateFieldElement popup = $(PopupDateFieldElement.class).first();
Assert.assertEquals("12/28/16", popup.getValue());
InlineDateFieldElement inline = $(InlineDateFieldElement.class).first();
Assert.assertEquals(String.valueOf(29),
inline.findElement(By.className(
"v-inline-datefield-calendarpanel-day-selected"))
.getText());

popup.findElement(By.tagName("button")).click();
waitUntil(ExpectedConditions
.visibilityOfElementLocated(By.className("v-datefield-popup")));
selectDay(findElement(By.className("v-datefield-popup")), 14, "v-");

waitUntil(driver -> "1. Popup value is : 2016.12.14"
.equals(getLogRow(0)));

selectDay(inline, 13, "v-inline-");
waitUntil(driver -> "2. Inline value is : 2016.12.13"
.equals(getLogRow(0)));

inline.findElement(By.className("v-button-prevmonth")).click();
WebElement monthTitle = inline.findElement(
By.className("v-inline-datefield-calendarpanel-month"));
Assert.assertEquals("November 2016", monthTitle.getText());

inline.findElement(By.className("v-button-nextyear")).click();
monthTitle = inline.findElement(
By.className("v-inline-datefield-calendarpanel-month"));
Assert.assertEquals("November 2017", monthTitle.getText());
}

private void selectDay(WebElement calendar, int day, String cssPrefix) {
List<WebElement> days = calendar.findElements(
By.className(cssPrefix + "datefield-calendarpanel-day"));
String dayValue = String.valueOf(day);
days.stream()
.filter(dayElement -> dayElement.getText().equals(dayValue))
.findFirst().get().click();
}
}

+ 0
- 85
uitest/src/test/java/com/vaadin/v7/tests/components/datefield/DateFieldDiscardValueTest.java View File

@@ -1,85 +0,0 @@
package com.vaadin.v7.tests.components.datefield;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.DateFieldElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class DateFieldDiscardValueTest extends SingleBrowserTest {

@Test
public void discardWhenDatasourceContentNonNullInvalidValue() {
discardWorks(DateFieldDiscardValue.PROP_NONULL, "1", "123", "25/07/16");
}

@Test
public void discardWhenDatasourceContentNonNullValidValue() {
discardWorks(DateFieldDiscardValue.PROP_NONULL, "1", "24/07/16",
"25/07/16");
}

@Test
public void discardWhenDatasourceContentNullInvalidValue() {
discardWorks(DateFieldDiscardValue.PROP_NULL_VALUE, "2", "123", "");
}

@Test
public void discardWhenDatasourceContentNullValidValue() {
discardWorks(DateFieldDiscardValue.PROP_NULL_VALUE, "2", "24/07/16",
"");
}

@Test
public void discardWhenDatasourceNull() {
// If the data source is null, discard should do nothing.
discardDoesntWork(DateFieldDiscardValue.PROP_NULL, "3", "123");
}

private void discardWorks(String caption, String id, String dateValue,
String resultValue) {
openTestURL();

ButtonElement discardButton = $(ButtonElement.class)
.caption("Discard " + id).first();
DateFieldElement dateField = $(DateFieldElement.class).caption(caption)
.first();
dateField.setValue(dateValue);

discardButton.click();

assertEquals(resultValue, dateField.getValue());

List<WebElement> elements = driver
.findElements(By.className("v-errorindicator"));

assertEquals(0, elements.size());
}

private void discardDoesntWork(String caption, String id,
String dateValue) {
openTestURL();

ButtonElement discardButton = $(ButtonElement.class)
.caption("Discard " + id).first();
DateFieldElement dateField = $(DateFieldElement.class).caption(caption)
.first();
dateField.setValue(dateValue);

discardButton.click();

assertEquals(dateValue, dateField.getValue());

List<WebElement> elements = driver
.findElements(By.className("v-errorindicator"));

assertEquals(1, elements.size());
}

}

Loading…
Cancel
Save