Skip to content

Commit

Permalink
rename model and rm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charmingduchess committed Jan 3, 2024
1 parent d70861e commit 386974c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pages/bib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/components/BibPage/BibDetail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(<BibDetails details={noParallelsBibModel.topDetails} />, {
Expand Down
2 changes: 1 addition & 1 deletion src/models/BibDetails.tsx → src/models/BibDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
46 changes: 17 additions & 29 deletions src/models/modelTests/Bib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,59 @@ 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"],
})
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"],
})
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."],
})
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;"],
})
expect(bib.extent.value[0]).toBe("700 sheets of woven gold")
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()
})
})
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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.',
Expand All @@ -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",
Expand All @@ -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",
])
})
})
})

0 comments on commit 386974c

Please sign in to comment.