✨ feat(frontend): 补齐本地文件免上传分享入口
This commit is contained in:
1 parent
7f9aaf8a4d
commit
638a56d894
16 files changed
+402
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
// Independent API fixture. Never sends requests to a deployed instance.
|
||||
export async function runLocalShareChecks(page, dark = false) {
|
||||
const headers={'access-control-allow-origin':'*','access-control-allow-headers':'*','access-control-allow-methods':'*'}
|
||||
let failShare=true, requests=0, failList=false
|
||||
await page.context().grantPermissions(['clipboard-read','clipboard-write'],{origin:'http://127.0.0.1:5180'})
|
||||
await page.route('**/*',route=>new URL(route.request().url()).hostname==='127.0.0.1'?route.continue():route.abort())
|
||||
const entry=(name,type='file',path=name)=>({name,file:name,path,type,size:type==='dir'?null:1024,ctime:null})
|
||||
await page.route('**/api/v1/config',route=>route.fulfill({headers,json:{code:200,detail:{config:{expireStyle:['day','count','forever'],max_save_seconds:604800}}}}))
|
||||
await page.route('**/admin/**',async route=>{
|
||||
const req=route.request(),url=new URL(req.url())
|
||||
if(req.method()==='OPTIONS') return route.fulfill({status:204,headers})
|
||||
if(url.pathname==='/admin/local/lists'){
|
||||
if(failList){failList=false;return route.fulfill({status:500,headers,json:{detail:'目录暂时不可用'}})}
|
||||
const path=url.searchParams.get('path'),size=Number(url.searchParams.get('size')||20),keyword=url.searchParams.get('keyword')||''
|
||||
let items=path==='文档'?[entry(' final 报告.txt ','file','文档/ final 报告.txt ')]:path==='空目录'?[]:[entry('文档','dir'),entry('空目录','dir'),...Array.from({length:23},(_,n)=>entry(`file-${String(n).padStart(2,'0')}.txt`))]
|
||||
items=items.filter(x=>x.name.includes(keyword));const total=items.length,p=Math.min(Number(url.searchParams.get('page')||1),Math.max(1,Math.ceil(total/size)))
|
||||
return route.fulfill({headers,json:{code:200,detail:{path,parent:'',items:items.slice((p-1)*size,p*size),total,page:p,size,truncated:false}}})
|
||||
}
|
||||
if(url.pathname==='/admin/local/share'){
|
||||
requests++; assert.deepEqual(req.postDataJSON(),{filename:'文档/ final 报告.txt ',expire_style:'count',expire_value:2})
|
||||
await new Promise(r=>setTimeout(r,180))
|
||||
if(failShare){failShare=false;return route.fulfill({status:500,headers,json:{detail:'文件暂时不可读'}})}
|
||||
return route.fulfill({headers,json:{code:200,detail:{id:18,code:'ABCD2345',name:' final 报告.txt ',path:'文档/ final 报告.txt '}}})
|
||||
}
|
||||
throw new Error('Unexpected API '+url.pathname)
|
||||
})
|
||||
await page.goto('http://127.0.0.1:5180/theme-assets/tests/local-files.html'+(dark?'?dark':''))
|
||||
await page.getByRole('button',{name:'打开 文档',exact:true}).waitFor()
|
||||
await page.getByRole('button',{name:'下一页',exact:true}).click()
|
||||
await page.getByText('file-22.txt',{exact:true}).waitFor()
|
||||
await page.getByRole('searchbox',{name:'在当前目录搜索'}).fill('文档')
|
||||
await page.getByRole('button',{name:'搜索',exact:true}).click()
|
||||
await page.getByRole('button',{name:'打开 文档',exact:true}).click()
|
||||
await page.getByRole('button',{name:/分享.*final 报告/}).click()
|
||||
const dialog=page.getByRole('dialog')
|
||||
await dialog.getByRole('combobox').selectOption('count')
|
||||
await dialog.locator('input[type=number]').fill('2')
|
||||
await dialog.getByRole('button',{name:'生成取件码',exact:true}).click()
|
||||
await dialog.getByRole('alert').waitFor()
|
||||
assert.ok((await dialog.getByRole('alert').textContent()).includes('文件暂时不可读'))
|
||||
await dialog.getByRole('button',{name:'生成取件码',exact:true}).click()
|
||||
await dialog.getByRole('textbox',{name:'取件码',exact:true}).waitFor()
|
||||
assert.equal(await dialog.getByRole('textbox',{name:'取件码',exact:true}).inputValue(),'ABCD2345')
|
||||
await dialog.getByRole('button',{name:'复制取件码',exact:true}).click()
|
||||
assert.equal(await page.evaluate(()=>navigator.clipboard.readText()),'ABCD2345')
|
||||
await dialog.getByRole('button',{name:'复制链接',exact:true}).click()
|
||||
assert.equal(await page.evaluate(()=>navigator.clipboard.readText()),'http://127.0.0.1:5180/#/?code=ABCD2345')
|
||||
assert.equal(requests,2)
|
||||
await dialog.getByRole('button',{name:'完成',exact:true}).click()
|
||||
await page.getByRole('button',{name:'返回上一级',exact:true}).click()
|
||||
await page.getByRole('button',{name:'打开 空目录',exact:true}).click()
|
||||
await page.getByText('当前目录还没有文件',{exact:true}).waitFor()
|
||||
failList=true
|
||||
await page.getByRole('button',{name:'刷新目录',exact:true}).click()
|
||||
await page.getByText('目录暂时不可用',{exact:true}).waitFor()
|
||||
await page.getByRole('button',{name:'重试目录',exact:true}).click()
|
||||
await page.getByText('当前目录还没有文件',{exact:true}).waitFor()
|
||||
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false)
|
||||
console.log(JSON.stringify({localShare:dark?'dark':'light',directorySearchPagination:true,shareRetryCopy:true,emptyErrorRetry:true,requests}))
|
||||
}
|
||||
Reference in new issue
Block a user