forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bloom-housing#1722 from bloom-housing/1721/househo…
…ld-member-form
- Loading branch information
Showing
6 changed files
with
90 additions
and
49 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
39 changes: 19 additions & 20 deletions
39
ui-components/__tests__/forms/HouseholdMemberForm.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,52 +1,51 @@ | ||
import React from "react" | ||
import { render, cleanup, fireEvent } from "@testing-library/react" | ||
import { HouseholdMemberForm } from "../../src/forms/HouseholdMemberForm" | ||
import { HouseholdMember } from "@bloom-housing/backend-core/types" | ||
import { t } from "../../src/helpers/translator" | ||
|
||
afterEach(cleanup) | ||
|
||
const Member1 = ({ | ||
firstName: "Breana", | ||
lastName: "Oquendo", | ||
} as unknown) as HouseholdMember | ||
|
||
const Member2 = ({ | ||
firstName: "Sonja", | ||
lastName: "Aldenkamp", | ||
orderId: 1234, | ||
} as unknown) as HouseholdMember | ||
|
||
describe("<HouseholdMemberForm>", () => { | ||
const useContext = jest.spyOn(require("react"), "useContext") | ||
|
||
it("renders as a primary applicant", () => { | ||
const router = { push: jest.fn().mockImplementation(() => Promise.resolve()) } | ||
useContext.mockReturnValue({ router }) | ||
global.scrollTo = jest.fn() | ||
const editMemberSpy = jest.fn() | ||
|
||
const { getByText } = render( | ||
<HouseholdMemberForm member={Member1} type={t("application.household.primaryApplicant")} /> | ||
<HouseholdMemberForm | ||
memberFirstName={"Breana"} | ||
memberLastName={"Oquendo"} | ||
key={"abcd"} | ||
subtitle={"Primary Applicant"} | ||
editMember={editMemberSpy} | ||
/> | ||
) | ||
expect(getByText(t("application.household.primaryApplicant"))).toBeTruthy() | ||
expect(getByText("Primary Applicant")).toBeTruthy() | ||
expect(getByText("Breana Oquendo")).toBeTruthy() | ||
fireEvent.click(getByText(t("t.edit"))) | ||
expect(router.push).toHaveBeenCalledWith("/applications/contact/name") | ||
expect(editMemberSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
it("renders as a household member", () => { | ||
const router = { push: jest.fn().mockImplementation(() => Promise.resolve()) } | ||
useContext.mockReturnValue({ router }) | ||
global.scrollTo = jest.fn() | ||
const editMemberSpy = jest.fn() | ||
|
||
const { getByText } = render( | ||
<HouseholdMemberForm member={Member2} type={t("application.household.householdMember")} /> | ||
<HouseholdMemberForm | ||
memberFirstName={"Sonja"} | ||
memberLastName={"Aldenkamp"} | ||
key={"abcd"} | ||
subtitle={"Household Member"} | ||
editMember={editMemberSpy} | ||
/> | ||
) | ||
expect(getByText(t("application.household.householdMember"))).toBeTruthy() | ||
expect(getByText("Sonja Aldenkamp")).toBeTruthy() | ||
fireEvent.click(getByText(t("t.edit"))) | ||
expect(router.push).toHaveBeenCalledWith({ | ||
pathname: "/applications/household/member", | ||
query: { memberId: 1234 }, | ||
}) | ||
expect(editMemberSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from "react" | ||
import HouseholdMemberForm from "./HouseholdMemberForm" | ||
|
||
export default { | ||
title: "Forms/HouseholdMemberForm", | ||
decorators: [(storyFn: any) => <div style={{ padding: "1rem" }}>{storyFn()}</div>], | ||
} | ||
|
||
export const editable = () => ( | ||
<HouseholdMemberForm | ||
memberFirstName={"Firstname"} | ||
memberLastName={"Lastname"} | ||
key={"FirstnameLastname"} | ||
subtitle={"Household Member"} | ||
editMember={() => {}} | ||
/> | ||
) | ||
|
||
export const notEditable = () => ( | ||
<HouseholdMemberForm | ||
memberFirstName={"Firstname"} | ||
memberLastName={"Lastname"} | ||
key={"FirstnameLastname"} | ||
subtitle={"Household Member"} | ||
editMode={false} | ||
/> | ||
) |
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