feat(web): Highlight (XSS-safe) + SearchResultRow components

This commit is contained in:
2026-06-04 12:34:27 +02:00
parent de830999d4
commit ee65b27595
3 changed files with 89 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import { expect, test } from "vitest";
import { render, screen } from "@testing-library/react";
import { Highlight } from "./highlight";
test("renders matched segments as <mark> and plain text around them", () => {
render(<Highlight text={"cast \x02bronze\x03 with patina"} />);
const mark = screen.getByText("bronze");
expect(mark.tagName).toBe("MARK");
expect(document.body).toHaveTextContent("cast bronze with patina");
});
test("renders plain text unchanged when there are no markers", () => {
render(<Highlight text="no markers here" />);
expect(document.body).toHaveTextContent("no markers here");
expect(screen.queryByRole("mark")).toBeNull();
});