Skip to content

Commit

Permalink
Add basic tests to search results
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Oct 19, 2023
1 parent dcde01a commit 394fc5b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/SearchResult/SearchResult.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react"
import { render, screen } from "@testing-library/react"
import SearchResult from "./SearchResult"
import SearchResultsBib from "../../models/SearchResultsBib"

describe("SearchResult with Physical Items", () => {
beforeEach(() => {
const bib = new SearchResultsBib({ numItemsTotal: 2 })
bib.title = "Bib Title"
bib.id = "b12345678"
bib.materialType = "Text"
bib.publicationStatement = "Publication Statement"
bib.yearPublished = "1999"
render(<SearchResult bib={bib} />)
})

it("renders a title link with the correct bib href", async () => {
const resultTitleLink = screen.getByRole("link", { name: "Bib Title" })
expect(resultTitleLink).toHaveAttribute("href", "/bib/b12345678")
})

it("renders the primary bib fields", async () => {
screen.getByText("Text")
screen.getByText("Publication Statement")
screen.getByText("1999")
screen.getByText("2 Items")
})
})

describe("SearchResult with Electronic Resources", () => {
it("renders the correct item message for bib with electronic resources", async () => {
const bib = new SearchResultsBib({ electronicResources: [{}] })
render(<SearchResult bib={bib} />)
screen.getByText("1 Resource")
})
})

0 comments on commit 394fc5b

Please sign in to comment.