fix(player): a description link keeps its sentence's punctuation and its own parentheses
The trailing .,;:!?)] was trimmed off the href and dropped from the text too, and a URL ending in a balanced ")" (a Wikipedia article) was cut short. The trim keeps a closing paren that has its opener, and the trimmed tail is put back after the link.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// @vitest-environment jsdom
|
||||
//
|
||||
// E28 review C6: 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(
|
||||
<div>
|
||||
{renderDescription(text, {
|
||||
currentId: "x",
|
||||
onSeek: vi.fn(),
|
||||
onLoadVideo: vi.fn(),
|
||||
t: ((k: string) => k) as unknown as TFunction,
|
||||
})}
|
||||
</div>,
|
||||
);
|
||||
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).");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user