From eb51352e4f44f6e6dee0b4034fb0b406fb88b894 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Thu, 7 Dec 2023 16:59:44 -0500 Subject: [PATCH 1/7] Add EDD component --- src/components/DRB/DRBCard.tsx | 7 +-- .../SearchResult/ElectronicResourcesLink.tsx | 58 +++++++++++++++++++ src/components/SearchResult/SearchResult.tsx | 9 ++- src/types/bibTypes.ts | 2 + 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/components/SearchResult/ElectronicResourcesLink.tsx diff --git a/src/components/DRB/DRBCard.tsx b/src/components/DRB/DRBCard.tsx index a83c8450f..f1ed04efd 100644 --- a/src/components/DRB/DRBCard.tsx +++ b/src/components/DRB/DRBCard.tsx @@ -66,12 +66,7 @@ const DRBCard = ({ drbResult }: DRBCardProps) => { sx={{ display: "flex", alignItems: "center" }} noSpace > - + Download {drbResult.downloadLink.mediaType || ""} diff --git a/src/components/SearchResult/ElectronicResourcesLink.tsx b/src/components/SearchResult/ElectronicResourcesLink.tsx new file mode 100644 index 000000000..9e537a75d --- /dev/null +++ b/src/components/SearchResult/ElectronicResourcesLink.tsx @@ -0,0 +1,58 @@ +import { + Box, + Heading, + Text, + Icon, + Link as DSLink, +} from "@nypl/design-system-react-components" + +import RCLink from "../RCLink/RCLink" +import type { ElectronicResource } from "../../types/bibTypes" + +interface ElectronicResourcesLinkProps { + bibUrl?: string + electronicResources: ElectronicResource[] +} + +/** + * The SearchResult component displays a single search result element. + */ +const ElectronicResourcesLink = ({ + bibUrl, + electronicResources, +}: ElectronicResourcesLinkProps) => { + return ( + + + Available Online + + {electronicResources.length === 1 ? ( + + {electronicResources[0].label || electronicResources[0].url} + + ) : ( + + + See All Available Online Resources{" "} + + + + )} + + ) +} + +export default ElectronicResourcesLink diff --git a/src/components/SearchResult/SearchResult.tsx b/src/components/SearchResult/SearchResult.tsx index 0d5fbe2a5..9ed489537 100644 --- a/src/components/SearchResult/SearchResult.tsx +++ b/src/components/SearchResult/SearchResult.tsx @@ -7,6 +7,7 @@ import { } from "@nypl/design-system-react-components" import RCLink from "../RCLink/RCLink" +import ElectronicResourcesLink from "./ElectronicResourcesLink" import type SearchResultsBib from "../../models/SearchResultsBib" import { PATHS } from "../../config/constants" @@ -29,12 +30,18 @@ const SearchResult = ({ bib }: SearchResultProps) => { {bib.title} - + {bib.materialType && {bib.materialType}} {bib.publicationStatement && {bib.publicationStatement}} {bib.yearPublished && {bib.yearPublished}} {bib.itemMessage} + {bib.electronicResources && ( + + )} ) diff --git a/src/types/bibTypes.ts b/src/types/bibTypes.ts index b5c7df251..50c30002f 100644 --- a/src/types/bibTypes.ts +++ b/src/types/bibTypes.ts @@ -1,3 +1,5 @@ export interface ElectronicResource { title?: string + url?: string + label?: string } From 297d7c3578c4f60422dc5adee65b6c87b040092a Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 10:18:48 -0500 Subject: [PATCH 2/7] Add tests for correct label --- .../searchResultElectronicResources.ts | 244 +++++++++++++++++- .../ElectronicResourcesLink.test.tsx | 88 +++++++ .../SearchResult/ElectronicResourcesLink.tsx | 2 +- src/types/bibTypes.ts | 2 +- 4 files changed, 333 insertions(+), 3 deletions(-) create mode 100644 src/components/SearchResult/ElectronicResourcesLink.test.tsx diff --git a/__test__/fixtures/searchResultElectronicResources.ts b/__test__/fixtures/searchResultElectronicResources.ts index 91bb9d81d..36fc77b9b 100644 --- a/__test__/fixtures/searchResultElectronicResources.ts +++ b/__test__/fixtures/searchResultElectronicResources.ts @@ -23,7 +23,7 @@ export const searchResultElectronicResources = { electronicResources: [ { title: "Access eNYPL", - url: "http://link.overdrive.com/?websiteId=37&titleId=5312492", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312492", prefLabel: "Access eNYPL", }, ], @@ -114,3 +114,245 @@ export const searchResultElectronicResources = { hasItemVolumes: false, hasItemDates: false, } + +export const searchResultMultipleElectronicResources = { + "@type": ["nypl:Item", "nypl:Resource"], + "@id": "res:b22133121", + carrierType: [ + { + "@id": "carriertypes:nc", + prefLabel: "volume", + }, + ], + contributorLiteral: [ + "Acosta, María", + "Gomez, Vanessa, 1984-", + "OverDrive, Inc.", + ], + createdString: ["2019"], + createdYear: 2019, + creatorLiteral: ["Persico, Nicky"], + dateStartYear: 2019, + dateString: ["2019"], + description: [ + "Un abogado en prácticas inexperto y un poco torpe se ve involucrado en la defensa de dos mujeres muy diferentes entre ellas por edad y clase social, unidas por el hecho de ser ambas víctimas de la violencia. A partir de aquí se desenmaraña, aderezado por intrigantes mezclas culinarias, un denso entramado de historias y personas que, entre el suspense y la gravedad, se adentra en el fenómeno del acoso y de la manipulación por medio de una sucesión de eventos destinados a revelar una realidad insospechable. En una encantadora Puglia, descripta de manera cuanto menos original, Nicky Persico guía al lector a través de un mundo de individuos peligrosos (enemigos invisibles ante los ojos de todo el mundo, y sin embargo envidiosos de la vida y la vitalidad de las víctimas que persiguen) proponiendo la receta que su protagonista ha ideado para transformar elementos triviales en filosofía de vida: los Spaghetti Paradiso.", + ], + electronicResources: [ + { + title: "Electronic Resource 1", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312493", + prefLabel: "Electronic Resource 1", + }, + { + title: "Access eNYPL", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312494", + prefLabel: "Electronic Resource 2", + }, + ], + extent: [ + "1 online resource (1 sound file (06 hr., 55 min., 34 sec.)) : digital", + ], + genreForm: ["Audiobooks.", "Fiction."], + idIsbn: ["9788835401155", "8835401151"], + idOclc: ["1144496190"], + identifier: [ + { + "@type": "nypl:Bnumber", + "@value": "22133121", + }, + { + "@type": "bf:Isbn", + "@value": "9788835401155", + }, + { + "@type": "bf:Isbn", + "@value": "8835401151", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "bf:Identifier", + "@value": "(OCoLC)1144496190", + }, + ], + issuance: [ + { + "@id": "urn:biblevel:m", + prefLabel: "monograph/item", + }, + ], + items: [], + language: [ + { + "@id": "lang:spa", + prefLabel: "Spanish", + }, + ], + lccClassification: ["PQ4916.E778 S63 2019"], + materialType: [ + { + "@id": "resourcetypes:aud", + prefLabel: "Audio", + }, + ], + mediaType: [ + { + "@id": "mediatypes:n", + prefLabel: "unmediated", + }, + ], + numAvailable: 0, + numCheckinCardItems: 0, + numElectronicResources: 1, + numItemDatesParsed: 0, + numItemVolumesParsed: 0, + numItems: 0, + numItemsMatched: 0, + numItemsTotal: 0, + nyplSource: ["sierra-nypl"], + placeOfPublication: ["[Solon, Ohio]"], + publicationStatement: ["[Solon, Ohio] : Tektime, 2019."], + publisherLiteral: ["Tektime"], + subjectLiteral: [ + "Sexual harassment of women -- Fiction.", + "Sexual harassment of women.", + "Puglia (Italy) -- Fiction.", + "Italy -- Puglia.", + ], + title: ["Spaghetti paradiso"], + titleDisplay: [ + "Spaghetti paradiso / Nicky Persico ; traducción por: María Acosta.", + ], + type: ["nypl:Item"], + updatedAt: 1681346906709, + uri: "b22133121", + suppressed: false, + hasItemVolumes: false, + hasItemDates: false, +} + +export const searchResultMultipleElectronicResourcesNoLabel = { + "@type": ["nypl:Item", "nypl:Resource"], + "@id": "res:b22133121", + carrierType: [ + { + "@id": "carriertypes:nc", + prefLabel: "volume", + }, + ], + contributorLiteral: [ + "Acosta, María", + "Gomez, Vanessa, 1984-", + "OverDrive, Inc.", + ], + createdString: ["2019"], + createdYear: 2019, + creatorLiteral: ["Persico, Nicky"], + dateStartYear: 2019, + dateString: ["2019"], + description: [ + "Un abogado en prácticas inexperto y un poco torpe se ve involucrado en la defensa de dos mujeres muy diferentes entre ellas por edad y clase social, unidas por el hecho de ser ambas víctimas de la violencia. A partir de aquí se desenmaraña, aderezado por intrigantes mezclas culinarias, un denso entramado de historias y personas que, entre el suspense y la gravedad, se adentra en el fenómeno del acoso y de la manipulación por medio de una sucesión de eventos destinados a revelar una realidad insospechable. En una encantadora Puglia, descripta de manera cuanto menos original, Nicky Persico guía al lector a través de un mundo de individuos peligrosos (enemigos invisibles ante los ojos de todo el mundo, y sin embargo envidiosos de la vida y la vitalidad de las víctimas que persiguen) proponiendo la receta que su protagonista ha ideado para transformar elementos triviales en filosofía de vida: los Spaghetti Paradiso.", + ], + electronicResources: [ + { + title: "Electronic Resource 1", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312493", + }, + { + title: "Access eNYPL", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312494", + }, + ], + extent: [ + "1 online resource (1 sound file (06 hr., 55 min., 34 sec.)) : digital", + ], + genreForm: ["Audiobooks.", "Fiction."], + idIsbn: ["9788835401155", "8835401151"], + idOclc: ["1144496190"], + identifier: [ + { + "@type": "nypl:Bnumber", + "@value": "22133121", + }, + { + "@type": "bf:Isbn", + "@value": "9788835401155", + }, + { + "@type": "bf:Isbn", + "@value": "8835401151", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "bf:Identifier", + "@value": "(OCoLC)1144496190", + }, + ], + issuance: [ + { + "@id": "urn:biblevel:m", + prefLabel: "monograph/item", + }, + ], + items: [], + language: [ + { + "@id": "lang:spa", + prefLabel: "Spanish", + }, + ], + lccClassification: ["PQ4916.E778 S63 2019"], + materialType: [ + { + "@id": "resourcetypes:aud", + prefLabel: "Audio", + }, + ], + mediaType: [ + { + "@id": "mediatypes:n", + prefLabel: "unmediated", + }, + ], + numAvailable: 0, + numCheckinCardItems: 0, + numElectronicResources: 1, + numItemDatesParsed: 0, + numItemVolumesParsed: 0, + numItems: 0, + numItemsMatched: 0, + numItemsTotal: 0, + nyplSource: ["sierra-nypl"], + placeOfPublication: ["[Solon, Ohio]"], + publicationStatement: ["[Solon, Ohio] : Tektime, 2019."], + publisherLiteral: ["Tektime"], + subjectLiteral: [ + "Sexual harassment of women -- Fiction.", + "Sexual harassment of women.", + "Puglia (Italy) -- Fiction.", + "Italy -- Puglia.", + ], + title: ["Spaghetti paradiso"], + titleDisplay: [ + "Spaghetti paradiso / Nicky Persico ; traducción por: María Acosta.", + ], + type: ["nypl:Item"], + updatedAt: 1681346906709, + uri: "b22133121", + suppressed: false, + hasItemVolumes: false, + hasItemDates: false, +} diff --git a/src/components/SearchResult/ElectronicResourcesLink.test.tsx b/src/components/SearchResult/ElectronicResourcesLink.test.tsx new file mode 100644 index 000000000..cd1b82a28 --- /dev/null +++ b/src/components/SearchResult/ElectronicResourcesLink.test.tsx @@ -0,0 +1,88 @@ +import React from "react" +import { render, screen } from "@testing-library/react" +import ElectronicResourcesLink from "./ElectronicResourcesLink" +import SearchResultsBib from "../../models/SearchResultsBib" +import { + searchResultElectronicResources, + searchResultMultipleElectronicResources, + searchResultMultipleElectronicResourcesNoLabel, +} from "../../../__test__/fixtures/searchResultElectronicResources" + +describe("Electronic Resources Link with a single resource", () => { + beforeEach(() => { + const bib = new SearchResultsBib(searchResultElectronicResources) + render( + + ) + }) + + it("renders the correct heading", async () => { + expect(screen.getByRole("heading", { level: 4 })).toHaveTextContent( + "Available Online" + ) + }) + it("renders the correct link with the label as the text when only one electronic resource is available", async () => { + const link = screen.getByRole("link", { + name: "https://link.overdrive.com/?websiteId=37&titleId=5312492", + }) + expect(link).toHaveAttribute( + "href", + "https://link.overdrive.com/?websiteId=37&titleId=5312492" + ) + }) + it("renders the correct link with the url as the text when only one electronic resource is available and prefLabel not present", async () => { + const bib = new SearchResultsBib(searchResultElectronicResources) + render( + + ) + const link = screen.getByRole("link", { + name: "https://link.overdrive.com/?websiteId=37&titleId=5312492", + }) + expect(link).toHaveAttribute( + "href", + "https://link.overdrive.com/?websiteId=37&titleId=5312492" + ) + }) +}) + +describe("Electronic Resources Link with a single resource and no label", () => { + it("renders the correct link with the url as the text when only one electronic resource is available and prefLabel not present", async () => { + const bib = new SearchResultsBib(searchResultElectronicResources) + render( + + ) + const link = screen.getByRole("link", { + name: "https://link.overdrive.com/?websiteId=37&titleId=5312492", + }) + expect(link).toHaveAttribute( + "href", + "https://link.overdrive.com/?websiteId=37&titleId=5312492" + ) + }) +}) + +describe("Electronic Resources Link with multiple resources", () => { + it("renders a link to the bib page when multiple resources are available", async () => { + const bib = new SearchResultsBib(searchResultMultipleElectronicResources) + render( + + ) + + const link = screen.getByRole("link", { + name: "See All Available Online Resources", + }) + expect(link).toHaveAttribute("href", "/bib/b22133121#electronic-resources") + }) +}) diff --git a/src/components/SearchResult/ElectronicResourcesLink.tsx b/src/components/SearchResult/ElectronicResourcesLink.tsx index 9e537a75d..4788e8169 100644 --- a/src/components/SearchResult/ElectronicResourcesLink.tsx +++ b/src/components/SearchResult/ElectronicResourcesLink.tsx @@ -32,7 +32,7 @@ const ElectronicResourcesLink = ({ target="_blank" rel="noreferrer" > - {electronicResources[0].label || electronicResources[0].url} + {electronicResources[0].prefLabel || electronicResources[0].url} ) : ( diff --git a/src/types/bibTypes.ts b/src/types/bibTypes.ts index 50c30002f..e48d27d16 100644 --- a/src/types/bibTypes.ts +++ b/src/types/bibTypes.ts @@ -1,5 +1,5 @@ export interface ElectronicResource { title?: string url?: string - label?: string + prefLabel?: string } From f1431fdd79e0c01d0b7d0ceae3c7784b00eacdfd Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 10:24:57 -0500 Subject: [PATCH 3/7] Add tests for correct label --- .../searchResultElectronicResources.ts | 236 +++++++++--------- .../ElectronicResourcesLink.test.tsx | 24 +- 2 files changed, 120 insertions(+), 140 deletions(-) diff --git a/__test__/fixtures/searchResultElectronicResources.ts b/__test__/fixtures/searchResultElectronicResources.ts index 36fc77b9b..34dc59bea 100644 --- a/__test__/fixtures/searchResultElectronicResources.ts +++ b/__test__/fixtures/searchResultElectronicResources.ts @@ -115,6 +115,122 @@ export const searchResultElectronicResources = { hasItemDates: false, } +export const searchResultElectronicResourcesNoLabel = { + "@type": ["nypl:Item", "nypl:Resource"], + "@id": "res:b22133121", + carrierType: [ + { + "@id": "carriertypes:nc", + prefLabel: "volume", + }, + ], + contributorLiteral: [ + "Acosta, María", + "Gomez, Vanessa, 1984-", + "OverDrive, Inc.", + ], + createdString: ["2019"], + createdYear: 2019, + creatorLiteral: ["Persico, Nicky"], + dateStartYear: 2019, + dateString: ["2019"], + description: [ + "Un abogado en prácticas inexperto y un poco torpe se ve involucrado en la defensa de dos mujeres muy diferentes entre ellas por edad y clase social, unidas por el hecho de ser ambas víctimas de la violencia. A partir de aquí se desenmaraña, aderezado por intrigantes mezclas culinarias, un denso entramado de historias y personas que, entre el suspense y la gravedad, se adentra en el fenómeno del acoso y de la manipulación por medio de una sucesión de eventos destinados a revelar una realidad insospechable. En una encantadora Puglia, descripta de manera cuanto menos original, Nicky Persico guía al lector a través de un mundo de individuos peligrosos (enemigos invisibles ante los ojos de todo el mundo, y sin embargo envidiosos de la vida y la vitalidad de las víctimas que persiguen) proponiendo la receta que su protagonista ha ideado para transformar elementos triviales en filosofía de vida: los Spaghetti Paradiso.", + ], + electronicResources: [ + { + title: "Access eNYPL", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312492", + }, + ], + extent: [ + "1 online resource (1 sound file (06 hr., 55 min., 34 sec.)) : digital", + ], + genreForm: ["Audiobooks.", "Fiction."], + idIsbn: ["9788835401155", "8835401151"], + idOclc: ["1144496190"], + identifier: [ + { + "@type": "nypl:Bnumber", + "@value": "22133121", + }, + { + "@type": "bf:Isbn", + "@value": "9788835401155", + }, + { + "@type": "bf:Isbn", + "@value": "8835401151", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "bf:Identifier", + "@value": "(OCoLC)1144496190", + }, + ], + issuance: [ + { + "@id": "urn:biblevel:m", + prefLabel: "monograph/item", + }, + ], + items: [], + language: [ + { + "@id": "lang:spa", + prefLabel: "Spanish", + }, + ], + lccClassification: ["PQ4916.E778 S63 2019"], + materialType: [ + { + "@id": "resourcetypes:aud", + prefLabel: "Audio", + }, + ], + mediaType: [ + { + "@id": "mediatypes:n", + prefLabel: "unmediated", + }, + ], + numAvailable: 0, + numCheckinCardItems: 0, + numElectronicResources: 1, + numItemDatesParsed: 0, + numItemVolumesParsed: 0, + numItems: 0, + numItemsMatched: 0, + numItemsTotal: 0, + nyplSource: ["sierra-nypl"], + placeOfPublication: ["[Solon, Ohio]"], + publicationStatement: ["[Solon, Ohio] : Tektime, 2019."], + publisherLiteral: ["Tektime"], + subjectLiteral: [ + "Sexual harassment of women -- Fiction.", + "Sexual harassment of women.", + "Puglia (Italy) -- Fiction.", + "Italy -- Puglia.", + ], + title: ["Spaghetti paradiso"], + titleDisplay: [ + "Spaghetti paradiso / Nicky Persico ; traducción por: María Acosta.", + ], + type: ["nypl:Item"], + updatedAt: 1681346906709, + uri: "b22133121", + suppressed: false, + hasItemVolumes: false, + hasItemDates: false, +} + export const searchResultMultipleElectronicResources = { "@type": ["nypl:Item", "nypl:Resource"], "@id": "res:b22133121", @@ -236,123 +352,3 @@ export const searchResultMultipleElectronicResources = { hasItemVolumes: false, hasItemDates: false, } - -export const searchResultMultipleElectronicResourcesNoLabel = { - "@type": ["nypl:Item", "nypl:Resource"], - "@id": "res:b22133121", - carrierType: [ - { - "@id": "carriertypes:nc", - prefLabel: "volume", - }, - ], - contributorLiteral: [ - "Acosta, María", - "Gomez, Vanessa, 1984-", - "OverDrive, Inc.", - ], - createdString: ["2019"], - createdYear: 2019, - creatorLiteral: ["Persico, Nicky"], - dateStartYear: 2019, - dateString: ["2019"], - description: [ - "Un abogado en prácticas inexperto y un poco torpe se ve involucrado en la defensa de dos mujeres muy diferentes entre ellas por edad y clase social, unidas por el hecho de ser ambas víctimas de la violencia. A partir de aquí se desenmaraña, aderezado por intrigantes mezclas culinarias, un denso entramado de historias y personas que, entre el suspense y la gravedad, se adentra en el fenómeno del acoso y de la manipulación por medio de una sucesión de eventos destinados a revelar una realidad insospechable. En una encantadora Puglia, descripta de manera cuanto menos original, Nicky Persico guía al lector a través de un mundo de individuos peligrosos (enemigos invisibles ante los ojos de todo el mundo, y sin embargo envidiosos de la vida y la vitalidad de las víctimas que persiguen) proponiendo la receta que su protagonista ha ideado para transformar elementos triviales en filosofía de vida: los Spaghetti Paradiso.", - ], - electronicResources: [ - { - title: "Electronic Resource 1", - url: "https://link.overdrive.com/?websiteId=37&titleId=5312493", - }, - { - title: "Access eNYPL", - url: "https://link.overdrive.com/?websiteId=37&titleId=5312494", - }, - ], - extent: [ - "1 online resource (1 sound file (06 hr., 55 min., 34 sec.)) : digital", - ], - genreForm: ["Audiobooks.", "Fiction."], - idIsbn: ["9788835401155", "8835401151"], - idOclc: ["1144496190"], - identifier: [ - { - "@type": "nypl:Bnumber", - "@value": "22133121", - }, - { - "@type": "bf:Isbn", - "@value": "9788835401155", - }, - { - "@type": "bf:Isbn", - "@value": "8835401151", - }, - { - "@type": "nypl:Oclc", - "@value": "1144496190", - }, - { - "@type": "nypl:Oclc", - "@value": "1144496190", - }, - { - "@type": "bf:Identifier", - "@value": "(OCoLC)1144496190", - }, - ], - issuance: [ - { - "@id": "urn:biblevel:m", - prefLabel: "monograph/item", - }, - ], - items: [], - language: [ - { - "@id": "lang:spa", - prefLabel: "Spanish", - }, - ], - lccClassification: ["PQ4916.E778 S63 2019"], - materialType: [ - { - "@id": "resourcetypes:aud", - prefLabel: "Audio", - }, - ], - mediaType: [ - { - "@id": "mediatypes:n", - prefLabel: "unmediated", - }, - ], - numAvailable: 0, - numCheckinCardItems: 0, - numElectronicResources: 1, - numItemDatesParsed: 0, - numItemVolumesParsed: 0, - numItems: 0, - numItemsMatched: 0, - numItemsTotal: 0, - nyplSource: ["sierra-nypl"], - placeOfPublication: ["[Solon, Ohio]"], - publicationStatement: ["[Solon, Ohio] : Tektime, 2019."], - publisherLiteral: ["Tektime"], - subjectLiteral: [ - "Sexual harassment of women -- Fiction.", - "Sexual harassment of women.", - "Puglia (Italy) -- Fiction.", - "Italy -- Puglia.", - ], - title: ["Spaghetti paradiso"], - titleDisplay: [ - "Spaghetti paradiso / Nicky Persico ; traducción por: María Acosta.", - ], - type: ["nypl:Item"], - updatedAt: 1681346906709, - uri: "b22133121", - suppressed: false, - hasItemVolumes: false, - hasItemDates: false, -} diff --git a/src/components/SearchResult/ElectronicResourcesLink.test.tsx b/src/components/SearchResult/ElectronicResourcesLink.test.tsx index cd1b82a28..433682266 100644 --- a/src/components/SearchResult/ElectronicResourcesLink.test.tsx +++ b/src/components/SearchResult/ElectronicResourcesLink.test.tsx @@ -4,8 +4,8 @@ import ElectronicResourcesLink from "./ElectronicResourcesLink" import SearchResultsBib from "../../models/SearchResultsBib" import { searchResultElectronicResources, + searchResultElectronicResourcesNoLabel, searchResultMultipleElectronicResources, - searchResultMultipleElectronicResourcesNoLabel, } from "../../../__test__/fixtures/searchResultElectronicResources" describe("Electronic Resources Link with a single resource", () => { @@ -26,23 +26,7 @@ describe("Electronic Resources Link with a single resource", () => { }) it("renders the correct link with the label as the text when only one electronic resource is available", async () => { const link = screen.getByRole("link", { - name: "https://link.overdrive.com/?websiteId=37&titleId=5312492", - }) - expect(link).toHaveAttribute( - "href", - "https://link.overdrive.com/?websiteId=37&titleId=5312492" - ) - }) - it("renders the correct link with the url as the text when only one electronic resource is available and prefLabel not present", async () => { - const bib = new SearchResultsBib(searchResultElectronicResources) - render( - - ) - const link = screen.getByRole("link", { - name: "https://link.overdrive.com/?websiteId=37&titleId=5312492", + name: "Access eNYPL", }) expect(link).toHaveAttribute( "href", @@ -52,8 +36,8 @@ describe("Electronic Resources Link with a single resource", () => { }) describe("Electronic Resources Link with a single resource and no label", () => { - it("renders the correct link with the url as the text when only one electronic resource is available and prefLabel not present", async () => { - const bib = new SearchResultsBib(searchResultElectronicResources) + it("renders the correct link with the url as the text when prefLabel is not available", async () => { + const bib = new SearchResultsBib(searchResultElectronicResourcesNoLabel) render( Date: Mon, 11 Dec 2023 10:25:16 -0500 Subject: [PATCH 4/7] Add tests for correct label --- .../searchResultElectronicResources.ts | 226 +++++++++--------- pages/search/advanced.tsx | 2 +- .../ElectronicResourcesLink.test.tsx | 2 +- 3 files changed, 115 insertions(+), 115 deletions(-) diff --git a/__test__/fixtures/searchResultElectronicResources.ts b/__test__/fixtures/searchResultElectronicResources.ts index 34dc59bea..0343d3337 100644 --- a/__test__/fixtures/searchResultElectronicResources.ts +++ b/__test__/fixtures/searchResultElectronicResources.ts @@ -116,119 +116,119 @@ export const searchResultElectronicResources = { } export const searchResultElectronicResourcesNoLabel = { - "@type": ["nypl:Item", "nypl:Resource"], - "@id": "res:b22133121", - carrierType: [ - { - "@id": "carriertypes:nc", - prefLabel: "volume", - }, - ], - contributorLiteral: [ - "Acosta, María", - "Gomez, Vanessa, 1984-", - "OverDrive, Inc.", - ], - createdString: ["2019"], - createdYear: 2019, - creatorLiteral: ["Persico, Nicky"], - dateStartYear: 2019, - dateString: ["2019"], - description: [ - "Un abogado en prácticas inexperto y un poco torpe se ve involucrado en la defensa de dos mujeres muy diferentes entre ellas por edad y clase social, unidas por el hecho de ser ambas víctimas de la violencia. A partir de aquí se desenmaraña, aderezado por intrigantes mezclas culinarias, un denso entramado de historias y personas que, entre el suspense y la gravedad, se adentra en el fenómeno del acoso y de la manipulación por medio de una sucesión de eventos destinados a revelar una realidad insospechable. En una encantadora Puglia, descripta de manera cuanto menos original, Nicky Persico guía al lector a través de un mundo de individuos peligrosos (enemigos invisibles ante los ojos de todo el mundo, y sin embargo envidiosos de la vida y la vitalidad de las víctimas que persiguen) proponiendo la receta que su protagonista ha ideado para transformar elementos triviales en filosofía de vida: los Spaghetti Paradiso.", - ], - electronicResources: [ - { - title: "Access eNYPL", - url: "https://link.overdrive.com/?websiteId=37&titleId=5312492", - }, - ], - extent: [ - "1 online resource (1 sound file (06 hr., 55 min., 34 sec.)) : digital", - ], - genreForm: ["Audiobooks.", "Fiction."], - idIsbn: ["9788835401155", "8835401151"], - idOclc: ["1144496190"], - identifier: [ - { - "@type": "nypl:Bnumber", - "@value": "22133121", - }, - { - "@type": "bf:Isbn", - "@value": "9788835401155", - }, - { - "@type": "bf:Isbn", - "@value": "8835401151", - }, - { - "@type": "nypl:Oclc", - "@value": "1144496190", - }, - { - "@type": "nypl:Oclc", - "@value": "1144496190", - }, - { - "@type": "bf:Identifier", - "@value": "(OCoLC)1144496190", - }, - ], - issuance: [ - { - "@id": "urn:biblevel:m", - prefLabel: "monograph/item", - }, - ], - items: [], - language: [ - { - "@id": "lang:spa", - prefLabel: "Spanish", - }, - ], - lccClassification: ["PQ4916.E778 S63 2019"], - materialType: [ - { - "@id": "resourcetypes:aud", - prefLabel: "Audio", - }, - ], - mediaType: [ - { - "@id": "mediatypes:n", - prefLabel: "unmediated", - }, - ], - numAvailable: 0, - numCheckinCardItems: 0, - numElectronicResources: 1, - numItemDatesParsed: 0, - numItemVolumesParsed: 0, - numItems: 0, - numItemsMatched: 0, - numItemsTotal: 0, - nyplSource: ["sierra-nypl"], - placeOfPublication: ["[Solon, Ohio]"], - publicationStatement: ["[Solon, Ohio] : Tektime, 2019."], - publisherLiteral: ["Tektime"], - subjectLiteral: [ - "Sexual harassment of women -- Fiction.", - "Sexual harassment of women.", - "Puglia (Italy) -- Fiction.", - "Italy -- Puglia.", - ], - title: ["Spaghetti paradiso"], - titleDisplay: [ - "Spaghetti paradiso / Nicky Persico ; traducción por: María Acosta.", - ], - type: ["nypl:Item"], - updatedAt: 1681346906709, - uri: "b22133121", - suppressed: false, - hasItemVolumes: false, - hasItemDates: false, + "@type": ["nypl:Item", "nypl:Resource"], + "@id": "res:b22133121", + carrierType: [ + { + "@id": "carriertypes:nc", + prefLabel: "volume", + }, + ], + contributorLiteral: [ + "Acosta, María", + "Gomez, Vanessa, 1984-", + "OverDrive, Inc.", + ], + createdString: ["2019"], + createdYear: 2019, + creatorLiteral: ["Persico, Nicky"], + dateStartYear: 2019, + dateString: ["2019"], + description: [ + "Un abogado en prácticas inexperto y un poco torpe se ve involucrado en la defensa de dos mujeres muy diferentes entre ellas por edad y clase social, unidas por el hecho de ser ambas víctimas de la violencia. A partir de aquí se desenmaraña, aderezado por intrigantes mezclas culinarias, un denso entramado de historias y personas que, entre el suspense y la gravedad, se adentra en el fenómeno del acoso y de la manipulación por medio de una sucesión de eventos destinados a revelar una realidad insospechable. En una encantadora Puglia, descripta de manera cuanto menos original, Nicky Persico guía al lector a través de un mundo de individuos peligrosos (enemigos invisibles ante los ojos de todo el mundo, y sin embargo envidiosos de la vida y la vitalidad de las víctimas que persiguen) proponiendo la receta que su protagonista ha ideado para transformar elementos triviales en filosofía de vida: los Spaghetti Paradiso.", + ], + electronicResources: [ + { + title: "Access eNYPL", + url: "https://link.overdrive.com/?websiteId=37&titleId=5312492", + }, + ], + extent: [ + "1 online resource (1 sound file (06 hr., 55 min., 34 sec.)) : digital", + ], + genreForm: ["Audiobooks.", "Fiction."], + idIsbn: ["9788835401155", "8835401151"], + idOclc: ["1144496190"], + identifier: [ + { + "@type": "nypl:Bnumber", + "@value": "22133121", + }, + { + "@type": "bf:Isbn", + "@value": "9788835401155", + }, + { + "@type": "bf:Isbn", + "@value": "8835401151", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "nypl:Oclc", + "@value": "1144496190", + }, + { + "@type": "bf:Identifier", + "@value": "(OCoLC)1144496190", + }, + ], + issuance: [ + { + "@id": "urn:biblevel:m", + prefLabel: "monograph/item", + }, + ], + items: [], + language: [ + { + "@id": "lang:spa", + prefLabel: "Spanish", + }, + ], + lccClassification: ["PQ4916.E778 S63 2019"], + materialType: [ + { + "@id": "resourcetypes:aud", + prefLabel: "Audio", + }, + ], + mediaType: [ + { + "@id": "mediatypes:n", + prefLabel: "unmediated", + }, + ], + numAvailable: 0, + numCheckinCardItems: 0, + numElectronicResources: 1, + numItemDatesParsed: 0, + numItemVolumesParsed: 0, + numItems: 0, + numItemsMatched: 0, + numItemsTotal: 0, + nyplSource: ["sierra-nypl"], + placeOfPublication: ["[Solon, Ohio]"], + publicationStatement: ["[Solon, Ohio] : Tektime, 2019."], + publisherLiteral: ["Tektime"], + subjectLiteral: [ + "Sexual harassment of women -- Fiction.", + "Sexual harassment of women.", + "Puglia (Italy) -- Fiction.", + "Italy -- Puglia.", + ], + title: ["Spaghetti paradiso"], + titleDisplay: [ + "Spaghetti paradiso / Nicky Persico ; traducción por: María Acosta.", + ], + type: ["nypl:Item"], + updatedAt: 1681346906709, + uri: "b22133121", + suppressed: false, + hasItemVolumes: false, + hasItemDates: false, } export const searchResultMultipleElectronicResources = { diff --git a/pages/search/advanced.tsx b/pages/search/advanced.tsx index 1e9ab2262..69f82acb3 100644 --- a/pages/search/advanced.tsx +++ b/pages/search/advanced.tsx @@ -37,7 +37,7 @@ import type { SearchFormActionType, } from "../../src/types/searchTypes" import { getQueryString } from "../../src/utils/searchUtils" -import FieldsetDate from "../../src/components/SearchFilters/FieldsetDate" +// import FieldsetDate from "../../src/components/SearchFilters/FieldsetDate" /** * The Advanced Search page is responsible for displaying the Advanced Search form fields and diff --git a/src/components/SearchResult/ElectronicResourcesLink.test.tsx b/src/components/SearchResult/ElectronicResourcesLink.test.tsx index 433682266..09aed991a 100644 --- a/src/components/SearchResult/ElectronicResourcesLink.test.tsx +++ b/src/components/SearchResult/ElectronicResourcesLink.test.tsx @@ -4,7 +4,7 @@ import ElectronicResourcesLink from "./ElectronicResourcesLink" import SearchResultsBib from "../../models/SearchResultsBib" import { searchResultElectronicResources, - searchResultElectronicResourcesNoLabel, + searchResultElectronicResourcesNoLabel, searchResultMultipleElectronicResources, } from "../../../__test__/fixtures/searchResultElectronicResources" From 6c5e27b3ac503f091dda3f2c0ab44275d9e6e634 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 14:07:27 -0500 Subject: [PATCH 5/7] Use standalone link type for eResources link --- src/components/RCLink/RCLink.tsx | 7 ++++++- .../SearchResult/ElectronicResourcesLink.tsx | 16 ++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/components/RCLink/RCLink.tsx b/src/components/RCLink/RCLink.tsx index 1713508b7..5d04144fa 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,8 @@ interface RCLinkProps { children: ReactNode className?: string color?: string + type?: LinkTypes + size?: string } /** diff --git a/src/components/SearchResult/ElectronicResourcesLink.tsx b/src/components/SearchResult/ElectronicResourcesLink.tsx index 4788e8169..3980f9ba4 100644 --- a/src/components/SearchResult/ElectronicResourcesLink.tsx +++ b/src/components/SearchResult/ElectronicResourcesLink.tsx @@ -35,20 +35,8 @@ const ElectronicResourcesLink = ({ {electronicResources[0].prefLabel || electronicResources[0].url} ) : ( - - - See All Available Online Resources{" "} - - + + See All Available Online Resources )} From 80f58a58dd2d02a36741d42037c751072f265a59 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 14:07:43 -0500 Subject: [PATCH 6/7] Use standalone link type for eResources link --- src/components/SearchResult/ElectronicResourcesLink.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/SearchResult/ElectronicResourcesLink.tsx b/src/components/SearchResult/ElectronicResourcesLink.tsx index 3980f9ba4..73d6cb40b 100644 --- a/src/components/SearchResult/ElectronicResourcesLink.tsx +++ b/src/components/SearchResult/ElectronicResourcesLink.tsx @@ -1,8 +1,6 @@ import { Box, Heading, - Text, - Icon, Link as DSLink, } from "@nypl/design-system-react-components" From ba6bb70d006655dc098b8f7d292c4014cd0a1b23 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Mon, 11 Dec 2023 14:08:54 -0500 Subject: [PATCH 7/7] Add hasElectronicResouces getter --- src/components/SearchResult/SearchResult.tsx | 2 +- src/models/SearchResultsBib.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/SearchResult/SearchResult.tsx b/src/components/SearchResult/SearchResult.tsx index 9ed489537..ab9a2a537 100644 --- a/src/components/SearchResult/SearchResult.tsx +++ b/src/components/SearchResult/SearchResult.tsx @@ -36,7 +36,7 @@ const SearchResult = ({ bib }: SearchResultProps) => { {bib.yearPublished && {bib.yearPublished}} {bib.itemMessage} - {bib.electronicResources && ( + {bib.hasElectronicResources && ( 0 } + get hasElectronicResources() { + return this.numElectronicResources > 0 + } + get numItems() { return this.hasPhysicalItems ? this.numPhysicalItems