forked from longtao.wu/droboticflow
91 lines
4.3 KiB
JavaScript
91 lines
4.3 KiB
JavaScript
// 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",
|
|
`<div id="root"></div><script type="module">
|
|
import React,{useState}from'react';import{createRoot}from'react-dom/client';import{SliceEditPanel}from'/src/components/SliceEditPanel.tsx';
|
|
function App(){const[target,setTarget]=useState({id:'k',start:5,end:10});const[exact,setExact]=useState(true);window.target=target;window.setExact=setExact;window.calls??=[];window.applied??=[];
|
|
return React.createElement(SliceEditPanel,{target,ordinal:2,total:2,focusBoundary:'start',fixed:{start:false,end:true},exactFrames:exact,frameIndexOf:t=>Math.round(t*30),saving:false,playheadLabel:'0',onFocusBoundary:()=>{},onStep:()=>{},onCoarse:()=>{},onSplit:()=>{},onDiscard:()=>{},onMerge:()=>{},onCancel:()=>{},onApply:()=>window.applied.push(target.start),onSetBoundary:(field,value)=>{window.calls.push({field,value});setTarget(t=>({...t,[field]:exact?value/30:value}));},dictionary:{items:[],onSelect:()=>{}},discard:{draft:null,reasons:[],allowManual:true,loading:false,error:'',onDraftChange:()=>{},onConfirm:()=>{},onCancel:()=>{}}});}
|
|
createRoot(document.getElementById('root')).render(React.createElement(React.StrictMode,null,React.createElement(App)));
|
|
</script>`,
|
|
),
|
|
);
|
|
});
|
|
},
|
|
},
|
|
],
|
|
});
|
|
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();
|
|
}
|