Skip to content

Commit

Permalink
feat: run lottery modals (#4168)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski authored Jul 3, 2024
1 parent e376d9c commit 12f3808
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/prisma/seed-helpers/address-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const yosemiteAddress = {
export const rockyMountainAddress = {
placeName: 'Rocky Mountain National Park',
city: 'Estes Park',
state: 'C0',
state: 'CO',
street: '1000 US-36',
zipCode: '80517',
latitude: 40.3800984,
Expand Down
2 changes: 1 addition & 1 deletion shared-helpers/__tests__/testHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export const application: Application = {
updatedAt: new Date(),
placeName: "Rocky Mountain National Park",
city: "Estes Park",
state: "C0",
state: "CO",
street: "1000 US-36",
zipCode: "80517",
latitude: 40.3800984,
Expand Down
2 changes: 1 addition & 1 deletion sites/partners/__tests__/pages/applications/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("applications", () => {
expect(getByText("Mailing City")).toBeInTheDocument()
expect(getByText("Estes Park")).toBeInTheDocument()
expect(getByText("Mailing State")).toBeInTheDocument()
expect(getByText("C0")).toBeInTheDocument()
expect(getByText("CO")).toBeInTheDocument()
expect(getByText("Mailing Zip")).toBeInTheDocument()
expect(getByText("80517")).toBeInTheDocument()
expect(getByText("Work Street Address")).toBeInTheDocument()
Expand Down
98 changes: 94 additions & 4 deletions sites/partners/__tests__/pages/listings/lottery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand All @@ -49,6 +52,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand All @@ -69,6 +75,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand All @@ -95,6 +104,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand All @@ -121,6 +133,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand All @@ -145,6 +160,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand Down Expand Up @@ -175,6 +193,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand Down Expand Up @@ -207,10 +228,13 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

const { getByText, findByText } = render(
const { getByText, findByText, findAllByText } = render(
<Lottery listing={{ ...listing, lotteryLastRunAt: new Date() }} />
)

Expand All @@ -219,7 +243,7 @@ describe("lottery", () => {

fireEvent.click(getByText("Re-run lottery"))
expect(await findByText("Are you sure?")).toBeInTheDocument()
expect(await findByText("I understand, re-run the lottery")).toBeInTheDocument()
expect(await findAllByText("Re-run lottery")).toHaveLength(2)
})

it("should show release modal if user clicks on release", async () => {
Expand All @@ -236,6 +260,9 @@ describe("lottery", () => {
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

Expand All @@ -247,11 +274,74 @@ describe("lottery", () => {
expect(header).toBeInTheDocument()

fireEvent.click(getByText("Release lottery"))
expect(await findByText("Confirmation needed")).toBeInTheDocument()
expect(await findByText("Are you sure?")).toBeInTheDocument()
expect(
await findByText(
"Releasing the lottery will give Partner users access to the lottery data, including the ability to publicize anonymous results to applicants."
"Releasing the lottery will give Partner users access to the lottery data, including the ability to publish results to applicants."
)
).toBeInTheDocument()
})

it("should show confirm modal if user clicks on run lottery with no unresolved duplicates", async () => {
mockNextRouter({ id: "Uvbk5qurpB2WI9V6WnNdH" })
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(
ctx.json({
id: "user1",
userRoles: { isAdmin: true },
})
)
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 0 }))
})
)

const { getByText, findByText } = render(<Lottery listing={listing} />)

const header = await findByText("Partners Portal")
expect(header).toBeInTheDocument()

fireEvent.click(getByText("Run lottery"))
expect(await findByText("Confirmation needed")).toBeInTheDocument()
expect(
await findByText("Make sure to add all paper applications before running the lottery.")
).toBeInTheDocument()
})

it("should show confirm with duplicates modal if user clicks on run lottery and listing does have unresolved duplicates", async () => {
mockNextRouter({ id: "Uvbk5qurpB2WI9V6WnNdH" })
document.cookie = "access-token-available=True"
server.use(
rest.get("http://localhost/api/adapter/user", (_req, res, ctx) => {
return res(
ctx.json({
id: "user1",
userRoles: { isAdmin: true },
})
)
}),
rest.post("http://localhost:3100/auth/token", (_req, res, ctx) => {
return res(ctx.json(""))
}),
rest.get("http://localhost/api/adapter/applicationFlaggedSets/meta", (_req, res, ctx) => {
return res(ctx.json({ totalCount: 5, totalPendingCount: 5 }))
})
)

const { getByText, findByText, findAllByText } = render(<Lottery listing={listing} />)

const header = await findByText("Partners Portal")
expect(header).toBeInTheDocument()

fireEvent.click(getByText("Run lottery"))
expect(await findByText("Confirmation needed")).toBeInTheDocument()
expect(await findByText("5 unresolved duplicate sets.")).toBeInTheDocument()
expect(await findAllByText("Run lottery")).toHaveLength(2)
})
})
4 changes: 2 additions & 2 deletions sites/partners/__tests__/pages/settings/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("settings", () => {
expect(headAndBody).toHaveLength(2)
const [head, body] = headAndBody
expect(within(head).getAllByRole("columnheader")).toHaveLength(4)
const rows = within(body).getAllByRole("row")
const rows = await within(body).findAllByRole("row")
expect(rows).toHaveLength(1)
const [name, jurisdiction, updated, actions] = within(rows[0]).getAllByRole("cell")
expect(name).toHaveTextContent(multiselectQuestionPreference.text)
Expand Down Expand Up @@ -207,7 +207,7 @@ describe("settings", () => {
`This preference is currently added to listings and needs to be removed before being deleted.`
)
)
expect(getByText(listing.name))
expect(await findByText(listing.name))
// verify delete button is not there
expect(queryAllByText("Delete")).toHaveLength(0)

Expand Down
12 changes: 8 additions & 4 deletions sites/partners/page_content/locale_overrides/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"applications.addConfirmModalAddApplicationPostLotteryConfirm": "I understand, add application",
"applications.addConfirmModalAddApplicationPostLotteryTitle": "Are you sure?",
"applications.addConfirmModalAddApplicationPostLotteryWeighted": "Adding a new application will require the lottery to be re-run.",
"applications.addConfirmModalContent": "This listing has closed, are you sure you want to add an application?",
"applications.addConfirmModalContent": "This listing has closed. Are you sure you want to add a paper application?",
"applications.addConfirmModalHeader": "Confirmation needed",
"applications.allApplications": "All Applications",
"applications.duplicate": "Duplicate",
Expand Down Expand Up @@ -216,20 +216,24 @@
"listings.listingStatusText": "Listing Status",
"listings.listingSubmitted": "Listing Submitted",
"listings.longitude": "Longitude",
"listings.lottery.duplicateContent": "This listing has",
"listings.lottery.duplicateString": "%{sets} unresolved duplicate set.",
"listings.lottery.duplicateStringPlural": "%{sets} unresolved duplicate sets.",
"listings.lottery.duplicatesConfirm": "You should resolve any duplicates before running the lottery.",
"listings.lottery.export": "Export lottery data",
"listings.lottery.exportFile": "File includes randomized general pool and preference data.",
"listings.lottery.history": "History",
"listings.lottery.noData": "No lottery data",
"listings.lottery.noDataDescription": "It looks like you haven't run a lottery for this listing yet.",
"listings.lottery.release": "Release lottery",
"listings.lottery.releaseButton": "Release lottery",
"listings.lottery.releaseContent": "Releasing the lottery will give Partner users access to the lottery data, including the ability to publicize anonymous results to applicants.",
"listings.lottery.releaseContent": "Releasing the lottery will give Partner users access to the lottery data, including the ability to publish results to applicants.",
"listings.lottery.reRun": "Re-run lottery",
"listings.lottery.reRunButton": "I understand, re-run the lottery",
"listings.lottery.reRunContent": "Re-running the lottery will reset current preference and general pool rankings.",
"listings.lottery.reRunContent": "Re-running the lottery will give all applications a new raw rank, which will impact the order in which they are processed.",
"listings.lottery.reRunHistory": "Re-running a lottery will also be tracked in the history log.",
"listings.lottery.reRunCannotBeUndone": "This action cannot be undone.",
"listings.lottery.runLottery": "Run lottery",
"listings.lottery.runLotteryContent": "Make sure to add all paper applications before running the lottery.",
"listings.lotteryDateNotes": "Lottery Date Notes",
"listings.lotteryDateQuestion": "When will the lottery be run?",
"listings.lotteryEndTime": "Lottery End Time",
Expand Down
2 changes: 1 addition & 1 deletion sites/partners/src/components/shared/NavigationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const NavigationHeader = ({
label: tabs.lotteryLabel,
path: `/listings/${listingId}/lottery`,
activePaths: [`/listings/${listingId}/lottery`],
content: t("t.new"),
content: undefined,
})
}

Expand Down
Loading

0 comments on commit 12f3808

Please sign in to comment.