From 019e2b278fef05a2dd0da9484db5a35d6c7c8a30 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 11:28:29 -0500 Subject: [PATCH 1/4] Render the View All link for search results --- src/components/SearchResult/SearchResult.tsx | 27 ++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/components/SearchResult/SearchResult.tsx b/src/components/SearchResult/SearchResult.tsx index 0d5fbe2a5..e4d411c7e 100644 --- a/src/components/SearchResult/SearchResult.tsx +++ b/src/components/SearchResult/SearchResult.tsx @@ -4,11 +4,13 @@ import { CardHeading, Box, Text, + CardActions, + Icon, } from "@nypl/design-system-react-components" import RCLink from "../RCLink/RCLink" import type SearchResultsBib from "../../models/SearchResultsBib" -import { PATHS } from "../../config/constants" +import { PATHS, ITEMS_PER_SEARCH_RESULT } from "../../config/constants" interface SearchResultProps { bib: SearchResultsBib @@ -29,12 +31,33 @@ const SearchResult = ({ bib }: SearchResultProps) => { {bib.title} - + {bib.materialType && {bib.materialType}} {bib.publicationStatement && {bib.publicationStatement}} {bib.yearPublished && {bib.yearPublished}} {bib.itemMessage} + {/* Move the code block below to the conditional for rendering the Item Table */} + {bib.numPhysicalItems > ITEMS_PER_SEARCH_RESULT && ( + + + + {`View All ${bib.itemMessage} `} + + + + + )} ) From 21b2274bb9cd809e10d99e3a3422ee77db38055b Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 11:42:36 -0500 Subject: [PATCH 2/4] Add test for view all link --- .../fixtures/searchResultManyPhysicalItems.ts | 323 ++++++++++++++++++ .../SearchResult/SearchResult.test.tsx | 18 + src/types/itemTypes.ts | 2 +- 3 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 __test__/fixtures/searchResultManyPhysicalItems.ts diff --git a/__test__/fixtures/searchResultManyPhysicalItems.ts b/__test__/fixtures/searchResultManyPhysicalItems.ts new file mode 100644 index 000000000..0d7ac0a19 --- /dev/null +++ b/__test__/fixtures/searchResultManyPhysicalItems.ts @@ -0,0 +1,323 @@ +export const searchResultManyPhysicalItems = { + "@type": ["nypl:Item", "nypl:Resource"], + "@id": "res:b14753192", + carrierType: [ + { + "@id": "carriertypes:nc", + prefLabel: "volume", + }, + ], + createdString: ["190"], + createdYear: 190, + dateStartYear: 190, + dateString: ["190"], + dimensions: ["20 cm."], + electronicResources: [], + extent: ["18 p. : col. ill. ;"], + identifier: [ + { + "@type": "bf:ShelfMark", + "@value": "*ZO-*OSH p.v. 3, no. 2", + }, + { + "@type": "nypl:Bnumber", + "@value": "14753192", + }, + { + "@type": "bf:Identifier", + "@value": "(WaOLN)R310002230", + }, + ], + issuance: [ + { + "@id": "urn:biblevel:m", + prefLabel: "monograph/item", + }, + ], + items: [ + { + "@id": "res:i14507546", + accessMessage: [ + { + "@id": "accessMessage:4", + prefLabel: "Restricted use", + }, + ], + catalogItemType: [ + { + "@id": "catalogItemType:2", + prefLabel: "book non-circ", + }, + ], + eddRequestable: false, + holdingLocation: [ + { + "@id": "loc:macc2", + prefLabel: "Schwarzman Building - Arents Collection Room 328", + endpoint: "schwarzman", + }, + ], + identifier: [ + { + "@type": "bf:ShelfMark", + "@value": "Arents BIP (Hearn. Japanese) AL 04-11 [Text]", + }, + ], + owner: [ + { + "@id": "orgs:1109", + prefLabel: "George Arents Collection", + }, + ], + physRequestable: false, + physicalLocation: ["Arents BIP (Hearn. Japanese) AL 04-11 [Text]"], + requestable: [false], + shelfMark: ["Arents BIP (Hearn. Japanese) AL 04-11 [Text]"], + specRequestable: false, + status: [ + { + "@id": "status:a", + prefLabel: "Available", + }, + ], + uri: "i14507546", + idNyplSourceId: { + "@type": "SierraNypl", + "@value": "14507546", + }, + }, + { + "@id": "res:i14507545", + accessMessage: [ + { + "@id": "accessMessage:p", + prefLabel: "Permit needed", + }, + ], + catalogItemType: [ + { + "@id": "catalogItemType:6", + prefLabel: "microfilm service copy", + }, + ], + eddRequestable: false, + holdingLocation: [ + { + "@id": "loc:mai82", + prefLabel: "Schwarzman Building M1 - Microforms Room 315", + endpoint: "schwarzman", + }, + ], + identifier: [ + { + "@type": "bf:ShelfMark", + "@value": "*ZO-*OSH p.v. 3, no. 2", + }, + ], + owner: [ + { + "@id": "orgs:1101", + prefLabel: "General Research Division", + }, + ], + physRequestable: false, + physicalLocation: ["*ZO-*OSH p.v. 3, no. 2"], + requestable: [false], + shelfMark: ["*ZO-*OSH p.v. 3, no. 2"], + specRequestable: false, + status: [ + { + "@id": "status:a", + prefLabel: "Available", + }, + ], + uri: "i14507545", + idNyplSourceId: { + "@type": "SierraNypl", + "@value": "14507545", + }, + }, + { + "@id": "res:i14507543", + accessMessage: [ + { + "@id": "accessMessage:p", + prefLabel: "Permit needed", + }, + ], + catalogItemType: [ + { + "@id": "catalogItemType:6", + prefLabel: "microfilm service copy", + }, + ], + eddRequestable: true, + holdingLocation: [ + { + "@id": "loc:rcmi2", + prefLabel: "Offsite", + }, + ], + idBarcode: ["33433105668333"], + identifier: [ + { + "@type": "bf:ShelfMark", + "@value": "*ZO-*OSH p.v. 3, no. 1", + }, + { + "@type": "bf:Barcode", + "@value": "33433105668333", + }, + ], + owner: [ + { + "@id": "orgs:1000", + prefLabel: "Stephen A. Schwarzman Building", + }, + ], + physRequestable: true, + physicalLocation: ["*ZO-*OSH p.v. 3, no. 1"], + recapCustomerCode: ["NA"], + requestable: [true], + shelfMark: ["*ZO-*OSH p.v. 3, no. 1"], + specRequestable: false, + status: [ + { + "@id": "status:a", + prefLabel: "Available", + }, + ], + uri: "i14507543", + idNyplSourceId: { + "@type": "SierraNypl", + "@value": "14507543", + }, + }, + { + "@id": "res:i30068374", + accessMessage: [ + { + "@id": "accessMessage:2", + prefLabel: "Request in advance", + }, + ], + catalogItemType: [ + { + "@id": "catalogItemType:6", + prefLabel: "microfilm service copy", + }, + ], + eddRequestable: true, + enumerationChronology: ["*OSH p.v. 1-2"], + holdingLocation: [ + { + "@id": "loc:rcmi2", + prefLabel: "Offsite", + }, + ], + idBarcode: ["33433105668325"], + identifier: [ + { + "@type": "bf:ShelfMark", + "@value": "*ZO-*OSH p.v. 1, no. 1 *OSH p.v. 1-2", + }, + { + "@type": "bf:Barcode", + "@value": "33433105668325", + }, + ], + owner: [ + { + "@id": "orgs:1000", + prefLabel: "Stephen A. Schwarzman Building", + }, + ], + physRequestable: true, + physicalLocation: ["*ZO-*OSH p.v. 1, no. 1"], + recapCustomerCode: ["NA"], + requestable: [true], + shelfMark: ["*ZO-*OSH p.v. 1, no. 1 *OSH p.v. 1-2"], + specRequestable: false, + status: [ + { + "@id": "status:a", + prefLabel: "Available", + }, + ], + uri: "i30068374", + idNyplSourceId: { + "@type": "SierraNypl", + "@value": "30068374", + }, + }, + ], + language: [ + { + "@id": "lang:eng", + prefLabel: "English", + }, + ], + materialType: [ + { + "@id": "resourcetypes:txt", + prefLabel: "Text", + }, + ], + mediaType: [ + { + "@id": "mediatypes:n", + prefLabel: "unmediated", + }, + ], + note: [ + { + noteType: "Note", + "@type": "bf:Note", + prefLabel: "Cover title.", + }, + { + noteType: "Note", + "@type": "bf:Note", + prefLabel: "Printed on double leaves folded in Japanese fashion.", + }, + { + noteType: "Note", + "@type": "bf:Note", + prefLabel: "Name of second publisher from stamp on t.p. verso.", + }, + { + noteType: "Indexed In", + "@type": "bf:Note", + prefLabel: "BAL", + }, + { + noteType: "Reproduction", + "@type": "bf:Note", + prefLabel: "Microfilm.", + }, + ], + numAvailable: 4, + numElectronicResources: 0, + numItems: 4, + numItemsMatched: 4, + numItemsTotal: 4, + nyplSource: ["sierra-nypl"], + placeOfPublication: ["Tokyo : [London] :"], + publicationStatement: [ + "Tokyo : T. Hasegawa ; [London] : Martin Hopkinson & Co., [190-?]", + ], + publisherLiteral: ["T. Hasegawa ; Martin Hopkinson & Co.,"], + shelfMark: ["*ZO-*OSH p.v. 3, no. 2"], + subjectLiteral: ["Fairy tales -- Japan."], + title: ["The boy who drew cats [microform]"], + titleAlt: ["Japanese fairy tale"], + titleDisplay: [ + "The boy who drew cats [microform] / rendered into English, by Lafcadio Hearn.", + ], + type: ["nypl:Item"], + updatedAt: 1636582835709, + uri: "b14753192", + suppressed: false, + hasItemVolumes: false, + hasItemDates: false, +} diff --git a/src/components/SearchResult/SearchResult.test.tsx b/src/components/SearchResult/SearchResult.test.tsx index 7aa4f3de4..8dd40c392 100644 --- a/src/components/SearchResult/SearchResult.test.tsx +++ b/src/components/SearchResult/SearchResult.test.tsx @@ -3,6 +3,7 @@ import { render, screen } from "@testing-library/react" import SearchResult from "./SearchResult" import SearchResultsBib from "../../models/SearchResultsBib" import { searchResultPhysicalItems } from "../../../__test__/fixtures/searchResultPhysicalItems" +import { searchResultManyPhysicalItems } from "../../../__test__/fixtures/searchResultManyPhysicalItems" import { searchResultElectronicResources } from "../../../__test__/fixtures/searchResultElectronicResources" describe("SearchResult with Physical Items", () => { @@ -26,6 +27,23 @@ describe("SearchResult with Physical Items", () => { }) }) +describe("SearchResult with Many Physical Items", () => { + beforeEach(() => { + const bib = new SearchResultsBib(searchResultManyPhysicalItems) + render() + }) + + it("renders a link to the bib page with the correct text when there are more than the set limit of items per search result", async () => { + const resultTitleLink = screen.getByRole("link", { + name: "View All 4 Items", + }) + expect(resultTitleLink).toHaveAttribute( + "href", + "/bib/b14753192#items-table" + ) + }) +}) + describe("SearchResult with Electronic Resources", () => { it("renders the correct item message for bib with electronic resources", async () => { const bib = new SearchResultsBib(searchResultElectronicResources) diff --git a/src/types/itemTypes.ts b/src/types/itemTypes.ts index 627ac096a..0d6440421 100644 --- a/src/types/itemTypes.ts +++ b/src/types/itemTypes.ts @@ -16,7 +16,7 @@ export interface SearchResultsItem { export interface ItemLocation extends JSONLDValue { customerCode?: string - endpoint?: ItemLocationEndpoint + endpoint?: string } export type ItemLocationKey = "Schwarzman" | "Performing" | "Schomburg" From 880b9244611fe130351bed9c09e0509d9931f7c2 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 13:56:53 -0500 Subject: [PATCH 3/4] Use SearchResult type and cast in SearchResult test --- src/components/SearchResult/SearchResult.test.tsx | 5 ++++- src/types/itemTypes.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/SearchResult/SearchResult.test.tsx b/src/components/SearchResult/SearchResult.test.tsx index 8dd40c392..e72db6202 100644 --- a/src/components/SearchResult/SearchResult.test.tsx +++ b/src/components/SearchResult/SearchResult.test.tsx @@ -5,6 +5,7 @@ import SearchResultsBib from "../../models/SearchResultsBib" import { searchResultPhysicalItems } from "../../../__test__/fixtures/searchResultPhysicalItems" import { searchResultManyPhysicalItems } from "../../../__test__/fixtures/searchResultManyPhysicalItems" import { searchResultElectronicResources } from "../../../__test__/fixtures/searchResultElectronicResources" +import type { SearchResult as SearchResultType } from "../../types/searchTypes" describe("SearchResult with Physical Items", () => { beforeEach(() => { @@ -29,7 +30,9 @@ describe("SearchResult with Physical Items", () => { describe("SearchResult with Many Physical Items", () => { beforeEach(() => { - const bib = new SearchResultsBib(searchResultManyPhysicalItems) + const bib = new SearchResultsBib( + searchResultManyPhysicalItems as SearchResultType + ) render() }) diff --git a/src/types/itemTypes.ts b/src/types/itemTypes.ts index 0d6440421..627ac096a 100644 --- a/src/types/itemTypes.ts +++ b/src/types/itemTypes.ts @@ -16,7 +16,7 @@ export interface SearchResultsItem { export interface ItemLocation extends JSONLDValue { customerCode?: string - endpoint?: string + endpoint?: ItemLocationEndpoint } export type ItemLocationKey = "Schwarzman" | "Performing" | "Schomburg" From d909e8103fa2bb9b79956678d2f0988e2947cbe7 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 14:02:48 -0500 Subject: [PATCH 4/4] Use standalone type for Link --- src/components/RCLink/RCLink.tsx | 6 +++++- src/components/SearchResult/SearchResult.tsx | 18 ++---------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/components/RCLink/RCLink.tsx b/src/components/RCLink/RCLink.tsx index 1713508b7..aab9ceea4 100644 --- a/src/components/RCLink/RCLink.tsx +++ b/src/components/RCLink/RCLink.tsx @@ -1,4 +1,7 @@ -import { Link as DSLink } from "@nypl/design-system-react-components" +import { + Link as DSLink, + type LinkTypes, +} from "@nypl/design-system-react-components" import Link from "next/link" import { type ReactNode } from "react" @@ -8,6 +11,7 @@ interface RCLinkProps { children: ReactNode className?: string color?: string + type?: LinkTypes } /** diff --git a/src/components/SearchResult/SearchResult.tsx b/src/components/SearchResult/SearchResult.tsx index e4d411c7e..78bd28fe4 100644 --- a/src/components/SearchResult/SearchResult.tsx +++ b/src/components/SearchResult/SearchResult.tsx @@ -5,7 +5,6 @@ import { Box, Text, CardActions, - Icon, } from "@nypl/design-system-react-components" import RCLink from "../RCLink/RCLink" @@ -40,21 +39,8 @@ const SearchResult = ({ bib }: SearchResultProps) => { {/* Move the code block below to the conditional for rendering the Item Table */} {bib.numPhysicalItems > ITEMS_PER_SEARCH_RESULT && ( - - - {`View All ${bib.itemMessage} `} - - + + {`View All ${bib.itemMessage} `} )}