-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from NYPL/SCC-3897/search-results-edd
SCC-3897 - Search Results Electronic Resources Link
- Loading branch information
Showing
9 changed files
with
371 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/components/SearchResult/ElectronicResourcesLink.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.