File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
packages/pf3-component-mapper/src
form-fields/date-time-picker
tests/form-fields/date-time-picker Expand file tree Collapse file tree 2 files changed +23
-1
lines changed 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 : typeof props . value === 'string' ? new Date ( props . value ) : 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 ,
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