From 394fc5bbac1360027ff476be1ed1945d4e27cc43 Mon Sep 17 00:00:00 2001 From: Diego Cohen Date: Thu, 19 Oct 2023 15:35:49 -0400 Subject: [PATCH] Add basic tests to search results --- .../SearchResult/SearchResult.test.tsx | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/components/SearchResult/SearchResult.test.tsx diff --git a/src/components/SearchResult/SearchResult.test.tsx b/src/components/SearchResult/SearchResult.test.tsx new file mode 100644 index 000000000..1188ceab6 --- /dev/null +++ b/src/components/SearchResult/SearchResult.test.tsx @@ -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() + }) + + 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() + screen.getByText("1 Resource") + }) +})