Skip to content

Commit bc526c1

Browse files
committed
added missing tests
1 parent 784c0c8 commit bc526c1

1 file changed

Lines changed: 77 additions & 7 deletions

File tree

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

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22
import { rest } from "msw"
33
import { setupServer } from "msw/node"
44
import { FormProvider, useForm } from "react-hook-form"
5-
import { screen } from "@testing-library/react"
5+
import { screen, fireEvent, act } from "@testing-library/react"
66
import RankingsAndResults from "../../../../../src/components/listings/PaperListingForm/sections/RankingsAndResults"
77
import { formDefaults, FormListing } from "../../../../../src/lib/listings/formTypes"
88
import { mockNextRouter, mockTipTapEditor, render } from "../../../../testUtils"
@@ -34,7 +34,7 @@ afterEach(() => server.resetHandlers())
3434
afterAll(() => server.close())
3535

3636
describe("RankingsAndResults", () => {
37-
const adminUserWithWaitlistLotteryFlag = {
37+
const userWithWaitlistLotteryFlag = {
3838
jurisdictions: [
3939
{
4040
id: "jurisdiction1",
@@ -48,8 +48,7 @@ describe("RankingsAndResults", () => {
4848
},
4949
],
5050
}
51-
52-
const adminUserWithoutWaitlistLotteryFlag = {
51+
const userWithoutWaitlistLotteryFlag = {
5352
jurisdictions: [
5453
{
5554
id: "jurisdiction1",
@@ -63,7 +62,7 @@ describe("RankingsAndResults", () => {
6362
document.cookie = "access-token-available=True"
6463
server.use(
6564
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
66-
return res(ctx.json(adminUserWithoutWaitlistLotteryFlag))
65+
return res(ctx.json(userWithoutWaitlistLotteryFlag))
6766
})
6867
)
6968

@@ -101,7 +100,7 @@ describe("RankingsAndResults", () => {
101100
document.cookie = "access-token-available=True"
102101
server.use(
103102
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
104-
return res(ctx.json(adminUserWithWaitlistLotteryFlag))
103+
return res(ctx.json(userWithWaitlistLotteryFlag))
105104
})
106105
)
107106

@@ -136,7 +135,7 @@ describe("RankingsAndResults", () => {
136135
document.cookie = "access-token-available=True"
137136
server.use(
138137
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
139-
return res(ctx.json(adminUserWithoutWaitlistLotteryFlag))
138+
return res(ctx.json(userWithoutWaitlistLotteryFlag))
140139
})
141140
)
142141

@@ -162,4 +161,75 @@ describe("RankingsAndResults", () => {
162161
expect(screen.getByRole("radio", { name: /First come first serve/i })).toBeInTheDocument()
163162
expect(screen.getByRole("radio", { name: "Lottery" })).toBeInTheDocument()
164163
})
164+
165+
it("should show review order options when availabilityQuestion is openWaitlist and enableWaitlistLottery is true as a non admin user", async () => {
166+
process.env.showLottery = "true"
167+
document.cookie = "access-token-available=True"
168+
server.use(
169+
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
170+
return res(ctx.json(userWithWaitlistLotteryFlag))
171+
})
172+
)
173+
174+
render(
175+
<FormComponent
176+
values={{
177+
...formDefaults,
178+
jurisdictions: { id: "jurisdiction1" },
179+
listingAvailabilityQuestion: "openWaitlist",
180+
}}
181+
>
182+
<RankingsAndResults
183+
requiredFields={[]}
184+
whatToExpectEditor={null}
185+
whatToExpectAdditionalTextEditor={null}
186+
/>
187+
</FormComponent>
188+
)
189+
190+
screen.getByRole("heading", { name: "Rankings & results" })
191+
const lotteryRadio = await screen.findByRole("radio", { name: "Lottery" })
192+
act(() => {
193+
fireEvent.click(lotteryRadio)
194+
})
195+
expect(
196+
screen.getByText(
197+
"Your lottery will be run in the Partners Portal. If you want to make alternative arrangements, please contact staff."
198+
)
199+
).toBeInTheDocument()
200+
})
201+
it("should show review order options when availabilityQuestion is openWaitlist and enableWaitlistLottery is true as an admin user", async () => {
202+
process.env.showLottery = "true"
203+
document.cookie = "access-token-available=True"
204+
server.use(
205+
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
206+
return res(ctx.json(userWithWaitlistLotteryFlag))
207+
})
208+
)
209+
210+
render(
211+
<FormComponent
212+
values={{
213+
...formDefaults,
214+
jurisdictions: { id: "jurisdiction1" },
215+
listingAvailabilityQuestion: "openWaitlist",
216+
}}
217+
>
218+
<RankingsAndResults
219+
isAdmin={true}
220+
listing={null}
221+
requiredFields={[]}
222+
whatToExpectEditor={null}
223+
whatToExpectAdditionalTextEditor={null}
224+
/>
225+
</FormComponent>
226+
)
227+
228+
screen.getByRole("heading", { name: "Rankings & results" })
229+
const lotteryRadio = await screen.findByRole("radio", { name: "Lottery" })
230+
act(() => {
231+
fireEvent.click(lotteryRadio)
232+
})
233+
expect(screen.getByText("Will the lottery be run in the partner portal?")).toBeInTheDocument()
234+
})
165235
})

0 commit comments

Comments
 (0)