* 在上传框持续显示校验提示、进度和明确的收尾失败状态 * 提供复用原上传会话的取件码重试入口,避免重复上传 * 调整忙碌与错误布局,验证桌面及手机状态提示和按钮可见性
35 lines
3.4 KiB
JavaScript
35 lines
3.4 KiB
JavaScript
import {test,before,after} from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import {createServer} from 'vite'
|
|
import {fileURLToPath} from 'node:url'
|
|
import {createSSRApp,h} from 'vue'
|
|
import {renderToString} from 'vue/server-renderer'
|
|
import {createI18n} from 'vue-i18n'
|
|
let server,Area,Detail,zh,originalWindow
|
|
before(async()=>{originalWindow=globalThis.window;globalThis.window={location:{origin:'https://test.example'}};server=await createServer({resolve:{alias:{'file-saver':fileURLToPath(new URL('./fixtures/browser-save.stub.mjs',import.meta.url))}},server:{middlewareMode:true,watch:null},appType:'custom'});Area=(await server.ssrLoadModule('/src/components/common/FileUploadArea.vue')).default;Detail=(await server.ssrLoadModule('/src/components/common/FileDetailModal.vue')).default;zh=(await server.ssrLoadModule('/src/i18n/locales/zh-CN.ts')).default})
|
|
after(async()=>{await server?.close();globalThis.window=originalWindow})
|
|
async function render(component,props){const context={};const app=createSSRApp({render:()=>h(component,props)});app.use(createI18n({legacy:false,locale:'zh-CN',messages:{'zh-CN':zh}}));return (await renderToString(app,context))+Object.values(context.teleports||{}).join('')}
|
|
test('upload area displays actual bytes while sending and verifying',async()=>{
|
|
for(const uploadStatus of ['uploading','confirming']){const html=await render(Area,{uploadStatus,uploadedBytes:52428800,totalBytes:94371840,progress:50});assert.ok(html.includes('50 MB / 90 MB'));assert.ok(!html.includes('0 B / 0 B'))}
|
|
})
|
|
test('retrieval detail uses accessible shared dialog and exposes entire long filename',async()=>{
|
|
const filename='FlClash-'+'long-'.repeat(25)+'android-arm64-v8a.apk';const html=await render(Detail,{visible:true,record:{filename,size:'51.58 MB',date:'2026/09/18 15:08:09',code:'ABCD2345',downloadUrl:'/share/download?code=ABCD2345'}})
|
|
assert.ok(html.includes('role="dialog"'));assert.ok(html.includes(filename));assert.ok(html.includes('aria-modal="true"'));assert.ok(html.includes('点击下载'))
|
|
})
|
|
test('retrieve form enables both complete legacy and current codes without truncating eight digits',async()=>{
|
|
const Form=(await server.ssrLoadModule('/src/components/common/RetrieveForm.vue')).default
|
|
for(const code of ['ABCDE','ABCD2345']){
|
|
const html=await render(Form,{modelValue:code,inputStatus:{readonly:false,loading:false}})
|
|
assert.ok(html.includes('maxlength="8"'));assert.ok(html.includes(`value="${code}"`));assert.ok(!/<button[^>]* disabled(?:=|>| )/.test(html))
|
|
}
|
|
const html=await render(Form,{modelValue:'ABC',inputStatus:{readonly:false,loading:false}});assert.ok(/<button[^>]* disabled(?:=|>| )/.test(html))
|
|
})
|
|
test('verification status is announced in the upload box and failure exposes a retry action',async()=>{
|
|
const waiting=await render(Area,{selectedFile:new File(['data'],'waiting.apk'),uploadStatus:'confirming',uploadedBytes:4,totalBytes:4,progress:99})
|
|
assert.match(waiting,/role="status" aria-live="polite"/);assert.match(waiting,/正在校验文件,完成后生成取件码/)
|
|
assert.match(waiting,/aria-busy="true"/);assert.match(waiting,/animate-spin/);assert.match(waiting,/disabled/)
|
|
assert.ok(!waiting.includes('支持各种常见格式'))
|
|
const failed=await render(Area,{uploadStatus:'error',errorMessage:zh.send.uploadArea.status.confirmationFailed,retryText:zh.send.uploadArea.retryConfirmation})
|
|
assert.match(failed,/暂未取得取件码/);assert.match(failed,/重试生成取件码/);assert.match(failed,/aria-busy="false"/)
|
|
})
|