-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
9 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { render, screen, waitFor } from "@testing-library/react"; | ||
import { act, render, screen, waitFor } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { NextIntlClientProvider } from "next-intl"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
|
@@ -80,24 +80,27 @@ describe("LoginPage", () => { | |
render( | ||
<QueryClientProvider client={queryClient}> | ||
<NextIntlClientProvider locale="en" messages={enTranslation}> | ||
<LoginPage title="test" oauthExlusiveLogin={false} /> | ||
<LoginPage title="test" oauthExclusiveLogin={false} oauthEnabled={true} /> | ||
</NextIntlClientProvider> | ||
</QueryClientProvider>, | ||
); | ||
}; | ||
|
||
it("renders login form correctly", () => { | ||
it("renders login form correctly", async () => { | ||
const useQueryMock = jest.fn().mockReturnValue({ | ||
data: null, | ||
isLoading: true, | ||
refetch: jest.fn(), | ||
}); | ||
api.public.getWelcomeMessage.useQuery = useQueryMock; | ||
renderLoginPage(); | ||
|
||
await act(async () => { | ||
renderLoginPage(); | ||
}); | ||
|
||
expect(screen.getByLabelText(/Email/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Password/i)).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /Sign in/i })).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /^Sign in$/i })).toBeInTheDocument(); | ||
}); | ||
|
||
it("handles form submission with valid credentials", async () => { | ||
|
@@ -144,7 +147,7 @@ describe("LoginPage", () => { | |
|
||
const emailInput = screen.getByLabelText(/Email/i); | ||
const passwordInput = screen.getByLabelText(/Password/i); | ||
const submitButton = screen.getByRole("button", { name: /Sign in/i }); | ||
const submitButton = screen.getByRole("button", { name: /^Sign in$/i }); | ||
|
||
await userEvent.type(emailInput, "[email protected]"); | ||
await userEvent.type(passwordInput, "wrongpassword"); | ||
|
@@ -160,20 +163,6 @@ describe("LoginPage", () => { | |
}); | ||
}); | ||
|
||
// it("validates email format", async () => { | ||
// renderLoginPage(); | ||
|
||
// const emailInput = screen.getByLabelText(/Email/i); | ||
// const submitButton = screen.getByRole("button", { name: /Sign in/i }); | ||
|
||
// await userEvent.type(emailInput, "invalidemail"); | ||
// await userEvent.click(submitButton); | ||
|
||
// await waitFor(() => { | ||
// expect(screen.getByText(/Please enter a valid email address/i)).toBeInTheDocument(); | ||
// }); | ||
// }); | ||
|
||
it("requires password input", async () => { | ||
(signIn as jest.Mock).mockResolvedValue({ | ||
error: "email or password is wrong!", | ||
|