// PageCaptureFacts (release 37 S4): a page record's capture in plain words. // // Run with: node_modules/.bin/tsx --test components/PageCaptureFacts.test.ts import { test } from "node:test"; import assert from "node:assert/strict"; import * as React from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { PageCaptureFacts } from "./PageCaptureFacts"; import { pageCaptureView, PAGE_NO_CONTENT_LINE } from "../lib/waybackPages/view"; (globalThis as { React?: typeof React }).React = React; test("a shell capture: the kind, no content, the fallback note, both links", () => { const url = "https://x.example/someone"; const v = pageCaptureView({ id: "20220101000000-0123456789ab", text: "", page: { originalUrl: url, captureTs: "20220101000000", waybackUrl: `https://web.archive.org/web/20220101000000/${url}`, rawUrl: `https://web.archive.org/web/20220101000000id_/${url}`, kind: "x-profile", noContent: true, extractor: "generic", extractorVersion: 1, extractorFallback: { from: "x", fromVersion: 1, error: "boom" }, }, })!; const html = renderToStaticMarkup(React.createElement(PageCaptureFacts, { view: v })); assert.match(html, /data-page-capture="x-profile"/); assert.match(html, /X\/Twitter profile ยท captured 2022-01-01/); assert.ok(html.includes(PAGE_NO_CONTENT_LINE)); assert.match(html, /data-page-fallback/); assert.match(html, /Original \(may be gone\)/); assert.match(html, /Wayback Machine copy, 2022-01-01/); const bare = renderToStaticMarkup(React.createElement(PageCaptureFacts, { view: v, links: false })); assert.doesNotMatch(bare, /may be gone/); });