@@ -4,6 +4,7 @@ import React from 'react';
4
4
import ReactDOM from 'react-dom' ;
5
5
import TestUtils from 'react-addons-test-utils' ;
6
6
import { Provider } from 'react-redux' ;
7
+ import { createStore } from 'redux' ;
7
8
import sinon from 'sinon' ;
8
9
import capitalize from '../src/utils/capitalize' ;
9
10
import _get from 'lodash.get' ;
@@ -19,13 +20,15 @@ import {
19
20
formReducer as _formReducer ,
20
21
Control as _Control ,
21
22
actions as _actions ,
23
+ combineForms as _combineForms ,
22
24
} from '../src' ;
23
25
import {
24
26
controls as immutableControls ,
25
27
modelReducer as immutableModelReducer ,
26
28
formReducer as immutableFormReducer ,
27
29
Control as immutableControl ,
28
30
actions as immutableActions ,
31
+ combineForms as immutableCombineForms ,
29
32
} from '../immutable' ;
30
33
31
34
const testContexts = {
@@ -39,6 +42,7 @@ const testContexts = {
39
42
get : _get ,
40
43
set : ( state , path , value ) => i . setIn ( state , path , value ) ,
41
44
getInitialState : ( state ) => state ,
45
+ combineForms : _combineForms ,
42
46
} ,
43
47
immutable : {
44
48
controls : immutableControls ,
@@ -57,6 +61,7 @@ const testContexts = {
57
61
} ,
58
62
set : ( state , path , value ) => state . setIn ( path , value ) ,
59
63
getInitialState : ( state ) => Immutable . fromJS ( state ) ,
64
+ combineForms : immutableCombineForms ,
60
65
} ,
61
66
} ;
62
67
@@ -70,6 +75,7 @@ Object.keys(testContexts).forEach((testKey) => {
70
75
const object = testContext . object ;
71
76
const get = testContext . get ;
72
77
const getInitialState = testContext . getInitialState ;
78
+ const combineForms = testContext . combineForms ;
73
79
74
80
describe ( `<Control> component (${ testKey } context)` , ( ) => {
75
81
describe ( 'existence check' , ( ) => {
@@ -948,6 +954,36 @@ Object.keys(testContexts).forEach((testKey) => {
948
954
} ) ;
949
955
} ) ;
950
956
957
+ describe ( 'deep initial value after reset' , ( ) => {
958
+ const store = createStore ( combineForms ( {
959
+ user : getInitialState ( {
960
+ nest : {
961
+ name : 'initial name' ,
962
+ email : 'initial email' ,
963
+ } ,
964
+ } ) ,
965
+ } ) ) ;
966
+
967
+ TestUtils . renderIntoDocument (
968
+ < Provider store = { store } >
969
+ < div >
970
+ < Control . text model = "user.nest.name" />
971
+ < Control . text type = "email" model = "user.nest.email" />
972
+ </ div >
973
+ </ Provider >
974
+ ) ;
975
+
976
+ it ( 'should reset the control to the last deeply loaded value' , ( ) => {
977
+ store . dispatch ( actions . load ( 'user' , getInitialState ( {
978
+ nest : { name : 'loaded name' , email : 'loaded email' } ,
979
+ } ) ) ) ;
980
+ store . dispatch ( actions . reset ( 'user' ) ) ;
981
+
982
+ assert . equal ( get ( store . getState ( ) . user , 'nest.name' ) , 'loaded name' ) ;
983
+ assert . equal ( get ( store . getState ( ) . user , 'nest.email' ) , 'loaded email' ) ;
984
+ } ) ;
985
+ } ) ;
986
+
951
987
describe ( 'errors property' , ( ) => {
952
988
const reducer = formReducer ( 'test' ) ;
953
989
0 commit comments