// A page record's moment page (release 37 S4): the shot named as the Wayback // copy, the capture's kind and date, the version list, the two links. // // Run with: node_modules/.bin/tsx --test components/report/MomentArticle.page.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 MomentArticle from "./MomentArticle"; import { MOMENT_PAGE_FORMAT, REPORT_VIEWS_VERSION, type MomentPageView } from "../../lib/report/views"; import { pageCaptureView } from "../../lib/waybackPages/view"; import type { Post } from "../../lib/posts"; (globalThis as { React?: typeof React }).React = React; const URL_A = "https://blog.example/a.html"; const rec = (id: string, ts: string, text: string): Post => ({ id, slug: `pages/${id}`, channelSlug: "pages", author: "blog.example", createdAt: "2014-03-04T18:30:00.000Z", uploadDate: "20140304", text, url: URL_A, platform: "webpage", isReply: false, isRepost: false, links: [], page: { originalUrl: URL_A, captureTs: ts, waybackUrl: `https://web.archive.org/web/${ts}/${URL_A}`, rawUrl: `https://web.archive.org/web/${ts}id_/${URL_A}`, kind: "generic", extractor: "generic", extractorVersion: 1, }, }); test("a page record's moment page: the capture, its versions, the original and the Wayback copy", () => { const a = rec("20140305120000-0123456789ab", "20140305120000", "First."); const b = rec("20150611090000-0123456789ab", "20150611090000", "Second."); const view: MomentPageView = { format: MOMENT_PAGE_FORMAT, version: REPORT_VIEWS_VERSION, key: `pages/${b.id}`, kind: "post", record: { channel: "pages", id: b.id, title: "A Post", originalUrl: URL_A, originalLabel: "Original (may be gone)", downloads: [{ label: "Wayback Machine copy, 2015-06-11", url: b.page!.waybackUrl }], }, quote: "Second.", post: { author: "blog.example", text: "Second.", shot: "/media/posts/pages/x/shot.png", page: pageCaptureView(b, [a]) }, citedIn: [], }; const html = renderToStaticMarkup(React.createElement(MomentArticle, { view })); assert.match(html, /alt="Screenshot of the Wayback Machine copy, 2015-06-11"/); assert.match(html, /Web page ยท captured 2015-06-11/); assert.match(html, /2 captures of this page; text changed on 2015-06-11\./); assert.match(html, />Original \(may be gone\)