Skip to content

Commit

Permalink
chore: add tests back to eslint (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludtkemorgan authored Sep 23, 2022
1 parent 9de739f commit fcab115
Show file tree
Hide file tree
Showing 31 changed files with 59 additions and 45 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ module.exports = {
"migration/",
"**/*.stories.tsx",
"**/.eslintrc.js",
"**/*.test.*",
],
}
6 changes: 3 additions & 3 deletions shared-helpers/__tests__/RequireLogin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GenericRouter, NavigationContext } from "@bloom-housing/ui-components"
const mockRouter: GenericRouter = {
pathname: "",
asPath: "",
back: () => {},
back: jest.fn(),
push(url: string) {
this.pathname = url
this.asPath = url
Expand Down Expand Up @@ -80,7 +80,7 @@ const itShouldNotRenderChildren = () =>

const itShouldRedirect = () =>
test("it should redirect", () => {
const { container, getByText } = render(
render(
<NavigationContext.Provider
value={{
router: mockRouter,
Expand All @@ -99,7 +99,7 @@ const itShouldRedirect = () =>

const itShouldNotRedirect = () =>
test("it should not redirect", () => {
const { container, getByText } = render(
render(
<NavigationContext.Provider
value={{
router: mockRouter,
Expand Down
8 changes: 4 additions & 4 deletions shared-helpers/__tests__/Timeout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AuthContext } from "../src/AuthContext"
afterEach(cleanup)

describe("<Timeout>", () => {
it("creates element if user is logged in", async () => {
it("creates element if user is logged in", () => {
const onTimeoutSpy = jest.fn()
const anchorMocked = document.createElement("div")
const createElementSpy = jest.spyOn(document, "createElement").mockReturnValueOnce(anchorMocked)
Expand All @@ -27,7 +27,7 @@ describe("<Timeout>", () => {
passwordValidForDays: 180,
agreedToTermsOfService: true,
},
signOut: () => {},
signOut: jest.fn(),
}}
>
<LoggedInUserIdleTimeout onTimeout={onTimeoutSpy} />
Expand All @@ -37,14 +37,14 @@ describe("<Timeout>", () => {
createElementSpy.mockRestore()
})

it("does not create element if user is not logged in", async () => {
it("does not create element if user is not logged in", () => {
const onTimeoutSpy = jest.fn()
const anchorMocked = document.createElement("div")
const createElementSpy = jest.spyOn(document, "createElement").mockReturnValueOnce(anchorMocked)
render(
<AuthContext.Provider
value={{
signOut: () => {},
signOut: jest.fn(),
}}
>
<LoggedInUserIdleTimeout onTimeout={onTimeoutSpy} />
Expand Down
2 changes: 1 addition & 1 deletion sites/partners/__tests__/DatesFormatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TimeFieldPeriod } from "@bloom-housing/ui-components"
import { createDate, createTime } from "../lib/helpers"
import { createTime } from "../lib/helpers"
import { YesNoAnswer } from "../src/applications/PaperApplicationForm/FormTypes"
import DatesFormatter from "../src/listings/PaperListingForm/formatters/DatesFormatter"
import { FormMetadata } from "../src/listings/PaperListingForm/formTypes"
Expand Down
4 changes: 2 additions & 2 deletions ui-components/__tests__/blocks/ImageCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ afterEach(cleanup)

describe("<ImageCard>", () => {
it("renders title, subtitle, image and alt text", () => {
const { getByText, getByAltText } = render(
const { getByAltText } = render(
<ImageCard imageUrl={"/images/listing.jpg"} description={"A description of the image"} />
)

Expand Down Expand Up @@ -79,7 +79,7 @@ describe("<ImageCard>", () => {
portalRoot.setAttribute("id", "__next")
document.body.appendChild(portalRoot)

const { getByAltText, getByTestId, container } = render(
const { getByAltText, getByTestId } = render(
<ImageCard
images={[
{ url: "/images/listing.jpg", description: "A description of the image" },
Expand Down
2 changes: 1 addition & 1 deletion ui-components/__tests__/blocks/InfoCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("<InfoCard>", () => {
})

it("if children are JSX, render as inputted", () => {
const { container, debug } = render(
const { container } = render(
<InfoCard title={"Info Card Title"} className={"custom-class"}>
<div>Children go here</div>
</InfoCard>
Expand Down
2 changes: 1 addition & 1 deletion ui-components/__tests__/blocks/StandardCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { render, cleanup, fireEvent } from "@testing-library/react"
import { render, cleanup } from "@testing-library/react"
import { StandardCard } from "../../src/blocks/StandardCard"
import { Button } from "../../src/actions/Button"

Expand Down
2 changes: 1 addition & 1 deletion ui-components/__tests__/blocks/StatusItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ afterEach(cleanup)

describe("<StatusItem>", () => {
it("renders without error", () => {
const { getByText, queryByText } = render(
const { getByText } = render(
<StatusItem
applicationDueDate={"March 10th, 2022"}
applicationURL={"application/1234abcd"}
Expand Down
1 change: 1 addition & 0 deletions ui-components/__tests__/forms/DOBField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useForm } from "react-hook-form"
afterEach(cleanup)
// Could not figure out how to test the field validations from here given this documentation: https://react-hook-form.com/advanced-usage/#TestingForm
const Optional = ({ disabled = false }) => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, watch, errors } = useForm({ mode: "onChange" })
return (
<DOBField
Expand Down
1 change: 1 addition & 0 deletions ui-components/__tests__/forms/DateField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useForm } from "react-hook-form"

afterEach(cleanup)
const Optional = ({ disabled = false }) => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, watch, errors } = useForm({ mode: "onChange" })
return (
<DateField
Expand Down
10 changes: 7 additions & 3 deletions ui-components/__tests__/forms/Field.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React from "react"
import { render, cleanup, fireEvent, getByPlaceholderText } from "@testing-library/react"
import { render, cleanup } from "@testing-library/react"
import { Field } from "../../src/forms/Field"
import { useForm } from "react-hook-form"

afterEach(cleanup)

const FieldDefault = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<Field register={register} name={"Test Input"} label={"Test Input Default"} type={"text"} />
)
}

const FieldError = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<Field
Expand All @@ -27,6 +29,7 @@ const FieldError = () => {
}

const FieldCustomProps = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<Field
Expand All @@ -46,6 +49,7 @@ const FieldCustomProps = () => {
}

const FieldCurrency = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, getValues, setValue } = useForm({ mode: "onChange" })
return (
<Field
Expand Down Expand Up @@ -74,11 +78,11 @@ describe("<Field>", () => {
expect(getByText("Uh oh!")).toBeTruthy()
expect(getByLabelText("Test Input Error")).toBeTruthy()
})
it("can render custom state", async () => {
it("can render custom state", () => {
const { getByLabelText } = render(<FieldCustomProps />)
expect(getByLabelText("Test Input Custom")).toBeTruthy()
})
it("can render currency field", async () => {
it("can render currency field", () => {
const { getByText, getByLabelText, getByPlaceholderText } = render(<FieldCurrency />)
expect(getByLabelText("Test Input Custom")).toBeTruthy()
expect(getByText("$")).toBeTruthy()
Expand Down
5 changes: 5 additions & 0 deletions ui-components/__tests__/forms/FieldGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useForm } from "react-hook-form"
afterEach(cleanup)

const FieldGroupCustom = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<FieldGroup
Expand All @@ -26,6 +27,7 @@ const FieldGroupCustom = () => {
}

const FieldGroupError = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<FieldGroup
Expand All @@ -43,6 +45,7 @@ const FieldGroupError = () => {
}

const FieldGroupDefaultValues = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<FieldGroup
Expand All @@ -63,6 +66,7 @@ const FieldGroupDefaultValues = () => {
}

const FieldGroupSubfieldsUnchecked = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<FieldGroup
Expand Down Expand Up @@ -98,6 +102,7 @@ const FieldGroupSubfieldsUnchecked = () => {
}

const FieldGroupSubfieldsChecked = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<FieldGroup
Expand Down
2 changes: 1 addition & 1 deletion ui-components/__tests__/forms/Form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ afterEach(cleanup)

describe("<Form>", () => {
it("renders without error", () => {
const { getByText } = render(<Form onSubmit={() => {}}>Children go here</Form>)
const { getByText } = render(<Form onSubmit={jest.fn()}>Children go here</Form>)
expect(getByText("Children go here")).not.toBeNull()
})
})
6 changes: 0 additions & 6 deletions ui-components/__tests__/forms/HouseholdMemberForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { t } from "../../src/helpers/translator"
afterEach(cleanup)

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()

Expand All @@ -29,8 +25,6 @@ describe("<HouseholdMemberForm>", () => {
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()

Expand Down
7 changes: 5 additions & 2 deletions ui-components/__tests__/forms/HouseholdSizeField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { t } from "../../src/helpers/translator"
afterEach(cleanup)

const DefaultHouseholdSize = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<HouseholdSizeField
assistanceUrl={""}
clearErrors={() => {}}
clearErrors={jest.fn()}
error={null}
householdSize={3}
householdSizeMax={3}
Expand All @@ -23,10 +24,12 @@ const DefaultHouseholdSize = () => {
}

type ErrorHouseholdSizeProps = {
clearErrorsSpy: jest.Mock<any, any>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
clearErrorsSpy: jest.Mock<unknown, any[]>
}

const ErrorHouseholdSize = (props: ErrorHouseholdSizeProps) => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<HouseholdSizeField
Expand Down
1 change: 1 addition & 0 deletions ui-components/__tests__/forms/MultiSelectField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ for (let i = 0; i < 10; i++) {
}

const DefaultMultiSelectField = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, getValues, setValue } = useForm({ mode: "onChange" })

return (
Expand Down
2 changes: 2 additions & 0 deletions ui-components/__tests__/forms/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ afterEach(cleanup)
const ethnicityKeys = ["hispanicLatino", "notHispanicLatino"]

const DefaultSelect = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<Select
Expand All @@ -25,6 +26,7 @@ const DefaultSelect = () => {
}

const ErrorSelect = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm({ mode: "onChange" })
return (
<Select
Expand Down
2 changes: 2 additions & 0 deletions ui-components/__tests__/forms/Textarea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { useForm } from "react-hook-form"
afterEach(cleanup)

const TextareaDefault = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm()
return <Textarea name={"textarea-test"} label={"Textarea Label"} register={register} />
}

const TextareaCustom = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register } = useForm()
return (
<Textarea
Expand Down
1 change: 1 addition & 0 deletions ui-components/__tests__/forms/TimeField.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useForm } from "react-hook-form"
afterEach(cleanup)

const DefaultTimeField = () => {
// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, watch, errors } = useForm({ mode: "onChange" })
return (
<TimeField
Expand Down
4 changes: 2 additions & 2 deletions ui-components/__tests__/headers/SiteHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { render, cleanup, getByLabelText } from "@testing-library/react"
import { render, cleanup } from "@testing-library/react"
import { SiteHeader } from "../../src/headers/SiteHeader"

afterEach(cleanup)
Expand Down Expand Up @@ -44,7 +44,7 @@ describe("<SiteHeader>", () => {
},
{
title: "Sign Out",
onClick: () => {},
onClick: jest.fn(),
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions ui-components/__tests__/navigation/LanguageNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe("<LanguageNav>", () => {
{
label: "English",
active: true,
onClick: () => {},
onClick: jest.fn(),
},
{
label: "Spanish",
active: false,
onClick: () => {},
onClick: jest.fn(),
},
]

Expand Down
2 changes: 1 addition & 1 deletion ui-components/__tests__/navigation/SideNav.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { render, cleanup, fireEvent } from "@testing-library/react"
import { render, cleanup } from "@testing-library/react"
import { SideNav } from "../../src/navigation/SideNav"

afterEach(cleanup)
Expand Down
2 changes: 1 addition & 1 deletion ui-components/__tests__/navigation/Tabs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { render, cleanup, fireEvent } from "@testing-library/react"
import { render, cleanup } from "@testing-library/react"
import { Tabs, TabList, Tab, TabPanel } from "../../src/navigation/Tabs"

afterEach(cleanup)
Expand Down
1 change: 1 addition & 0 deletions ui-components/__tests__/notifications/SiteAlert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("<SiteAlert>", () => {
jest.spyOn(window.sessionStorage.__proto__, "setItem")
window.sessionStorage.__proto__.setItem = jest.fn()
setSiteAlertMessage("Alert Message Goes Here", "success")
// eslint-disable-next-line @typescript-eslint/unbound-method
expect(sessionStorage.setItem).toHaveBeenCalledWith(
"alert_message_success",
"Alert Message Goes Here"
Expand Down
Loading

0 comments on commit fcab115

Please sign in to comment.