@@ -7,6 +7,7 @@ import expect from 'expect';
77import { useGetOne } from '../dataProvider' ;
88import useLogout from './useLogout' ;
99import { CoreAdminContext } from '../core/CoreAdminContext' ;
10+ import { Redirect } from './useLogout.stories' ;
1011
1112import { TestMemoryRouter } from '../routing' ;
1213
@@ -54,98 +55,21 @@ describe('useLogout', () => {
5455 ) . toBeUndefined ( ) ;
5556 } ) ;
5657 it ( 'should redirect to `/login` by default' , async ( ) => {
57- const LogoutButton = ( ) => {
58- const logout = useLogout ( ) ;
59- return < button onClick = { logout } > Logout</ button > ;
60- } ;
61- const authProvider = {
62- logout : ( ) => Promise . resolve ( ) ,
63- } as any ;
64- const Page = ( ) => < div > Page</ div > ;
65- const Login = ( ) => < div > Login</ div > ;
66- render (
67- < TestMemoryRouter >
68- < CoreAdminContext authProvider = { authProvider } >
69- < Routes >
70- < Route path = "/" element = { < Page /> } />
71- < Route path = "/login" element = { < Login /> } />
72- </ Routes >
73-
74- < LogoutButton />
75- </ CoreAdminContext >
76- </ TestMemoryRouter >
77- ) ;
58+ render ( < Redirect redirectTo = "default" /> ) ;
7859 await screen . findByText ( 'Page' ) ;
7960 fireEvent . click ( screen . getByText ( 'Logout' ) ) ;
8061 await screen . findByText ( 'Login' ) ;
8162 } ) ;
8263 it ( 'should redirect to the url returned by the authProvider.logout call' , async ( ) => {
83- const LogoutButton = ( ) => {
84- const logout = useLogout ( ) ;
85- return < button onClick = { logout } > Logout</ button > ;
86- } ;
87- const authProvider = {
88- logout : ( ) => Promise . resolve ( '/not_login' ) ,
89- } as any ;
90- const queryClient = new QueryClient ( ) ;
91- const Page = ( ) => < div > Page</ div > ;
92- const Login = ( ) => < div > Login</ div > ;
93- const NotLogin = ( ) => < div > NotLogin</ div > ;
94- render (
95- < TestMemoryRouter >
96- < CoreAdminContext
97- authProvider = { authProvider }
98- queryClient = { queryClient }
99- >
100- < Routes >
101- < Route path = "/" element = { < Page /> } />
102- < Route path = "/login" element = { < Login /> } />
103- < Route path = "/not_login" element = { < NotLogin /> } />
104- </ Routes >
105-
106- < LogoutButton />
107- </ CoreAdminContext >
108- </ TestMemoryRouter >
109- ) ;
64+ render ( < Redirect redirectTo = "authProvider.logout" /> ) ;
11065 await screen . findByText ( 'Page' ) ;
11166 fireEvent . click ( screen . getByText ( 'Logout' ) ) ;
112- await screen . findByText ( 'NotLogin ' ) ;
67+ await screen . findByText ( 'Custom from authProvider.logout ' ) ;
11368 } ) ;
11469 it ( 'should redirect to the url returned by the caller' , async ( ) => {
115- const LogoutButton = ( ) => {
116- const logout = useLogout ( ) ;
117- return (
118- < button onClick = { ( ) => logout ( undefined , '/caller_redirect' ) } >
119- Logout
120- </ button >
121- ) ;
122- } ;
123- const authProvider = {
124- logout : ( ) => Promise . resolve ( '/not_login' ) ,
125- } as any ;
126- const Page = ( ) => < div > Page</ div > ;
127- const Login = ( ) => < div > Login</ div > ;
128- const NotLogin = ( ) => < div > NotLogin</ div > ;
129- const CallerRedirect = ( ) => < div > CallerRedirect</ div > ;
130- render (
131- < TestMemoryRouter >
132- < CoreAdminContext authProvider = { authProvider } >
133- < Routes >
134- < Route path = "/" element = { < Page /> } />
135- < Route path = "/login" element = { < Login /> } />
136- < Route path = "/not_login" element = { < NotLogin /> } />
137- < Route
138- path = "/caller_redirect"
139- element = { < CallerRedirect /> }
140- />
141- </ Routes >
142-
143- < LogoutButton />
144- </ CoreAdminContext >
145- </ TestMemoryRouter >
146- ) ;
70+ render ( < Redirect redirectTo = "caller" /> ) ;
14771 await screen . findByText ( 'Page' ) ;
14872 fireEvent . click ( screen . getByText ( 'Logout' ) ) ;
149- await screen . findByText ( 'CallerRedirect ' ) ;
73+ await screen . findByText ( 'Custom from useLogout caller ' ) ;
15074 } ) ;
15175} ) ;
0 commit comments