Skip to content

Commit

Permalink
fix: updated application checks (#3781)
Browse files Browse the repository at this point in the history
* fix: updated application checks

* fix: disable apply online in draft state

* fix: improved testing coverage

* fix: stronger typing

* fix: top level listing checks

* fix: improved url approach

* fix: updated testing

* fix: rexolve testing issues pt. 2
  • Loading branch information
ColinBuyck authored Jan 3, 2024
1 parent de93fbb commit 5d98f95
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 15 deletions.
35 changes: 33 additions & 2 deletions sites/public/__tests__/components/listing/GetApplication.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("<Applications>", () => {
zipCode: "90210",
}}
preview={false}
listingStatus="active"
listingName={"Listing name"}
/>
)
Expand Down Expand Up @@ -56,12 +57,13 @@ describe("<Applications>", () => {
zipCode: "90210",
}}
preview={false}
listingStatus="active"
listingName={"Listing name"}
/>
)
expect(queryByTestId("get-application-section")).toBeNull()
})
it("disables apply online button in preview state", () => {
it("disables apply online button if draft listing and not in preview state", () => {
const { getByText } = render(
<GetApplication
onlineApplicationURL={"online-app-url"}
Expand All @@ -81,12 +83,40 @@ describe("<Applications>", () => {
street: "Pick Up Address Street",
zipCode: "90210",
}}
preview={true}
preview={false}
listingStatus="pending"
listingName={"Listing name"}
/>
)
expect(getByText("Apply Online").closest("button")?.disabled).toBe(true)
})
it("enables apply online button if draft listing and in preview state", () => {
const { getByText } = render(
<GetApplication
onlineApplicationURL={"online-app-url"}
applicationsOpen={true}
applicationsOpenDate={"November 20th, 2021"}
paperApplications={[
{ fileURL: "file-url-en", languageString: "English" },
{ fileURL: "file-url-es", languageString: "Spanish" },
]}
paperMethod={true}
postmarkedApplicationsReceivedByDate={"November 30th, 2021"}
applicationPickUpAddressOfficeHours={"M-F 9am-5pm"}
applicationPickUpAddress={{
city: "City",
state: "State",
street2: "Street 2",
street: "Pick Up Address Street",
zipCode: "90210",
}}
preview={true}
listingStatus="pending"
listingName={"Listing name"}
/>
)
expect(getByText("Apply Online").closest("a")?.getAttribute("href")).toBe("online-app-url")
})
it("hides buttons if application is not open", () => {
const { getByText, queryByText } = render(
<GetApplication
Expand All @@ -108,6 +138,7 @@ describe("<Applications>", () => {
zipCode: "90210",
}}
preview={false}
listingStatus="active"
listingName={"Listing name"}
/>
)
Expand Down
11 changes: 7 additions & 4 deletions sites/public/src/components/listing/GetApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Button } from "@bloom-housing/ui-seeds"
import { useForm } from "react-hook-form"
import { downloadExternalPDF } from "../../lib/helpers"
import { ListingStatus } from "@bloom-housing/backend-core"

export interface PaperApplication {
fileURL: string
Expand All @@ -39,7 +40,9 @@ export interface ApplicationsProps {
paperMethod?: boolean
/** The date mailed applications must be received by */
postmarkedApplicationsReceivedByDate?: string
/** Whether or not to hide actionable application buttons */
/** Informs whether or not to hide actionable application buttons */
listingStatus?: string
/** Whether or not to block submission of test application */
preview?: boolean
strings?: {
applicationsOpenInFuture?: string
Expand All @@ -57,8 +60,8 @@ const GetApplication = (props: ApplicationsProps) => {
const showSection =
props.onlineApplicationURL ||
(props.applicationsOpen && props.paperMethod && !!props.paperApplications?.length)
const disableApplyButton = !props.preview && props.listingStatus !== ListingStatus.active
const [showDownloadModal, setShowDownloadModal] = useState(false)

// eslint-disable-next-line @typescript-eslint/unbound-method
const { register, watch } = useForm()
const paperApplicationURL: string = watch(
Expand All @@ -84,11 +87,11 @@ const GetApplication = (props: ApplicationsProps) => {
)}
{props.applicationsOpen && props.onlineApplicationURL && (
<div style={{ boxSizing: "border-box" }}>
{props.preview ? (
{disableApplyButton ? (
<Button
variant="primary-outlined"
disabled
className="w-full mb-2"
disabled
id={"listing-view-apply-button"}
>
{props.strings?.applyOnline ?? t("listings.apply.applyOnline")}
Expand Down
2 changes: 2 additions & 0 deletions sites/public/src/components/listing/ListingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export const ListingView = (props: ListingProps) => {
let onlineApplicationURL
if (hasMethod(listing.applicationMethods, ApplicationMethodType.Internal)) {
onlineApplicationURL = `/applications/start/choose-language?listingId=${listing.id}`
onlineApplicationURL += `${props.preview ? "&preview=true" : ""}`
} else if (hasMethod(listing.applicationMethods, ApplicationMethodType.ExternalLink)) {
onlineApplicationURL =
getMethod(listing.applicationMethods, ApplicationMethodType.ExternalLink)
Expand Down Expand Up @@ -361,6 +362,7 @@ export const ListingView = (props: ListingProps) => {
applicationPickUpAddress={getAddress(listing.applicationPickUpAddressType, "pickUp")}
preview={props.preview}
listingName={listing.name}
listingStatus={listing.status}
/>
{!(
listing.status === ListingStatus.closed ||
Expand Down
14 changes: 10 additions & 4 deletions sites/public/src/pages/applications/review/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
AuthContext,
listingSectionQuestions,
} from "@bloom-housing/shared-helpers"
import { ApplicationReviewStatus, ApplicationSection } from "@bloom-housing/backend-core"
import {
ApplicationReviewStatus,
ApplicationSection,
ListingStatus,
} from "@bloom-housing/backend-core"
import FormsLayout from "../../../layouts/forms"
import FormSummaryDetails from "../../../components/shared/FormSummaryDetails"
import { useFormConductor } from "../../../lib/hooks"
Expand Down Expand Up @@ -40,9 +44,11 @@ const ApplicationSummary = () => {
}, [profile])

useEffect(() => {
if (listing?.status === "closed") {
setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert")
void router.push(`/${router.locale}/listing/${listing?.id}/${listing.urlSlug}`)
if (listing && router.isReady) {
if (listing?.status !== ListingStatus.active) {
setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert")
void router.push(`/${router.locale}/listing/${listing?.id}/${listing.urlSlug}`)
}
}
}, [listing, router])

Expand Down
10 changes: 6 additions & 4 deletions sites/public/src/pages/applications/start/choose-language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
pushGtmEvent,
AuthContext,
} from "@bloom-housing/shared-helpers"
import { Language } from "@bloom-housing/backend-core/types"
import { Language, ListingStatus } from "@bloom-housing/backend-core/types"
import { Heading, Icon, Button, Message } from "@bloom-housing/ui-seeds"
import { CardSection } from "@bloom-housing/ui-seeds/src/blocks/Card"
import { faClock } from "@fortawesome/free-regular-svg-icons"
Expand Down Expand Up @@ -68,9 +68,11 @@ const ApplicationChooseLanguage = () => {
}, [router, conductor, context, listingId])

useEffect(() => {
if (listing?.status === "closed") {
setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert")
void router.push(`/${router.locale}/listing/${listing?.id}/${listing.urlSlug}`)
if (listing && router.isReady) {
if (listing?.status !== ListingStatus.active && router.query.preview !== "true") {
setSiteAlertMessage(t("listings.applicationsClosedRedirect"), "alert")
void router.push(`/${router.locale}/listing/${listing?.id}/${listing?.urlSlug}`)
}
}
}, [listing, router])

Expand Down
2 changes: 1 addition & 1 deletion sites/public/src/pages/preview/listings/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function ListingPage(props: ListingProps) {
>
{t("listings.listingPreviewOnly")}
</AlertBox>
<ListingView listing={listing} preview={false} jurisdiction={props.jurisdiction} />
<ListingView listing={listing} preview={true} jurisdiction={props.jurisdiction} />
</Layout>
)
}
Expand Down

0 comments on commit 5d98f95

Please sign in to comment.