Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Note SPBoucher AI8 * File : tests/e2e/next/shots-next.mjs9 * Module : tests10 * Repository : https://git.spboucher.ai/note-spboucher-ai11 * Project Website : https://note.spboucher.ai12 * Created : 2026-11-1913 * 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 */4243// file: tests/e2e/next/shots-next.mjs44// description: before/after screenshots (light + dark, desktop + phone) of home, a rich page and the command palette.45// author: Simon-Pierre Boucher — contact@spboucher.ai46// usage: E2E_BASE_URL=http://localhost:8485 node tests/e2e/next/shots-next.mjs <label> <outDir> [docJsonFile]47import { chromium } from "@playwright/test"; import fs from "node:fs";48const base = process.env.E2E_BASE_URL ?? "http://localhost:8485"; const label = process.argv[2] ?? "after"; const out = process.argv[3] ?? "test-results/shots"; fs.mkdirSync(out, { recursive: true });49const T = (text, marks) => ({ type: "text", text, ...(marks ? { marks } : {}) }); const P = (...c) => ({ type: "paragraph", content: c });50const baseDoc = [51 { type: "heading", attrs: { level: 1 }, content: [T("Knowledge systems")] },52 P(T("A note is a "), T("living document", [{ type: "bold" }]), T(": it links to other pages, carries "), T("structured blocks", [{ type: "italic" }]), T(" and stays readable. See "), T("the specification", [{ type: "link", attrs: { href: "https://example.org" } }]), T(" and inline "), T("code", [{ type: "code" }]), T(".")),53 { type: "heading", attrs: { level: 2 }, content: [T("Plan")] },54 { type: "taskList", content: [{ type: "taskItem", attrs: { checked: true }, content: [P(T("Collect the sources"))] }, { type: "taskItem", attrs: { checked: false }, content: [P(T("Write the synthesis"))] }] },55 { type: "callout", attrs: { kind: "info", icon: "💡" }, content: [P(T("Callouts keep a decision or a warning visible in the flow of the text."))] },56 { type: "blockquote", content: [P(T("What is written without effort is in general read without pleasure."))] },57 { type: "codeBlock", attrs: { language: "typescript" }, content: [T("export const lumen = (t: number) => `linear-gradient(135deg, accent, ai ${t}%)`;")] },58 { type: "table", content: [{ type: "tableRow", content: ["Token", "Light", "Dark"].map((h) => ({ type: "tableHeader", content: [P(T(h))] })) }, { type: "tableRow", content: ["accent", "#3157D5", "#8AA2FF"].map((h) => ({ type: "tableCell", content: [P(T(h))] })) }] },59 { type: "aiBlock", attrs: { model: "assistant", at: "2026-11-19T12:00:00Z" }, content: [P(T("AI-generated content is always marked as such."))] },60 { type: "heading", attrs: { level: 3 }, content: [T("Notes")] },61 { type: "bulletList", content: ["First idea", "Second idea", "Third idea"].map((s) => ({ type: "listItem", content: [P(T(s))] })) },62];63const extra = process.argv[4] ? JSON.parse(fs.readFileSync(process.argv[4], "utf8")) : [];64const b = await chromium.launch();65for (const theme of ["light", "dark"]) for (const [dev, w, h] of [["desktop", 1280, 800], ["phone", 375, 667]]) {66 const ctx = await b.newContext({ baseURL: base, storageState: "test-results/.auth/state.json", viewport: { width: w, height: h }, hasTouch: dev === "phone", isMobile: dev === "phone", deviceScaleFactor: 2, colorScheme: theme });67 await ctx.addInitScript((t) => { try { localStorage.setItem("note-theme", t); const u = JSON.parse(localStorage.getItem("note-ui") ?? '{"state":{},"version":0}'); u.state.theme = t; localStorage.setItem("note-ui", JSON.stringify(u)); } catch {} }, theme);68 const p = await ctx.newPage(); const errs = []; p.on("pageerror", (e) => errs.push(e.message.slice(0, 200)));69 const r = await p.request.post("/api/pages", { data: { title: "Lumen showcase", icon: "🧭", content: { type: "doc", content: [...baseDoc, ...extra] } }, headers: { origin: base, "content-type": "application/json" } }); const pg = await r.json();70 const shot = async (name, full) => { await p.waitForTimeout(900); await p.screenshot({ path: `${out}/${label}-${dev}-${theme}-${name}.png`, fullPage: false }); if (full) { const m = await p.evaluate(() => { const el = document.getElementById("main-scroll"); return el ? el.scrollHeight : 0; }); if (m > h) { await p.setViewportSize({ width: w, height: Math.min(m + 120, 9000) }); await p.waitForTimeout(700); await p.screenshot({ path: `${out}/${label}-${dev}-${theme}-${name}-full.png` }); await p.setViewportSize({ width: w, height: h }); } } };71 await p.goto("/"); await shot("home");72 await p.goto(`/p/${pg.id}`); await p.locator(".ProseMirror").first().waitFor(); await shot("page", true);73 if (dev === "desktop") { await p.keyboard.press("Control+k"); await shot("palette"); await p.keyboard.press("Escape"); }74 else { try { await p.getByRole("button", { name: "More" }).click({ timeout: 3000 }); await shot("drawer"); await p.keyboard.press("Escape"); } catch {} }75 await p.request.delete(`/api/pages/${pg.id}`, { headers: { origin: base } });76 console.log(label, dev, theme, errs.length ? "ERRORS: " + errs.join(" | ") : "ok"); await ctx.close();77}78await b.close();79