@@ -1295,5 +1295,39 @@ describe('useEditController', () => {
12951295 expect ( dataProvider . getOne ) . toHaveBeenCalled ( ) ;
12961296 expect ( authProvider . checkAuth ) . not . toHaveBeenCalled ( ) ;
12971297 } ) ;
1298+
1299+ it ( 'should not call checkAuth nor canAccess when disableAuthentication is true' , async ( ) => {
1300+ const authProvider : AuthProvider = {
1301+ checkAuth : jest . fn ( ) . mockResolvedValue ( true ) ,
1302+ login : ( ) => Promise . resolve ( ) ,
1303+ logout : ( ) => Promise . resolve ( ) ,
1304+ checkError : ( ) => Promise . resolve ( ) ,
1305+ getPermissions : ( ) => Promise . resolve ( ) ,
1306+ canAccess : jest . fn ( ) . mockResolvedValue ( false ) ,
1307+ } ;
1308+ render ( < DisableAuthentication authProvider = { authProvider } /> ) ;
1309+ await screen . findByText ( 'Post #1 - 90 votes' ) ;
1310+ expect ( authProvider . checkAuth ) . not . toHaveBeenCalled ( ) ;
1311+ expect ( authProvider . canAccess ) . not . toHaveBeenCalled ( ) ;
1312+ } ) ;
1313+
1314+ it ( 'should not call checkAuth nor canAccess when disableAuthentication is true even if useAuthState was called before' , async ( ) => {
1315+ const authProvider : AuthProvider = {
1316+ checkAuth : jest . fn ( ) . mockResolvedValue ( true ) ,
1317+ login : ( ) => Promise . resolve ( ) ,
1318+ logout : ( ) => Promise . resolve ( ) ,
1319+ checkError : ( ) => Promise . resolve ( ) ,
1320+ getPermissions : ( ) => Promise . resolve ( ) ,
1321+ canAccess : jest . fn ( ) . mockResolvedValue ( false ) ,
1322+ } ;
1323+ render ( < DisableAuthentication authProvider = { authProvider } /> ) ;
1324+ await screen . findByText ( 'Post #1 - 90 votes' ) ;
1325+ fireEvent . click ( await screen . findByText ( 'List' ) ) ;
1326+ await screen . findByText ( 'List view' ) ;
1327+ fireEvent . click ( await screen . findByText ( 'Edit' ) ) ;
1328+ await screen . findByText ( 'Post #1 - 90 votes' ) ;
1329+ expect ( authProvider . checkAuth ) . toHaveBeenCalledTimes ( 1 ) ;
1330+ expect ( authProvider . canAccess ) . not . toHaveBeenCalled ( ) ;
1331+ } ) ;
12981332 } ) ;
12991333} ) ;
0 commit comments