Files
siftlode/frontend/src/features/player/descriptionLinks.dom.test.tsx
T
peter 63a0fecc8b refactor(frontend): the flat components/ folder moves into shell/, modules/<page>/ and features/<name>/
A pure move (git mv, history kept): 333 files leave components/, which now holds only the platform
layer (ui/) and the legal pages. The shell is the frame (App, header, nav rail, palette, boot); each
page lives in modules/<page>/ with its rail, store and tests; what several pages share sits in
features/<name>/; the shared-link page is watch/. Domain-free helpers went straight to ui/
(ViewSwitcher, FilterRail, the confirm dialog, the language switcher, the copy rows).

Every relative specifier was rewritten (imports, dynamic imports, vi.mock, new URL), and the
contract tests that scan sources now scan the whole app source, not only components/ — each glob
was counted before and after so none went green over fewer files. The locale-format rule matched
`/src/components/` only, so the move would have taken ~300 files out from under its i18n-singleton
check; it now covers every folder that holds components, with a test per folder.
2026-10-22 23:12:45 +02:00

44 lines
1.6 KiB
TypeScript

// @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(
<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).");
});
});