@@ -11,16 +11,21 @@ describe('local forms', () => {
11
11
12
12
describe ( 'standard usage with onUpdate' , ( ) => {
13
13
let innerFormState ;
14
+ let dispatch ;
14
15
15
16
const form = TestUtils . renderIntoDocument (
16
- < LocalForm onUpdate = { ( formValue ) => innerFormState = formValue } >
17
+ < LocalForm
18
+ getDispatch = { d => dispatch = d }
19
+ onUpdate = { ( formValue ) => innerFormState = formValue }
20
+ >
17
21
< Control . text model = ".foo" />
18
22
</ LocalForm >
19
23
) ;
20
24
21
25
const input = TestUtils . findRenderedDOMComponentWithTag ( form , 'input' ) ;
22
26
23
- it ( 'should initially update with the loaded form value' , ( ) => {
27
+ it ( 'should update with the loaded form value' , ( ) => {
28
+ dispatch ( actions . setPristine ( 'local' ) ) ;
24
29
assert . containSubset ( innerFormState , {
25
30
$form : {
26
31
pristine : true ,
@@ -45,36 +50,33 @@ describe('local forms', () => {
45
50
} ) ;
46
51
47
52
describe ( 'standard usage with onChange' , ( ) => {
48
- let innerModelState ;
53
+ let dispatch ;
49
54
50
55
const form = TestUtils . renderIntoDocument (
51
- < LocalForm onChange = { ( modelValue ) => innerModelState = modelValue } >
56
+ < LocalForm getDispatch = { d => dispatch = d } >
52
57
< Control . text model = ".foo" />
53
58
</ LocalForm >
54
59
) ;
55
60
56
61
const input = TestUtils . findRenderedDOMComponentWithTag ( form , 'input' ) ;
57
62
58
63
it ( 'should initially have an empty object (by default) as the model value' , ( ) => {
59
- assert . deepEqual ( innerModelState , { } ) ;
64
+ assert . equal ( input . value , '' ) ; // { foo: '' }
60
65
} ) ;
61
66
62
67
it ( 'should behave like a normal form, with an internal Redux state' , ( ) => {
63
- input . value = 'changed' ;
64
- TestUtils . Simulate . change ( input ) ;
68
+ dispatch ( actions . change ( 'local' , { foo : 'changed' } ) ) ;
65
69
66
- assert . deepEqual ( innerModelState , {
67
- foo : 'changed' ,
68
- } ) ;
70
+ assert . equal ( input . value , 'changed' ) ;
69
71
} ) ;
70
72
} ) ;
71
73
72
74
describe ( 'onChange with initialState' , ( ) => {
73
- let innerModelState ;
75
+ let dispatch ;
74
76
75
77
const form = TestUtils . renderIntoDocument (
76
78
< LocalForm
77
- onChange = { ( modelValue ) => innerModelState = modelValue }
79
+ getDispatch = { d => dispatch = d }
78
80
initialState = { { foo : 'bar' } }
79
81
>
80
82
< Control . text model = ".foo" />
@@ -84,16 +86,13 @@ describe('local forms', () => {
84
86
const input = TestUtils . findRenderedDOMComponentWithTag ( form , 'input' ) ;
85
87
86
88
it ( 'should initially have an empty object (by default) as the model value' , ( ) => {
87
- assert . deepEqual ( innerModelState , { foo : 'bar' } ) ;
89
+ assert . equal ( input . value , 'bar' ) ;
88
90
} ) ;
89
91
90
92
it ( 'should behave like a normal form, with an internal Redux state' , ( ) => {
91
- input . value = 'changed' ;
92
- TestUtils . Simulate . change ( input ) ;
93
+ dispatch ( actions . change ( 'local' , { foo : 'changed' } ) ) ;
93
94
94
- assert . deepEqual ( innerModelState , {
95
- foo : 'changed' ,
96
- } ) ;
95
+ assert . equal ( input . value , 'changed' ) ;
97
96
} ) ;
98
97
} ) ;
99
98
0 commit comments