Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,105 +30,180 @@ beforeAll(() => {
mockTipTapEditor()
})

afterEach(() => server.resetHandlers())
afterAll(() => server.close())

describe("RankingsAndResults", () => {
const adminUserWithWaitlistLotteryFlag = {
jurisdictions: [
{
id: "jurisdiction1",
name: "jurisdictionWithWaitlistLottery",
featureFlags: [
{
name: FeatureFlagEnum.enableWaitlistLottery,
active: true,
},
],
},
],
}

const adminUserWithoutWaitlistLotteryFlag = {
jurisdictions: [
{
id: "jurisdiction1",
name: "jurisdictionWithoutWaitlistLottery",
featureFlags: [],
},
],
}

it("should not show lottery fields when enableWaitlistLottery is false and waitlist is open", async () => {
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(ctx.json(adminUserWithoutWaitlistLotteryFlag))
})
)

render(
<FormComponent
values={{
...formDefaults,
jurisdictions: { id: "jurisdiction1" },
listingAvailabilityQuestion: "openWaitlist",
}}
>
<RankingsAndResults
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

await screen.findByText("Rankings & results")

const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
await userEvent.click(waitlistYesRadio)

expect(
screen.queryByText("How is the application review order determined?")
).not.toBeInTheDocument()

expect(screen.queryByTestId("lottery-start-date")).not.toBeInTheDocument()
expect(screen.queryByTestId("lottery-start-time")).not.toBeInTheDocument()
expect(screen.queryByTestId("lottery-end-time")).not.toBeInTheDocument()
describe("RankingsAndResults enableWaitlistLottery", () => {
afterEach(() => server.resetHandlers())
afterAll(() => server.close())
const userWithWaitlistLotteryFlag = {
jurisdictions: [
{
id: "jurisdiction1",
name: "jurisdictionWithWaitlistLottery",
featureFlags: [
{
name: FeatureFlagEnum.enableWaitlistLottery,
active: true,
},
],
},
],
}
const userWithoutWaitlistLotteryFlag = {
jurisdictions: [
{
id: "jurisdiction1",
name: "jurisdictionWithoutWaitlistLottery",
featureFlags: [],
},
],
}

it("should not show lottery fields when enableWaitlistLottery is false and waitlist is open", async () => {
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(ctx.json(userWithoutWaitlistLotteryFlag))
})
)

render(
<FormComponent
values={{
...formDefaults,
jurisdictions: { id: "jurisdiction1" },
listingAvailabilityQuestion: "openWaitlist",
}}
>
<RankingsAndResults
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

await screen.findByText("Rankings & results")

const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
await userEvent.click(waitlistYesRadio)

expect(
screen.queryByText("How is the application review order determined?")
).not.toBeInTheDocument()

expect(screen.queryByTestId("lottery-start-date")).not.toBeInTheDocument()
expect(screen.queryByTestId("lottery-start-time")).not.toBeInTheDocument()
expect(screen.queryByTestId("lottery-end-time")).not.toBeInTheDocument()
})

it("should show review order options when waitlist is open and feature flag is enabled", async () => {
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(ctx.json(userWithWaitlistLotteryFlag))
})
)

render(
<FormComponent
values={{
...formDefaults,
jurisdictions: { id: "jurisdiction1" },
listingAvailabilityQuestion: "openWaitlist",
}}
>
<RankingsAndResults
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

screen.getByRole("heading", { name: "Rankings & results" })

const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
await userEvent.click(waitlistYesRadio)

await screen.findByText("How is the application review order determined?")

expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
})

it("should show review order options when availabilityQuestion is availableUnits and enableWaitlistLottery is false", () => {
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(ctx.json(userWithoutWaitlistLotteryFlag))
})
)

render(
<FormComponent
values={{
...formDefaults,
jurisdictions: { id: "jurisdiction1" },
listingAvailabilityQuestion: "availableUnits",
}}
>
<RankingsAndResults
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

screen.getByRole("heading", { name: "Rankings & results" })
expect(
screen.getByText("How is the application review order determined?")
).toBeInTheDocument()

expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
})
})

it("should show review order options when waitlist is open and feature flag is enabled", async () => {
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(ctx.json(adminUserWithWaitlistLotteryFlag))
})
)

render(
<FormComponent
values={{
...formDefaults,
jurisdictions: { id: "jurisdiction1" },
listingAvailabilityQuestion: "openWaitlist",
}}
>
<RankingsAndResults
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

screen.getByRole("heading", { name: "Rankings & results" })

const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
await userEvent.click(waitlistYesRadio)

await screen.findByText("How is the application review order determined?")

expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
describe("Verifying text when selecting lottery radio button", () => {
it("should show proper message when selecting lottery as a non admin user", async () => {
process.env.showLottery = "true"
render(
<FormComponent>
<RankingsAndResults
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

screen.getByRole("heading", { name: "Rankings & results" })
const lotteryRadio = await screen.findByRole("radio", { name: "Lottery" })
await userEvent.click(lotteryRadio)
expect(
screen.getByText(
"Your lottery will be run in the Partners Portal. If you want to make alternative arrangements, please contact staff."
)
).toBeInTheDocument()
})
it("should show proper message when selecting lottery as an admin user", async () => {
process.env.showLottery = "true"
render(
<FormComponent>
<RankingsAndResults
isAdmin={true}
listing={null}
requiredFields={[]}
whatToExpectEditor={null}
whatToExpectAdditionalTextEditor={null}
/>
</FormComponent>
)

screen.getByRole("heading", { name: "Rankings & results" })
const lotteryRadio = await screen.findByRole("radio", { name: "Lottery" })
await userEvent.click(lotteryRadio)
expect(screen.getByText("Will the lottery be run in the partner portal?")).toBeInTheDocument()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ const RankingsAndResults = ({
selectedJurisdictionId
)

const showFSFCLotterySection = enableWaitlistLottery && waitlistOpen
const showFSFCLotterySection =
(enableWaitlistLottery && waitlistOpen) ||
(availabilityQuestion !== "openWaitlist" && !enableWaitlistLottery)

// Ensure the lottery fields only show when it's "available units" listing
const showLotteryFields =
Expand Down
Loading