增加群文件、图片和视频视图
This commit is contained in:
1 parent
d5f4afb485
commit
52c0e52ffd
4 files changed
+102
-13
No files matched your search
@@ -10,6 +10,7 @@ import { _electron, chromium } from 'playwright'
|
||||
const base = process.env.XHCHAT_TEST_URL ?? 'http://127.0.0.1:8080'
|
||||
const work = (page) => page.getByRole('navigation', { name: '工作区' })
|
||||
const chat = (page) => page.getByRole('region', { name: '群消息' })
|
||||
const historyView = (page, name) => chat(page).getByRole('group', { name: '群历史视图' }).getByRole('button', { name, exact: true })
|
||||
const id = () => randomBytes(6).toString('hex')
|
||||
|
||||
async function register(page, username, password) {
|
||||
@@ -286,9 +287,19 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + filename }).waitFor()
|
||||
assert.equal(await chat(owner).getByRole('listitem').count(), 1)
|
||||
await keyword.clear()
|
||||
const attachmentRequests = []
|
||||
const trackAttachment = (request) => { if (request.url().includes('/attachments/')) attachmentRequests.push(request.url()) }
|
||||
owner.on('request', trackAttachment)
|
||||
await historyView(owner, '群文件').click()
|
||||
const fileShelf = chat(owner).getByRole('list', { name: '群文件' })
|
||||
await keyword.fill(filename.toUpperCase())
|
||||
const fileButton = fileShelf.getByRole('button', { name: '下载 ' + filename })
|
||||
await fileButton.waitFor()
|
||||
assert.deepEqual(attachmentRequests, [])
|
||||
owner.off('request', trackAttachment)
|
||||
const fileDownload = owner.waitForEvent('download')
|
||||
const fileResponse = owner.waitForResponse((item) => item.url().includes('/attachments/') && item.request().method() === 'GET')
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + filename }).click()
|
||||
await fileButton.click()
|
||||
const response = await fileResponse
|
||||
assert.equal(response.status(), 200)
|
||||
const ciphertext = await response.body()
|
||||
@@ -303,23 +314,66 @@ test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员
|
||||
tampered[0] ^= 1
|
||||
await route.fulfill({ status: 200, contentType: 'application/octet-stream', body: tampered })
|
||||
}, { times: 1 })
|
||||
await chat(owner).getByRole('button', { name: '下载 ' + filename }).click()
|
||||
await fileButton.click()
|
||||
await chat(owner).getByRole('alert').getByText('附件完整性校验失败').waitFor()
|
||||
await keyword.clear()
|
||||
await historyView(owner, '消息').click()
|
||||
|
||||
const photo = '群图片-' + id() + '.png'
|
||||
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aX2sAAAAASUVORK5CYII=', 'base64')
|
||||
await sendFile(owner, photo, 'image/png', pixel)
|
||||
await chat(windows).getByRole('button', { name: '预览 ' + photo }).click()
|
||||
await historyView(windows, '群图片').click()
|
||||
const gallery = chat(windows).getByRole('list', { name: '群图片' })
|
||||
assert.equal(await gallery.getByText(filename, { exact: false }).count(), 0)
|
||||
await gallery.getByRole('button', { name: '预览 ' + photo }).click()
|
||||
const image = chat(windows).getByRole('img', { name: photo })
|
||||
await image.evaluate((element) => element.decode())
|
||||
assert.equal(await image.evaluate((element) => element.naturalWidth), 1)
|
||||
await chat(windows).getByRole('button', { name: '关闭预览' }).click()
|
||||
await historyView(windows, '群视频').click()
|
||||
await image.waitFor({ state: 'detached' })
|
||||
await chat(windows).getByText('没有匹配的群视频。', { exact: true }).waitFor()
|
||||
await historyView(windows, '群图片').click()
|
||||
await gallery.getByRole('button', { name: '预览 ' + photo }).waitFor()
|
||||
const photoLine = chat(owner).getByRole('listitem').filter({ hasText: photo })
|
||||
assert.equal(await photoLine.getByRole('button', { name: '编辑', exact: true }).count(), 0)
|
||||
await photoLine.getByRole('button', { name: '撤回', exact: true }).click()
|
||||
await chat(owner).getByRole('button', { name: '确认撤回' }).click()
|
||||
await chat(windows).getByRole('button', { name: '预览 ' + photo }).waitFor({ state: 'detached' })
|
||||
await chat(windows).getByText('没有匹配的群图片。', { exact: true }).waitFor()
|
||||
|
||||
const clip = '群视频-' + id() + '.webm'
|
||||
const videoBytes = await owner.evaluate(async () => {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = 32
|
||||
canvas.height = 24
|
||||
const paint = canvas.getContext('2d')
|
||||
const stream = canvas.captureStream(15)
|
||||
const recorder = new MediaRecorder(stream, { mimeType: 'video/webm;codecs=vp8' })
|
||||
const recorded = new Promise((resolve, reject) => {
|
||||
const chunks = []
|
||||
recorder.ondataavailable = ({ data }) => chunks.push(data)
|
||||
recorder.onstop = async () => resolve(Array.from(new Uint8Array(await new Blob(chunks).arrayBuffer())))
|
||||
recorder.onerror = () => reject(new Error('无法生成验收视频'))
|
||||
})
|
||||
recorder.start()
|
||||
for (const color of ['#108760', '#2052a4', '#f5a12f']) {
|
||||
paint.fillStyle = color
|
||||
paint.fillRect(0, 0, 32, 24)
|
||||
await new Promise((resolve) => setTimeout(resolve, 150))
|
||||
}
|
||||
recorder.stop()
|
||||
stream.getTracks().forEach((track) => track.stop())
|
||||
return recorded
|
||||
})
|
||||
await sendFile(owner, clip, 'video/webm', Buffer.from(videoBytes))
|
||||
await historyView(windows, '群视频').click()
|
||||
const videos = chat(windows).getByRole('list', { name: '群视频' })
|
||||
await videos.getByRole('button', { name: '预览 ' + clip }).click()
|
||||
const player = videos.locator('video')
|
||||
await player.evaluate((element) => element.play())
|
||||
assert.equal(await player.evaluate((element) => element.videoWidth), 32)
|
||||
assert.match(await player.getAttribute('src'), /^blob:/)
|
||||
await historyView(windows, '消息').click()
|
||||
await player.waitFor({ state: 'detached' })
|
||||
|
||||
const voiceUploads = []
|
||||
windows.on('request', (request) => {
|
||||
|
||||
Reference in new issue
Block a user