完成50%
This commit is contained in:
@@ -1,9 +1,166 @@
|
||||
const sleep=(ms)=>new Promise(r=>setTimeout(r,ms));const origin=process.argv[2]||"http://localhost:5173";
|
||||
const connect=async()=>{const pages=await(await fetch("http://127.0.0.1:9222/json/list")).json();const page=pages.find(x=>x.type==="page"&&x.url.startsWith(`${origin}/`));if(!page)throw new Error("No project Chrome page");const socket=new WebSocket(page.webSocketDebuggerUrl);await new Promise((r,j)=>{socket.addEventListener("open",r,{once:true});socket.addEventListener("error",j,{once:true})});let id=0;const pending=new Map();socket.addEventListener("message",e=>{const m=JSON.parse(e.data),p=pending.get(m.id);if(!p)return;pending.delete(m.id);m.error?p.reject(new Error(m.error.message)):p.resolve(m.result)});const send=(method,params={})=>new Promise((resolve,reject)=>{id+=1;pending.set(id,{resolve,reject});socket.send(JSON.stringify({id,method,params}))});return{socket,send};};
|
||||
const val=async(s,e)=>(await s("Runtime.evaluate",{expression:e,returnByValue:true})).result?.value;const wait=async(s,e,m)=>{for(let i=0;i<60;i++){if(await val(s,e))return;await sleep(100)}throw new Error(m)};let n=0;const open=async(s,route,selector)=>{n+=1;const url=`${origin}/?rBusiness=${n}#${route}`;await s("Page.navigate",{url});await wait(s,`location.href===${JSON.stringify(url)}`,`navigation failed ${route}`);await wait(s,`Boolean(document.querySelector(${JSON.stringify(selector)}))`,`missing ${selector} ${route}`);};const click=(s,q)=>val(s,`document.querySelector(${JSON.stringify(q)}).click()`);const inputAt=(s,q,index,v)=>val(s,`(()=>{const e=document.querySelectorAll(${JSON.stringify(q)})[${index}];e.value=${JSON.stringify(v)};e.dispatchEvent(new Event('input',{bubbles:true}));return e.value})()`);
|
||||
const routes=[["/pages/records/r03-gift-list?count=50",".record-card"],["/pages/records/r04-gift-editor?mode=create",".form-card"],["/pages/records/r05-ritual-list?count=50",".record-card"],["/pages/records/r06-ritual-detail?ritualId=501",".detail-card"],["/pages/records/r07-ritual-editor?mode=create",".form-card"],["/pages/records/r08-growth-journal",".timeline-card"],["/pages/records/r09-life-events",".timeline-card"],["/pages/records/r10-memo-list",".memo-card"],["/pages/records/r11-merit-records",".merit-card"]];
|
||||
const run=async()=>{const{socket,send}=await connect();try{await send("Page.enable");await send("Runtime.enable");for(const size of[{width:320,height:568},{width:412,height:915}]){await send("Emulation.setDeviceMetricsOverride",{...size,deviceScaleFactor:1,mobile:true,screenWidth:size.width,screenHeight:size.height});for(const[route,selector]of routes){await open(send,route,selector);if(await val(send,`document.documentElement.scrollWidth>${size.width+1}`))throw new Error(`${route} overflows at ${size.width}`);}await open(send,"/pages/records/r08-growth-journal",".timeline-card");await val(send,"(()=>{const p=document.querySelector('.page-content'),c=document.querySelector('.timeline-card');for(let i=0;i<48;i++)p.insertBefore(c.cloneNode(true),p.lastElementChild);p.querySelectorAll('.timeline-card')[49].scrollIntoView();return p.querySelectorAll('.timeline-card').length})()");if((await val(send,"document.querySelectorAll('.timeline-card').length"))!==50)throw new Error("R08 capacity stress failed");}
|
||||
await open(send,"/pages/records/r03-gift-list",".record-card");await click(send,".record-card");await wait(send,"location.hash.includes('/pages/records/r04-gift-editor?mode=view&giftId=301')","R03 did not open R04");
|
||||
await open(send,"/pages/records/r05-ritual-list",".record-card");await click(send,".record-card");await wait(send,"location.hash.includes('/pages/records/r06-ritual-detail?ritualId=501')","R05 did not open R06");
|
||||
await open(send,"/pages/records/r08-growth-journal",".header-action");await click(send,".header-action");await wait(send,"Boolean(document.querySelector('.app-dialog-layer'))","R08 dialog missing");await inputAt(send,".dialog-form input",0,"第一次远行");await inputAt(send,".dialog-form input",1,"2026 年 7 月");await click(send,".app-dialog__actions .app-button:last-child");await wait(send,"document.querySelector('.timeline-card').innerText.includes('第一次远行')","R08 save failed");
|
||||
await open(send,"/pages/records/r11-merit-records",".header-action");await click(send,".header-action");await inputAt(send,".dialog-form input",0,"整理旧谱");await inputAt(send,".dialog-form input",1,"汤文清");await click(send,".app-dialog__actions .app-button:last-child");await wait(send,"document.querySelector('.merit-summary').innerText.includes('3 次')","R11 total did not update");process.stdout.write("R-BUSINESS-FLOW-RUNTIME-SMOKE PASS\n");}finally{try{await send("Emulation.clearDeviceMetricsOverride")}catch(_){}socket.close();}};run().catch(e=>{process.stderr.write(`${e.stack||e.message}\n`);process.exit(1)});
|
||||
"use strict";
|
||||
|
||||
const assert = require("assert");
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const origin = process.argv[2] || "http://localhost:5173";
|
||||
|
||||
const connect = async () => {
|
||||
const pages = await (await fetch("http://127.0.0.1:9222/json/list")).json();
|
||||
const page = pages.find(
|
||||
(candidate) => candidate.type === "page" && candidate.url.startsWith(`${origin}/`),
|
||||
);
|
||||
if (!page) throw new Error(`Chrome debugging has no ${origin} project page`);
|
||||
const socket = new WebSocket(page.webSocketDebuggerUrl);
|
||||
await new Promise((resolve, reject) => {
|
||||
socket.addEventListener("open", resolve, { once: true });
|
||||
socket.addEventListener("error", reject, { once: true });
|
||||
});
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
socket.addEventListener("message", (event) => {
|
||||
const message = JSON.parse(event.data);
|
||||
const request = pending.get(message.id);
|
||||
if (!request) return;
|
||||
pending.delete(message.id);
|
||||
message.error
|
||||
? request.reject(new Error(message.error.message))
|
||||
: request.resolve(message.result);
|
||||
});
|
||||
const send = (method, params = {}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
id += 1;
|
||||
pending.set(id, { resolve, reject });
|
||||
socket.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
return { socket, send };
|
||||
};
|
||||
|
||||
const valueOf = async (send, expression) =>
|
||||
(await send("Runtime.evaluate", { expression, returnByValue: true })).result?.value;
|
||||
const waitFor = async (send, expression, message) => {
|
||||
for (let attempt = 0; attempt < 60; attempt += 1) {
|
||||
if (await valueOf(send, expression)) return;
|
||||
await sleep(100);
|
||||
}
|
||||
throw new Error(message);
|
||||
};
|
||||
let auditId = 0;
|
||||
const open = async (send, route, selector) => {
|
||||
auditId += 1;
|
||||
const url = `${origin}/?rBusiness=${auditId}#${route}`;
|
||||
await send("Page.navigate", { url });
|
||||
await waitFor(send, `location.href===${JSON.stringify(url)}`, `navigation failed: ${route}`);
|
||||
await waitFor(
|
||||
send,
|
||||
`Boolean(document.querySelector(${JSON.stringify(selector)}))`,
|
||||
`missing ${selector}: ${route}`,
|
||||
);
|
||||
};
|
||||
const click = (send, selector) =>
|
||||
valueOf(send, `document.querySelector(${JSON.stringify(selector)})?.click()`);
|
||||
const inputAt = (send, selector, index, value) =>
|
||||
valueOf(
|
||||
send,
|
||||
`(() => { const input=document.querySelectorAll(${JSON.stringify(selector)})[${index}]; input.value=${JSON.stringify(value)}; input.dispatchEvent(new Event('input',{bubbles:true})); return input.value; })()`,
|
||||
);
|
||||
|
||||
const routes = [
|
||||
["/pages/records/r03-gift-list?genealogyId=1001", ".record-card"],
|
||||
["/pages/records/r04-gift-editor?genealogyId=1001&mode=create", ".form-card"],
|
||||
["/pages/records/r05-ritual-list?genealogyId=1001", ".record-card"],
|
||||
["/pages/records/r06-ritual-detail?genealogyId=1001&ceremonyId=501", ".detail-card"],
|
||||
["/pages/records/r07-ritual-editor?genealogyId=1001&mode=create", ".form-card"],
|
||||
["/pages/records/r08-growth-journal?genealogyId=1001&personId=101", ".timeline-card"],
|
||||
["/pages/records/r09-life-events?genealogyId=1001&personId=101", ".service-state--unavailable"],
|
||||
["/pages/records/r10-memo-list?genealogyId=1001", ".memo-card"],
|
||||
["/pages/records/r11-merit-records?genealogyId=1001", ".merit-card"],
|
||||
];
|
||||
|
||||
const run = async () => {
|
||||
const { socket, send } = await connect();
|
||||
try {
|
||||
await send("Page.enable");
|
||||
await send("Runtime.enable");
|
||||
for (const size of [
|
||||
{ width: 320, height: 568 },
|
||||
{ width: 412, height: 915 },
|
||||
]) {
|
||||
await send("Emulation.setDeviceMetricsOverride", {
|
||||
...size,
|
||||
deviceScaleFactor: 1,
|
||||
mobile: true,
|
||||
screenWidth: size.width,
|
||||
screenHeight: size.height,
|
||||
});
|
||||
for (const [route, selector] of routes) {
|
||||
await open(send, route, selector);
|
||||
const documentWidth = await valueOf(send, "document.documentElement.scrollWidth");
|
||||
assert(documentWidth <= size.width + 1, `${route} overflows at ${size.width}`);
|
||||
}
|
||||
}
|
||||
|
||||
await open(send, "/pages/records/r08-growth-journal?genealogyId=1002&personId=101", ".timeline-state--invalid");
|
||||
await open(send, "/pages/records/r09-life-events", ".service-state--invalid");
|
||||
|
||||
await open(send, "/pages/records/r03-gift-list?genealogyId=1001", ".record-card");
|
||||
await click(send, ".record-card");
|
||||
await waitFor(
|
||||
send,
|
||||
"location.hash.includes('genealogyId=1001&mode=view&relativeId=301&sourceKey=R03')",
|
||||
"R03 did not open the scoped R04 record",
|
||||
);
|
||||
|
||||
await open(send, "/pages/records/r05-ritual-list?genealogyId=1001", ".record-card");
|
||||
await click(send, ".record-card");
|
||||
await waitFor(
|
||||
send,
|
||||
"location.hash.includes('genealogyId=1001&ceremonyId=501&sourceKey=R05')",
|
||||
"R05 did not open the scoped R06 ceremony",
|
||||
);
|
||||
|
||||
await open(send, "/pages/records/r08-growth-journal?genealogyId=1001&personId=101", ".timeline-card");
|
||||
const growthCount = await valueOf(send, "document.querySelectorAll('.timeline-card').length");
|
||||
await click(send, ".header-action");
|
||||
await waitFor(send, "Boolean(document.querySelector('.app-dialog-layer'))", "R08 editor missing");
|
||||
await inputAt(send, ".dialog-form input", 0, "第一次远行");
|
||||
await click(send, ".app-dialog__actions .app-button:last-child");
|
||||
await waitFor(
|
||||
send,
|
||||
"document.querySelector('.preview-card')?.innerText.includes('第一次远行')",
|
||||
"R08 local preview missing",
|
||||
);
|
||||
assert.strictEqual(
|
||||
await valueOf(send, "document.querySelectorAll('.timeline-card').length"),
|
||||
growthCount,
|
||||
"R08 local preview must not enter the official timeline",
|
||||
);
|
||||
|
||||
await open(send, "/pages/records/r11-merit-records?genealogyId=1001", ".merit-card");
|
||||
const meritCount = await valueOf(send, "document.querySelectorAll('.merit-card').length");
|
||||
await click(send, ".header-action");
|
||||
await inputAt(send, ".dialog-form input", 0, "整理旧谱");
|
||||
await inputAt(send, ".dialog-form input", 1, "汤文清");
|
||||
await click(send, ".app-dialog__actions .app-button:last-child");
|
||||
await waitFor(
|
||||
send,
|
||||
"document.querySelector('.preview-card')?.innerText.includes('整理旧谱')",
|
||||
"R11 local preview missing",
|
||||
);
|
||||
assert.strictEqual(
|
||||
await valueOf(send, "document.querySelectorAll('.merit-card').length"),
|
||||
meritCount,
|
||||
"R11 local preview must not change the official count",
|
||||
);
|
||||
process.stdout.write("R-BUSINESS-FLOW-RUNTIME-SMOKE PASS\n");
|
||||
} finally {
|
||||
try {
|
||||
await send("Emulation.clearDeviceMetricsOverride");
|
||||
} catch (_) {}
|
||||
socket.close();
|
||||
}
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
process.stderr.write(`${error.stack || error.message}\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user