Skip to content

Commit 668e7ef

Browse files
millordmcgarrye
authored andcommitted
fix: [5441]-waitlist-lotteries-allow-selection-fcfs-fixes (bloom-housing#5548)
fixing logic and adding tests for waitlist lottery changes
1 parent 8c0f6e4 commit 668e7ef

2 files changed

Lines changed: 176 additions & 99 deletions

File tree

sites/partners/__tests__/components/listings/PaperListingForm/sections/RankingsAndResults.test.tsx

Lines changed: 173 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -30,105 +30,180 @@ beforeAll(() => {
3030
mockTipTapEditor()
3131
})
3232

33-
afterEach(() => server.resetHandlers())
34-
afterAll(() => server.close())
35-
3633
describe("RankingsAndResults", () => {
37-
const adminUserWithWaitlistLotteryFlag = {
38-
jurisdictions: [
39-
{
40-
id: "jurisdiction1",
41-
name: "jurisdictionWithWaitlistLottery",
42-
featureFlags: [
43-
{
44-
name: FeatureFlagEnum.enableWaitlistLottery,
45-
active: true,
46-
},
47-
],
48-
},
49-
],
50-
}
51-
52-
const adminUserWithoutWaitlistLotteryFlag = {
53-
jurisdictions: [
54-
{
55-
id: "jurisdiction1",
56-
name: "jurisdictionWithoutWaitlistLottery",
57-
featureFlags: [],
58-
},
59-
],
60-
}
61-
62-
it("should not show lottery fields when enableWaitlistLottery is false and waitlist is open", async () => {
63-
document.cookie = "access-token-available=True"
64-
server.use(
65-
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
66-
return res(ctx.json(adminUserWithoutWaitlistLotteryFlag))
67-
})
68-
)
69-
70-
render(
71-
<FormComponent
72-
values={{
73-
...formDefaults,
74-
jurisdictions: { id: "jurisdiction1" },
75-
listingAvailabilityQuestion: "openWaitlist",
76-
}}
77-
>
78-
<RankingsAndResults
79-
requiredFields={[]}
80-
whatToExpectEditor={null}
81-
whatToExpectAdditionalTextEditor={null}
82-
/>
83-
</FormComponent>
84-
)
85-
86-
await screen.findByText("Rankings & results")
87-
88-
const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
89-
await userEvent.click(waitlistYesRadio)
90-
91-
expect(
92-
screen.queryByText("How is the application review order determined?")
93-
).not.toBeInTheDocument()
94-
95-
expect(screen.queryByTestId("lottery-start-date")).not.toBeInTheDocument()
96-
expect(screen.queryByTestId("lottery-start-time")).not.toBeInTheDocument()
97-
expect(screen.queryByTestId("lottery-end-time")).not.toBeInTheDocument()
34+
describe("RankingsAndResults enableWaitlistLottery", () => {
35+
afterEach(() => server.resetHandlers())
36+
afterAll(() => server.close())
37+
const userWithWaitlistLotteryFlag = {
38+
jurisdictions: [
39+
{
40+
id: "jurisdiction1",
41+
name: "jurisdictionWithWaitlistLottery",
42+
featureFlags: [
43+
{
44+
name: FeatureFlagEnum.enableWaitlistLottery,
45+
active: true,
46+
},
47+
],
48+
},
49+
],
50+
}
51+
const userWithoutWaitlistLotteryFlag = {
52+
jurisdictions: [
53+
{
54+
id: "jurisdiction1",
55+
name: "jurisdictionWithoutWaitlistLottery",
56+
featureFlags: [],
57+
},
58+
],
59+
}
60+
61+
it("should not show lottery fields when enableWaitlistLottery is false and waitlist is open", async () => {
62+
document.cookie = "access-token-available=True"
63+
server.use(
64+
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
65+
return res(ctx.json(userWithoutWaitlistLotteryFlag))
66+
})
67+
)
68+
69+
render(
70+
<FormComponent
71+
values={{
72+
...formDefaults,
73+
jurisdictions: { id: "jurisdiction1" },
74+
listingAvailabilityQuestion: "openWaitlist",
75+
}}
76+
>
77+
<RankingsAndResults
78+
requiredFields={[]}
79+
whatToExpectEditor={null}
80+
whatToExpectAdditionalTextEditor={null}
81+
/>
82+
</FormComponent>
83+
)
84+
85+
await screen.findByText("Rankings & results")
86+
87+
const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
88+
await userEvent.click(waitlistYesRadio)
89+
90+
expect(
91+
screen.queryByText("How is the application review order determined?")
92+
).not.toBeInTheDocument()
93+
94+
expect(screen.queryByTestId("lottery-start-date")).not.toBeInTheDocument()
95+
expect(screen.queryByTestId("lottery-start-time")).not.toBeInTheDocument()
96+
expect(screen.queryByTestId("lottery-end-time")).not.toBeInTheDocument()
97+
})
98+
99+
it("should show review order options when waitlist is open and feature flag is enabled", async () => {
100+
document.cookie = "access-token-available=True"
101+
server.use(
102+
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
103+
return res(ctx.json(userWithWaitlistLotteryFlag))
104+
})
105+
)
106+
107+
render(
108+
<FormComponent
109+
values={{
110+
...formDefaults,
111+
jurisdictions: { id: "jurisdiction1" },
112+
listingAvailabilityQuestion: "openWaitlist",
113+
}}
114+
>
115+
<RankingsAndResults
116+
requiredFields={[]}
117+
whatToExpectEditor={null}
118+
whatToExpectAdditionalTextEditor={null}
119+
/>
120+
</FormComponent>
121+
)
122+
123+
screen.getByRole("heading", { name: "Rankings & results" })
124+
125+
const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
126+
await userEvent.click(waitlistYesRadio)
127+
128+
await screen.findByText("How is the application review order determined?")
129+
130+
expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
131+
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
132+
})
133+
134+
it("should show review order options when availabilityQuestion is availableUnits and enableWaitlistLottery is false", () => {
135+
document.cookie = "access-token-available=True"
136+
server.use(
137+
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
138+
return res(ctx.json(userWithoutWaitlistLotteryFlag))
139+
})
140+
)
141+
142+
render(
143+
<FormComponent
144+
values={{
145+
...formDefaults,
146+
jurisdictions: { id: "jurisdiction1" },
147+
listingAvailabilityQuestion: "availableUnits",
148+
}}
149+
>
150+
<RankingsAndResults
151+
requiredFields={[]}
152+
whatToExpectEditor={null}
153+
whatToExpectAdditionalTextEditor={null}
154+
/>
155+
</FormComponent>
156+
)
157+
158+
screen.getByRole("heading", { name: "Rankings & results" })
159+
expect(
160+
screen.getByText("How is the application review order determined?")
161+
).toBeInTheDocument()
162+
163+
expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
164+
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
165+
})
98166
})
99-
100-
it("should show review order options when waitlist is open and feature flag is enabled", async () => {
101-
document.cookie = "access-token-available=True"
102-
server.use(
103-
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
104-
return res(ctx.json(adminUserWithWaitlistLotteryFlag))
105-
})
106-
)
107-
108-
render(
109-
<FormComponent
110-
values={{
111-
...formDefaults,
112-
jurisdictions: { id: "jurisdiction1" },
113-
listingAvailabilityQuestion: "openWaitlist",
114-
}}
115-
>
116-
<RankingsAndResults
117-
requiredFields={[]}
118-
whatToExpectEditor={null}
119-
whatToExpectAdditionalTextEditor={null}
120-
/>
121-
</FormComponent>
122-
)
123-
124-
screen.getByRole("heading", { name: "Rankings & results" })
125-
126-
const waitlistYesRadio = await screen.findByRole("radio", { name: "Yes" })
127-
await userEvent.click(waitlistYesRadio)
128-
129-
await screen.findByText("How is the application review order determined?")
130-
131-
expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
132-
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
167+
describe("Verifying text when selecting lottery radio button", () => {
168+
it("should show proper message when selecting lottery as a non admin user", async () => {
169+
process.env.showLottery = "true"
170+
render(
171+
<FormComponent>
172+
<RankingsAndResults
173+
requiredFields={[]}
174+
whatToExpectEditor={null}
175+
whatToExpectAdditionalTextEditor={null}
176+
/>
177+
</FormComponent>
178+
)
179+
180+
screen.getByRole("heading", { name: "Rankings & results" })
181+
const lotteryRadio = await screen.findByRole("radio", { name: "Lottery" })
182+
await userEvent.click(lotteryRadio)
183+
expect(
184+
screen.getByText(
185+
"Your lottery will be run in the Partners Portal. If you want to make alternative arrangements, please contact staff."
186+
)
187+
).toBeInTheDocument()
188+
})
189+
it("should show proper message when selecting lottery as an admin user", async () => {
190+
process.env.showLottery = "true"
191+
render(
192+
<FormComponent>
193+
<RankingsAndResults
194+
isAdmin={true}
195+
listing={null}
196+
requiredFields={[]}
197+
whatToExpectEditor={null}
198+
whatToExpectAdditionalTextEditor={null}
199+
/>
200+
</FormComponent>
201+
)
202+
203+
screen.getByRole("heading", { name: "Rankings & results" })
204+
const lotteryRadio = await screen.findByRole("radio", { name: "Lottery" })
205+
await userEvent.click(lotteryRadio)
206+
expect(screen.getByText("Will the lottery be run in the partner portal?")).toBeInTheDocument()
207+
})
133208
})
134209
})

sites/partners/src/components/listings/PaperListingForm/sections/RankingsAndResults.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ const RankingsAndResults = ({
9393
selectedJurisdictionId
9494
)
9595

96-
const showFSFCLotterySection = enableWaitlistLottery && waitlistOpen
96+
const showFSFCLotterySection =
97+
(enableWaitlistLottery && waitlistOpen) ||
98+
(availabilityQuestion !== "openWaitlist" && !enableWaitlistLottery)
9799

98100
// Ensure the lottery fields only show when it's "available units" listing
99101
const showLotteryFields =

0 commit comments

Comments
 (0)