// Isolated real React inputs; no API, customer data, or media requests. import assert from "node:assert/strict"; import { createServer } from "vite"; import { chromium } from "playwright"; const server = await createServer({ configFile: false, cacheDir: "local-data/vite-slice-edit-input", server: { host: "127.0.0.1", port: 0 }, preview: { port: 0 }, optimizeDeps: { noDiscovery: true, entries: [], include: ["react", "react-dom/client", "react-dom", "react/jsx-dev-runtime", "react/jsx-runtime"], }, plugins: [ { name: "slice-input-fixture", configureServer(s) { s.middlewares.use("/__panel", async (_req, res) => { res.setHeader("Content-Type", "text/html"); res.end( await s.transformIndexHtml( "/__panel", `
`, ), ); }); }, }, ], }); let browser; try { await server.listen(); browser = await chromium.launch({ executablePath: process.env.BROWSER_EXECUTABLE || "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", headless: true, args: ["--no-proxy-server"], }); const page = await browser.newPage(); const errors = []; page.on("pageerror", (e) => errors.push(e.message)); await page.route("**/*", (route) => new URL(route.request().url()).hostname === "127.0.0.1" ? route.continue() : route.abort(), ); const open = async () => { await page.goto(server.resolvedUrls.local[0] + "__panel"); await page.waitForFunction(() => window.target); }; await open(); const input = page.getByRole("spinbutton", { name: "首帧帧号", exact: true }); await input.fill("60"); await input.press("Escape"); assert.equal(await page.evaluate(() => window.target.start), 5, "Escape must discard the uncommitted numeric draft"); assert.deepEqual( await page.evaluate(() => window.calls), [], "Escape must not invoke boundary mutation through blur", ); console.log("PASS Escape discards numeric draft without boundary mutation"); await input.fill("60"); await input.press("Enter"); assert.equal(await page.evaluate(() => window.target.start), 2); assert.equal(await page.evaluate(() => window.calls.length), 1, "Enter commits exactly once"); console.log("PASS Enter commits once"); await open(); await input.fill("60"); await page.getByTestId("slice-edit-panel-apply").click(); assert.deepEqual(await page.evaluate(() => window.applied), [2], "Apply must observe the boundary committed by blur"); console.log("PASS mouse Apply includes focused input"); await open(); await page.evaluate(() => window.setExact(false)); const seconds = page.getByRole("spinbutton", { name: "首帧时间(秒)", exact: true }); await seconds.fill("2.125"); await seconds.press("Escape"); assert.equal(await page.evaluate(() => window.target.start), 5); await seconds.fill("3.125"); await seconds.press("Tab"); assert.deepEqual(await page.evaluate(() => window.calls), [{ field: "start", value: 3.125 }]); console.log("PASS seconds Escape followed by Tab commits only the later edit"); assert.deepEqual(errors, []); } finally { await browser?.close(); await server.close(); }