Simon Egersand
2018-02-11 db7315ac35b5257824ba2cdbf46b150450f961ed
commit | author | age
752fa8 1 import * as React from "react";
KJ 2 import { Moment } from "moment";
3 import * as ReactDatetime from "react-datetime";
a20f58 4
AS 5 /*
6  Test the datetime picker.
7  */
8
9 const TEST_BASIC_USAGE: JSX.Element = <ReactDatetime />;
10
11 /*
12  Test date properties
13  */
14
15 const TEST_DATE_PROPS_FOR_VALUE: JSX.Element = <ReactDatetime
16         value={ new Date() }
17     />;
18
19 const TEST_DATE_PROPS_FOR_DEFAULT_VALUE: JSX.Element = <ReactDatetime
20         defaultValue={ new Date() }
21     />;
22
23 /*
24  Test formats
25  */
26
27 const TEST_FORMAT_PROPS_AS_STRINGS: JSX.Element = <ReactDatetime
28         dateFormat='mm/dd/yyyy'
29         timeFormat='hh:mm:ss'
30     />;
31
32 const TEST_FORMAT_PROPS_AS_BOOLEANS: JSX.Element = <ReactDatetime
33         dateFormat={ false }
34         timeFormat={ false }
35     />;
36
37 /*
38  Test boolean options
39  */
40
41 const TEST_BOOLEAN_PROPS: JSX.Element = <ReactDatetime
42         input={ false }
43         open={ false }
44         strictParsing={ false }
45         closeOnSelect={ false }
46         disableOnClickOutside={ false }
47         utc={ false }
48     />;
49
50 /*
51  Test locale options
52  */
53
54 const TEST_LOCALE_PROPS: JSX.Element = <ReactDatetime
55         locale='en-us'
56     />;
57
58 /*
59  Test input props
60  */
61
62 const TEST_INPUT_PROPS: JSX.Element = <ReactDatetime
63         inputProps={
64             {
65                 'placeholder': 'mm/dd/yyyy'
66             }
67         }
68     />;
69
70 /*
71  Test Event handlers
72  */
73
74  const TEST_EVENT_HANDLERS_WITH_STRINGS: JSX.Element = <ReactDatetime
75          onChange={
76              (momentOrInputString:string) => {}
77          }
78         onFocus={
79             () => {}
80         }
81         onBlur={
82             (momentOrInputString:string) => {}
83         }
b8d07e 84         onViewModeChange={
SE 85              (viewMode:string) => {}
86          }
a20f58 87      />;
AS 88
89 const TEST_EVENT_HANDLERS_WITH_MOMENT: JSX.Element = <ReactDatetime
90         onChange={
91             (momentOrInputString:Moment) => {}
92         }
93         onBlur={
94             (momentOrInputString:Moment) => {}
95         }
96     />;
97
98 /*
99  Test view mode and className
100  */
101
102 const TEST_VIEW_MODE_AND_CLASS_PROPS: JSX.Element = <ReactDatetime
103         viewMode='days'
104         className='rdt'
105     />;
106
107 /*
108  Test date validator
109  */
110
111 const TEST_DATE_VALIDATOR_PROP: JSX.Element = <ReactDatetime
112         isValidDate={ (currentDate:any, selectedDate:any) => {
113             return true;
114         } }
115     />;
116
117 /*
118  Test customizable components
119  */
120
121 const TEST_CUSTOMIZABLE_COMPONENT_PROPS: JSX.Element = <ReactDatetime
752fa8 122         renderDay={ (props: any, currentDate: any, selectedDate: any) => {
a20f58 123             return <td {...props}>{ '0' + currentDate.date() }</td>;
AS 124         } }
752fa8 125         renderMonth={ (props: any, month: any, year: any, selectedDate: any) => {
a20f58 126             return <td {...props}>{ month }</td>;
AS 127         } }
752fa8 128         renderYear={ (props: any, year: any, selectedDate: any) => {
a20f58 129             return <td {...props}>{ year % 100 }</td>;
AS 130         } }
131     />;
132
133 /*
134  Test time constraints.
135  */
136
137 const TEST_BASIC_TIME_CONSTRAINTS: JSX.Element = <ReactDatetime
138         timeConstraints={ {} }
139     />;
140
141 const TEST_TIME_CONSTRAINTS_WITH_ONE: JSX.Element = <ReactDatetime
142         timeConstraints={ {
143             'hours': {
144                 'min': 0,
145                 'max': 23,
146                 'step': 1
147             }
148         } }
149     />;
150
151 const TEST_TIME_CONSTRAINTS_WITH_ALL: JSX.Element = <ReactDatetime
152         timeConstraints={ {
153             'hours': {
154                 'min': 0,
155                 'max': 23,
156                 'step': 1
157             },
158             'minutes': {
159                 'min': 0,
160                 'max': 59,
161                 'step': 1
162             },
163             'seconds': {
164                 'min': 0,
165                 'max': 59,
166                 'step': 1,
167             },
168             'milliseconds': {
169                 'min': 0,
170                 'max': 999,
171                 'step': 1
172             }
173         } }
174     />;