Skip to content

Commit

Permalink
Merge pull request #55 from NYPL/SCC-3897/search-results-edd
Browse files Browse the repository at this point in the history
SCC-3897 - Search Results Electronic Resources Link
  • Loading branch information
dgcohen authored Dec 12, 2023
2 parents 424f107 + 75e60ed commit 5764ef6
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 7 deletions.
240 changes: 239 additions & 1 deletion __test__/fixtures/searchResultElectronicResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
Expand Down Expand Up @@ -114,3 +114,241 @@ export const searchResultElectronicResources = {
hasItemVolumes: false,
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",
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,
}
1 change: 1 addition & 0 deletions pages/search/advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
SearchFormActionType,
} from "../../src/types/searchTypes"
import { getQueryString } from "../../src/utils/searchUtils"
// import FieldsetDate from "../../src/components/SearchFilters/FieldsetDate"

/**
* The Advanced Search page is responsible for displaying the Advanced Search form fields and
Expand Down
7 changes: 1 addition & 6 deletions src/components/DRB/DRBCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ const DRBCard = ({ drbResult }: DRBCardProps) => {
sx={{ display: "flex", alignItems: "center" }}
noSpace
>
<Icon
className="more-link"
name="download"
align="left"
size="small"
/>
<Icon name="download" align="left" size="small" />
Download {drbResult.downloadLink.mediaType || ""}
</Text>
</DSLink>
Expand Down
1 change: 1 addition & 0 deletions src/components/RCLink/RCLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface RCLinkProps {
className?: string
color?: string
type?: LinkTypes
size?: string
hasWhiteFocusRing?: boolean
}

Expand Down
72 changes: 72 additions & 0 deletions src/components/SearchResult/ElectronicResourcesLink.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from "react"
import { render, screen } from "@testing-library/react"
import ElectronicResourcesLink from "./ElectronicResourcesLink"
import SearchResultsBib from "../../models/SearchResultsBib"
import {
searchResultElectronicResources,
searchResultElectronicResourcesNoLabel,
searchResultMultipleElectronicResources,
} from "../../../__test__/fixtures/searchResultElectronicResources"

describe("Electronic Resources Link with a single resource", () => {
beforeEach(() => {
const bib = new SearchResultsBib(searchResultElectronicResources)
render(
<ElectronicResourcesLink
bibUrl={bib.url}
electronicResources={bib.electronicResources}
/>
)
})

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: "Access eNYPL",
})
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 prefLabel is not available", async () => {
const bib = new SearchResultsBib(searchResultElectronicResourcesNoLabel)
render(
<ElectronicResourcesLink
bibUrl={bib.url}
electronicResources={bib.electronicResources}
/>
)
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(
<ElectronicResourcesLink
bibUrl={bib.url}
electronicResources={bib.electronicResources}
/>
)

const link = screen.getByRole("link", {
name: "See All Available Online Resources",
})
expect(link).toHaveAttribute("href", "/bib/b22133121#electronic-resources")
})
})
44 changes: 44 additions & 0 deletions src/components/SearchResult/ElectronicResourcesLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Box,
Heading,
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 (
<Box>
<Heading level="four" size="callout" mb="xxs">
Available Online
</Heading>
{electronicResources.length === 1 ? (
<DSLink
href={electronicResources[0].url}
target="_blank"
rel="noreferrer"
>
{electronicResources[0].prefLabel || electronicResources[0].url}
</DSLink>
) : (
<RCLink href={`${bibUrl}#electronic-resources`} type="standalone">
See All Available Online Resources
</RCLink>
)}
</Box>
)
}

export default ElectronicResourcesLink
Loading

0 comments on commit 5764ef6

Please sign in to comment.