@@ -2042,6 +2042,106 @@ Object.keys(testContexts).forEach((testKey) => {
20422042 } ) ;
20432043 } ) ;
20442044
2045+
2046+ describe ( 'form validation with models in collections' , ( ) => {
2047+ it ( 'validates if item in initialState' , ( ) => {
2048+ const initialState = getInitialState ( { test1 : { } } ) ;
2049+
2050+ const store = testCreateStore ( {
2051+ test : modelReducer ( 'tests' , initialState ) ,
2052+ testForm : formReducer ( 'tests' , initialState ) ,
2053+ } ) ;
2054+
2055+ let handleSubmitFailedCalledWith = null ;
2056+
2057+ function handleSubmitFailed ( val ) {
2058+ handleSubmitFailedCalledWith = val ;
2059+ }
2060+
2061+ const form = TestUtils . renderIntoDocument (
2062+ < Provider store = { store } >
2063+ < Form
2064+ model = "tests.test1"
2065+ onSubmitFailed = { handleSubmitFailed }
2066+ validators = { {
2067+ foo : ( val ) => val ,
2068+ } }
2069+ >
2070+ < Control model = ".foo" />
2071+ </ Form >
2072+ </ Provider >
2073+ ) ;
2074+
2075+ const formNode = TestUtils . findRenderedDOMComponentWithTag ( form , 'form' ) ;
2076+
2077+ TestUtils . Simulate . submit ( formNode ) ;
2078+
2079+ assert . containSubset ( handleSubmitFailedCalledWith , {
2080+ $form : {
2081+ model : 'tests.test1' ,
2082+ valid : false ,
2083+ } ,
2084+ foo : {
2085+ model : 'tests.test1.foo' ,
2086+ valid : false ,
2087+ errors : true ,
2088+ } ,
2089+ } ) ;
2090+
2091+ assert . isFalse ( store . getState ( ) . testForm . test1 . $form . pending ) ;
2092+ assert . isTrue ( store . getState ( ) . testForm . test1 . $form . submitFailed ) ;
2093+ } ) ;
2094+
2095+ it ( 'validates if item not in initialState' , ( ) => {
2096+ const initialState = getInitialState ( { test1 : { } } ) ;
2097+
2098+ const store = testCreateStore ( {
2099+ test : modelReducer ( 'tests' , initialState ) ,
2100+ testForm : formReducer ( 'tests' , initialState ) ,
2101+ } ) ;
2102+
2103+ let handleSubmitFailedCalledWith = null ;
2104+
2105+ function handleSubmitFailed ( val ) {
2106+ handleSubmitFailedCalledWith = val ;
2107+ }
2108+
2109+ const form = TestUtils . renderIntoDocument (
2110+ < Provider store = { store } >
2111+ < Form
2112+ model = "tests.test2"
2113+ onSubmitFailed = { handleSubmitFailed }
2114+ validators = { {
2115+ foo : ( val ) => val ,
2116+ } }
2117+ >
2118+ < Control model = ".foo" />
2119+ </ Form >
2120+ </ Provider >
2121+ ) ;
2122+
2123+ const formNode = TestUtils . findRenderedDOMComponentWithTag ( form , 'form' ) ;
2124+
2125+ TestUtils . Simulate . submit ( formNode ) ;
2126+
2127+ assert . containSubset ( handleSubmitFailedCalledWith , {
2128+ $form : {
2129+ model : 'tests.test2' ,
2130+ valid : false ,
2131+ } ,
2132+ foo : {
2133+ model : 'tests.test2.foo' ,
2134+ valid : false ,
2135+ errors : true ,
2136+ } ,
2137+ } ) ;
2138+
2139+ assert . isFalse ( store . getState ( ) . testForm . test2 . $form . pending ) ;
2140+ assert . isTrue ( store . getState ( ) . testForm . test2 . $form . submitFailed ) ;
2141+ } ) ;
2142+ } ) ;
2143+
2144+
20452145 describe ( 'getDispatch() prop' , ( ) => {
20462146 it ( 'should provide dispatch to callback' , ( done ) => {
20472147 const initialState = getInitialState ( { foo : '' } ) ;
0 commit comments