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