'use strict';
// Separate temporary browser; all network requests blocked. No user profile or forum access.
const {test}=require('node:test');
const assert=require('node:assert/strict');
const {chromium}=require('playwright');
const path=require('node:path');
const gif='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
function html({moderation=true,author=true,duplicateTid=false,lazy=false}={}) {
return `
原创标题
${moderation?'(审核中)':''}复制链接
${duplicateTid?'冲突链接':''} |
登录者
`;
}
test('结果页适配:真实主题、首帖范围、状态、图文与延迟加载',async()=>{
const browser=await chromium.launch({headless:true,executablePath:process.env.CHROME_PATH||'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'});
try {
const page=await browser.newPage();await page.route('**/*',r=>r.abort());
async function inspect(options={},snapshot={title:'原创标题',text:'原创正文',images:[{aid:'attachimg_42'}]}) {
await page.setContent(html(options));await page.addScriptTag({path:path.resolve(__dirname,'../browser/results.js')});
return page.evaluate(snapshot=>window.DWW11Results.inspect(document,'https://www.dww11.com/thread/23699911.html',snapshot),snapshot);
}
const accepted=await inspect();assert.equal(accepted.kind,'accepted');assert.equal(accepted.thread_id,'236999');assert.equal(accepted.first_post_pid,'238791');assert.equal(accepted.author_uid,'123');assert.equal(accepted.fid,90);assert.deepEqual(accepted.evidence.integrity_issues,[]);
assert.equal((await inspect({author:false})).kind,'incomplete','top login/replies cannot supply the author');
assert.equal((await inspect({moderation:false})).kind,'incomplete','absence of moderation is not public proof');
assert.equal((await inspect({duplicateTid:true})).kind,'incomplete');
const lazy=await inspect({lazy:true});assert.equal(lazy.evidence.images[0].loaded,false);
assert.ok(lazy.evidence.integrity_issues.length);
const changed=await inspect({}, {text:'被修改的正文',images:[{aid:'attachimg_99'}]});assert.equal(changed.evidence.integrity_issues.length,2);
await page.setContent('');
await page.addScriptTag({path:path.resolve(__dirname,'../browser/results.js')});
const prompt=await page.evaluate(()=>window.DWW11Results.inspect(document,'https://www.dww11.com/forum.php?topicsubmit=yes'));
assert.equal(prompt.kind,'waiting');assert.ok(prompt.prompt.includes('需要审核'));
await page.setContent('抱歉,您填写的标题超过 80 个字符限制
');
await page.addScriptTag({path:path.resolve(__dirname,'../browser/results.js')});
assert.equal((await page.evaluate(()=>window.DWW11Results.inspect(document,'https://www.dww11.com/forum.php'))).kind,'rejected');
}finally{await browser.close();}
});