/g)||[]).length,5);assert.match(receipts,/客户-a/);assert.match(receipts,/客户-b/);assert.match(receipts,/收款冲回/);assert.match(receipts,/¥-10\.00/);assert.match(receipts,/收款明细合计<\/td>| ¥133\.45/);
assert.doesNotMatch(receipts,/客户-r<|客户-rr<|退款冲回/);assert.match(refunds,/退款冲回/);assert.match(refunds,/¥-0\.01/);assert.match(refunds,/退款明细合计<\/td> | ¥5\.00/);
assert.match(html,/收款明细/);assert.match(html,/role="region" aria-label="助理所属订单收款明细表"/);
assert.match(receipts,/2026-10-23/);assert.match(receipts,/普通订单 · 开单 2026-10-22/);
assert.match(table(html,'麦麦所属订单收款逐笔明细'),/锁价 · 按实际收付日/);
assert.equal(h.calls.length,1);assert.equal(h.calls[0].url,'/api/report?basis=orderDate&from='+D+'&date='+D);
});
test('单号与锁价单沿用现有只读打开动作,客户和备注安全转义,缺单号仍可核对',async()=>{
const response=report(),item=response.recipientReceipts.assistant.items[0];item.customer=' ';item.reference='';item.paper_number='纸单 "<01>';
const h=harness(response);await h.run('renderReport()');const html=table(h.content.innerHTML,'助理所属订单收款逐笔明细');
assert.match(html,/<img src=x onerror="alert\(1\)">/);assert.match(html,/<script>alert\(2\)<\/script>/);assert.match(html,/纸单 "<01>/);assert.doesNotMatch(html,/ ]*data-id="lock-l"/);assert.match(locks,/data-action="open-order"[^>]*data-id="order-d"/);assert.match(locks,/data-id="lock-d">原锁价单/);
for(const [action,id] of [['open-order','order-a'],['open-price-lock','lock-l']]){
const button={dataset:{action,id},closest(){return null;}};for(const handler of h.handlers.click)await handler({target:{closest:()=>button}});
}
assert.deepEqual(JSON.parse(JSON.stringify(h.calls.slice(1))),[{openOrder:'order-a'},{openPriceLock:'lock-l'}]);
h.context.__item={kind:'receipt',amount:0,account:'助理现金',date:D,order_id:null,price_lock_id:null,order_date:null,number:null,paper_number:null};
const identity=h.run('reportReceiptIdentityHTML(__item)');assert.match(identity,/订单记录/);assert.match(identity,/未填客户称呼/);assert.doesNotMatch(identity,/data-action/);
});
test('老板全部成员空日显示简洁空态,只有退款时仍显示退款及负净收入',async()=>{
const h=harness(report(D,D,true));await h.run('renderReport()');const html=h.content.innerHTML;
assert.equal((html.match(/class="report-recipient-total">¥0\.00/g)||[]).length,0);
assert.match(html,/所选范围暂无所属订单收入、成本或待转记录/);assert.doesNotMatch(html,/aria-label="助理所属订单退款明细"/);
const response=report(D,D,true),refund=payment('only-refund','refund',100,'助理现金');response.recipientReceipts.assistant={recipient:'assistant',name:'助理',receipt:0,refund:100,net:-100,items:[refund]};response.receiptsByOrderDate={receipt:0,refund:100,net:-100};response.ownershipReceipts.assistant=ownershipPerson('assistant','助理',[refund]);response.accounts=[{account:'助理现金',receipt:0,refund:100,net:-100}];syncBusiness(response);
h.context.__response=response;await h.run('renderReport()');assert.match(h.content.innerHTML,/助理所属订单净收入<\/h2>¥-1\.00/);assert.match(h.content.innerHTML,/实收 ¥0\.00<\/span> 实退 ¥1\.00/);assert.match(table(h.content.innerHTML,'助理所属订单收款逐笔明细'),/所选范围没有助理所属订单收款记录/);assert.match(table(h.content.innerHTML,'助理所属订单退款逐笔明细'),/客户-only-refund/);
});
test('切换日月立即清空旧明细,晚到响应和失败不恢复旧收款,下载只取当前完整报告',async()=>{
const h=harness();await h.run('renderReport()');assert.equal(h.run('requireCurrentReport().date'),D);
const pending=[];h.context.__pending=pending;h.run('api=function(url){__calls.push({url});return new Promise((resolve,reject)=>__pending.push({resolve,reject}));};');
h.range(NEXT);const first=h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.equal(h.content.attributes['aria-busy'],'true');assert.doesNotMatch(h.content.innerHTML,/收款明细|133\.45/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);
h.range(NEXT,true);const second=h.run('renderReport()'),month=report(NEXT,'2026-10-01',true);pending[1].resolve(month);await second;
assert.equal(h.run('requireCurrentReport().from'),'2026-10-01');assert.match(h.content.innerHTML,/2026-10-01 至 2026-10-23/);assert.match(h.content.innerHTML,/所选范围暂无所属订单收入、成本或待转记录/);
pending[0].resolve(report(NEXT));await first;assert.equal(h.run('currentReport.from'),'2026-10-01');assert.doesNotMatch(h.content.innerHTML,/客户-a/);
const failure=h.run('renderReport()');pending[2].reject(new Error('合成网络失败'));await failure;assert.equal(h.run('currentReport'),null);assert.equal(h.content.attributes['aria-busy'],'false');assert.match(h.content.innerHTML,/合成网络失败/);assert.doesNotMatch(h.content.innerHTML,/收款明细/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);
const wrongUser=h.run('renderReport()');h.run("state={...state,user:{id:'different-user'}};");pending[3].resolve(month);await wrongUser;assert.equal(h.run('currentReport'),null);assert.doesNotMatch(h.content.innerHTML,/收款明细/);
});
test('缺收款人字段、错金额或明细不完整时不渲染成零,也不能下载或保存快照',async()=>{
const mutations=[r=>delete r.recipientReceipts,r=>delete r.recipientReceipts.owner,r=>r.recipientReceipts.assistant.items[0].amount='12345',r=>r.recipientReceipts.assistant.items[0].kind='expense',r=>r.recipientReceipts.assistant.items[0].date='2026-02-30',r=>r.recipientReceipts.assistant.items.pop(),r=>r.recipientReceipts.assistant.net++,r=>r.receiptsByOrderDate.receipt++];
for(const mutate of mutations){
const response=report();mutate(response);const h=harness(response);await h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.match(h.content.innerHTML,/收款人汇总与明细/);assert.doesNotMatch(h.content.innerHTML,/report-recipient-total/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);
}
});
test('下载包含双方总收款、实际日期、账户及有符号收退款明细,并保持既有对账信息',async()=>{
const h=harness();await h.run('renderReport()');const text=h.run('reportDownloadText(requireCurrentReport())');
assert.match(text,/助理总收款:¥133\.45;退款 ¥5\.00;净收款 ¥128\.45/);assert.match(text,/麦麦总收款:¥600\.03;退款 ¥10\.00;净收款 ¥590\.03/);
assert.match(text,/2026-10-23 \/ 普通订单 · 开单 2026-10-22 \/ 纸单-c \/ 客户 客户-c \/ 娜娜微信 \/ 收款冲回 ¥-10\.00/);assert.match(text,/退款冲回 ¥-0\.01/);assert.match(text,/收款明细合计:¥133\.45/);assert.match(text,/锁价 · 按实际收付日/);
assert.match(text,/按收款账户核对/);assert.match(text,/双方支出成本/);assert.match(text,/订单与售后净额明细/);assert.match(text,/账面库存/);
});
test('所属净收入已经含他人代收,展示本人加实际代收账户关系且不再加一次',async()=>{
const response=report(),collected=response.recipientReceipts.owner.items.find(item=>item.id==='l'),assistant=response.recipientReceipts.assistant.items;
response.ownershipReceipts={assistant:ownershipPerson('assistant','助理',[...assistant,collected]),owner:ownershipPerson('owner','麦麦',response.recipientReceipts.owner.items.filter(item=>item.id!=='l'))};
syncBusiness(response);const h=harness(response);await h.run('renderReport()');const html=h.content.innerHTML;
assert.ok(html.startsWith('¥628\.46/);assert.match(html,/本人收款净额 ¥128\.45<\/b>/);assert.match(html,/麦麦现金代收净额 ¥500\.01<\/b>/);assert.match(html,/=<\/span>¥628\.46/);assert.match(html,/本人收款<\/h3>/);assert.match(html,/他人代收<\/h3>/);assert.doesNotMatch(html,/助理净收款<\/h2>|¥1,128\.47/);
const details=table(html,'助理所属订单收款逐笔明细');assert.match(details,/客户-l/);assert.match(details,/客户-a/);assert.match(details,/收款明细合计<\/td>¥633\.46/);
const text=h.run('reportDownloadText(requireCurrentReport())');assert.match(text,/助理所属订单净收入:¥628\.46/);assert.match(text,/他人代收 \/ 麦麦现金:实收 ¥500\.01/);assert.equal(h.calls.length,1);assert.ok(h.nodes.get('#main').innerHTML.indexOf('id="report-content"'){
const response=report(D,D,true),items=[payment('same-receipt','receipt',100,'助理微信'),payment('same-refund','refund',100,'助理微信'),payment('only-refund','refund',80,'麦麦支付宝'),payment('correct-before','receipt',50,'麦麦信用卡'),payment('correct-after','receipt',-50,'麦麦信用卡')];
for(const member of ['owner','assistant']){const rows=items.filter(item=>item.account.startsWith(member==='owner'?'麦麦':'助理')),person=ownershipPerson(member,member==='owner'?'麦麦':'助理',rows);response.ownershipReceipts[member]=person;response.recipientReceipts[member]={recipient:member,name:person.name,receipt:person.receipt,refund:person.refund,net:person.net,items:rows};}
response.receiptsByOrderDate={receipt:100,refund:180,net:-80};response.accounts=Object.values(response.ownershipReceipts).flatMap(person=>person.accounts.map(({account,receipt,refund,net})=>({account,receipt,refund,net}))).concat([{account:'助理现金',receipt:0,refund:0,net:0}]);syncBusiness(response);
const h=harness(response);await h.run('renderReport()');const accounts=table(h.content.innerHTML,'按收款账户核对');assert.doesNotMatch(accounts,/娜娜现金/);for(const account of ['娜娜微信','麦麦支付宝','麦麦信用卡'])assert.ok(accounts.includes(account),account);assert.match(accounts,/麦麦支付宝<\/td>| ¥0\.00<\/td> | ¥0\.80<\/td> | ¥-0\.80/);assert.match(accounts,/麦麦信用卡<\/td> | ¥0\.00<\/td> | ¥0\.00<\/td> | ¥0\.00/);
assert.equal(h.run('reportActiveAccounts(currentReport).length'),3);assert.match(table(h.content.innerHTML,'麦麦所属订单收款逐笔明细'),/收款冲回/);
});
test('三人老板全部只显示有活动成员,选择成员或助理只显示该归属且允许跨人代收',async()=>{
const response=report();response.ownershipReceipts.assistant2=ownershipPerson('assistant2','助理2',[]);response.recipientReceipts.assistant2={recipient:'assistant2',name:'助理2',receipt:0,refund:0,net:0,items:[]};syncBusiness(response);const all=harness(response);all.run("state={...state,user:{...state.user,member:'owner'}};");await all.run('renderReport()');assert.doesNotMatch(all.content.innerHTML,/report-ownership-assistant2-title/);assert.match(all.content.innerHTML,/report-ownership-assistant-title/);assert.match(all.content.innerHTML,/report-ownership-owner-title/);
const owned=report(),items=Object.values(owned.recipientReceipts).flatMap(person=>person.items);owned.ownershipReceipts={assistant:ownershipPerson('assistant','助理1',items)};syncBusiness(owned);
const selected=harness(owned);selected.run("state={...state,user:{...state.user,member:'owner'}};reportMember='assistant';");await selected.run('renderReport()');assert.match(selected.content.innerHTML,/助理1所属订单净收入/);assert.doesNotMatch(selected.content.innerHTML,/report-ownership-owner-title|report-ownership-assistant2-title/);assert.ok(selected.calls[0].url.endsWith('&member=assistant'));
const assistant=harness(owned);assistant.run("state={...state,user:{id:'assistant-user',role:'assistant',name:'助理1',member:'assistant'}};");await assistant.run('renderReport()');assert.match(assistant.content.innerHTML,/助理1所属订单净收入/);assert.doesNotMatch(assistant.content.innerHTML,/report-ownership-owner-title/);assert.match(assistant.content.innerHTML,/麦麦现金/);assert.equal(assistant.run('currentReport.ownershipReceipts.assistant.net'),71848);
});
test('选定成员空日保留本人0收入说明,旧双人助理保持原可见两组范围',async()=>{
const empty=report(D,D,true);empty.ownershipReceipts={assistant:empty.ownershipReceipts.assistant};syncBusiness(empty);const h=harness(empty);h.run("state={...state,user:{...state.user,member:'owner'}};reportMember='assistant';");await h.run('renderReport()');assert.match(h.content.innerHTML,/助理所属订单净收入/);assert.match(h.content.innerHTML,/report-recipient-total">¥0\.00/);assert.match(h.content.innerHTML,/所选范围暂无收退款记录/);assert.doesNotMatch(h.content.innerHTML,/report-ownership-owner-title/);
const legacy=harness();legacy.run("state={...state,user:{id:'legacy-assistant',role:'assistant',name:'助理'}};");await legacy.run('renderReport()');assert.match(legacy.content.innerHTML,/助理所属订单净收入/);assert.match(legacy.content.innerHTML,/麦麦所属订单净收入/);assert.equal(legacy.run('currentReport.receiptsByOrderDate.net'),71848);
});
test('缺失所属收入、漏账户、金额或条数不符及跨权限成员均阻止展示和保存',async()=>{
const changes=[r=>delete r.ownershipReceipts,r=>r.ownershipReceipts.assistant.net++,r=>r.ownershipReceipts.assistant.accounts[0].entryCount--,r=>r.ownershipReceipts.assistant.accounts[0].net++,r=>r.ownershipReceipts.assistant.accounts.pop(),r=>r.ownershipReceipts.assistant.member='owner',r=>r.ownershipReceipts.assistant.items=r.ownershipReceipts.assistant.items.slice(0,-1)];
for(const change of changes){const response=report();change(response);const h=harness(response);await h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.match(h.content.innerHTML,/所属订单净收入与账户明细/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);assert.doesNotMatch(h.content.innerHTML,/report-ownership-assistant-title/);}
const leaked=harness();leaked.run("state={...state,user:{id:'assistant-user',role:'assistant',name:'助理1',member:'assistant'}};");await leaked.run('renderReport()');assert.equal(leaked.run('currentReport'),null);assert.match(leaked.content.innerHTML,/所属订单净收入与账户明细/);
});
test('所属账户和成员显示名转义,0净冲回明细不能被漏掉而伪装完整',async()=>{
const response=report(),item=response.recipientReceipts.assistant.items[0];item.account=' | | |