Skip to content

Commit

Permalink
test: DAH-3110 add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tallulahkay committed Jan 3, 2025
1 parent 3de921d commit 4a0def8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
29 changes: 28 additions & 1 deletion app/javascript/__tests__/pages/SignIn.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react"

import SignIn from "../../pages/sign-in"
import { renderAndLoadAsync } from "../__util__/renderUtils"
import { render, screen, waitFor } from "@testing-library/react"
import { fireEvent, render, screen, waitFor } from "@testing-library/react"
import { userEvent } from "@testing-library/user-event"
import { post } from "../../api/apiService"
import { SiteAlert } from "../../components/SiteAlert"
Expand Down Expand Up @@ -197,6 +197,33 @@ describe("<SignIn />", () => {
})
})

it("handles enter key press as submit", async () => {
const { getByTestId } = render(<SignIn assetPaths={{}} />)
;(post as jest.Mock).mockRejectedValue({
response: {
status: 422,
data: { error: "not_confirmed", email: "[email protected]" },
},
})

const emailField = getByTestId("email-field")
const passwordField = getByTestId("password-field")

fireEvent.change(emailField, { target: { value: "[email protected]" } })
fireEvent.change(passwordField, { target: { value: "test1234" } })
fireEvent.keyPress(emailField, { key: "Enter", code: "Enter" })

await waitFor(() => {
expect(post).toHaveBeenCalled()
})

fireEvent.keyPress(passwordField, { key: "Enter", code: "Enter" })

await waitFor(() => {
expect(post).toHaveBeenCalled()
})
})

it("shows the correct new account modal", async () => {
;(post as jest.Mock).mockRejectedValueOnce({
response: {
Expand Down
1 change: 1 addition & 0 deletions app/javascript/pages/account/components/EmailFieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const EmailFieldset = ({ register, errors, defaultEmail, onChange, note }: Email
return (
<Fieldset hasError={errors.email} label={t("label.emailAddress")} note={note}>
<Field
dataTestId="email-field"
className="pb-4"
controlClassName="mt-1"
type="email"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const PasswordField = ({ passwordVisibilityDefault = false, ...props }: Password
return (
<>
<Field
dataTestId="password-field"
{...props}
type={showPassword ? "text" : "password"}
inputProps={{ className: "input", required: true }}
Expand Down

0 comments on commit 4a0def8

Please sign in to comment.