SPB Git

Repository Public

next-k-phones.spec.ts 11.5 KB 91 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Note SPBoucher AI8 * File             : tests/e2e/next-k-phones.spec.ts9 * Description      : the knowledge screens on phones (360×740, 375×667,10 *                    430×932, touch): no horizontal overflow, the bottom11 *                    navigation stays visible, one scroll container, panels12 *                    open as bottom sheets inside the viewport, touch targets13 *                    of the new controls are at least 44 px, and each screen14 *                    works with a finger (view switcher, insights sheet,15 *                    timeline filters, health drill-down, zoom levels, scope16 *                    selector).17 * Module           : tests18 * Repository       : https://git.spboucher.ai/note-spboucher-ai19 * Project Website  : https://note.spboucher.ai20 * Created          : 2026-11-1921 * Last Modified    : 2026-11-1922 *23 * Author           : Simon-Pierre Boucher24 * Position         : Professor of Finance25 * Institution      : Université du Québec en Outaouais (UQO)26 * Organization     : SP Boucher27 * Website          : https://spboucher.ai28 * Git              : https://git.spboucher.ai29 *30 * Preferred Contact: contact@spboucher.ai31 * Development      : dev@spboucher.ai32 * Support          : support@spboucher.ai33 * Security/Admin   : admin@spboucher.ai34 *35 * Copyright (c) 202636 * Simon-Pierre Boucher37 * All rights reserved where applicable. This file is governed by the38 * applicable project license, copyright notices and relevant law.39 * Existing third-party rights and notices remain unaffected.40 *41 * License          : None specified (no license file in this repository)42 *43 * Do not embed credentials, private keys, access tokens,44 * certificates or confidential personal information.45 *46 * =============================================================================47 * END OF SP BOUCHER SOURCE HEADER48 * =============================================================================49 */5051import { test, expect, type Page } from "@playwright/test";52import { apiCall, docOf, para, expectNoHorizontalOverflow, sql } from "./helpers";5354const PFX = "E2E-KP"; const made: string[] = [];55const H = (level: number, text: string) => ({ type: "heading", attrs: { level }, content: [{ type: "text", text }] });56const newPage = async (page: Page, title: string, content?: unknown, extra: Record<string, unknown> = {}) => { const r = await apiCall(page, "POST", "/api/pages", { title: `${PFX} ${title} ${Date.now().toString(36)}`, ...(content ? { content } : {}), ...extra }); expect(r.status).toBe(201); made.push(r.body.id); return r.body as { id: string; title: string; version: number }; };57test.afterAll(async () => { if (made.length) { await sql`delete from tasks where page_id = any(${made}::uuid[])`; await sql`delete from knowledge_edges where from_id = any(${made}::uuid[]) or to_id = any(${made}::uuid[])`; await sql`delete from chunks where page_id = any(${made}::uuid[])`; await sql`delete from knowledge_events where page_id = any(${made}::uuid[])`; await sql`delete from pages where id = any(${made}::uuid[])`; } await sql`delete from pages where title like ${PFX + "%"}`; await sql`delete from settings where key like 'graph.constellation:%'`; });58const fits = async (page: Page) => { await expectNoHorizontalOverflow(page); await expect(page.getByRole("navigation", { name: "Primary" })).toBeVisible(); expect(await page.evaluate(() => document.documentElement.scrollHeight <= window.innerHeight + 1), "one scroll container: the document itself does not scroll").toBe(true); await expect(page.locator("main")).not.toContainText(/Application error|Could not load/); };59const inside = async (page: Page, sel: ReturnType<Page["locator"]>) => { const b = (await sel.boundingBox())!; const vp = page.viewportSize()!; expect(b.x).toBeGreaterThanOrEqual(-0.5); expect(b.x + b.width).toBeLessThanOrEqual(vp.width + 0.5); };60const tall = async (sel: ReturnType<Page["locator"]>, what: string) => { for (const el of await sel.all()) { if (!(await el.isVisible())) continue; const b = (await el.boundingBox())!; expect(b.height, `${what}: touch target height`).toBeGreaterThanOrEqual(43.5); } };6162test("graph, constellation, timeline, time machine, health, brief and ask fit the phone and work by touch", async ({ page }) => {63  test.setTimeout(180_000); await page.goto("/");64  const a = await newPage(page, "Alpha", docOf(H(2, "Part one"), para("Alpha first sentence. More."), H(2, "Part two"), para("Second part."))); const b = await newPage(page, "Beta", docOf(para("beta")));65  expect((await apiCall(page, "POST", "/api/graph/relations", { fromId: a.id, toId: b.id, relType: "supports" })).status).toBe(201);66  const ws = (await sql`select workspace_id from pages where id = ${a.id}`)[0].workspace_id; await sql`delete from chunks where page_id = any(${[a.id, b.id]}::uuid[])`;67  for (const [i, p] of [a, b].entries()) { const v = new Array(1536).fill(0); v[5 + i * 400] = 1; // the worker may index the page between the delete above and this insert: take the chunk over instead of failing on chunks_unique68    const [c] = await sql`insert into chunks (workspace_id, source_type, source_id, page_id, ordinal, content, content_hash) values (${ws}, 'page', ${p.id}, ${p.id}, 0, 'fixture', ${`kp-${p.id}`}) on conflict (source_type, source_id, ordinal) do update set content = excluded.content, content_hash = excluded.content_hash returning id`;69    await sql`delete from embeddings where chunk_id = ${c.id}`; await sql`insert into embeddings (chunk_id, model, embedding) values (${c.id}, 'text-embedding-3-small', ${`[${v.join(",")}]`}::vector)`; }70  await test.step("home: brief + health chip + dashboard", async () => { await page.goto("/"); await page.getByTestId("brief-tasks").waitFor(); await fits(page); await expect(page.getByTestId("health-chip")).toBeVisible(); await tall(page.getByTestId("health-chip"), "health chip"); await inside(page, page.getByTestId("brief-summary")); await tall(page.getByTestId("brief-summarise"), "summarise"); await page.getByTestId("dashboard-widgets").scrollIntoViewIfNeeded(); await fits(page); });71  await test.step("graph: switcher scrolls inside itself, panels are bottom sheets", async () => {72    await page.goto(`/graph?view=local&pageId=${a.id}`); await page.getByTestId("graph-canvas").waitFor(); await fits(page); await tall(page.getByRole("radiogroup", { name: "Graph view" }).getByRole("radio"), "view switcher");73    await page.getByTestId("view-references").scrollIntoViewIfNeeded(); await page.getByTestId("view-concepts").tap(); await expect(page.getByTestId("knowledge-graph")).toHaveAttribute("data-view", "concepts"); await fits(page);74    await page.getByTestId("view-global").scrollIntoViewIfNeeded(); await page.getByTestId("view-global").tap(); await page.getByTestId("open-insights").scrollIntoViewIfNeeded(); await page.getByTestId("open-insights").tap(); const panel = page.getByTestId("insights-panel"); await expect(panel).toHaveCount(1); await expect(panel).toBeVisible(); await inside(page, panel); await tall(panel.getByTestId("run-ai-analysis"), "run analysis"); await fits(page);75    await page.getByTestId("open-insights").tap(); await expect(panel).toHaveCount(0); await page.getByTestId("graph-filters-btn").tap(); const sheet = page.getByRole("dialog", { name: "Graph filters" }); await expect(sheet).toBeVisible(); await inside(page, sheet); await tall(sheet.locator("[data-rel]"), "filter chips"); await page.keyboard.press("Escape");76    await page.getByRole("button", { name: "New relation" }).tap(); const form = page.getByTestId("relation-form"); await expect(form).toBeVisible(); await inside(page, form); await tall(form.locator("button, select, input"), "relation form"); await page.keyboard.press("Escape"); await fits(page);77  });78  await test.step("constellation", async () => { await page.goto("/constellation"); const sky = page.getByTestId("constellation-canvas"); await sky.waitFor(); await fits(page); await sky.focus(); await page.keyboard.press("ArrowRight"); await page.keyboard.press("Enter"); const pv = page.getByTestId("constellation-preview"); await expect(pv).toBeVisible(); await inside(page, pv); await fits(page); });79  await test.step("timeline", async () => { await page.goto(`/timeline?pageId=${a.id}`); await page.getByTestId("event-list").waitFor(); await fits(page); await tall(page.getByTestId("timeline-kinds").getByRole("button"), "kind chips"); await page.getByTestId("timeline-kinds").locator("[data-family='links']").tap(); await expect(page.getByTestId("event-list").locator("[data-event='relation.created']")).toBeVisible(); await fits(page); });80  await test.step("time machine", async () => { await page.goto(`/timemachine?pageId=${a.id}`); await page.getByTestId("tm-honesty").waitFor(); await fits(page); await inside(page, page.getByTestId("tm-scrubber")); await tall(page.getByTestId("tm-range"), "scrubber"); await page.getByTestId("tm-range").fill("0"); await expect(page.getByTestId("tm-label")).toHaveText("Did not exist yet"); await fits(page); });81  await test.step("health", async () => { await page.goto("/health"); await page.getByTestId("health-score").waitFor(); await fits(page); await page.getByTestId("health-orphans").tap(); const d = page.getByTestId("health-detail"); await expect(d).toBeVisible(); await inside(page, d); await tall(d.getByRole("link"), "health rows"); await fits(page); });82  await test.step("ask", async () => { await page.goto("/ai"); const ask = page.getByTestId("ask-page"); await ask.getByTestId("starter-questions").waitFor(); await fits(page); await tall(ask.getByTestId("ask-scope").getByRole("radio"), "scope"); await tall(ask.getByTestId("starter-questions").getByRole("button"), "starters"); await expect(ask.getByLabel("Message")).toBeVisible(); await inside(page, ask.getByLabel("Message")); });83  await test.step("semantic zoom on a page", async () => {84    await page.goto(`/p/${a.id}`); await page.locator(".note-editor .ProseMirror").first().waitFor(); const levels = page.getByRole("radiogroup", { name: "Semantic zoom" }); await tall(levels.getByRole("radio"), "zoom levels"); await inside(page, levels); await expectNoHorizontalOverflow(page);85    await page.getByTestId("zoom-2").tap(); await expect(page.getByTestId("zoom-outline").locator("li")).toHaveCount(2); await expect(page.getByTestId("zoom-outline")).toContainText("Alpha first sentence."); await expectNoHorizontalOverflow(page);86    await page.getByTestId("zoom-1").tap(); await expect(page.getByTestId("zoom-synopsis")).toHaveAttribute("data-status", "missing"); await tall(page.getByTestId("zoom-generate"), "generate"); await expectNoHorizontalOverflow(page);87    await page.getByTestId("zoom-4").scrollIntoViewIfNeeded(); await page.getByTestId("zoom-4").tap(); await expect(page.getByTestId("zoom-connections")).toContainText("supports"); await inside(page, page.getByTestId("zoom-connections")); await expectNoHorizontalOverflow(page);88  });89  await test.step("drawer lists the new screens", async () => { await page.goto("/"); await page.getByRole("navigation", { name: "Primary" }).getByRole("button", { name: "More" }).tap(); const drawer = page.getByRole("dialog"); for (const l of ["Ask My Knowledge", "Timeline", "Time machine", "Knowledge health", "Constellation · Labs"]) await expect(drawer.getByRole("link", { name: l, exact: true })).toBeVisible(); await drawer.getByRole("link", { name: "Knowledge health", exact: true }).tap(); await expect(page).toHaveURL(/\/health$/); });90});91
Files main
Menu

Theme