File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,29 @@ describe("SignInForm", () => {
55
55
act ( ( ) => elem . click ( ) )
56
56
57
57
// Then
58
- // Should redirect because login was successfully
58
+ // Should redirect because login was successful
59
59
await waitFor ( ( ) => expect ( singletonRouter ) . toMatchObject ( { asPath : "/" } ) )
60
60
} )
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 : "test@coder.com" } } )
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
+ } )
61
83
} )
You can’t perform that action at this time.
0 commit comments