Files
dxdesigner-part-replacement/tools/verify_dsh_file_ui.mjs
阿白叔 705c15eb93
Core regression / Python core and release configuration (push) Successful in 20s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 15s
Core regression / JavaScript syntax (pull_request) Successful in 3s
fix(dsh): restore native file tools and official loading UI
2026-11-04 19:05:21 +08:00

45 lines
2.5 KiB
JavaScript

/** Upload owned files via the real composer menu and Qt's actual file chooser. */
import assert from 'node:assert/strict';
import {writeFile,readdir,readFile} from 'node:fs/promises';
import path from 'node:path';
export async function verifyFileUi(c,output){
const wait=async(expression)=>{
const end=Date.now()+30000;
while(Date.now()<end){if(await c.evaluate(expression))return;await new Promise(r=>setTimeout(r,100));}
throw Error('File UI timed out: '+expression);
};
const fixtures=path.join(output,'file-fixtures');
const files=['dsh-upload.txt','dsh-upload.zip'].map(name=>path.join(fixtures,name));
await writeFile(path.join(output,'file-picker-request.json'),JSON.stringify(files));
// Plus opens the official command menu; choose its native attachment action.
const plus=`[...document.querySelectorAll('button[aria-label="添加文件或调用指令"]')].find(e=>e.getBoundingClientRect().width>0)`;
await c.click(plus);
const fileOption=`[...document.querySelectorAll('[role="option"],button')].find(e=>e.getBoundingClientRect().width>0&&/^文件\\s*file/.test(e.textContent.trim()))`;
await wait(`!!(${fileOption})`);
await c.click(fileOption);
await wait(`document.body.innerText.includes('dsh-upload.txt')&&document.body.innerText.includes('dsh-upload.zip')`);
await wait(`![...document.querySelectorAll('[role="progressbar"]')].some(e=>e.getBoundingClientRect().width>0)`);
await c.screenshot(path.join(output,'file-uploaded.png'));
// Validate the uploaded bytes in Harness's actual owned storage, not the DOM echo.
const roots=(await readdir(output)).filter(x=>x.startsWith('data-'));
assert.equal(roots.length,1);
const home=path.join(output,roots[0],'dsh/harness-home');
const expected=await Promise.all(files.map(f=>readFile(f)));
const found=new Set();
async function scan(dir){
for(const entry of await readdir(dir,{withFileTypes:true})){
const filename=path.join(dir,entry.name);
if(entry.isDirectory())await scan(filename);
else if(entry.isFile()){
const data=await readFile(filename);
expected.forEach((bytes,i)=>{if(data.equals(bytes))found.add(i);});
}
}
}
const end=Date.now()+20000;
while(found.size<files.length&&Date.now()<end){await scan(home);if(found.size<files.length)await new Promise(r=>setTimeout(r,150));}
assert.equal(found.size,2,'text and ZIP must reach actual Harness file storage unchanged');
return {status:'passed',realQtFilePicker:true,textAndZipUploaded:true,storedBytesMatched:true};
}