1
23import { test, expect } from "../fixtures";
24import { createPage } from "../utils/api";
25import { waitForCondition } from "../utils/wait";
26
27const unique = (prefix: string) =>
28 `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
29
30
32async function recentViewedRecorded(
33 api: { get: (u: string) => Promise<{ json: () => Promise<unknown> }> },
34 itemType: string,
35 refId: string,
36): Promise<boolean> {
37 const res = await api.get("/api/v1/users/me/recent");
38 const body = (await res.json()) as { data: Array<{ itemType: string; refId: string }> };
39 return (body.data ?? []).some((it) => it.itemType === itemType && it.refId === refId);
40}
41
42test.describe("Confluence P2 — ⌘K home (T-153/T-154)", () => {
43 test("opening a page records it; the ⌘K home lists + resolves + navigates it", async ({
44 authPage,
45 api,
46 freshWorkspace,
47 }) => {
48 const ws = await freshWorkspace("Recent Viewed Space");
49 const token = unique("RECENTVIEW");
50 const page = await createPage(api, ws.id, { title: `${token} Launch Plan` });
51
52
53 await authPage.goto(`/w/${ws.id}/page/${page.id}`);
54 await authPage.getByText(`${token} Launch Plan`).first().waitFor({ timeout: 15_000 });
55
56
57 await waitForCondition(
58 authPage,
59 () => recentViewedRecorded(api, "page", page.id),
60 { timeoutMs: 10_000, message: "recent-viewed record did not persist" },
61 );
62
63
64
65 await authPage.getByTestId("search-button").click();
66 await expect(authPage.getByTestId("search-dialog")).toBeVisible();
67 await expect(authPage.getByTestId("search-recent-viewed")).toBeVisible();
68 const item = authPage.getByTestId("search-recent-viewed-item").filter({ hasText: token }).first();
69 await expect(item).toBeVisible({ timeout: 10_000 });
70
71 await item.click();
72 await authPage.waitForURL(/\/page\
73 expect(authPage.url()).toContain(`/page/${page.id}`);
74 });
75
76 test("a database open is recorded as a database; the home navigates to /databases/:id", async ({
77 authPage,
78 api,
79 freshWorkspace,
80 }) => {
81 const ws = await freshWorkspace("Recent DB Space");
82 const token = unique("RECENTDB");
83
84
85
86 const dbPage = (await (
87 await api.post(`/api/v1/workspaces/${ws.id}/pages`, {
88 data: { title: `${token} Inventory`, type: "database" },
89 })
90 ).json()) as { id: string; databaseId?: string };
91 if (!dbPage.databaseId) throw new Error(`no databaseId: ${JSON.stringify(dbPage)}`);
92 const dbId = dbPage.databaseId;
93
94
95
96 await authPage.goto(`/w/${ws.id}/databases/${dbId}`);
97 await waitForCondition(
98 authPage,
99 () => recentViewedRecorded(api, "database", dbId),
100 { timeoutMs: 10_000, message: "recent-viewed database record did not persist" },
101 );
102
103 await authPage.getByTestId("search-button").click();
104 const item = authPage
105 .getByTestId("search-recent-viewed-item")
106 .filter({ hasText: token })
107 .first();
108 await expect(item).toBeVisible({ timeout: 10_000 });
109 await item.click();
110 await authPage.waitForURL(/\/databases\
111 expect(authPage.url()).toContain(`/databases/${dbId}`);
112 });
113
114 test("Save persists the committed query; the home chip re-runs it", async ({
115 authPage,
116 api,
117 freshWorkspace,
118 }) => {
119 const ws = await freshWorkspace("Saved Search Space");
120 const token = unique("SAVEDSRCH");
121 await createPage(api, ws.id, { title: `${token} Budget` });
122
123 await authPage.goto(`/w/${ws.id}`);
124 await authPage.getByTestId("search-button").click();
125 await expect(authPage.getByTestId("search-dialog")).toBeVisible();
126
127
128 const input = authPage.getByTestId("search-input");
129 await input.fill(token);
130 await expect(authPage.getByTestId("search-result").first()).toBeVisible({
131 timeout: 10_000,
132 });
133 const save = authPage.getByTestId("search-save-current");
134 await expect(save).toBeVisible();
135 await save.click();
136
137
138 await waitForCondition(
139 authPage,
140 async () => {
141 const res = await api.get("/api/v1/users/me/saved-searches");
142 const body = (await res.json()) as { data: Array<{ name: string; queryJson: { q: string } }> };
143 return (body.data ?? []).some((s) => s.queryJson?.q === token);
144 },
145 { timeoutMs: 10_000, message: "saved search did not persist" },
146 );
147
148
149 await input.fill("");
150 const chip = authPage.getByTestId("search-saved-item").filter({ hasText: token }).first();
151 await expect(chip).toBeVisible({ timeout: 10_000 });
152
153
154 await chip.click();
155 await expect(input).toHaveValue(token);
156 });
157});
158