1
16import * as fs from "node:fs";
17import { test, expect } from "../fixtures";
18import { createPage, createBlock } from "../utils/api";
19import type { PageDto } from "../fixtures";
20
21test.describe("T-180 page Markdown export", () => {
22 test("topbar More → Export as Markdown downloads the rendered markdown", async ({
23 authPage,
24 api,
25 freshWorkspace
26 }) => {
27 const ws = await freshWorkspace("Export Space");
28 const page = await createPage(api, ws.id, { title: "Export Doc" });
29 const heading = await createBlock(api, page.id, {
30 type: "HEADING_1",
31 content: { text: "Section" }
32 });
33 await createBlock(api, page.id, {
34 type: "PARAGRAPH",
35 content: { text: "Body text" },
36 afterBlockId: heading.id
37 });
38
39 await authPage.goto(`/w/${ws.slug}/page/${page.id}`);
40
41 await authPage.getByRole("button", { name: "More actions" }).waitFor();
42
43 const [download] = await Promise.all([
44 authPage.waitForEvent("download", { timeout: 20_000 }),
45 (async () => {
46 await authPage.getByRole("button", { name: "More actions" }).click();
47 await authPage.getByRole("menuitem", { name: "Export as Markdown…" }).click();
48 })()
49 ]);
50
51
52 expect(download.suggestedFilename()).toBe("Export-Doc.md");
53 const dlPath = await download.path();
54 expect(dlPath, "Playwright captures the download to a temp file").toBeTruthy();
55 const md = await fs.promises.readFile(dlPath!, "utf8");
56 expect(md).toContain("# Export Doc");
57 expect(md).toContain("# Section");
58 expect(md).toContain("Body text");
59
60 expect(md.indexOf("Section")).toBeLessThan(md.indexOf("Body text"));
61 });
62
63 test("a non-member (NONE) is denied the export (403)", async ({ api, secondUser, freshWorkspace }) => {
64 const ws = await freshWorkspace("Export Deny");
65 const page = (await createPage(api, ws.id, { title: "Restricted" })) as PageDto;
66 await createBlock(api, page.id, { type: "PARAGRAPH", content: { text: "secret" } });
67
68
69 const { api: outsider } = await secondUser();
70 const res = await outsider.get(`/api/v1/pages/${page.id}/export/markdown`);
71 expect(res.status()).toBe(403);
72 });
73});
74