/**
* The shared clinician share-link CREATE flow. It is mounted from two places
* — Settings → Sharing and the document detail sheet's Share action — so the
* test pins the two behaviours the document entry point relies on:
* 1. Mounted bare (the Settings default) it renders the create form with the
* 90-day-capped expiry, the attach affordance, the frozen-set warning,
* and no pre-attached document.
* 2. Mounted with `initialDocuments` + `initialLabel` (the document flow) it
* pre-fills the label and seeds the attached-document chip, so sharing a
* document lands on a create form already scoped to it.
*
* SSR-static render only (no jsdom), matching the sibling settings tests. The
* TanStack hooks are mocked; the QR (`qrcode`) only ever renders in an effect
* after a create, so it never runs under `renderToStaticMarkup`.
*
* Mutation checks (each verified red, then reverted):
* - seed `selectedLeaves` from `STANDARD_TEMPLATE_LEAVES` again → "starts a
* record link with an empty scope" goes red.
* - drop `selectedLeaves.size === 0` from the submit `disabled` expression →
* "refuses to mint a record link with an empty scope" goes red.
*/
import type { ReportLeafId } from "@/lib/report-selection/catalogue";
import { describe, expect, it, vi } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
vi.mock("@tanstack/react-query", () => ({
// The always-mounted ShareDocumentPicker reads via useQuery; the form
// itself creates via useMutation.
useQuery: () => ({ data: undefined, isPending: false, isError: false }),
useMutation: () => ({ mutate: vi.fn(), isPending: false }),
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
}));
import { I18nProvider } from "@/lib/i18n/context";
import {
ShareLinkCreateForm,
buildShareLinkCreatePayload,
} from "../share-link-create-form";
import type { PickedDocument } from "../share-document-picker";
function render(
props: {
documentOnly?: boolean;
initialDocuments?: PickedDocument[];
initialLabel?: string;
} = {},
locale: "en" | "de" = "en",
) {
return renderToStaticMarkup(
,
);
}
/** Whether the create control refuses the press. */
function createDisabled(html: string): boolean {
const button = html.match(
/