@@ -7,45 +7,62 @@ describe("DateTimeField", function() {
7
7
const moment = require ( "moment" ) ;
8
8
const DateTimeField = require ( "../DateTimeField.js" ) ;
9
9
const happyDate = moment ( "1990-06-05 07:30" ) ;
10
- let parent , TestParent ;
11
-
12
- beforeEach ( ( ) => {
13
- TestParent = React . createFactory ( React . createClass ( {
14
- getInitialState ( ) {
15
- return { dateTime : happyDate . format ( "x" ) } ;
16
- } ,
17
-
18
- render ( ) {
19
- return < DateTimeField { ...this . state } /> ;
20
- }
21
- } ) ) ;
22
- parent = TestUtils . renderIntoDocument ( TestParent ( ) ) ; // eslint-disable-line
23
- } ) ;
10
+ let createParent , TestParent ;
11
+
24
12
25
13
describe ( "By default" , function ( ) {
26
14
27
15
it ( "shows the right date for a given dateTime and inputFormat" , function ( ) {
28
- const input = TestUtils . findRenderedDOMComponentWithTag ( parent , "input" ) ;
16
+ const component = TestUtils . renderIntoDocument ( < DateTimeField dateTime = { happyDate . format ( "x" ) } /> ) ;
17
+ const input = TestUtils . findRenderedDOMComponentWithTag ( component , "input" ) ;
29
18
expect ( input . getDOMNode ( ) . value ) . toBe ( "06/05/90 7:30 AM" ) ;
30
19
} ) ;
31
20
32
21
} ) ;
33
22
34
23
describe ( "When changing props" , function ( ) {
35
24
36
- it ( "changes the displayed date when dateTime changes" , function ( ) {
37
- const input = TestUtils . findRenderedDOMComponentWithTag ( parent , "input" ) ;
38
- expect ( input . getDOMNode ( ) . value ) . toBe ( "06/05/90 7:30 AM" ) ;
39
- parent . setState ( { dateTime : moment ( "1981-06-04 05:45" ) . format ( "x" ) } ) ;
40
- expect ( input . getDOMNode ( ) . value ) . toBe ( "06/04/81 5:45 AM" ) ;
25
+ beforeEach ( ( ) => {
26
+ TestParent = React . createFactory ( React . createClass ( {
27
+ getInitialState ( ) {
28
+ return {
29
+ dateTime : happyDate . format ( "x" ) ,
30
+ ...this . props
31
+ } ;
32
+ } ,
33
+
34
+ render ( ) {
35
+ return < DateTimeField { ...this . state } /> ;
36
+ }
37
+ } ) ) ;
38
+ createParent = ( initalState ) => TestUtils . renderIntoDocument ( TestParent ( initalState ) ) ; // eslint-disable-line
41
39
} ) ;
42
40
43
- it ( "changes the displayed format when inputFormat changes" , function ( ) {
44
- const input = TestUtils . findRenderedDOMComponentWithTag ( parent , "input" ) ;
45
- expect ( input . getDOMNode ( ) . value ) . toBe ( "06/05/90 7:30 AM" ) ;
46
- parent . setState ( { inputFormat : "x" } ) ;
47
- expect ( input . getDOMNode ( ) . value ) . toBe ( happyDate . format ( "x" ) ) ;
41
+ it ( "changes the displayed date when dateTime changes" , function ( ) {
42
+ const Parent = createParent ( ) ;
43
+ const input = TestUtils . findRenderedDOMComponentWithTag ( Parent , "input" ) ;
44
+ expect ( input . getDOMNode ( ) . value ) . toBe ( "06/05/90 7:30 AM" ) ;
45
+ Parent . setState ( { dateTime : moment ( "1981-06-04 05:45" ) . format ( "x" ) } ) ;
46
+ expect ( input . getDOMNode ( ) . value ) . toBe ( "06/04/81 5:45 AM" ) ;
47
+ } ) ;
48
+
49
+ it ( "changes the displayed format when inputFormat changes" , function ( ) {
50
+ const Parent = createParent ( ) ;
51
+ const input = TestUtils . findRenderedDOMComponentWithTag ( Parent , "input" ) ;
52
+ expect ( input . getDOMNode ( ) . value ) . toBe ( "06/05/90 7:30 AM" ) ;
53
+ Parent . setState ( { inputFormat : "x" } ) ;
54
+ expect ( input . getDOMNode ( ) . value ) . toBe ( happyDate . format ( "x" ) ) ;
55
+ } ) ;
56
+
57
+ it ( "doesn't change the defaultText if dateTime didn't change" , function ( ) {
58
+ const Parent = createParent ( { defaultText : "Pick a date" } ) ;
59
+ const input = TestUtils . findRenderedDOMComponentWithTag ( Parent , "input" ) ;
60
+ expect ( input . getDOMNode ( ) . value ) . toBe ( "Pick a date" ) ;
61
+ Parent . setState ( { } ) ;
62
+ expect ( input . getDOMNode ( ) . value ) . toBe ( "Pick a date" ) ;
48
63
} ) ;
49
64
65
+
50
66
} ) ;
67
+
51
68
} ) ;
0 commit comments