Skip to content

Commit 99054f9

Browse files
committed
Add test to cover redirect case
1 parent a88b109 commit 99054f9

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

site/components/SignIn/SignInForm.test.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff 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: "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+
})
6183
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy