Skip to content

Commit

Permalink
Add coverage for page statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Nov 22, 2024
1 parent 85e5088 commit 340671e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
49 changes: 46 additions & 3 deletions __test__/pages/hold/eddRequestPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
EDD_FORM_FIELD_COPY,
} from "../../../src/config/constants"
import { fetchDeliveryLocations } from "../../../src/server/api/hold"
import { EDDPageStatusMessages } from "../../../src/utils/holdPageUtils"

jest.mock("../../../src/server/auth")
jest.mock("../../../src/server/api/bib")
Expand Down Expand Up @@ -163,7 +164,6 @@ describe("EDD Request page", () => {
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[2]}
patronId="123"
eddRequestable={true}
isAuthenticated={true}
/>
)
Expand Down Expand Up @@ -191,14 +191,13 @@ describe("EDD Request page", () => {
expect(screen.getByTestId("edd-request-form")).toBeInTheDocument()
})
})
describe("EDD Request error handling", () => {
describe("EDD Request form validation", () => {
beforeEach(async () => {
render(
<EDDRequestPage
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[0]}
patronId="123"
eddRequestable={true}
isAuthenticated={true}
/>
)
Expand Down Expand Up @@ -300,4 +299,48 @@ describe("EDD Request page", () => {
).toBeInTheDocument()
})
})
describe("EDD page status banner messages", () => {
it("shows an unavailable error message when the page loads with an unavailable status", async () => {
render(
<EDDRequestPage
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[0]}
patronId="123"
isAuthenticated={true}
pageStatus="unavailable"
/>
)
expect(
screen.getByText(EDDPageStatusMessages.unavailable.heading)
).toBeInTheDocument()
})
it("shows a failed error message when the page loads with an failed status", async () => {
render(
<EDDRequestPage
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[0]}
patronId="123"
isAuthenticated={true}
pageStatus="failed"
/>
)
expect(
screen.getByText(EDDPageStatusMessages.failed.heading)
).toBeInTheDocument()
})
it("shows an invalid error message when the page loads with an invalid status", async () => {
render(
<EDDRequestPage
discoveryBibResult={bibWithItems.resource}
discoveryItemResult={bibWithItems.resource.items[0]}
patronId="123"
isAuthenticated={true}
pageStatus="invalid"
/>
)
expect(
screen.getByText(EDDPageStatusMessages.invalid.message)
).toBeInTheDocument()
})
})
})
2 changes: 1 addition & 1 deletion pages/hold/request/[id]/edd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export async function getServerSideProps({ params, req, res, query }) {
isAuthenticated,
pageStatus: !isEddAvailable
? "unavailable"
: query?.formInvalid
: query?.formInvalid === true
? "invalid"
: null,
},
Expand Down

0 comments on commit 340671e

Please sign in to comment.