1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui.appwithinminutes

File DateClassFieldTest.java

 

Code metrics

0
35
2
1
120
63
2
0.06
17.5
2
1

Classes

Class Line # Actions
DateClassFieldTest 38 35 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.ui.appwithinminutes;
21   
22    import java.text.SimpleDateFormat;
23    import java.util.Calendar;
24   
25    import org.junit.Assert;
26    import org.junit.Test;
27    import org.xwiki.appwithinminutes.test.po.DateClassFieldEditPane;
28    import org.xwiki.test.ui.browser.IgnoreBrowser;
29    import org.xwiki.test.ui.browser.IgnoreBrowsers;
30    import org.xwiki.test.ui.po.editor.DatePicker;
31   
32    /**
33    * Special class editor tests that address only the Date class field type.
34    *
35    * @version $Id: 671e888d00fd1b9485470dad32282f69e8d2ea7c $
36    * @since 3.5
37    */
 
38    public class DateClassFieldTest extends AbstractClassEditorTest
39    {
40    /**
41    * Tests that the user can select a date using the date picker.
42    */
 
43  1 toggle @Test
44    @IgnoreBrowsers({
45    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
46    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
47    })
48    public void testDatePicker()
49    {
50    // First select a date using the picker and assert the value of the date input.
51  1 DateClassFieldEditPane dateField = new DateClassFieldEditPane(editor.addField("Date").getName());
52  1 DatePicker datePicker = dateField.openDatePicker();
53  1 datePicker.setYear("2011");
54  1 datePicker.setMonth("October");
55  1 datePicker.setDay("13");
56  1 datePicker.setHour("8 AM");
57  1 datePicker.setMinute("15");
58  1 String selectedDate = dateField.getDefaultValue();
59    // Ignore the number of seconds.
60  1 Assert.assertTrue(selectedDate.startsWith("13/10/2011 08:15:"));
61   
62    // Set the value of the date input and assert the date selected by the picker.
63  1 dateField.setDefaultValue("17/03/2020 19:43:34");
64   
65    // Currently the date picker doesn't know how to parse a date with a specified format. The workaround is to pass
66    // the date time stamp when generating the date input, but for this the page needs to be saved and reloaded.
67  1 editor.clickSaveAndView().edit();
68  1 datePicker = new DateClassFieldEditPane("date1").openDatePicker();
69   
70  1 Assert.assertEquals("2020", datePicker.getYear());
71  1 Assert.assertEquals("March", datePicker.getMonth());
72  1 Assert.assertEquals("17", datePicker.getDay());
73  1 Assert.assertEquals("7 PM", datePicker.getHour());
74  1 Assert.assertEquals("40", datePicker.getMinute());
75    }
76   
77    /**
78    * Tests that the date picker can parse dates using the specified date format and that the selected date is
79    * serialized using the specified date format.
80    */
 
81  1 toggle @Test
82    @IgnoreBrowsers({
83    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
84    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
85    })
86    public void testDateFormat()
87    {
88    // Add a date field and change the date format.
89  1 DateClassFieldEditPane dateField = new DateClassFieldEditPane(editor.addField("Date").getName());
90  1 dateField.openConfigPanel();
91  1 String dateFormat = "yyyy.MM.dd";
92  1 dateField.setDateFormat(dateFormat);
93   
94    // Close the configuration panel to refresh the date field preview.
95  1 dateField.closeConfigPanel();
96   
97    // Select a date using the date picker.
98  1 DatePicker datePicker = dateField.openDatePicker();
99    // The current date format doesn't include time information.
100  1 Assert.assertFalse(datePicker.hasHourSelector());
101  1 datePicker.setDay("22");
102  1 Calendar now = Calendar.getInstance();
103  1 now.set(Calendar.DAY_OF_MONTH, 22);
104  1 Assert.assertEquals(new SimpleDateFormat(dateFormat).format(now.getTime()), dateField.getDefaultValue());
105   
106    // Test if the date picker knows how to parse dates with a custom date format.
107    // Set the value of the date input and assert the date selected by the picker.
108  1 dateField.setDefaultValue("2012.11.10");
109   
110    // Currently the date picker doesn't know how to parse a date with a specified format. The workaround is to pass
111    // the date time stamp when generating the date input, but for this the page needs to be saved and reloaded.
112  1 editor.clickSaveAndView().edit();
113  1 datePicker = new DateClassFieldEditPane("date1").openDatePicker();
114   
115  1 Assert.assertEquals("2012", datePicker.getYear());
116  1 Assert.assertEquals("November", datePicker.getMonth());
117  1 Assert.assertEquals("10", datePicker.getDay());
118  1 Assert.assertFalse(datePicker.hasHourSelector());
119    }
120    }