1
17import { test, expect } from "../fixtures";
18import { createPage, createBlock } from "../utils/api";
19import type { PageDto } from "../fixtures";
20
21interface VersionRow {
22 id: string;
23 version: number;
24 note: string | null;
25}
26
27test.describe("Versions compare/preview — P2 (T-150/T-151)", () => {
28 test("history → compare shows the diff → preview shows the snapshot text", async ({
29 authPage,
30 api,
31 freshWorkspace
32 }) => {
33 const ws = await freshWorkspace("Versions Space");
34 const page = (await createPage(api, ws.id, { title: "Versioned Doc" })) as PageDto;
35 const block = await createBlock(api, page.id, {
36 type: "PARAGRAPH",
37 content: { text: "Original text" }
38 });
39
40
41 const snap1 = await api.post(`/api/v1/pages/${page.id}/versions`, { data: { note: "snapshot-1" } });
42 expect(snap1.status(), await snap1.text()).toBe(201);
43 const up = await api.patch(`/api/v1/blocks/${block.id}`, { data: { content: { text: "Changed text" } } });
44 expect(up.status(), await up.text()).toBe(200);
45 const snap2 = await api.post(`/api/v1/pages/${page.id}/versions`, { data: { note: "snapshot-2" } });
46 expect(snap2.status(), await snap2.text()).toBe(201);
47
48
49 const list = (await (await api.get(`/api/v1/pages/${page.id}/versions`)).json()) as { data: VersionRow[] };
50 expect(list.data.map((v) => v.version).sort()).toEqual([1, 2]);
51 const v2 = list.data.find((v) => v.version === 2)!;
52 const v1 = list.data.find((v) => v.version === 1)!;
53
54
55 await authPage.goto(`/w/${ws.slug}/page/${page.id}`);
56 const historyButton = authPage.getByRole("button", { name: "Page history" });
57 await expect(historyButton).toBeVisible({ timeout: 20_000 });
58 await historyButton.click();
59
60
61 const menu = authPage.getByRole("menu", { name: "Page history" });
62 await expect(menu).toBeVisible();
63 await expect(menu).toContainText("v2 — snapshot-2");
64 await expect(menu).toContainText("v1 — snapshot-1");
65
66
67 await menu.getByTestId(`version-compare-${v2.id}`).click();
68 const dialog = authPage.getByTestId("version-compare-dialog");
69 await expect(dialog).toBeVisible({ timeout: 15_000 });
70 await expect(dialog.getByTestId("version-diff-from")).toHaveValue(String(v1.version), { timeout: 10_000 });
71 await expect(dialog.getByTestId("version-diff-summary")).toContainText("1 modified", { timeout: 10_000 });
72 await expect(dialog.getByTestId("version-diff-summary")).toContainText("0 added");
73 await expect(dialog.getByTestId(`version-diff-item-${block.id}`)).toContainText("content");
74
75
76 await dialog.getByTestId("version-tab-preview").click();
77 const blocksEl = dialog.getByTestId("version-preview-blocks");
78 await expect(blocksEl.getByTestId(`version-preview-block-${block.id}`)).toContainText("Changed text", {
79 timeout: 15_000
80 });
81
82
83 await expect(dialog.getByTestId("version-preview-blocks")).toContainText("Versioned Doc");
84 });
85});
86