@@ -8,13 +8,14 @@ import {
88 DefaultTitle ,
99 NoAuthProvider ,
1010 WithAuthProviderNoAccessControl ,
11+ WithRenderProps ,
1112} from './EditBase.stories' ;
1213
1314describe ( 'EditBase' , ( ) => {
1415 it ( 'should give access to the save function' , async ( ) => {
1516 const dataProvider = testDataProvider ( {
16- // @ts -ignore
1717 getOne : ( ) =>
18+ // @ts -ignore
1819 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
1920 update : jest . fn ( ( _ , { id, data, previousData } ) =>
2021 Promise . resolve ( { data : { id, ...previousData , ...data } } )
@@ -44,8 +45,8 @@ describe('EditBase', () => {
4445
4546 it ( 'should allow to override the onSuccess function' , async ( ) => {
4647 const dataProvider = testDataProvider ( {
47- // @ts -ignore
4848 getOne : ( ) =>
49+ // @ts -ignore
4950 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
5051 update : jest . fn ( ( _ , { id, data, previousData } ) =>
5152 Promise . resolve ( { data : { id, ...previousData , ...data } } )
@@ -84,8 +85,8 @@ describe('EditBase', () => {
8485
8586 it ( 'should allow to override the onSuccess function at call time' , async ( ) => {
8687 const dataProvider = testDataProvider ( {
87- // @ts -ignore
8888 getOne : ( ) =>
89+ // @ts -ignore
8990 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
9091 update : jest . fn ( ( _ , { id, data, previousData } ) =>
9192 Promise . resolve ( { data : { id, ...previousData , ...data } } )
@@ -128,8 +129,8 @@ describe('EditBase', () => {
128129 it ( 'should allow to override the onError function' , async ( ) => {
129130 jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
130131 const dataProvider = testDataProvider ( {
131- // @ts -ignore
132132 getOne : ( ) =>
133+ // @ts -ignore
133134 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
134135 // @ts -ignore
135136 update : jest . fn ( ( ) => Promise . reject ( { message : 'test' } ) ) ,
@@ -162,8 +163,8 @@ describe('EditBase', () => {
162163
163164 it ( 'should allow to override the onError function at call time' , async ( ) => {
164165 const dataProvider = testDataProvider ( {
165- // @ts -ignore
166166 getOne : ( ) =>
167+ // @ts -ignore
167168 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
168169 // @ts -ignore
169170 update : jest . fn ( ( ) => Promise . reject ( { message : 'test' } ) ) ,
@@ -199,8 +200,8 @@ describe('EditBase', () => {
199200
200201 it ( 'should allow to override the transform function' , async ( ) => {
201202 const dataProvider = testDataProvider ( {
202- // @ts -ignore
203203 getOne : ( ) =>
204+ // @ts -ignore
204205 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
205206 update : jest . fn ( ( _ , { id, data, previousData } ) =>
206207 Promise . resolve ( { data : { id, ...previousData , ...data } } )
@@ -239,8 +240,8 @@ describe('EditBase', () => {
239240
240241 it ( 'should allow to override the transform function at call time' , async ( ) => {
241242 const dataProvider = testDataProvider ( {
242- // @ts -ignore
243243 getOne : ( ) =>
244+ // @ts -ignore
244245 Promise . resolve ( { data : { id : 12 , test : 'previous' } } ) ,
245246 update : jest . fn ( ( _ , { id, data, previousData } ) =>
246247 Promise . resolve ( { data : { id, ...previousData , ...data } } )
@@ -376,4 +377,32 @@ describe('EditBase', () => {
376377 fireEvent . click ( screen . getByText ( 'FR' ) ) ;
377378 await screen . findByText ( "Modifier l'article Hello (fr)" ) ;
378379 } ) ;
380+
381+ it ( 'should allow renderProp' , async ( ) => {
382+ const dataProvider = testDataProvider ( {
383+ getOne : ( ) =>
384+ // @ts -ignore
385+ Promise . resolve ( { data : { id : 12 , test : 'Hello' } } ) ,
386+ update : jest . fn ( ( _ , { id, data, previousData } ) =>
387+ Promise . resolve ( { data : { id, ...previousData , ...data } } )
388+ ) ,
389+ } ) ;
390+ render (
391+ < WithRenderProps
392+ dataProvider = { dataProvider }
393+ mutationMode = "pessimistic"
394+ />
395+ ) ;
396+ await screen . findByText ( '12' ) ;
397+ await screen . findByText ( 'Hello' ) ;
398+ fireEvent . click ( screen . getByText ( 'save' ) ) ;
399+
400+ await waitFor ( ( ) => {
401+ expect ( dataProvider . update ) . toHaveBeenCalledWith ( 'posts' , {
402+ id : 12 ,
403+ data : { test : 'test' } ,
404+ previousData : { id : 12 , test : 'Hello' } ,
405+ } ) ;
406+ } ) ;
407+ } ) ;
379408} ) ;
0 commit comments