@@ -254,5 +254,39 @@ describe('useShowController', () => {
254254 expect ( dataProvider . getOne ) . toHaveBeenCalled ( ) ;
255255 expect ( authProvider . checkAuth ) . not . toHaveBeenCalled ( ) ;
256256 } ) ;
257+
258+ it ( 'should not call checkAuth nor canAccess when disableAuthentication is true' , async ( ) => {
259+ const authProvider : AuthProvider = {
260+ checkAuth : jest . fn ( ) . mockResolvedValue ( true ) ,
261+ login : ( ) => Promise . resolve ( ) ,
262+ logout : ( ) => Promise . resolve ( ) ,
263+ checkError : ( ) => Promise . resolve ( ) ,
264+ getPermissions : ( ) => Promise . resolve ( ) ,
265+ canAccess : jest . fn ( ) . mockResolvedValue ( false ) ,
266+ } ;
267+ render ( < DisableAuthentication authProvider = { authProvider } /> ) ;
268+ await screen . findByText ( 'Post #1 - 90 votes' ) ;
269+ expect ( authProvider . checkAuth ) . not . toHaveBeenCalled ( ) ;
270+ expect ( authProvider . canAccess ) . not . toHaveBeenCalled ( ) ;
271+ } ) ;
272+
273+ it ( 'should not call checkAuth nor canAccess when disableAuthentication is true even if useAuthState was called before' , async ( ) => {
274+ const authProvider : AuthProvider = {
275+ checkAuth : jest . fn ( ) . mockResolvedValue ( true ) ,
276+ login : ( ) => Promise . resolve ( ) ,
277+ logout : ( ) => Promise . resolve ( ) ,
278+ checkError : ( ) => Promise . resolve ( ) ,
279+ getPermissions : ( ) => Promise . resolve ( ) ,
280+ canAccess : jest . fn ( ) . mockResolvedValue ( false ) ,
281+ } ;
282+ render ( < DisableAuthentication authProvider = { authProvider } /> ) ;
283+ await screen . findByText ( 'Post #1 - 90 votes' ) ;
284+ fireEvent . click ( await screen . findByText ( 'List' ) ) ;
285+ await screen . findByText ( 'List view' ) ;
286+ fireEvent . click ( await screen . findByText ( 'Show' ) ) ;
287+ await screen . findByText ( 'Post #1 - 90 votes' ) ;
288+ expect ( authProvider . checkAuth ) . toHaveBeenCalledTimes ( 1 ) ;
289+ expect ( authProvider . canAccess ) . not . toHaveBeenCalled ( ) ;
290+ } ) ;
257291 } ) ;
258292} ) ;
0 commit comments