在登录页面显示分步错误与可复制诊断
This commit is contained in:
1 parent
de032f1b13
commit
36ddf35da0
2 files changed
+81
-4
No files matched your search
@@ -89,3 +89,25 @@ test('二进制Excel读取沿用账号校验与有限GET重试,HTML成功页
|
||||
const html=harness(()=>new Response('<html>login</html>',{headers:{'Content-Type':'text/html'}}));await assert.rejects(html.run("api('/api/inventory/movements/export.xlsx',undefined,undefined,{responseType:'xlsx'})"),/文件格式异常/);assert.equal(html.calls.length,1);
|
||||
const denied=harness(()=>httpError(403,'仅用于明确权限拒绝'));await assert.rejects(denied.run("api('/api/inventory/movements/export.xlsx',undefined,undefined,{responseType:'xlsx'})"),/明确权限拒绝/);assert.equal(denied.calls.length,1);
|
||||
});
|
||||
|
||||
test('登录诊断区分传输中断、超时、服务端拒绝和读取响应失败,隐藏提交内容',async()=>{
|
||||
const cases=[
|
||||
{fetcher:()=>{throw new TypeError('Load failed');},text:['提交登录失败','HTTP 状态:未收到','浏览器提示:Load failed']},
|
||||
{fetcher:(_url,{signal})=>new Promise((_,reject)=>signal.addEventListener('abort',()=>reject(new Error('fetch is aborted')))),timeout:true,text:['等待超过 25 秒','HTTP 状态:未收到']},
|
||||
{fetcher:()=>httpError(401,'账号或密码不正确'),text:['账号或密码不正确','HTTP 状态:401']},
|
||||
{fetcher:()=>new Response('private-response-content'),text:['未能读取完整','HTTP 状态:200']}
|
||||
];
|
||||
for(const c of cases){
|
||||
const h=harness(c.fetcher,{timeout:c.timeout});
|
||||
const html=await h.run("api('/api/login',{password:'secret-input'}).catch(err=>loginErrorHTML(err,'提交登录'))");
|
||||
for(const text of [...c.text,'北京时间','POST /api/login','复制诊断信息'])assert.ok(html.includes(text),text);
|
||||
assert.doesNotMatch(html,/secret-input|private-response-content/);
|
||||
assert.equal(h.calls.length,1);
|
||||
}
|
||||
for(const [route,stage] of [['/api/session','检查登录状态'],['/api/state','读取账本']]){
|
||||
const h=harness(()=>{throw new TypeError('Load failed');});
|
||||
const html=await h.run(`api('${route}').catch(err=>loginErrorHTML(err,'打开账本页面'))`);
|
||||
assert.ok(html.includes(stage+'失败'));
|
||||
assert.ok(html.includes('GET '+route));
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user