-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into johanna/5600_replace_…
…generic_exceptions Merged with latest main code
- Loading branch information
Showing
13 changed files
with
321 additions
and
365 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
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
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
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
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
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
186 changes: 77 additions & 109 deletions
186
frontend/src/app/signUp/IdentityVerification/QuestionsForm.test.tsx
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,140 +1,108 @@ | ||
import { | ||
act, | ||
fireEvent, | ||
render, | ||
screen, | ||
waitFor, | ||
} from "@testing-library/react"; | ||
import { act, render, screen, waitFor } from "@testing-library/react"; | ||
import userEvent, { UserEvent } from "@testing-library/user-event"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
|
||
import { exampleQuestionSet } from "./constants"; | ||
import QuestionsForm from "./QuestionsForm"; | ||
import { answerIdVerificationQuestions } from "./QuestionsFormContainer.test"; | ||
|
||
describe("QuestionsForm", () => { | ||
let onSubmit: jest.Mock; | ||
let onFail: jest.Mock; | ||
|
||
const renderWithUser = () => ({ | ||
user: userEvent.setup(), | ||
...render( | ||
<MemoryRouter> | ||
<QuestionsForm | ||
questionSet={exampleQuestionSet} | ||
saving={false} | ||
onSubmit={onSubmit} | ||
onFail={onFail} | ||
/> | ||
</MemoryRouter> | ||
), | ||
}); | ||
|
||
beforeEach(() => { | ||
onSubmit = jest.fn(); | ||
onFail = jest.fn(); | ||
|
||
render( | ||
<QuestionsForm | ||
questionSet={exampleQuestionSet} | ||
saving={false} | ||
onSubmit={onSubmit} | ||
onFail={onFail} | ||
/> | ||
); | ||
}); | ||
|
||
it("initializes with the submit button enabled", () => { | ||
renderWithUser(); | ||
expect(screen.getByText("Submit")).toBeEnabled(); | ||
}); | ||
|
||
describe("tests with fake timers", () => { | ||
beforeAll(() => { | ||
jest.useFakeTimers(); | ||
it("initializes with a counter and starts counting down", async () => { | ||
jest.useFakeTimers(); | ||
renderWithUser(); | ||
expect(screen.getByText("5:00")).toBeInTheDocument(); | ||
await act(async () => { | ||
jest.advanceTimersByTime(1000); | ||
}); | ||
|
||
it("initializes with a counter and starts counting down", async () => { | ||
expect(screen.getByText("5:00")).toBeInTheDocument(); | ||
await act(async () => { | ||
jest.advanceTimersByTime(1000); | ||
}); | ||
expect(screen.getByText("4:59")).toBeInTheDocument(); | ||
await act(async () => { | ||
jest.advanceTimersByTime(2000); | ||
}); | ||
expect(screen.getByText("4:59")).toBeInTheDocument(); | ||
await act(async () => { | ||
jest.advanceTimersByTime(2000); | ||
}); | ||
jest.runOnlyPendingTimers(); | ||
jest.useRealTimers(); | ||
}); | ||
|
||
afterAll(() => { | ||
jest.runOnlyPendingTimers(); | ||
jest.useRealTimers(); | ||
}); | ||
it("enables the submit button when one field completed", async () => { | ||
const { user } = renderWithUser(); | ||
await user.click(screen.getByLabelText("2002", { exact: false })); | ||
await waitFor(() => expect(screen.getByText("Submit")).toBeEnabled()); | ||
}); | ||
|
||
describe("One field entered", () => { | ||
it("enables the submit button", async () => { | ||
fireEvent.click(screen.getByLabelText("2002", { exact: false })); | ||
await waitFor(() => expect(screen.getByText("Submit")).toBeEnabled()); | ||
it("shows errors for required fields on submit of incomplete form", async () => { | ||
const { user } = renderWithUser(); | ||
await user.click(screen.getByLabelText("2002", { exact: false })); | ||
await user.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
await waitFor(() => { | ||
expect(screen.queryAllByText("This field is required").length).toBe(4); | ||
}); | ||
}); | ||
|
||
describe("On submit", () => { | ||
it("shows errors for required fields", async () => { | ||
fireEvent.click(screen.getByLabelText("2002", { exact: false })); | ||
fireEvent.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
await waitFor(() => { | ||
expect(screen.queryAllByText("This field is required").length).toBe( | ||
4 | ||
); | ||
}); | ||
}); | ||
|
||
it("does not call the onSubmit callback", async () => { | ||
fireEvent.click(screen.getByLabelText("2002", { exact: false })); | ||
fireEvent.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
await waitFor(() => { | ||
expect(onSubmit).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
it("does not call the onSubmit callback", async () => { | ||
const { user } = renderWithUser(); | ||
await user.click(screen.getByLabelText("2002", { exact: false })); | ||
await user.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
await waitFor(() => { | ||
expect(onSubmit).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("Completed form", () => { | ||
describe("On submit", () => { | ||
it("does not show an error", async () => { | ||
fireEvent.click(screen.getByLabelText("2002", { exact: false })); | ||
fireEvent.click( | ||
screen.getByLabelText("OPTICIAN / OPTOMETRIST", { exact: false }) | ||
); | ||
fireEvent.click( | ||
screen.getByLabelText("MID AMERICA MORTGAGE", { exact: false }) | ||
); | ||
fireEvent.click(screen.getByLabelText("TWO", { exact: false })); | ||
fireEvent.click( | ||
screen.getByLabelText("AGUA DULCE HIGH SCHOOL", { exact: false }) | ||
); | ||
fireEvent.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
await waitFor(() => { | ||
expect(screen.queryAllByText("This field is required").length).toBe( | ||
0 | ||
); | ||
}); | ||
}); | ||
it("does not show error on submit of completed form", async () => { | ||
const { user } = renderWithUser(); | ||
await fillAndSubmitIdVerificationQuestions(user); | ||
await waitFor(() => { | ||
expect(screen.queryAllByText("This field is required").length).toBe(0); | ||
}); | ||
}); | ||
|
||
it("calls the onSubmit callback", async () => { | ||
fireEvent.click(screen.getByLabelText("2002", { exact: false })); | ||
fireEvent.click( | ||
screen.getByLabelText("OPTICIAN / OPTOMETRIST", { exact: false }) | ||
); | ||
fireEvent.click( | ||
screen.getByLabelText("MID AMERICA MORTGAGE", { exact: false }) | ||
); | ||
fireEvent.click(screen.getByLabelText("TWO", { exact: false })); | ||
fireEvent.click( | ||
screen.getByLabelText("AGUA DULCE HIGH SCHOOL", { exact: false }) | ||
); | ||
fireEvent.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
await waitFor(() => { | ||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); | ||
it("calls the onSubmit callback on submit of completed form", async () => { | ||
const { user } = renderWithUser(); | ||
await fillAndSubmitIdVerificationQuestions(user); | ||
await waitFor(() => { | ||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
const fillAndSubmitIdVerificationQuestions = async (user: UserEvent) => { | ||
await answerIdVerificationQuestions(user); | ||
await user.click( | ||
screen.queryAllByText("Submit", { | ||
exact: false, | ||
})[0] | ||
); | ||
}; |
Oops, something went wrong.