Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Note SPBoucher AI8 * File : tests/e2e/mobile-data.spec.ts9 * Module : tests10 * Repository : https://git.spboucher.ai/note-spboucher-ai11 * Project Website : https://note.spboucher.ai12 * Created : 2026-11-1713 * Last Modified : 2026-11-1714 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { test, expect, type Page } from "@playwright/test";44import { apiCall, docOf, para, expectNoHorizontalOverflow, sql } from "./helpers";4546/** Phone journeys on structured data: a database, a property change, an export, an agent proposal. Same three viewports as mobile.spec.ts. */47const made: string[] = []; const execs: string[] = [];48const uniq = (t: { project: { name: string } }, s: string) => `${s} ${t.project.name} ${Date.now().toString(36)}`;49test.afterAll(async () => { if (execs.length) await sql`delete from ai_executions where id = any(${execs}::uuid[])`; if (made.length) { await sql`delete from tasks where page_id = any(${made}::uuid[])`; await sql`delete from pages where id = any(${made}::uuid[]) or parent_id = any(${made}::uuid[])`; } });50async function seedDb(page: Page, title: string) {51 const c = await apiCall(page, "POST", "/api/pages", { title, type: "database", section: "databases" }); expect(c.status).toBe(201); made.push(c.body.id);52 expect((await apiCall(page, "POST", `/api/databases/${c.body.id}/apply-template`, { template: "tasks" })).status).toBe(200);53 for (const r of ["E2E row with a long title that has to wrap on a narrow phone", "E2E short row"]) expect((await apiCall(page, "POST", `/api/databases/${c.body.id}/rows`, { title: r })).status).toBeLessThan(300);54 return c.body.id as string;55}5657test("a database on a phone: cards, every view fits, a new row, a property changed from the row sheet", async ({ page }, t) => {58 await page.goto("/"); const id = await seedDb(page, uniq(t, "E2E-db")); await page.goto(`/p/${id}`);59 const card = page.getByRole("button", { name: "Open E2E short row" }); await expect(card).toBeVisible(); await expectNoHorizontalOverflow(page);60 for (const b of [page.getByRole("button", { name: "New", exact: true }), page.getByRole("button", { name: /View options/ })]) expect((await b.boundingBox())!.height).toBeGreaterThanOrEqual(44);61 // every saved view renders without pushing the page sideways62 const tabs = page.getByRole("tab"); const n = await tabs.count(); expect(n).toBeGreaterThanOrEqual(3);63 for (let i = 0; i < n; i++) { if ((await tabs.nth(i).getAttribute("aria-selected")) !== "true") await tabs.nth(i).click(); await expect(tabs.nth(i)).toHaveAttribute("aria-selected", "true"); await page.waitForTimeout(350); await test.step(`view ${await tabs.nth(i).innerText()}`, async () => { await expectNoHorizontalOverflow(page); await expect(page.locator("main")).not.toContainText(/couldn.t load|Application error/i); }); }64 await tabs.first().click(); await expect(tabs.first()).toHaveAttribute("aria-selected", "true"); // (a second tap on the selected view opens its settings — not wanted here)65 // quick create keeps its draft66 await page.getByRole("button", { name: "New", exact: true }).click(); let sheet = page.getByRole("dialog"); await sheet.getByLabel("Title").fill("E2E created on phone"); await page.keyboard.press("Escape");67 await page.getByRole("button", { name: "New", exact: true }).click(); sheet = page.getByRole("dialog"); await expect(sheet.getByLabel("Title"), "the draft survives closing the sheet").toHaveValue("E2E created on phone");68 await sheet.getByRole("button", { name: "Create row" }).click(); await expect(page.getByRole("button", { name: "Open E2E created on phone" })).toBeVisible();69 // change a property from the row sheet70 await card.click(); sheet = page.getByRole("dialog").first(); await expect(sheet.getByLabel("Title")).toHaveValue("E2E short row");71 await sheet.getByRole("button", { name: "Status" }).click(); await page.getByRole("dialog").last().getByText("In progress", { exact: true }).click();72 await expect.poll(async () => JSON.stringify((await sql`select r.values from database_rows r join pages p on p.id = r.page_id where p.title = 'E2E short row' and r.database_id in (select id from databases where page_id = ${id})`)[0]?.values ?? {}), { timeout: 10_000 }).toContain("doing");73 await expectNoHorizontalOverflow(page);74 await page.reload(); await expect(page.getByRole("button", { name: "Open E2E short row" })).toBeVisible(); await expect(page.locator("main").getByText("In progress", { exact: true }).first(), "the card shows the new value after a reload").toBeVisible();75 // the full grid is still reachable and scrolls inside itself76 await page.getByRole("button", { name: /View options/ }).click(); await page.getByRole("dialog").getByRole("button", { name: /Grid/ }).click(); await page.getByRole("dialog").getByRole("button", { name: "Done", exact: true }).click();77 await expect(page.locator(".db-scroll table")).toBeVisible(); await expectNoHorizontalOverflow(page);78 expect(await page.locator(".db-scroll").evaluate((el) => ["auto", "scroll"].includes(getComputedStyle(el).overflowX))).toBe(true);79});8081test("export: a page as Markdown; the whole workspace only with a fresh passkey; the report says what is inside", async ({ page }, t) => {82 await page.goto("/"); const title = uniq(t, "E2E-export"); const c = await apiCall(page, "POST", "/api/pages", { title, content: docOf(para("exported paragraph")) }); made.push(c.body.id);83 const md = await page.request.get(`/api/export?format=md&pageId=${c.body.id}`); expect(md.status()).toBe(200); const text = await md.text(); expect(text).toContain("exported paragraph"); expect(text).toContain(title);84 await sql`update sessions set verified_at = now() - interval '10 minutes' where revoked_at is null`;85 const stale = await page.request.get("/api/export?format=json"); expect(stale.status(), "whole-workspace export needs a fresh passkey").toBe(403); expect((await stale.json()).code).toBe("reauth_required");86 await sql`update sessions set verified_at = now() where revoked_at is null`;87 const full = await page.request.get("/api/export?format=json&versions=0"); expect(full.status()).toBe(200); const j = await full.json();88 expect(j.report, "the export carries its own report").toBeTruthy(); expect(j.pages.some((p: any) => p.id === c.body.id)).toBe(true);89 const [a] = await sql`select action from audit_logs where action like 'export%' order by created_at desc limit 1`; expect(a?.action).toBeTruthy();90 await page.goto("/settings#data"); await expect(page.getByText("Workspace ZIP")).toBeVisible(); await expectNoHorizontalOverflow(page);91});9293test("an agent proposal is reviewed on the phone: preview, approve, the change is applied, undo restores", async ({ page }, t) => {94 await page.goto("/"); const title = uniq(t, "E2E-agent"); const c = await apiCall(page, "POST", "/api/pages", { title, content: docOf(para("page to tag")) }); made.push(c.body.id);95 const [ws] = await sql`select id from workspaces limit 1`; const now = new Date().toISOString();96 const proposal = { idx: 0, tool: "propose_tags", kind: "tags", rationale: "Looks like an end-to-end test page.", title: `Tag “${title}”`, destructive: false, status: "proposed", pageId: c.body.id, before: { label: "Tags now", lines: ["(none)"] }, after: { label: "Tags after", lines: ["#e2e-agent-tag"] }, at: now, payload: { pageId: c.body.id, add: ["e2e-agent-tag"] } };97 const [ex] = await sql`insert into ai_executions (workspace_id, agent, task, model, status, scopes, proposed_changes, tools_invoked, documents_accessed, outcome, result, started_at, finished_at) values (${ws.id}, 'suggest_tags', 'Suggest tags', 'test-seed', 'awaiting_approval', ${sql.json(["read:page", "propose:tags"])}, ${sql.json([proposal])}, ${sql.json([])}, ${sql.json([c.body.id])}, null, '1 proposal', now(), now()) returning id`; execs.push(ex.id);98 await page.goto("/ai/agents"); await expect(page.getByText("to review").first()).toBeVisible(); await page.getByText("to review").first().click();99 const card = page.getByRole("article", { name: "Proposal 1" }); await expect(card).toBeVisible(); await expect(card).toContainText("#e2e-agent-tag"); await expect(card).toContainText("Looks like an end-to-end test page."); await expectNoHorizontalOverflow(page);100 expect((await sql`select count(*)::int as n from page_tags where page_id = ${c.body.id}`)[0].n, "nothing is written before approval").toBe(0);101 await card.getByRole("button", { name: "Approve" }).click(); await expect(card.getByRole("button", { name: "Undo" })).toBeVisible({ timeout: 10_000 });102 expect((await sql`select t.name from page_tags pt join tags t on t.id = pt.tag_id where pt.page_id = ${c.body.id}`).map((r) => r.name)).toEqual(["e2e-agent-tag"]);103 await card.getByRole("button", { name: "Undo" }).click(); await expect(card.getByText(/Undone/)).toBeVisible({ timeout: 10_000 });104 expect((await sql`select count(*)::int as n from page_tags where page_id = ${c.body.id}`)[0].n).toBe(0);105 const acts = (await sql`select action from audit_logs where action like 'agent%' and created_at > now() - interval '1 minute'`).map((r) => r.action); expect(acts.length).toBeGreaterThan(0);106 await sql`delete from tags where name = 'e2e-agent-tag'`;107});108