Skip to content

Commit

Permalink
add edge case test
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Jan 3, 2025
1 parent adb16e9 commit ed9d4f3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 30 deletions.
14 changes: 13 additions & 1 deletion src/components/ItemTable/ItemAvailability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ import {
itemUnavailable,
} from "../../../__test__/fixtures/itemFixtures"
import { searchResultPhysicalItems } from "../../../__test__/fixtures/searchResultPhysicalItems"
import { notDeepEqual } from "assert"

const parentBib = new SearchResultsBib(searchResultPhysicalItems)

describe("ItemAvailability", () => {
describe("special collections", () => {
it("edge case", () => {
const item = new Item(itemPhysicallyRequestable, parentBib)
item.availability.key = "edgeCase"
render(<ItemAvailability item={item} />)
expect(screen.getByText("contact a librarian")).toBeInTheDocument()
expect(
screen.queryByText("Available by appointment")
).not.toBeInTheDocument()
expect(screen.queryByRole("link")).not.toBeInTheDocument()
expect(
screen.queryByText("Schwarzman Building - Main Reading Room 315")
).not.toBeInTheDocument()
})
it("onsite aeon finding aid", () => {
const item = new Item(itemPhysicallyRequestable, parentBib)
item.availability = new ItemAvailabilityModel({
Expand Down
6 changes: 3 additions & 3 deletions src/components/ItemTable/ItemAvailability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Text } from "@nypl/design-system-react-components"
import ExternalLink from "../Links/ExternalLink/ExternalLink"
import { appConfig } from "../../config/config"
import type Item from "../../models/Item"
import { availabilityKeys } from "../../config/constants"
import { AVAILABILITY_KEYS } from "../../config/constants"
import {
AvailableByAppointment,
AvailableAt,
Expand Down Expand Up @@ -32,7 +32,7 @@ const {
RECAP_FINDING_AID,
ONSITE_NO_FINDING_AID_NO_AEON,
RECAP_NO_FINDING_AID_NO_AEON,
} = availabilityKeys
} = AVAILABILITY_KEYS

/**
* The ItemAvailability component appears below the Item table and displays
Expand Down Expand Up @@ -98,7 +98,7 @@ const ItemAvailability = ({ item }: ItemAvailabilityProps) => {
message = (
<>
<AvailableByAppointment displayPeriod />
<ContactALibrarian item={itemMetadata} />
<ContactALibrarian item={item} />
</>
)
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import type Item from "../../../models/Item"
const ContactALibrarian = ({
item,
}: {
item: {
id: string
barcode: string
callNumber: string
bibId: string
}
item: Pick<Item, "id" | "barcode" | "callNumber" | "bibId">
}) => {
const { onOpen, setItemMetadata } = useContext(FeedbackContext)
const onContact = (metadata: ItemMetadata) => {
Expand Down
7 changes: 1 addition & 6 deletions src/components/ItemTable/ItemAvailability/NotAvailable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ const NotAvailable = ({
dueDate,
}: {
dueDate: string
item: {
id: string
barcode: string
callNumber: string
bibId: string
}
item: Pick<Item, "id" | "barcode" | "callNumber" | "bibId">
}) => {
const itemMetadata = {
id: item.id,
Expand Down
2 changes: 1 addition & 1 deletion src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const NYPL_LOCATIONS = {
},
}

export const availabilityKeys = {
export const AVAILABILITY_KEYS = {
// anything not covered by the cases below is EDGE_CASE
EDGE_CASE: "edgeCase",
// there is only one not available case, so availability is assumed as the default
Expand Down
4 changes: 2 additions & 2 deletions src/models/ItemAvailability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { availabilityKeys } from "../config/constants"
import { AVAILABILITY_KEYS } from "../config/constants"

const {
EDGE_CASE,
Expand All @@ -14,7 +14,7 @@ const {
RECAP_FINDING_AID,
ONSITE_NO_FINDING_AID_NO_AEON,
RECAP_NO_FINDING_AID_NO_AEON,
} = availabilityKeys
} = AVAILABILITY_KEYS

class ItemAvailability {
key: string
Expand Down
24 changes: 13 additions & 11 deletions src/models/modelTests/ItemAvailability.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { availabilityKeys } from "../../config/constants"
import { AVAILABILITY_KEYS } from "../../config/constants"
import ItemAvailability from "../ItemAvailability"

describe("ItemAvailabilityFactory", () => {
Expand All @@ -10,7 +10,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: null,
isSpecRequestable: false,
})
expect(availability.key).toBe(availabilityKeys.NOT_AVAILABLE)
expect(availability.key).toBe(AVAILABILITY_KEYS.NOT_AVAILABLE)
})
it("recap not special collections", () => {
const availability = new ItemAvailability({
Expand All @@ -20,7 +20,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: null,
isSpecRequestable: false,
})
expect(availability.key).toBe(availabilityKeys.RECAP_GENERAL_COLLECTIONS)
expect(availability.key).toBe(AVAILABILITY_KEYS.RECAP_GENERAL_COLLECTIONS)
})
it("recap aeon", () => {
const availability = new ItemAvailability({
Expand All @@ -30,7 +30,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: null,
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.RECAP_AEON)
expect(availability.key).toBe(AVAILABILITY_KEYS.RECAP_AEON)
})
it("recap aeon finding aid", () => {
const availability = new ItemAvailability({
Expand All @@ -40,7 +40,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: "meatballs.com",
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.RECAP_AEON_FINDING_AID)
expect(availability.key).toBe(AVAILABILITY_KEYS.RECAP_AEON_FINDING_AID)
})
it("onsite aeon", () => {
const availability = new ItemAvailability({
Expand All @@ -50,7 +50,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: false,
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.ONSITE_AEON)
expect(availability.key).toBe(AVAILABILITY_KEYS.ONSITE_AEON)
})
it("onsite aeon finding aid", () => {
const availability = new ItemAvailability({
Expand All @@ -60,7 +60,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: "meatballs.com",
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.ONSITE_AEON_FINDING_AID)
expect(availability.key).toBe(AVAILABILITY_KEYS.ONSITE_AEON_FINDING_AID)
})
it("onsite finding aid - no aeon", () => {
const availability = new ItemAvailability({
Expand All @@ -70,7 +70,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: "meatballs.com",
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.ONSITE_FINDING_AID)
expect(availability.key).toBe(AVAILABILITY_KEYS.ONSITE_FINDING_AID)
})
it("recap finding aid - no aeon", () => {
const availability = new ItemAvailability({
Expand All @@ -80,7 +80,7 @@ describe("ItemAvailabilityFactory", () => {
findingAid: "meatballs.com",
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.RECAP_FINDING_AID)
expect(availability.key).toBe(AVAILABILITY_KEYS.RECAP_FINDING_AID)
})
it("recap no finding aid no aeon", () => {
const availability = new ItemAvailability({
Expand All @@ -90,7 +90,9 @@ describe("ItemAvailabilityFactory", () => {
findingAid: false,
isSpecRequestable: true,
})
expect(availability.key).toBe(availabilityKeys.RECAP_NO_FINDING_AID_NO_AEON)
expect(availability.key).toBe(
AVAILABILITY_KEYS.RECAP_NO_FINDING_AID_NO_AEON
)
})
it("recap no finding aid no aeon", () => {
const availability = new ItemAvailability({
Expand All @@ -101,7 +103,7 @@ describe("ItemAvailabilityFactory", () => {
isSpecRequestable: true,
})
expect(availability.key).toBe(
availabilityKeys.ONSITE_NO_FINDING_AID_NO_AEON
AVAILABILITY_KEYS.ONSITE_NO_FINDING_AID_NO_AEON
)
})
})

0 comments on commit ed9d4f3

Please sign in to comment.