Search in sources :

Example 1 with DateClassFieldEditPane

use of org.xwiki.appwithinminutes.test.po.DateClassFieldEditPane in project xwiki-platform by xwiki.

the class DateClassFieldTest method testDatePicker.

/**
 * Tests that the user can select a date using the date picker.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testDatePicker() {
    // First select a date using the picker and assert the value of the date input.
    DateClassFieldEditPane dateField = new DateClassFieldEditPane(editor.addField("Date").getName());
    DatePicker datePicker = dateField.openDatePicker();
    datePicker.setYear("2011");
    datePicker.setMonth("October");
    datePicker.setDay("13");
    datePicker.setHour("8 AM");
    datePicker.setMinute("15");
    String selectedDate = dateField.getDefaultValue();
    // Ignore the number of seconds.
    Assert.assertTrue(selectedDate.startsWith("13/10/2011 08:15:"));
    // Set the value of the date input and assert the date selected by the picker.
    dateField.setDefaultValue("17/03/2020 19:43:34");
    // Currently the date picker doesn't know how to parse a date with a specified format. The workaround is to pass
    // the date time stamp when generating the date input, but for this the page needs to be saved and reloaded.
    editor.clickSaveAndView().edit();
    datePicker = new DateClassFieldEditPane("date1").openDatePicker();
    Assert.assertEquals("2020", datePicker.getYear());
    Assert.assertEquals("March", datePicker.getMonth());
    Assert.assertEquals("17", datePicker.getDay());
    Assert.assertEquals("7 PM", datePicker.getHour());
    Assert.assertEquals("40", datePicker.getMinute());
}
Also used : DatePicker(org.xwiki.test.ui.po.editor.DatePicker) DateClassFieldEditPane(org.xwiki.appwithinminutes.test.po.DateClassFieldEditPane) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Example 2 with DateClassFieldEditPane

use of org.xwiki.appwithinminutes.test.po.DateClassFieldEditPane in project xwiki-platform by xwiki.

the class DateClassFieldTest method testDateFormat.

/**
 * Tests that the date picker can parse dates using the specified date format and that the selected date is
 * serialized using the specified date format.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testDateFormat() {
    // Add a date field and change the date format.
    DateClassFieldEditPane dateField = new DateClassFieldEditPane(editor.addField("Date").getName());
    dateField.openConfigPanel();
    String dateFormat = "yyyy.MM.dd";
    dateField.setDateFormat(dateFormat);
    // Close the configuration panel to refresh the date field preview.
    dateField.closeConfigPanel();
    // Select a date using the date picker.
    DatePicker datePicker = dateField.openDatePicker();
    // The current date format doesn't include time information.
    Assert.assertFalse(datePicker.hasHourSelector());
    datePicker.setDay("22");
    Calendar now = Calendar.getInstance();
    now.set(Calendar.DAY_OF_MONTH, 22);
    Assert.assertEquals(new SimpleDateFormat(dateFormat).format(now.getTime()), dateField.getDefaultValue());
    // Test if the date picker knows how to parse dates with a custom date format.
    // Set the value of the date input and assert the date selected by the picker.
    dateField.setDefaultValue("2012.11.10");
    // Currently the date picker doesn't know how to parse a date with a specified format. The workaround is to pass
    // the date time stamp when generating the date input, but for this the page needs to be saved and reloaded.
    editor.clickSaveAndView().edit();
    datePicker = new DateClassFieldEditPane("date1").openDatePicker();
    Assert.assertEquals("2012", datePicker.getYear());
    Assert.assertEquals("November", datePicker.getMonth());
    Assert.assertEquals("10", datePicker.getDay());
    Assert.assertFalse(datePicker.hasHourSelector());
}
Also used : Calendar(java.util.Calendar) DatePicker(org.xwiki.test.ui.po.editor.DatePicker) DateClassFieldEditPane(org.xwiki.appwithinminutes.test.po.DateClassFieldEditPane) SimpleDateFormat(java.text.SimpleDateFormat) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DateClassFieldEditPane (org.xwiki.appwithinminutes.test.po.DateClassFieldEditPane)2 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)2 DatePicker (org.xwiki.test.ui.po.editor.DatePicker)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1