From 386974c51e6b437b9f025ace21ef494722939055 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Wed, 3 Jan 2024 11:13:10 -0500 Subject: [PATCH] rename model and rm tests --- pages/bib/index.tsx | 4 +- src/components/BibPage/BibDetail.test.tsx | 6 +-- src/models/{BibDetails.tsx => BibDetails.ts} | 2 +- src/models/modelTests/Bib.test.ts | 46 ++++++++------------ 4 files changed, 23 insertions(+), 35 deletions(-) rename src/models/{BibDetails.tsx => BibDetails.ts} (99%) diff --git a/pages/bib/index.tsx b/pages/bib/index.tsx index bcd3cafd0..6035a50cf 100644 --- a/pages/bib/index.tsx +++ b/pages/bib/index.tsx @@ -5,10 +5,10 @@ import { yiddishBib, } from "../../__test__/fixtures/bibFixtures" import BibDetails from "../../src/components/BibPage/BibDetail" -import Bib from "../../src/models/BibDetails" +import BibDetailsModel from "../../src/models/BibDetails" const BibPage = () => { - const bibModel = new Bib(noParallels) + const bibModel = new BibDetailsModel(noParallels) const { topDetails, bottomDetails, holdingsDetails } = bibModel return [topDetails, bottomDetails, holdingsDetails] .filter((d) => d.length) diff --git a/src/components/BibPage/BibDetail.test.tsx b/src/components/BibPage/BibDetail.test.tsx index 1f78e781c..2e5423020 100644 --- a/src/components/BibPage/BibDetail.test.tsx +++ b/src/components/BibPage/BibDetail.test.tsx @@ -3,7 +3,7 @@ import { bibWithSupplementaryContent, noParallels, } from "../../../__test__/fixtures/bibFixtures" -import Bib from "../../models/BibDetails" +import BibDetailsModel from "../../models/BibDetails" import BibDetails from "./BibDetail" import { render, screen, act } from "@testing-library/react" @@ -13,8 +13,8 @@ import { MemoryRouterProvider } from "next-router-mock/MemoryRouterProvider" jest.mock("next/router", () => jest.requireActual("next-router-mock")) describe("BibDetail component", () => { - const suppBib = new Bib(bibWithSupplementaryContent) - const noParallelsBibModel = new Bib(noParallels) + const suppBib = new BibDetailsModel(bibWithSupplementaryContent) + const noParallelsBibModel = new BibDetailsModel(noParallels) it("internal link", async () => { mockRouter.push("/bib/b12345678") render(, { diff --git a/src/models/BibDetails.tsx b/src/models/BibDetails.ts similarity index 99% rename from src/models/BibDetails.tsx rename to src/models/BibDetails.ts index fdc0e4330..f4fd2175e 100644 --- a/src/models/BibDetails.tsx +++ b/src/models/BibDetails.ts @@ -2,7 +2,7 @@ import type { ProcessedSearchResult, SearchResult } from "../types/searchTypes" import type { LinkedBibDetail, BibDetail } from "../types/bibDetail" import { preProcess } from "../utils/bibModelPreprocessing" -export default class Bib { +export default class BibDetailsModel { bib: ProcessedSearchResult constructor(bib: SearchResult) { diff --git a/src/models/modelTests/Bib.test.ts b/src/models/modelTests/Bib.test.ts index e0acde4a3..9f526c83e 100644 --- a/src/models/modelTests/Bib.test.ts +++ b/src/models/modelTests/Bib.test.ts @@ -4,14 +4,16 @@ import { parallelsBib, yiddishBib, } from "../../../__test__/fixtures/bibFixtures" -import Bib from "../BibDetails" +import BibDetailsModel from "../BibDetails" describe("Bib model", () => { - const bibWithSupContentModel = new Bib(bibWithSupplementaryContent) - const bibWithParallelsModel = new Bib(parallelsBib) + const bibWithSupContentModel = new BibDetailsModel( + bibWithSupplementaryContent + ) + const bibWithParallelsModel = new BibDetailsModel(parallelsBib) describe("extent", () => { it("should add a semicolon after extent if there is not one already", () => { - const bib = new Bib({ + const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], extent: ["99 bottles of beer"], dimensions: ["99 x 99 cm"], @@ -19,7 +21,7 @@ describe("Bib model", () => { expect(bib.extent.value[0].includes("; ")) }) it("should append dimensions to extent", () => { - const bib = new Bib({ + const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], extent: ["99 bottles of beer"], dimensions: ["99 x 99 cm"], @@ -27,7 +29,7 @@ describe("Bib model", () => { expect(bib.extent.value[0]).toBe("99 bottles of beer; 99 x 99 cm") }) it("should not add semicolon if it already is in extent", () => { - const bib = new Bib({ + const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], extent: ["700 sheets of woven gold; "], dimensions: ["1 x 1 in."], @@ -35,11 +37,11 @@ describe("Bib model", () => { expect(bib.extent.value[0]).toBe("700 sheets of woven gold; 1 x 1 in.") }) it("should remove semicolon if there is no dimensions", () => { - const bib = new Bib({ + const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], extent: ["700 sheets of woven gold; "], }) - const anotherBib = new Bib({ + const anotherBib = new BibDetailsModel({ identifier: [{ uri: "123456" }], extent: ["700 sheets of woven gold;"], }) @@ -47,14 +49,14 @@ describe("Bib model", () => { expect(anotherBib.extent.value[0]).toBe("700 sheets of woven gold") }) it("should display dimensions if there are dimensions and no extent", () => { - const bib = new Bib({ + const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }], dimensions: ["1,000,000mm x 7ft"], }) expect(bib.extent.value[0]).toBe("1,000,000mm x 7ft") }) it("should do nothing if there are no dimensions or extent", () => { - const bib = new Bib({ identifier: [{ uri: "123456" }] }) + const bib = new BibDetailsModel({ identifier: [{ uri: "123456" }] }) expect(bib.extent).toBeNull() }) }) @@ -93,7 +95,7 @@ describe("Bib model", () => { }) describe("internal linking fields", () => { it("can handle missing fields", () => { - const bogusBib = new Bib({ + const bogusBib = new BibDetailsModel({ ...parallelsBib, contributorLiteral: undefined, }) @@ -122,17 +124,8 @@ describe("Bib model", () => { }) describe("preprocessing", () => { - it("compresses the subject literal array, no parallel subject literal", () => { - const model = new Bib(parallelsBib) - expect(model.bib.compressedSubjectLiteral).toStrictEqual([ - "Civilization", - "Serbia > Civilization > Periodicals", - "Serbia", - "Serbia and Montenegro", - ]) - }) it("combines parallels and primaries with null values", () => { - const model = new Bib(parallelsBib) + const model = new BibDetailsModel(parallelsBib) expect(model.bib.contributorLiteral).toStrictEqual([ 'Народна библиотека "Стефан Првовенчани," issuing body.', 'Narodna biblioteka "Stefan Prvovenčani", issuing body.', @@ -148,14 +141,14 @@ describe("Bib model", () => { ]) }) it("parallels RTL script", () => { - const model = new Bib(yiddishBib) + const model = new BibDetailsModel(yiddishBib) expect(model.bib.title).toStrictEqual([ "‏ספר חורוסטוב = Chrostkow book", "Sefer Ḥorosṭḳov = Chorostkow book", ]) }) it("groups notes", () => { - const model = new Bib(parallelsBib) + const model = new BibDetailsModel(parallelsBib) expect(model.bib.groupedNotes).toStrictEqual({ "Linking Entry (note)": [ "Has supplement, <2005-> : Preporučeno, ISSN 1452-3531", @@ -171,13 +164,8 @@ describe("Bib model", () => { }) }) it("can handle no parallels, and no notes", () => { - const model = new Bib(noParallels) + const model = new BibDetailsModel(noParallels) expect(model.bib.groupedNotes).toStrictEqual({}) - expect(model.bib.compressedSubjectLiteral).toStrictEqual([ - "Authors, French > 20th century > Biography", - "Autobiographical Narrative", - "Cortanze, Gérard de > Childhood and youth", - ]) }) }) })