// @vitest-environment jsdom // // A link at the end of a sentence lost the punctuation after it — the trailing // `.,;:!?)]` was trimmed off the href and then dropped from the text too — and a URL whose own path // ends in a balanced ")" (a Wikipedia article) was cut short and broken. import { afterEach, describe, expect, it, vi } from "vitest"; import { cleanup, render } from "@testing-library/react"; import type { TFunction } from "i18next"; import { renderDescription } from "./descriptionLinks"; afterEach(cleanup); function shown(text: string) { const { container } = render(
{renderDescription(text, { currentId: "x", onSeek: vi.fn(), onLoadVideo: vi.fn(), t: ((k: string) => k) as unknown as TFunction, })}
, ); return { text: container.textContent, hrefs: [...container.querySelectorAll("a")].map((a) => a.getAttribute("href")), }; } describe("a link in a description", () => { it("keeps the punctuation after it in the text, out of the link", () => { const r = shown("See https://example.com/page. And (https://example.org/x), too!"); expect(r.text).toBe("See https://example.com/page. And (https://example.org/x), too!"); expect(r.hrefs).toEqual(["https://example.com/page", "https://example.org/x"]); }); it("keeps a balanced parenthesis that belongs to the address", () => { const r = shown("Read https://en.wikipedia.org/wiki/Mercury_(planet)."); expect(r.hrefs).toEqual(["https://en.wikipedia.org/wiki/Mercury_(planet)"]); expect(r.text).toBe("Read https://en.wikipedia.org/wiki/Mercury_(planet)."); }); });