import { afterAll, describe, expect, test } from "bun:test"; import { getComposeIntentWaypoints } from "@aturi.to/waypoints"; import { t } from "../../src/lib/i18n/index.ts"; import { shareMenu } from "../../src/views/share.ts"; import { cleanupWikiAndDependents } from "../helpers/cleanup.ts"; import { ALICE, createDiff, emitNote, emitRevision, emitWiki, } from "../integration/helpers.ts"; import { fetch } from "../integration/http-helpers.ts"; const msg = t("en"); const NOTE_URL = "https://lichen.wiki/@alice.test/kitchen/risotto"; describe("shareMenu", () => { test("offers every client that prefills the post text", () => { const prefilling = getComposeIntentWaypoints().filter( (w) => w.composeIntent?.textParam, ); expect(prefilling.length).toBeGreaterThan(1); const html = shareMenu("Risotto", NOTE_URL, msg); for (const waypoint of prefilling) { expect(html).toContain(waypoint.name); expect(html).toContain(waypoint.composeIntent?.url ?? ""); } }); test("omits clients that route the intent but drop the text", () => { const dropping = getComposeIntentWaypoints().filter( (w) => !w.composeIntent?.textParam, ); expect(dropping.length).toBeGreaterThan(0); const html = shareMenu("Risotto", NOTE_URL, msg); for (const waypoint of dropping) { expect(html).not.toContain(waypoint.name); } }); test("carries the title and URL into every link", () => { const html = shareMenu("Risotto", NOTE_URL, msg); const hrefs = [...html.matchAll(/href="([^"]+)"/g)].map((m) => m[1] ?? ""); expect(hrefs.length).toBeGreaterThan(1); for (const href of hrefs) { const text = new URL(href.replaceAll("&", "&")).searchParams.get( "text", ); expect(text).toBe(`Risotto ${NOTE_URL}`); } }); test("needs no script, per the CSP", () => { const html = shareMenu("Risotto", NOTE_URL, msg); expect(html).toContain(" { const html = shareMenu('">', NOTE_URL, msg); expect(html).not.toContain(""); }); }); describe("note page", () => { const SLUG = "share-menu-wiki"; const wikiUri = emitWiki(ALICE.did, "Share Wiki", "public", SLUG).uri; const noteUri = emitNote(ALICE.did, "risotto", "Risotto", wikiUri).uri; emitRevision(ALICE.did, noteUri, createDiff("", "# Risotto\n")); afterAll(() => { cleanupWikiAndDependents(SLUG); }); test("renders the share menu", async () => { const res = await fetch("GET", `/@${ALICE.handle}/${SLUG}/risotto`); const html = await res.text(); expect(res.status).toBe(200); expect(html).toContain("intent/compose"); }); });