A /watch link is opened by whoever it was sent to — signed out, often on a phone on mobile data — and it booted through main.tsx: every app provider, the app's i18n (every locale of every area), the flag sprites, ~392 KB gzip before the player could start. It now has its own HTML entry, watch.html → watchMain.tsx, which imports WatchPage and what it renders; the server hands every /watch/ path that page (the OG block injected as before), and vite dev does the same. Measured on the build: /watch JS 290 → 87 KB gzip, CSS 104 → 19 KB; the app's own bytes unchanged. Two leaks had to go for that: lib/format imported the app's i18n for one "just now" string (the relative-time formatters now take `t`, like the file's other t-formatters), and the boundary's crash copy came from the same i18n (CrashBoundary takes its copy; ErrorBoundary is the app's wrapper, the watch entry gives it the page's own strings). The page's popover tree went too: it renders no popover. Held by: a contract test walking the entry's runtime imports, naming the path to anything only the app may load (red on a planted i18n import in lib/format), and holding watch.html's head equal to index.html's; a DB-lane test that every /watch/ path gets the player's page with the link's OG tags and app paths get the app (red on the old routing). Screenshots at 375 px, EN and HU, video / audio / password / gone / wrong password / unlocked: identical to the old entry's, bar the video's buffered bar.
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
// @vitest-environment jsdom
|
|
//
|
|
// docs/DESIGN.md "Copy": a relative time in a list carries the exact moment on hover.
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { cleanup, render } from "@testing-library/react";
|
|
import { formatDateTime, formatDateTimeSec, relativeTime } from "../../lib/format";
|
|
import i18n from "../../i18n"; // the real instance, in English: the component names time in the UI language
|
|
import { RelativeTime } from "./RelativeTime";
|
|
|
|
afterEach(cleanup);
|
|
|
|
const THREE_DAYS_AGO = new Date(Date.now() - 3 * 86400_000).toISOString();
|
|
|
|
describe("RelativeTime", () => {
|
|
it("says how long ago, and names the exact minute on hover", () => {
|
|
const { container } = render(<RelativeTime at={THREE_DAYS_AGO} />);
|
|
const el = container.querySelector("time")!;
|
|
expect(el.textContent).toBe(relativeTime(THREE_DAYS_AGO, "en", i18n.t));
|
|
expect(el.getAttribute("title")).toBe(formatDateTime(THREE_DAYS_AGO, "en"));
|
|
expect(el.getAttribute("dateTime")).toBe(THREE_DAYS_AGO);
|
|
});
|
|
|
|
it("takes epoch millis, and the log form with seconds", () => {
|
|
const ms = Date.parse(THREE_DAYS_AGO);
|
|
const { container } = render(<RelativeTime at={ms} seconds />);
|
|
expect(container.querySelector("time")!.getAttribute("title")).toBe(
|
|
formatDateTimeSec(THREE_DAYS_AGO, "en"),
|
|
);
|
|
});
|
|
|
|
it("shows the placeholder for a missing or unreadable moment, never a bare title", () => {
|
|
const { container } = render(
|
|
<>
|
|
<RelativeTime at={null} empty="—" />
|
|
<RelativeTime at="not a date" />
|
|
</>,
|
|
);
|
|
expect(container.textContent).toBe("—");
|
|
expect(container.querySelector("time")).toBeNull();
|
|
});
|
|
});
|