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