From 16a38e52a7bed3131d4beeeacc1280dd993e918f Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Mon, 2 Dec 2024 12:40:49 -0500 Subject: [PATCH] rename subjectheading and return only values --- src/models/BibDetails.ts | 25 ++-- src/models/modelTests/BibDetails.test.ts | 162 +++++++++++------------ 2 files changed, 86 insertions(+), 101 deletions(-) diff --git a/src/models/BibDetails.ts b/src/models/BibDetails.ts index 95d514118..ae304a08b 100644 --- a/src/models/BibDetails.ts +++ b/src/models/BibDetails.ts @@ -20,7 +20,7 @@ export default class BibDetails { groupedNotes: AnyBibDetail[] supplementaryContent: LinkedBibDetail extent: string[] - subjectHeadings: SubjectHeadingDetail + subjectLiteral: BibDetailURL[][] owner: string[] constructor( @@ -34,7 +34,7 @@ export default class BibDetails { this.extent = this.buildExtent() this.owner = this.buildOwner() // If we can't retreive subject headings from the SHEP API, we'll use the subjectLiteral - this.subjectHeadings = + this.subjectLiteral = this.buildSubjectHeadings() || this.buildSubjectLiterals() // these are the actual arrays of details that will be displayed this.annotatedMarcDetails = this.buildAnnotatedMarcDetails( @@ -136,11 +136,10 @@ export default class BibDetails { ] .map((fieldMapping: FieldMapping): AnyBibDetail => { let detail: AnyBibDetail - // TODO: standardize detail building by returning array of strings from all instance variables, so the detail can be returned from buildStandardDetail. That way, we won't be maintaining two different locations for labels. if (fieldMapping.field === "contributorLiteral") detail = this.buildInternalLinkedDetail(fieldMapping) - else if (fieldMapping.field === "subjectLiteral") - detail = this.subjectHeadings + // else if (fieldMapping.field === "subjectLiteral") + // detail = this.subjectHeadings else detail = this.buildStandardDetail(fieldMapping) return detail }) @@ -376,21 +375,16 @@ export default class BibDetails { return this.buildExternalLinkedDetail(convertToSentenceCase(label), values) } - buildSubjectHeadings(): SubjectHeadingDetail { + buildSubjectHeadings(): BibDetailURL[][] { if (!this.bib.subjectHeadings) return const subjectHeadingsUrls = this.bib.subjectHeadings.map((heading) => this.flattenSubjectHeadingUrls(heading) ) - return ( - subjectHeadingsUrls?.length && { - label: "Subject", - value: subjectHeadingsUrls, - } - ) + return subjectHeadingsUrls?.length && subjectHeadingsUrls } - buildSubjectLiterals(): SubjectHeadingDetail { + buildSubjectLiterals(): BibDetailURL[][] { if (!this.bib.subjectLiteral) return const subjectLiteralUrls = this.bib.subjectLiteral.map( (subject: string) => { @@ -412,10 +406,7 @@ export default class BibDetails { }) } ) - return { - label: "Subject", - value: subjectLiteralUrls, - } + return subjectLiteralUrls } constructSubjectLiteralsArray(subject: string) { diff --git a/src/models/modelTests/BibDetails.test.ts b/src/models/modelTests/BibDetails.test.ts index dd9ea8bc0..d91bd2514 100644 --- a/src/models/modelTests/BibDetails.test.ts +++ b/src/models/modelTests/BibDetails.test.ts @@ -73,96 +73,90 @@ describe("Bib model", () => { }) describe("subjectHeadings", () => { it("correctly formats the subjectHeading urls when the subjectHeadings are present in the bib result", () => { - const subjectHeadingsObject = { - label: "Subject", - value: [ - [ - { - url: "/subject_headings/cf347108-e1f2-4c0f-808a-ac4ace2f0765?label=Cortanze%2C%20G%C3%A9rard%20de", - urlLabel: "Cortanze, Gérard de", - }, - { - url: "/subject_headings/74746d11-638b-4cfb-a72a-9a2bd296e6fd?label=Cortanze%2C%20G%C3%A9rard%20de%20--%20Childhood%20and%20youth", - urlLabel: "Childhood and youth", - }, - ], - [ - { - url: "/subject_headings/5fd065df-b4e9-48cb-b13c-ea15f36b96b4?label=Authors%2C%20French", - urlLabel: "Authors, French", - }, - { - url: "/subject_headings/e43674a7-5f02-44f1-95cd-dbcc776331b7?label=Authors%2C%20French%20--%2020th%20century", - urlLabel: "20th century", - }, - { - url: "/subject_headings/9391bc26-e44c-44ac-98cc-e3800da51926?label=Authors%2C%20French%20--%2020th%20century%20--%20Biography", - urlLabel: "Biography", - }, - ], - [ - { - url: "/subject_headings/3a779ed6-8a07-4d27-80ef-e0c2b10fe78e?label=Autobiographical%20Narrative", - urlLabel: "Autobiographical Narrative", - }, - ], + const subjectHeadings = [ + [ + { + url: "/subject_headings/cf347108-e1f2-4c0f-808a-ac4ace2f0765?label=Cortanze%2C%20G%C3%A9rard%20de", + urlLabel: "Cortanze, Gérard de", + }, + { + url: "/subject_headings/74746d11-638b-4cfb-a72a-9a2bd296e6fd?label=Cortanze%2C%20G%C3%A9rard%20de%20--%20Childhood%20and%20youth", + urlLabel: "Childhood and youth", + }, + ], + [ + { + url: "/subject_headings/5fd065df-b4e9-48cb-b13c-ea15f36b96b4?label=Authors%2C%20French", + urlLabel: "Authors, French", + }, + { + url: "/subject_headings/e43674a7-5f02-44f1-95cd-dbcc776331b7?label=Authors%2C%20French%20--%2020th%20century", + urlLabel: "20th century", + }, + { + url: "/subject_headings/9391bc26-e44c-44ac-98cc-e3800da51926?label=Authors%2C%20French%20--%2020th%20century%20--%20Biography", + urlLabel: "Biography", + }, + ], + [ + { + url: "/subject_headings/3a779ed6-8a07-4d27-80ef-e0c2b10fe78e?label=Autobiographical%20Narrative", + urlLabel: "Autobiographical Narrative", + }, ], - } - expect(bibWithSubjectHeadingsModel.subjectHeadings).toMatchObject( - subjectHeadingsObject + ] + expect(bibWithSubjectHeadingsModel.subjectLiteral).toStrictEqual( + subjectHeadings ) }) it("falls back to subject literals when subject headings are absent in the bib and correctly formats the urls", () => { const filterQueryForSubjectLiteral = "/search?filters[subjectLiteral]=" - const subjectHeadingsObject = { - label: "Subject", - value: [ - [ - { - url: `${filterQueryForSubjectLiteral}${encodeURI( - "Authors, French" - )}`, - urlLabel: "Authors, French", - }, - { - url: `${filterQueryForSubjectLiteral}${encodeURI( - "Authors, French -- 20th century" - )}`, - urlLabel: "20th century", - }, - { - url: `${filterQueryForSubjectLiteral}${encodeURI( - "Authors, French -- 20th century -- Biography" - )}`, - urlLabel: "Biography", - }, - ], - [ - { - url: `${filterQueryForSubjectLiteral}${encodeURI( - "Autobiographical Narrative" - )}`, - urlLabel: "Autobiographical Narrative", - }, - ], - [ - { - url: `${filterQueryForSubjectLiteral}${encodeURI( - "Cortanze, Gérard de" - )}`, - urlLabel: "Cortanze, Gérard de", - }, - { - url: `${filterQueryForSubjectLiteral}${encodeURI( - "Cortanze, Gérard de -- Childhood and youth" - )}`, - urlLabel: "Childhood and youth", - }, - ], + const subjectHeadings = [ + [ + { + url: `${filterQueryForSubjectLiteral}${encodeURI( + "Authors, French" + )}`, + urlLabel: "Authors, French", + }, + { + url: `${filterQueryForSubjectLiteral}${encodeURI( + "Authors, French -- 20th century" + )}`, + urlLabel: "20th century", + }, + { + url: `${filterQueryForSubjectLiteral}${encodeURI( + "Authors, French -- 20th century -- Biography" + )}`, + urlLabel: "Biography", + }, + ], + [ + { + url: `${filterQueryForSubjectLiteral}${encodeURI( + "Autobiographical Narrative" + )}`, + urlLabel: "Autobiographical Narrative", + }, + ], + [ + { + url: `${filterQueryForSubjectLiteral}${encodeURI( + "Cortanze, Gérard de" + )}`, + urlLabel: "Cortanze, Gérard de", + }, + { + url: `${filterQueryForSubjectLiteral}${encodeURI( + "Cortanze, Gérard de -- Childhood and youth" + )}`, + urlLabel: "Childhood and youth", + }, ], - } - expect(bibWithNoParallelsModel.subjectHeadings).toMatchObject( - subjectHeadingsObject + ] + expect(bibWithNoParallelsModel.subjectLiteral).toStrictEqual( + subjectHeadings ) }) })