支持私聊附件多选拖拽和批量重试
This commit is contained in:
1 parent
ec2679b991
commit
2931383906
8 files changed
+166
-35
No files matched your search
@@ -161,8 +161,37 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
|
||||
|
||||
const contents = Buffer.from('端到端文件 ' + randomBytes(32).toString('hex'))
|
||||
const fileName = '跨端验收.txt'
|
||||
const remainingFile = '私聊批量重试.txt'
|
||||
const discardedFile = '待移除附件.txt'
|
||||
const payload = (name, buffer = Buffer.from(name)) => ({ name, mimeType: 'text/plain', buffer })
|
||||
const dropZone = (page) => page.getByRole('region', { name: '私聊附件发送区' })
|
||||
const sendBatch = (page) => dropZone(page).getByRole('button', { name: '发送私聊附件', exact: true }).click()
|
||||
const queue = dropZone(windows).getByRole('list', { name: '待发私聊附件' })
|
||||
const transfer = await windows.evaluateHandle((name) => {
|
||||
const data = new DataTransfer()
|
||||
data.items.add(new File([name], name, { type: 'text/plain' }))
|
||||
return data
|
||||
}, remainingFile)
|
||||
await dropZone(windows).locator('input:enabled').setInputFiles([payload(fileName, contents), payload(discardedFile)])
|
||||
assert.equal(await queue.getByRole('listitem').count(), 2)
|
||||
await queue.getByRole('button', { name: '移除 ' + discardedFile, exact: true }).click()
|
||||
await dropZone(windows).dispatchEvent('dragover', { dataTransfer: transfer })
|
||||
await dropZone(windows).dispatchEvent('drop', { dataTransfer: transfer })
|
||||
await transfer.dispose()
|
||||
assert.deepEqual(await queue.getByRole('listitem').locator('span').allTextContents(), [fileName, remainingFile])
|
||||
assert.equal(await web.getByRole('button', { name: '下载 ' + fileName, exact: true }).count(), 0)
|
||||
|
||||
const uploadMatcher = (url) => url.pathname.startsWith('/api/v1/attachments/') && url.searchParams.has('recipient')
|
||||
let attempts = 0
|
||||
const failSecond = async (route) => {
|
||||
if (route.request().method() === 'POST' && ++attempts === 2) {
|
||||
await route.fulfill({ status: 503, headers: { 'access-control-allow-origin': 'xhchat://app' },
|
||||
json: { error: { message: '私聊附件上传暂不可用' } } })
|
||||
} else await route.continue()
|
||||
}
|
||||
await windows.route(uploadMatcher, failSecond)
|
||||
const upload = windows.waitForRequest((req) => req.method() === 'POST' && req.url().includes('/api/v1/attachments/'))
|
||||
await windows.locator('input[type=file]').setInputFiles({ name: fileName, mimeType: 'text/plain', buffer: contents })
|
||||
await sendBatch(windows)
|
||||
const fileRequest = await upload
|
||||
const uploaded = fileRequest.postDataBuffer()
|
||||
assert.ok(uploaded)
|
||||
@@ -171,6 +200,14 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
|
||||
assert.ok(!fileRequest.url().includes(encodeURIComponent(fileName)))
|
||||
const fileButton = web.getByRole('button', { name: '下载 ' + fileName, exact: true })
|
||||
await fileButton.waitFor()
|
||||
await windows.getByRole('alert').getByText('私聊附件上传暂不可用', { exact: true }).waitFor()
|
||||
assert.deepEqual(await queue.getByRole('listitem').locator('span').allTextContents(), [remainingFile])
|
||||
await windows.unroute(uploadMatcher, failSecond)
|
||||
await sendBatch(windows)
|
||||
await web.getByRole('button', { name: '下载 ' + remainingFile, exact: true }).waitFor()
|
||||
await queue.waitFor({ state: 'detached' })
|
||||
assert.equal(await fileButton.count(), 1)
|
||||
assert.equal(await web.getByRole('button', { name: '下载 ' + discardedFile, exact: true }).count(), 0)
|
||||
const fileURL = new URL(fileRequest.url())
|
||||
await web.route(fileURL.origin + fileURL.pathname, async (route) => {
|
||||
const response = await route.fetch()
|
||||
@@ -205,7 +242,17 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
|
||||
})
|
||||
|
||||
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jf2sAAAAASUVORK5CYII=', 'base64')
|
||||
await web.locator('input[type=file]').setInputFiles({ name: '加密预览.png', mimeType: 'image/png', buffer: pixel })
|
||||
const webInput = dropZone(web).locator('input:enabled')
|
||||
const webQueue = dropZone(web).getByRole('list', { name: '待发私聊附件' })
|
||||
await webInput.setInputFiles(Array.from({ length: 9 }, (_, index) => payload('容量测试' + index + '.txt')))
|
||||
await web.getByText('每批最多发送 8 个私聊附件', { exact: true }).waitFor()
|
||||
assert.equal(await webQueue.count(), 0)
|
||||
await webInput.setInputFiles(payload('清空测试.txt'))
|
||||
await webQueue.getByText('清空测试.txt', { exact: true }).waitFor()
|
||||
await dropZone(web).getByRole('button', { name: '清空待发附件', exact: true }).click()
|
||||
await webQueue.waitFor({ state: 'detached' })
|
||||
await webInput.setInputFiles({ name: '加密预览.png', mimeType: 'image/png', buffer: pixel })
|
||||
await sendBatch(web)
|
||||
await windows.getByRole('button', { name: '预览 加密预览.png' }).click()
|
||||
const image = windows.getByRole('img', { name: '加密预览.png' })
|
||||
await image.waitFor()
|
||||
|
||||
@@ -628,12 +628,11 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await windows.getByRole('link', { name: names[0] }).click()
|
||||
await windows.getByRole('button', { name: '启用本机加密聊天' }).click()
|
||||
const privateFile = '私聊文件-' + id() + '.txt'
|
||||
const privateAttachments = windows.getByRole('region', { name: '私聊附件发送区' })
|
||||
await privateAttachments.locator('input:enabled').setInputFiles({ name: privateFile, mimeType: 'text/plain', buffer: contents })
|
||||
const originalUpload = windows.waitForResponse((item) => /\/api\/v1\/attachments\//.test(item.url()) && item.request().method() === 'POST')
|
||||
const attachmentInput = windows.locator('input[type=file]:enabled')
|
||||
const [originalFile] = await Promise.all([
|
||||
originalUpload,
|
||||
attachmentInput.setInputFiles({ name: privateFile, mimeType: 'text/plain', buffer: contents }),
|
||||
])
|
||||
await privateAttachments.getByRole('button', { name: '发送私聊附件', exact: true }).click()
|
||||
const originalFile = await originalUpload
|
||||
assert.equal(originalFile.status(), 204)
|
||||
const originalBytes = originalFile.request().postDataBuffer()
|
||||
assert.ok(originalBytes && originalBytes.length === contents.length + 16)
|
||||
|
||||
Reference in new issue
Block a user