Skip to content

Commit

Permalink
Merge pull request #334 from NYPL/SFR-914_edition_page_author_title
Browse files Browse the repository at this point in the history
SFR-914: Add author and work title to edition page
  • Loading branch information
jackiequach authored Jun 28, 2022
2 parents ab745dc + bae8933 commit 21cd4b8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- CHORE: removes tugboat deploy
- Change format filters to "Readable", "Downloadable", and "Requestable"
- Upgrade to Web Reader version 3.1.0
- Adds author and work title to edition detail page

## [0.13.1]
- Added "Back to search results" link for works and editions
Expand Down
17 changes: 16 additions & 1 deletion src/__tests__/fixtures/edition-detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,22 @@
"table_of_contents": "La marchandisation des services d'eau : les réformes des années 1980-1990. La fragmentation par les réseaux. Géographie des nouveaux assemblages en Afrique subsaharienne. Le pluralisme sans l'équité? L'écartèlement des territoires nationaux. Spatialisation et territorialisation des services d'eau : une inégale fragmentation.",
"title": "A history of South Africa from the earliest European settlement",
"volume": "Volume number",
"work_uuid": "0007511d-29be-4a3c-9965-fe367c55b1f8"
"work_authors": [
{
"lcnaf": "",
"name": "Edgar, John, 1876-",
"primary": "true",
"viaf": ""
},
{
"lcnaf": "n78095332",
"name": "Shakespeare, William- ()",
"primary": "true",
"viaf": "96994048"
}
],
"work_uuid": "0007511d-29be-4a3c-9965-fe367c55b1f8",
"work_title": "A history of South Africa from the earliest European settlement"
},
"responseType": "singleEdition",
"status": 200,
Expand Down
26 changes: 23 additions & 3 deletions src/components/EditionDetail/Edition.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,35 @@ describe("Renders edition component when given valid edition", () => {
"/advanced-search"
);
});
test("Shows edition Title in Heading", () => {
test("Shows work work Title in Heading", () => {
expect(
screen.getByRole("heading", { name: apiEdition.data.title })
screen.getByRole("heading", { name: apiEdition.data.work_title })
).toBeInTheDocument();
});
test("Shows edition Subtitle", () => {
expect(screen.getByText(apiEdition.data.sub_title)).toBeInTheDocument();
});

test("Shows Author name in Link", () => {
apiEdition.data.work_authors.forEach((author) =>
expect(screen.getByText(author.name)).toBeInTheDocument()
);
});
describe("Author links redirect to correct search query", () => {
test("Author without viaf", () => {
const authorElement = screen.getByText("Edgar, John, 1876-");
expect(authorElement.closest("a").href).toContain(
"query=author%3AEdgar%2C+John%2C+1876-"
);
});
test("Author with viaf", () => {
const authorElementWithViaf = screen.getByText(
"Shakespeare, William- ()"
);
expect(authorElementWithViaf.closest("a").href).toContain(
"query=viaf%3A96994048&display=author%3AShakespeare%2C+William-+%28%29"
);
});
});
test("Three cards show up in page", () => {
expect(
screen.getByRole("heading", { name: "Featured Copy" })
Expand Down
14 changes: 11 additions & 3 deletions src/components/EditionDetail/Edition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import Link from "~/src/components/Link/Link";
import { InstanceCard } from "../InstanceCard/InstanceCard";
import { defaultBreadcrumbs } from "~/src/constants/labels";
import SearchHeader from "../SearchHeader/SearchHeader";
import { truncateStringOnWhitespace } from "~/src/util/Util";
import {
joinArrayOfElements,
truncateStringOnWhitespace,
} from "~/src/util/Util";
import { MAX_TITLE_LENGTH } from "~/src/constants/editioncard";
import { Instance } from "~/src/types/DataModel";
import EditionCardUtils from "~/src/util/EditionCardUtils";

const Edition: React.FC<{ editionResult: EditionResult; backUrl?: string }> = (
props
Expand All @@ -35,6 +39,7 @@ const Edition: React.FC<{ editionResult: EditionResult; backUrl?: string }> = (
const { pathname, query } = router;
const featuredItemId = query.featured as string;
const edition: ApiEdition = props.editionResult.data;
const authorsList = EditionCardUtils.getAuthorsList(edition.work_authors);

const passedInFeaturedItem = featuredItemId
? edition.instances.find((instance) => {
Expand Down Expand Up @@ -90,9 +95,9 @@ const Edition: React.FC<{ editionResult: EditionResult; backUrl?: string }> = (
to={{
pathname: `/work/${edition.work_uuid}`,
}}
title={edition.title}
title={edition.work_title}
>
{edition.title}
{edition.work_title}
</Link>
</Heading>
)}
Expand All @@ -107,6 +112,9 @@ const Edition: React.FC<{ editionResult: EditionResult; backUrl?: string }> = (
)}
</Flex>
{edition.sub_title && <Box>{edition.sub_title}</Box>}
{authorsList && authorsList.length && (
<Box>By {joinArrayOfElements(authorsList, "")}</Box>
)}
<Box>
{featuredInstance && (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Work/Work.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const WorkDetail: React.FC<{ workResult: WorkResult; backUrl?: string }> = (
</Flex>
{work.sub_title && <Box>{work.sub_title}</Box>}
{authorsList && authorsList.length && (
<Box>By {joinArrayOfElements(authorsList, ", ")}</Box>
<Box>By {joinArrayOfElements(authorsList, "")}</Box>
)}
</Box>
{featuredEdition && (
Expand Down
2 changes: 2 additions & 0 deletions src/types/EditionQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ export type ApiEdition = {
instances: Instance[];
title?: string;
sub_title?: string;
work_title?: string;
work_authors?: Agent[];
};

1 comment on commit 21cd4b8

@vercel
Copy link

@vercel vercel bot commented on 21cd4b8 Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.