Files
JIANT/web/emu/browser_pm_test.mjs
T
Claude 80d999b713 Emulator Project Manager redesigned as Studio's project library (#280): compact rows that open one at a time (a large slot number, the name, chips A–D, OPEN / GEN), inside them small-titled groups (NOW: Load / Save what's playing here; NAME + Save; FILE: Share / Download / Import; COPY TO and MOVE TO with numbered buttons; FM-1: Send / Get with Web MIDI; Delete apart in red), empty slots dimmed with Save and Import only; presets ticked into a bank with its own action bar, a bank's import / send / get with a per-preset target picker (Same slots, Into empty slots, Leave all out; two into one slot refused before Go)
- pm-ui.js: a black HUD card of its own (the firmware's thermal accents, DotGothic16 for numbers and names, IBM Plex Mono), every target 40 px or more, one column on a phone; no prompts: a replace or a delete asks inside the group it came from, with "download a copy first"; a bank write that replaces presets now asks too and keeps them first as one bank file (JIANT-FM-bank-before-*.jfmb); progress and messages shown where the action was; still device-neutral and loaded only when opened; EN / ES switch kept. A page restyles it with --pm-* tokens on `#box .pm-body`
- pm.js / pm-fm.js: list items may carry chips [{ label, on }] (JIANT FM: a project's parts A–D)
- devices.html: the panel's look through the tokens (the old button overrides removed)
- browser_pm_test.mjs: the new structure (rows, groups, numbered targets, the open project not a target, asks with the copy first for copy / delete / bank), the bank picker's quick choices, the language switch, a 390 px Android phone (no sideways scroll, 40 px targets) and an iPhone without Web MIDI in Spanish; screenshots at 390 px and on a desktop. pm_test.mjs unchanged, passing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
2026-11-28 23:59:49 +00:00

330 lines
26 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-License-Identifier: GPL-3.0-only
// Copyright (C) 2026 Juan Ignacio Antonucci (Juan Jiant)
// (pm) The Project Manager in a real browser (Playwright's Chromium), on the site's emulator pages as the workflow builds
// them (EMU_DIR: that emu/, default build/emu):
// node web/emu/browser_pm_test.mjs [out-dir-for-screenshots]
// navigator.requestMIDIAccess is a simulated FM-1 (fm1mock.mjs) whose firmware is a second felucca.wasm (its PROJECT 3
// saved by the device's own SAVE). Checks: nothing of the panel loaded until it is opened; Studio's library structure
// (compact rows that open one at a time: the number, the name, chips A–D, OPEN / GEN; inside, the small-titled groups NOW,
// NAME, FILE, COPY TO, MOVE TO, FM-1 and Delete apart in red; an empty slot dimmed, Save and Import only); SAVE / RENAME /
// COPY / MOVE (numbered buttons) / DELETE / LOAD of a project and a preset; a replace asked where it was asked, with the
// copy downloaded first; DOWNLOAD (.jfm, Studio's keys) and IMPORT of it; SHARE (navigator.share with the File); a bank
// (ticked presets) downloaded and imported into chosen slots (the picker's quick choices, two into one slot refused, a
// replace asked with a copy of the bank it replaces); CONNECT, SEND TO and GET FROM the FM-1, a bank sent and got; a
// phone (390 px: no sideways scroll, every target 40 px or more), English and Spanish, a browser without Web MIDI (the
// files only); devices.html's SMK-37 and MPC. With an out dir: screenshots at 390 px and on a desktop (the list, an
// opened project, an opened preset, a bank ticked, the bank import picker).
import fs from "fs";
import http from "http";
import path from "path";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const { chromium } = require("playwright");
const ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), "../..");
const OUT = process.argv[2] || null;
const EMU = process.env.EMU_DIR || path.join(ROOT, "build/emu");
const SITE = { "/emu/fm1mock.mjs": "web/emu/fm1mock.mjs", "/fm1backup.js": "web/fm1backup.js" };
const TYPES = { ".html": "text/html", ".js": "text/javascript", ".mjs": "text/javascript", ".wasm": "application/wasm", ".woff": "font/woff", ".json": "application/json" };
const asked = [];
const server = http.createServer((q, r) => {
let u = decodeURIComponent(q.url.split("?")[0]);
asked.push(u);
if (u === "/emu/") u = "/emu/index.html";
const file = SITE[u] ? path.join(ROOT, SITE[u]) : u.startsWith("/emu/") ? path.join(EMU, u.slice(5)) : null;
if (!file || !fs.existsSync(file)) { r.writeHead(404); r.end(); return; }
r.writeHead(200, { "content-type": TYPES[path.extname(file)] || "application/octet-stream" }); r.end(fs.readFileSync(file));
});
await new Promise((res) => server.listen(0, res));
const base = `http://127.0.0.1:${server.address().port}/emu/`;
let fails = 0;
const check = (what, ok) => { console.log(`browser-pm: ${what.padEnd(84)} ${ok ? "ok" : "FAIL"}`); if (!ok) fails++; };
/* the simulated FM-1: a second firmware; its PROJECT 3 "FM ONE" saved as the device saves (pm-api.h), a preset in 20 */
const FAKE = ({ midi }) => {
if (!midi) { delete Navigator.prototype.requestMIDIAccess; return; }
window.__shared = [];
Object.defineProperty(navigator, "canShare", { value: (d) => !!(d && d.files && d.files.length), configurable: true });
Object.defineProperty(navigator, "share", { value: async (d) => { window.__shared.push(...d.files.map((f) => ({ name: f.name, type: f.type, size: f.size }))); }, configurable: true });
navigator.requestMIDIAccess = async () => {
if (window.__fm1) return window.__fm1.access;
const [{ wasmDevice, midiAccess }, { edServe, edVersion, pmServe }] = await Promise.all([import("./fm1mock.mjs"), import("./worklet.js")]);
const { instance } = await WebAssembly.instantiate(await (await fetch("felucca.wasm")).arrayBuffer(), {});
const ex = instance.exports; ex._initialize(); ex.web_nor_erase(); ex.web_seed(5); ex.web_boot();
for (let i = 0; i < 12; i++) ex.web_render(1024);
ex.web_gen(3, 42, 70, 2); for (let i = 0; i < 30; i++) ex.web_render(1024);
pmServe(ex, { pm: "save", n: 2, name: "FM ONE" });
edServe(ex, [8, 12, 1]); edServe(ex, [19, 19, ..."FM KEYS".split("").map((c) => c.charCodeAt(0)), 0]);
const access = midiAccess(wasmDevice(ex, edServe, "JIANT " + edVersion(ex)), { name: "FM-1", delay: 1 });
window.__fm1 = { ex, access, edServe };
return access;
};
};
async function page(browser, opt = {}) {
const ctx = await browser.newContext({ viewport: opt.phone ? { width: 390, height: 844 } : { width: 1100, height: 900 }, deviceScaleFactor: 2,
locale: opt.lang || "en-US", acceptDownloads: true, isMobile: !!opt.phone, hasTouch: !!opt.phone });
const p = await ctx.newPage();
p.on("pageerror", (e) => console.log("pageerror:", e.message));
p.on("console", (m) => { if (m.type() === "error" || (m.type() === "warning" && /project manager/i.test(m.text()))) console.log("console:", m.text()); });
await p.addInitScript(FAKE, { midi: opt.midi !== false });
await p.goto(base + (opt.url || ""));
return p;
}
async function switchOn(p, sel = "#go") {
await p.click(sel);
await p.waitForFunction(() => { const s = document.querySelector("#start, .start"); return !s || s.hidden; }, null, { timeout: 20000 });
}
const pm = "#pm";
const text = (p) => p.locator(pm).innerText();
const save = (name) => OUT ? (fs.mkdirSync(OUT, { recursive: true }), path.join(OUT, name)) : null;
const shot = async (p, name) => { if (OUT) await p.locator(pm).screenshot({ path: save(name) }); };
/* the page from the top of `from` to the bottom of `to` (the panel's head to an opened row, say) */
const shotSpan = async (p, name, from, to = from, pad = 8) => {
if (!OUT) return;
const a = await p.locator(from).first().boundingBox(), b = await p.locator(to).first().boundingBox(), sx = await p.evaluate(() => [scrollX, scrollY]);
const box = await p.locator(pm).boundingBox();
await p.screenshot({ path: save(name), fullPage: true, clip: { x: Math.max(0, box.x - pad + sx[0]), y: Math.max(0, a.y - pad + sx[1]), width: box.width + 2 * pad, height: b.y + b.height - a.y + 2 * pad } });
};
const waitText = async (p, re, ms = 30000) => {
try { await p.waitForFunction(([r, s]) => new RegExp(r).test(document.querySelector(s).innerText), [re.source, pm], { timeout: ms }); }
catch (e) { console.log("panel:", await text(p)); throw e; }
};
const idle = (p) => p.waitForFunction((s) => !document.querySelector(s + " .pm-body button:disabled[data-act=refresh]"), pm, { timeout: 60000 });
const status = (p) => p.locator(`${pm} .msg[role=status]`).innerText().catch(() => "");
const row = (p, n) => p.locator(`${pm} .pm-item[data-slot="${n}"]`);
const act = (p, a) => p.locator(`${pm} .pm-row.sel [data-act="${a}"]`);
const dlg = (p, a) => p.locator(`${pm} .pm-dlg [data-act="${a}"]`);
const to = (p, op, n) => p.locator(`${pm} .pm-row.sel [data-act="${op}-to"][data-k="${op}-to:${n}"]`);
const pickIn = (p, n) => p.locator(`${pm} .pm-dlg [data-act=pick][data-k="pick:${n}"]`);
const tick = (p, n) => p.locator(`${pm} [data-pick="${n}"] input[type=checkbox]`).check();
async function open(p, n) { if ((await row(p, n).getAttribute("aria-expanded")) !== "true") await row(p, n).click(); }
async function name(p, v) { await p.fill(`${pm} .pm-row.sel input[data-field=name]`, v); }
async function saveAs(p, n, v) { await open(p, n); await name(p, v); await act(p, "save").click(); await idle(p); }
async function download(p, click) { const [d] = await Promise.all([p.waitForEvent("download"), click()]); const f = await d.path(); return { name: d.suggestedFilename(), text: fs.readFileSync(f, "utf8"), path: f }; }
async function importFile(p, click, file) { const [fc] = await Promise.all([p.waitForEvent("filechooser"), click()]); await fc.setFiles(file); await idle(p); }
const groups = (p) => p.locator(`${pm} .pm-row.sel .pm-gt`).allInnerTexts();
const acts = (p) => p.locator(`${pm} .pm-row.sel .pm-in [data-act]`).evaluateAll((l) => [...new Set(l.map((e) => e.dataset.act))]);
/* every visible control of the panel at least 40 px tall (a checkbox: its label) */
const small = (p) => p.evaluate((s) => [...document.querySelectorAll(`${s} .pm-body button, ${s} .pm-body input[type=text], ${s} .pm-body select, ${s} .pm-body .pm-pick, ${s} .pm-body .pm-chk`)]
.filter((e) => e.offsetParent).map((e) => [e.dataset.act || e.className || e.tagName, Math.round(e.getBoundingClientRect().height), Math.round(e.getBoundingClientRect().width)])
.filter(([, hh, ww]) => hh < 40 || ww < 40), pm);
const wide = (p) => p.evaluate(() => [document.documentElement.scrollWidth, innerWidth]);
const browser = await chromium.launch();
try {
{ /* the public page (ADDITIVE): projects */
const p = await page(browser);
await switchOn(p);
check("closed, the panel costs nothing: pm-ui.js / pm-fm.js not even fetched", !asked.some((u) => /pm-(ui|fm)\.js/.test(u)) && await p.locator(pm).count() === 1);
await p.click(`${pm} summary`);
await p.waitForSelector(`${pm} .pm-item[data-slot="5"]`, { timeout: 20000 });
await idle(p);
check("opened: pm-ui.js and the adapter loaded, the 6 projects listed", asked.some((u) => /pm-ui\.js/.test(u)) && await p.locator(`${pm} .pm-item`).count() === 6);
const head0 = await row(p, 0).innerText();
check(`closed rows, none opened: the large number, OPEN on the open one, empty slots dimmed ("${head0.replace(/\s+/g, " ")}")`, /^1\b/.test(head0) && /OPEN/.test(head0) &&
await p.locator(`${pm} .pm-row.sel`).count() === 0 && /Empty/.test(await row(p, 1).innerText()) && await p.locator(`${pm} .pm-row.empty`).count() === 6);
await open(p, 1);
check(`an empty slot: NAME + Save what's playing, FILE: Import only (${await acts(p)})`, (await acts(p)).filter((a) => a !== "get").join() === "save,import" && (await groups(p)).slice(0, 2).join() === "NAME,FILE");
await name(p, "night"); await act(p, "save").click(); await idle(p);
await waitText(p, /Saved: PROJECT 2/);
check(`SAVE into PROJECT 2 (the open one stays PROJECT 1, as on the device): "${(await row(p, 1).innerText()).replace(/\s+/g, " ")}"`, /NIGHT/.test(await row(p, 1).innerText()) && /OPEN/.test(await row(p, 0).innerText()));
check("its row: chips A–D, the parts it holds lit", await p.locator(`${pm} .pm-item[data-slot="1"] .pm-chips i`).count() === 4 && await p.locator(`${pm} .pm-item[data-slot="1"] .pm-chips i.on`).count() >= 1 &&
(await p.locator(`${pm} .pm-item[data-slot="1"] .pm-chips`).innerText()).replace(/\s+/g, "") === "ABCD");
await open(p, 0);
check("rows open one at a time", await p.locator(`${pm} .pm-row.sel`).count() === 1 && (await row(p, 1).getAttribute("aria-expanded")) === "false");
await open(p, 1);
const g = await groups(p);
check(`an opened project: groups ${g.join(" / ")}, Delete apart in red`, g.join() === "NOW,NAME,FILE,COPY TO,MOVE TO,FM-1" &&
await p.locator(`${pm} .pm-row.sel .pm-del button.danger[data-act=remove]`).count() === 1);
check("COPY TO / MOVE TO: numbered buttons, the other 5 projects; the open one not a target", await p.locator(`${pm} .pm-row.sel [data-act=copy-to]`).count() === 5 &&
await to(p, "copy", 0).isDisabled() && await to(p, "move", 0).isDisabled() && (await to(p, "copy", 3).innerText()).trim() === "4");
await name(p, "dub night"); await act(p, "rename").click(); await idle(p);
check("RENAME (NAME > Save) -> DUB NIGHT", /DUB NIGHT/.test(await row(p, 1).innerText()));
await open(p, 1); await to(p, "copy", 3).click(); await idle(p);
check("COPY 2 -> 4 (an empty one: no question)", /DUB NIGHT/.test(await row(p, 3).innerText()) && /Copied/.test(await status(p)));
await open(p, 3); await to(p, "move", 4).click(); await idle(p);
check("MOVE 4 -> 5", /DUB NIGHT/.test(await row(p, 4).innerText()) && /Empty/.test(await row(p, 3).innerText()));
await open(p, 4); await act(p, "load").click(); await idle(p);
check("LOAD PROJECT 5: now the open one", /OPEN/.test(await row(p, 4).innerText()) && !/OPEN/.test(await row(p, 1).innerText()));
check("the open project: no MOVE TO, Delete off", !(await groups(p)).includes("MOVE TO") && await act(p, "remove").isDisabled());
await open(p, 1); await act(p, "load").click(); await idle(p);
await open(p, 4); await act(p, "remove").click();
const askDel = await p.locator(`${pm} .pm-row.sel .pm-dlg`).innerText();
check(`DELETE asks first, in the row, a copy offered ("${askDel.split("\n")[0]}")`, /Delete PROJECT 5/.test(askDel) && await p.locator(`${pm} .pm-row.sel .pm-dlg input[data-act=keep]`).count() === 1);
await dlg(p, "ok").click(); await idle(p);
check("DELETE PROJECT 5", /Empty/.test(await row(p, 4).innerText()));
await open(p, 1);
const jfm = await download(p, () => act(p, "download").click());
const f = JSON.parse(jfm.text);
check(`DOWNLOAD: ${jfm.name}: "${f.format}" v${f.version}, Studio's keys, a complete backup`, jfm.name === "JIANT-FM-project-2-DUB_NIGHT.jfm" && f.format === "jiant-fm-project" &&
["format", "version", "firmware", "created", "name", "gen", "web", "backup"].every((k) => k in f) && f.backup.objects.length === 35);
await idle(p);
await act(p, "share").click(); await idle(p);
const shared = await p.evaluate(() => window.__shared);
check(`SHARE: navigator.share with the File (${shared[0]?.name}, ${shared[0]?.type})`, shared.length === 1 && /\.jfm$/.test(shared[0].name) && shared[0].type === "application/json");
await open(p, 5);
await importFile(p, () => act(p, "import").click(), jfm.path);
check("IMPORT the .jfm into PROJECT 6", /DUB NIGHT/.test(await row(p, 5).innerText()) && /Imported/.test(await status(p)));
/* a copy onto a project that holds something: asked in COPY TO, the copy of what it replaces downloaded first */
await open(p, 1); await to(p, "copy", 5).click();
const askCp = await p.locator(`${pm} .pm-row.sel .pm-dlg`).innerText();
check(`COPY onto PROJECT 6 (holds DUB NIGHT): asked in its group, the target lit ("${askCp.split("\n").slice(0, 2).join(" ")}")`, /This replaces/.test(askCp) && /PROJECT 6/.test(askCp) &&
await p.locator(`${pm} .pm-row.sel .pm-to.pick`).count() === 1);
await p.locator(`${pm} .pm-dlg input[data-act=keep]`).check();
const before = await download(p, () => dlg(p, "ok").click()); await idle(p);
check(`... "download a copy first" ticked: ${before.name}, then copied`, before.name === "JIANT-FM-project-6-DUB_NIGHT.jfm" && /Copied/.test(await status(p)));
await p.click(`${pm} [data-act=lang]`);
const es = await text(p);
check("the language switch: Spanish (COPIAR A, ARCHIVO, Borrar), and back", /COPIAR A/.test(es) && /ARCHIVO/.test(es) && /Borrar/.test(es));
await p.click(`${pm} [data-act=lang]`);
// ------------------------------------------------------------------ the FM-1
await p.click(`${pm} [data-act=connect]`); await idle(p);
check(`CONNECT: "${(await p.locator(pm + " .pm-st [data-hw]").innerText())}"`, /JIANT V10/.test(await text(p)));
await open(p, 1); await act(p, "send").click(); await idle(p);
check("SEND: the FM-1's projects as numbered buttons with their names", await p.locator(`${pm} .pm-row.sel .pm-dlg [data-act=pick]`).count() === 6 && /FM ONE/.test(await pickIn(p, 2).innerText()));
await pickIn(p, 2).click();
const keep = await download(p, () => dlg(p, "ok").click()); // (the FM-1's PROJECT 3 replaced: a copy kept first, asked with it ticked)
await idle(p);
const fmName = await p.evaluate(() => { const a = window.__fm1.edServe(window.__fm1.ex, [95]); return String.fromCharCode(...a.slice(2 + 2 * 15 + 3, 2 + 2 * 15 + 15).filter((c) => c)); });
check(`SEND TO FM-1: PROJECT 2 -> its PROJECT 3 ("${fmName}"); what it replaced kept (${keep.name})`, fmName === "DUB NIGHT" && /Sent to the FM-1/.test(await status(p)) && /project-3-FM_ONE\.jfm$/.test(keep.name));
await open(p, 3); await act(p, "get").click(); await idle(p); await pickIn(p, 2).click(); await idle(p);
check("GET FROM FM-1: its PROJECT 3 -> PROJECT 4 (an empty slot: Get there too)", /DUB NIGHT/.test(await row(p, 3).innerText()) && /Got it/.test(await status(p)));
await open(p, 3);
await shotSpan(p, "desktop-2-project-open.png", pm, `${pm} .pm-row.sel`);
await row(p, 3).click(); // (closed again: the list for the shot)
await shot(p, "desktop-1-list.png");
// ------------------------------------------------------------------ presets and banks
await p.click(`${pm} .pm-tabs button[data-tab=preset]`);
await p.waitForSelector(`${pm} .pm-item[data-slot="31"]`); await idle(p);
check("PRESETS: 32 slots, two-digit numbers, a checkbox each (the empty ones off)", await p.locator(`${pm} .pm-item`).count() === 32 &&
(await row(p, 4).locator(".pm-num").innerText()) === "05" && await p.locator(`${pm} .pm-pick input:disabled`).count() >= 30);
await saveAs(p, 2, "glass");
await open(p, 2); await name(p, "glass keys"); await act(p, "rename").click(); await idle(p);
check(`SAVE + RENAME preset 3: "${(await row(p, 2).innerText()).replace(/\s+/g, " ")}" (its engine under the name)`, /GLASS KEYS/.test(await row(p, 2).innerText()) && (await row(p, 2).locator(".pm-meta").innerText()).length > 1);
await open(p, 2);
const gp = await groups(p);
check(`an opened preset: ${gp.join(" / ")}`, gp.join() === "NOW,NAME,FILE,COPY TO,MOVE TO,FM-1" && await p.locator(`${pm} .pm-row.sel [data-act=copy-to]`).count() === 31);
await shotSpan(p, "desktop-3-preset-open.png", pm, `${pm} .pm-row.sel`);
await to(p, "copy", 6).click(); await idle(p);
check("COPY preset 3 -> 7", /GLASS KEYS/.test(await row(p, 6).innerText()));
await open(p, 2); await to(p, "copy", 6).click();
await p.locator(`${pm} .pm-dlg input[data-act=keep]`).check();
const keepP = await download(p, () => dlg(p, "ok").click()); await idle(p);
check(`COPY onto preset 7 again: asked, its copy first (${keepP.name})`, keepP.name === "JIANT-FM-preset-07-GLASS_KEYS.jfmp" && /Copied/.test(await status(p)));
await tick(p, 2); await tick(p, 6);
const bar = await p.locator(`${pm} .pm-bank`).innerText();
check(`BANK: two ticked, the bar says so ("${bar.split("\n").slice(0, 2).join(" ")}"), the rows marked`, /2 selected/.test(bar) && await p.locator(`${pm} .pm-row.picked`).count() === 2);
if ((await row(p, 6).getAttribute("aria-expanded")) === "true") await row(p, 6).click(); // (no row open: the bank and the list for the shot)
await shotSpan(p, "desktop-4-bank-selected.png", pm, `${pm} .pm-row:nth-child(8)`);
const jfmb = await download(p, () => p.click(`${pm} [data-act=bank-download]`));
const b = JSON.parse(jfmb.text);
check(`DOWNLOAD BANK: ${jfmb.name}: "${b.format}", presets ${b.presets.map((x) => x.slot + 1)}`, /\.jfmb$/.test(jfmb.name) && b.format === "jiant-preset-bank" && b.presets.map((x) => x.slot).join() === "2,6");
await importFile(p, () => p.click(`${pm} [data-act=bank-import]`), jfmb.path);
check("IMPORT BANK: the picker, one row per preset, each into its own slot to begin with", await p.locator(`${pm} .pm-dlg .pm-mr`).count() === 2 &&
await p.locator(`${pm} .pm-dlg select[data-src="2"]`).inputValue() === "2");
await dlg(p, "map-free").click();
const free = [await p.locator(`${pm} .pm-dlg select[data-src="2"]`).inputValue(), await p.locator(`${pm} .pm-dlg select[data-src="6"]`).inputValue()];
check(`... "Into empty slots": ${free.map((v) => +v + 1)}`, free.join() === "0,1");
await p.selectOption(`${pm} .pm-dlg select[data-src="6"]`, "0");
check("... two into one slot: said, Go off", /Two presets into slot 01/.test(await p.locator(`${pm} .pm-bank`).innerText()) && await dlg(p, "ok").isDisabled());
await p.selectOption(`${pm} .pm-dlg select[data-src="2"]`, "24");
await p.selectOption(`${pm} .pm-dlg select[data-src="6"]`, "-1");
await shotSpan(p, "desktop-5-bank-import.png", `${pm} .pm-bank`);
await dlg(p, "ok").click(); await idle(p);
check("IMPORT BANK, chosen: preset 3 -> 25, preset 7 left out", /GLASS KEYS/.test(await row(p, 24).innerText()) && /Empty/.test(await row(p, 25).innerText()) && /1 presets written/.test(await status(p)));
await importFile(p, () => p.click(`${pm} [data-act=bank-import]`), jfmb.path);
await p.selectOption(`${pm} .pm-dlg select[data-src="2"]`, "24");
await p.selectOption(`${pm} .pm-dlg select[data-src="6"]`, "-1");
await dlg(p, "ok").click(); await idle(p);
const askBank = await p.locator(`${pm} .pm-bank .pm-dlg`).innerText();
check("... again into 25 (holds GLASS KEYS): asked first, a copy offered", /This replaces/.test(askBank) && /preset 25/.test(askBank));
await p.locator(`${pm} .pm-dlg input[data-act=keep]`).check();
const keepB = await download(p, () => dlg(p, "ok").click()); await idle(p);
check(`... the replaced presets kept first as a bank (${keepB.name})`, /^JIANT-FM-bank-before-.*\.jfmb$/.test(keepB.name) && JSON.parse(keepB.text).presets.map((x) => x.slot).join() === "24" && /1 presets written/.test(await status(p)));
await p.click(`${pm} [data-act=bank-send]`); await idle(p);
await p.selectOption(`${pm} .pm-dlg select[data-src="2"]`, "9");
await p.selectOption(`${pm} .pm-dlg select[data-src="6"]`, "10");
await dlg(p, "ok").click(); await idle(p);
const fmP = await p.evaluate(() => [9, 10, 19].map((k) => window.__fm1.ex.web_test_user_preset(k)));
check(`SEND BANK TO FM-1: into its 10, 11 (its 20 kept): ${fmP}`, fmP.join() === "1,1,1" && /2 presets written on the FM-1/.test(await status(p)));
await p.click(`${pm} [data-act=bank-get]`); await idle(p);
await p.selectOption(`${pm} .pm-dlg select[data-src="9"]`, "-1");
await p.selectOption(`${pm} .pm-dlg select[data-src="10"]`, "-1");
await p.selectOption(`${pm} .pm-dlg select[data-src="19"]`, "30");
await dlg(p, "ok").click(); await idle(p);
check("GET BANK FROM FM-1: its 20 (FM KEYS) -> 31", /FM KEYS/.test(await row(p, 30).innerText()));
await open(p, 6); await act(p, "remove").click(); await dlg(p, "ok").click(); await idle(p);
check("DELETE preset 7 (and it leaves the bank)", /Empty/.test(await row(p, 6).innerText()) && /1 selected/.test(await p.locator(`${pm} .pm-bank`).innerText()));
await p.context().close();
}
{ /* a phone (Android: Chrome with Web MIDI), 390 px: the shots, no sideways scroll, 40 px targets */
const p = await page(browser, { phone: true });
await switchOn(p);
await p.click(`${pm} summary`);
await p.waitForSelector(`${pm} .pm-item[data-slot="5"]`, { timeout: 20000 }); await idle(p);
await saveAs(p, 1, "night"); await row(p, 1).click();
await shot(p, "phone-1-list.png");
let bad = await small(p);
await open(p, 1);
bad = bad.concat(await small(p));
const w1 = await wide(p);
await shotSpan(p, "phone-2-project-open.png", pm, `${pm} .pm-row.sel`);
await p.click(`${pm} .pm-tabs button[data-tab=preset]`); await p.waitForSelector(`${pm} .pm-item[data-slot="31"]`); await idle(p);
await saveAs(p, 2, "glass"); await saveAs(p, 6, "bass");
await open(p, 2);
bad = bad.concat(await small(p));
const w2 = await wide(p);
await shotSpan(p, "phone-3-preset-open.png", pm, `${pm} .pm-row.sel`);
await row(p, 2).click();
await tick(p, 2); await tick(p, 6);
await shotSpan(p, "phone-4-bank-selected.png", pm, `${pm} .pm-row:nth-child(8)`);
const jfmb = await download(p, () => p.click(`${pm} [data-act=bank-download]`));
await importFile(p, () => p.click(`${pm} [data-act=bank-import]`), jfmb.path);
await p.selectOption(`${pm} .pm-dlg select[data-src="6"]`, "7");
bad = bad.concat(await small(p));
const w3 = await wide(p);
await shotSpan(p, "phone-5-bank-import.png", `${pm} .pm-bank`);
check(`phone (390 px): no sideways scroll with a project, a preset, the bank picker open (${w1} ${w2} ${w3})`, [w1, w2, w3].every(([a, b]) => a <= b));
check(`phone: every button, field, select and checkbox label 40 px or more${bad.length ? " (" + JSON.stringify(bad.slice(0, 4)) + ")" : ""}`, !bad.length);
await p.context().close();
}
{ /* an iPhone: no Web MIDI (the files only), Spanish */
const p = await page(browser, { phone: true, midi: false, lang: "es-AR" });
await switchOn(p);
await p.click(`${pm} summary`);
await p.waitForSelector(`${pm} .pm-item[data-slot="5"]`, { timeout: 20000 }); await idle(p);
await saveAs(p, 1, "noche"); await open(p, 1);
const w = await wide(p);
const t = await text(p);
check(`iPhone (390 px, no Web MIDI, es): no sideways scroll (${w}), the files only, in Spanish`, w[0] <= w[1] && /Guardado: el PROYECTO 2/.test(t) && /Guardar acá lo que suena/.test(t) && /Descargar/.test(t) &&
/ARCHIVO/.test(t) && !/Enviar|Traer|Conectar/.test(t) && /no tiene Web MIDI/.test(t) && !(await groups(p)).includes("FM-1"));
await p.locator(pm).scrollIntoViewIfNeeded();
await shotSpan(p, "phone-6-iphone-es.png", pm, `${pm} .pm-row.sel`);
await p.context().close();
}
{ /* devices.html: the SMK-37 runs felucca.wasm (the panel works), the MPC its own build (said) */
const p = await page(browser, { url: "devices.html#smk37" });
await p.waitForSelector(".start button"); await p.click(".start button");
await p.waitForFunction(() => document.querySelector(".dev.on, .on"), null, { timeout: 20000 });
await p.click(`${pm} summary`);
await p.waitForSelector(`${pm} .pm-item[data-slot="5"]`, { timeout: 20000 }); await idle(p);
check("devices.html SMK-37: the 6 projects listed (this browser's flash), the page's tokens", await p.locator(`${pm} .pm-item`).count() === 6 &&
await p.evaluate(() => getComputedStyle(document.querySelector("#pm .pm-body")).getPropertyValue("--pm-hud").trim()) !== "#ffc23a");
await open(p, 0);
await shotSpan(p, "desktop-6-devices-smk37.png", pm, `${pm} .pm-row.sel`);
await p.evaluate(() => { location.hash = "#mpc"; });
await p.waitForSelector(".start button:not([disabled])"); await p.click(".start button");
await p.waitForFunction(() => /no project library/.test(document.querySelector("#pm").innerText), null, { timeout: 30000 }).catch(() => {});
check("devices.html MPC (its own build, no editor): the panel says it has no project library", /no project library/.test(await text(p)));
await p.context().close();
}
} catch (e) { console.log("browser-pm:", e); fails++; }
await browser.close();
server.close();
console.log(fails ? `browser-pm: ${fails} FAILED` : "browser-pm: all ok");
process.exit(fails ? 1 : 0);