Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Note SPBoucher AI8 * File : tests/e2e/desktop.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-1914 *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 } from "@playwright/test";44import { apiCall, sql, expectNoHorizontalOverflow } from "./helpers";4546const made: string[] = [];47test.afterAll(async () => { if (made.length) await sql`delete from pages where id = any(${made}::uuid[])`; });4849test("a repeated mutation with the same Idempotency-Key creates one page and replays the answer", async ({ page }) => {50 await page.goto("/"); const key = `e2e-${Date.now()}-abcdef`; const title = `E2E-idem ${key}`;51 const a = await apiCall(page, "POST", "/api/pages", { title }, { "idempotency-key": key }); const b = await apiCall(page, "POST", "/api/pages", { title }, { "idempotency-key": key });52 expect(a.status).toBe(201); expect(b.status).toBe(201); expect(b.body.id).toBe(a.body.id); expect(b.headers["idempotent-replay"]).toBe("true"); made.push(a.body.id);53 expect((await sql`select count(*)::int as n from pages where title = ${title}`)[0].n).toBe(1);54 // five parallel sends of one capture (a retry storm after a timeout): still one note55 const k2 = `e2e-${Date.now()}-storm1`; const t2 = `E2E-storm ${k2}`;56 const rs = await Promise.all(Array.from({ length: 5 }, () => apiCall(page, "POST", "/api/capture", { kind: "note", text: t2 }, { "idempotency-key": k2 })));57 expect(rs.every((r) => r.status === 201 || (r.status === 409 && r.body.code === "in_progress"))).toBe(true);58 const rows = await sql`select id from pages where title = ${t2}`; expect(rows.length).toBe(1); made.push(rows[0].id);59 // the key cannot be reused for another request, and a malformed key is refused60 expect((await apiCall(page, "POST", "/api/capture", { kind: "note", text: "x" }, { "idempotency-key": key })).status).toBe(422);61 expect((await apiCall(page, "POST", "/api/pages", { title: "x" }, { "idempotency-key": "bad key!" })).status).toBe(400);62});63test("responses carry a request id and are never cacheable; mutations need our origin", async ({ page }) => {64 await page.goto("/"); const r = await apiCall(page, "GET", "/api/tree"); expect(r.headers["x-request-id"]).toMatch(/^[A-Za-z0-9_-]{8,64}$/); expect(r.headers["cache-control"]).toContain("no-store");65 const html = await page.request.get("/"); expect(html.headers()["cache-control"]).toContain("no-store");66 const cross = await page.request.post("/api/pages", { data: { title: "csrf" }, headers: { origin: "https://evil.example" } }); expect(cross.status()).toBe(403);67 const none = await page.request.fetch("/api/pages", { method: "POST", data: { title: "csrf" }, headers: { origin: "" } }); expect([403]).toContain(none.status());68 expect((await sql`select count(*)::int as n from pages where title = 'csrf'`)[0].n).toBe(0);69 const bad = await apiCall(page, "POST", "/api/pages", { title: "bad doc", content: { type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text: "x", marks: [{ type: "link", attrs: { href: "javascript:alert(1)" } }] }] }] } }); expect(bad.status).toBe(400);70});71test("the service worker caches the app shell only — no API, no page HTML", async ({ page }) => {72 await page.goto("/"); await page.evaluate(async () => { await navigator.serviceWorker.ready; });73 await page.goto("/search"); await page.goto("/inbox"); await page.waitForTimeout(800);74 const urls: string[] = await page.evaluate(async () => { const out: string[] = []; for (const k of await caches.keys()) for (const r of await (await caches.open(k)).keys()) out.push(new URL(r.url).pathname); return out; });75 expect(urls.length).toBeGreaterThan(3); expect(urls).toContain("/offline");76 for (const u of urls) expect(u.startsWith("/_next/static/") || u.startsWith("/icons/") || u === "/offline" || u === "/manifest.webmanifest", `unexpected cached URL ${u}`).toBe(true);77});78test("desktop layout still works: sidebar, capture to inbox, settings sections", async ({ page }) => {79 await page.goto("/"); await expect(page.getByRole("navigation", { name: "Workspace" })).toBeVisible(); await expect(page.getByRole("navigation", { name: "Primary" })).toBeHidden();80 const t = `E2E-desk ${Date.now()}`; await page.getByRole("navigation", { name: "Workspace" }).getByLabel("Quick capture").fill(t); await page.keyboard.press("Enter"); await expect(page.getByText("Captured to inbox")).toBeVisible();81 await page.getByRole("navigation", { name: "Workspace" }).getByRole("link", { name: "Inbox" }).click(); await expect(page.getByRole("main").getByText(t)).toBeVisible(); // in the inbox list (the sidebar tree may list the capture too)82 const [row] = await sql`select id from pages where title = ${t}`; made.push(row.id);83 await page.goto("/settings"); for (const name of ["Security", "Appearance", "Data & backups", "AI & costs", "Indexing", "Jobs", "Tasks", "Profile", "About"]) { await page.getByRole("tab", { name }).click(); await expect(page.locator("main")).not.toContainText(/couldn.t load/i); }84 await page.getByRole("tab", { name: "Jobs" }).click(); await expect(page.getByText(/Worker running/)).toBeVisible(); await expectNoHorizontalOverflow(page);85});86