From ed9d4f3f306a53b87747be8854639575857646e6 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 3 Jan 2025 11:38:36 -0500 Subject: [PATCH] add edge case test --- .../ItemTable/ItemAvailability.test.tsx | 14 ++++++++++- src/components/ItemTable/ItemAvailability.tsx | 6 ++--- .../ItemAvailability/ContactALibrarian.tsx | 7 +----- .../ItemAvailability/NotAvailable.tsx | 7 +----- src/config/constants.ts | 2 +- src/models/ItemAvailability.ts | 4 ++-- .../modelTests/ItemAvailability.test.ts | 24 ++++++++++--------- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/components/ItemTable/ItemAvailability.test.tsx b/src/components/ItemTable/ItemAvailability.test.tsx index e2dd007c..eab85cd2 100644 --- a/src/components/ItemTable/ItemAvailability.test.tsx +++ b/src/components/ItemTable/ItemAvailability.test.tsx @@ -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() + 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({ diff --git a/src/components/ItemTable/ItemAvailability.tsx b/src/components/ItemTable/ItemAvailability.tsx index 5368ea25..4e11bc2c 100644 --- a/src/components/ItemTable/ItemAvailability.tsx +++ b/src/components/ItemTable/ItemAvailability.tsx @@ -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, @@ -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 @@ -98,7 +98,7 @@ const ItemAvailability = ({ item }: ItemAvailabilityProps) => { message = ( <> - + ) break diff --git a/src/components/ItemTable/ItemAvailability/ContactALibrarian.tsx b/src/components/ItemTable/ItemAvailability/ContactALibrarian.tsx index 6e271400..da3b52dc 100644 --- a/src/components/ItemTable/ItemAvailability/ContactALibrarian.tsx +++ b/src/components/ItemTable/ItemAvailability/ContactALibrarian.tsx @@ -7,12 +7,7 @@ import type Item from "../../../models/Item" const ContactALibrarian = ({ item, }: { - item: { - id: string - barcode: string - callNumber: string - bibId: string - } + item: Pick }) => { const { onOpen, setItemMetadata } = useContext(FeedbackContext) const onContact = (metadata: ItemMetadata) => { diff --git a/src/components/ItemTable/ItemAvailability/NotAvailable.tsx b/src/components/ItemTable/ItemAvailability/NotAvailable.tsx index 9bec2192..7fc18ac3 100644 --- a/src/components/ItemTable/ItemAvailability/NotAvailable.tsx +++ b/src/components/ItemTable/ItemAvailability/NotAvailable.tsx @@ -7,12 +7,7 @@ const NotAvailable = ({ dueDate, }: { dueDate: string - item: { - id: string - barcode: string - callNumber: string - bibId: string - } + item: Pick }) => { const itemMetadata = { id: item.id, diff --git a/src/config/constants.ts b/src/config/constants.ts index 2f704b1c..f91caf13 100644 --- a/src/config/constants.ts +++ b/src/config/constants.ts @@ -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 diff --git a/src/models/ItemAvailability.ts b/src/models/ItemAvailability.ts index 6c72f8ff..fa0b546b 100644 --- a/src/models/ItemAvailability.ts +++ b/src/models/ItemAvailability.ts @@ -1,4 +1,4 @@ -import { availabilityKeys } from "../config/constants" +import { AVAILABILITY_KEYS } from "../config/constants" const { EDGE_CASE, @@ -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 diff --git a/src/models/modelTests/ItemAvailability.test.ts b/src/models/modelTests/ItemAvailability.test.ts index c0883062..97d0b4ab 100644 --- a/src/models/modelTests/ItemAvailability.test.ts +++ b/src/models/modelTests/ItemAvailability.test.ts @@ -1,4 +1,4 @@ -import { availabilityKeys } from "../../config/constants" +import { AVAILABILITY_KEYS } from "../../config/constants" import ItemAvailability from "../ItemAvailability" describe("ItemAvailabilityFactory", () => { @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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 ) }) })