@@ -106,6 +106,83 @@ test('browser plugin integration test withRPCRedux', async t => {
106106 t . end ( ) ;
107107} ) ;
108108
109+ test ( 'browser plugin integration test withRPCRedux and options' , async t => {
110+ setup ( ) ;
111+ const fetch = ( url , options ) => {
112+ if ( ! options || ! options . body || typeof options . body !== 'string' ) {
113+ throw new Error ( `Expected a string from options.body` ) ;
114+ }
115+ const body : string = options . body ;
116+
117+ t . equal ( url , '/api/test' , 'fetches to expected url' ) ;
118+ t . deepLooseEqual (
119+ JSON . parse ( body ) ,
120+ { arg : 1 , state : 2 , prop : 3 } ,
121+ 'sends correct body'
122+ ) ;
123+ t . equal ( options . method , 'POST' , 'makes POST request' ) ;
124+ return Promise . resolve (
125+ new Response (
126+ JSON . stringify ( {
127+ status : 'success' ,
128+ data : {
129+ a : 'b' ,
130+ } ,
131+ } )
132+ )
133+ ) ;
134+ } ;
135+
136+ const expectedActions = [
137+ { type : initActionPattern } ,
138+ { type : / T E S T _ S T A R T / , payload : { arg : 1 , state : 2 , prop : 3 } } ,
139+ { type : / T E S T _ S U C C E S S / , payload : { a : 'b' } } ,
140+ ] ;
141+ const store = createStore (
142+ ( state , action ) => {
143+ const fixture = expectedActions . shift ( ) ;
144+ t . ok ( fixture . type . test ( action . type ) , 'dispatches expected action type' ) ;
145+ t . deepLooseEqual (
146+ action . payload ,
147+ // $FlowFixMe
148+ fixture . payload ,
149+ 'dispatches expected action payload'
150+ ) ;
151+ return { ...state , ...action . payload } ;
152+ } ,
153+ { state : 2 }
154+ ) ;
155+
156+ const Component = props => {
157+ t . equal ( typeof props . test , 'function' , 'passes correct prop to component' ) ;
158+ return React . createElement ( 'span' , null , 'hello world' ) ;
159+ } ;
160+
161+ const mapStateToParams = ( state , args , props ) => {
162+ return { ...state , ...args , ...props } ;
163+ } ;
164+
165+ const withTest = compose (
166+ withRPCRedux ( 'test' , { mapStateToParams} ) ,
167+ connect ( s => s ) ,
168+ prepared ( props => ( props . a ? Promise . resolve ( ) : props . test ( { arg : 1 } ) ) )
169+ ) ( Component ) ;
170+
171+ const element = React . createElement (
172+ Provider ,
173+ { store} ,
174+ React . createElement ( withTest , { prop : 3 } )
175+ ) ;
176+ const app = new App ( element ) ;
177+ app . register ( Plugin ) ;
178+ app . register ( FetchToken , fetch ) ;
179+ await getSimulator ( app ) . render ( '/' ) ;
180+ t . equal ( expectedActions . length , 0 , 'dispatches all actions' ) ;
181+
182+ teardown ( ) ;
183+ t . end ( ) ;
184+ } ) ;
185+
109186test ( 'browser plugin integration test withRPCRedux - failure' , async t => {
110187 setup ( ) ;
111188 const fetch = ( url , options ) => {
0 commit comments