File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
packages/pf3-component-mapper
form-fields/date-time-picker
tests/form-fields/date-time-picker Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -449,6 +449,7 @@ const output = {
449
449
title : 'Datepicker with past days' ,
450
450
component : components . DATE_PICKER ,
451
451
variant : 'date-time' ,
452
+ initialValue : '2019-11-04T12:31:00.000Z' ,
452
453
} ,
453
454
] ,
454
455
component : components . SUB_FORM ,
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export class DateTimePicker extends React.Component {
31
31
super ( props ) ;
32
32
this . state = {
33
33
positionLeft : 0 ,
34
- selectedDay : props . value ,
34
+ selectedDay : props . value ? typeof props . value === 'string' ? new Date ( props . value ) : props . value : undefined ,
35
35
selectingMonth : false ,
36
36
selectingYear : false ,
37
37
isOpen : false ,
@@ -169,7 +169,7 @@ DateTimePicker.propTypes = {
169
169
showTodayButton : PropTypes . bool ,
170
170
isDisabled : PropTypes . bool ,
171
171
disabledDays : PropTypes . array ,
172
- value : PropTypes . instanceOf ( Date ) ,
172
+ value : PropTypes . oneOfType ( [ PropTypes . instanceOf ( Date ) , PropTypes . string ] ) ,
173
173
closeOnDaySelect : PropTypes . bool ,
174
174
onChange : PropTypes . func . isRequired ,
175
175
isClearable : PropTypes . bool ,
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { mount } from 'enzyme' ;
3
+
4
+ import { DateTimePicker } from '../../../form-fields/date-time-picker/date-time-picker' ;
5
+
6
+ describe ( '<DateTimePicker />' , ( ) => {
7
+ it ( 'should use value of type Date' , ( ) => {
8
+ const wrapper = mount ( < DateTimePicker value = { new Date ( ) } /> ) ;
9
+ expect ( wrapper . state ( ) . selectedDay ) . toBeInstanceOf ( Date ) ;
10
+ } ) ;
11
+
12
+ it ( 'should convert string value into Date object' , ( ) => {
13
+ const wrapper = mount ( < DateTimePicker value = '2019-11-01T12:31:00.000Z' /> ) ;
14
+ expect ( wrapper . state ( ) . selectedDay ) . toBeInstanceOf ( Date ) ;
15
+ } ) ;
16
+
17
+ it ( 'should not set state for undefined value' , ( ) => {
18
+ const wrapper = mount ( < DateTimePicker /> ) ;
19
+ expect ( wrapper . state ( ) . selectedDay ) . toBeUndefined ( ) ;
20
+ } ) ;
21
+ } ) ;
22
+
You can’t perform that action at this time.
0 commit comments