File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,29 @@ describe("SignInForm", () => {
5555 act ( ( ) => elem . click ( ) )
5656
5757 // Then
58- // Should redirect because login was successfully
58+ // Should redirect because login was successful
5959 await waitFor ( ( ) => expect ( singletonRouter ) . toMatchObject ( { asPath : "/" } ) )
6060 } )
61+
62+ it ( "respects ?redirect query parameter when complete" , async ( ) => {
63+ // Given
64+ const loginHandler = ( _email : string , _password : string ) => Promise . resolve ( )
65+ // Set a path to redirect to after login is successful
66+ mockRouter . setCurrentUrl ( "/login?redirect=%2Fsome%2Fother%2Fpath" )
67+
68+ // When
69+ // Render the component
70+ const { container } = render ( < SignInForm loginHandler = { loginHandler } /> )
71+ // Set user / password
72+ const inputs = container . querySelectorAll ( "input" )
73+ fireEvent . change ( inputs [ 0 ] , { target :
{ value :
"[email protected] " } } ) 74+ fireEvent . change ( inputs [ 1 ] , { target : { value : "password" } } )
75+ // Click sign-in
76+ const elem = await screen . findByText ( "Sign In" )
77+ act ( ( ) => elem . click ( ) )
78+
79+ // Then
80+ // Should redirect to /some/other/path because ?redirect was specified and login was successful
81+ await waitFor ( ( ) => expect ( singletonRouter ) . toMatchObject ( { asPath : "/some/other/path" } ) )
82+ } )
6183} )
You can’t perform that action at this time.
0 commit comments