增加加密群消息引用、编辑和撤回

This commit is contained in:
xhgit committed 2026-11-14 09:25:45 +08:00
1 parent de722039d6
commit 7beb0cf795
7 files changed
+177 -36

No files matched your search

+42 -4
View File
@@ -55,10 +55,10 @@ async function publish(owner, pages) {
await Promise.all(pages.map((page) => chat(page).getByText('群加密已建立', { exact: true }).waitFor()))
}
async function send(sender, text) {
async function send(sender, text, action = '发送群消息') {
await chat(sender).getByRole('textbox', { name: '群消息' }).fill(text)
const response = sender.waitForResponse((item) => /\/groups\/[^/]+\/messages$/.test(item.url()) && item.request().method() === 'POST')
await chat(sender).getByRole('button', { name: '发送群消息' }).click()
await chat(sender).getByRole('button', { name: action, exact: true }).click()
const sent = await response
assert.equal(sent.status(), 200, await sent.text())
const packet = sent.request().postDataJSON()
@@ -114,7 +114,7 @@ async function playVoice(page, sender, downloadPath) {
assert.equal(await player.evaluate((element) => element.paused), true)
}
test('Windows 与 Web 群聊加密投递文字、附件和语音,成员变更后隔离访问', { timeout: 120_000 }, async () => {
test('Windows 与 Web 加密群聊支持消息操作、附件、语音和成员隔离', { timeout: 120_000 }, async () => {
const browser = await chromium.launch({ channel: process.env.XHCHAT_TEST_BROWSER ?? 'msedge', args: ['--use-fake-device-for-media-stream'] })
const profile = await mkdtemp(join(tmpdir(), 'xhchat-group-test-'))
let desktop
@@ -170,6 +170,37 @@ test('Windows 与 Web 群聊加密投递文字、附件和语音,成员变更
await chat(removed).getByRole('button', { name: '启用本机群聊' }).click()
await chat(removed).getByText(first, { exact: true }).waitFor()
const original = chat(owner).getByRole('listitem').filter({ hasText: first })
assert.equal(await original.getByRole('button', { name: '编辑', exact: true }).count(), 0)
assert.equal(await original.getByRole('button', { name: '撤回', exact: true }).count(), 0)
await original.getByRole('button', { name: '引用', exact: true }).click()
const reply = '加密引用回复 ' + id()
assert.equal(await send(owner, reply), epoch)
const receivedReply = chat(windows).getByRole('listitem').filter({ hasText: reply })
await receivedReply.locator('blockquote').getByText(first, { exact: true }).waitFor()
await work(removed).getByRole('link', { name: '联系人' }).click()
const own = chat(windows).getByRole('listitem').filter({ has: windows.getByText(first, { exact: true }) }).first()
await own.getByRole('button', { name: '编辑', exact: true }).click()
const edited = '已修改群消息 ' + id()
assert.equal(await send(windows, edited, '保存编辑'), epoch)
const incomingEdit = chat(owner).getByRole('listitem').filter({ has: owner.getByText(edited, { exact: true }) })
await incomingEdit.getByText('已编辑', { exact: true }).waitFor()
await work(removed).getByRole('link', { name: '群组' }).click()
await removed.getByRole('link', { name: new RegExp(group) }).click()
await chat(removed).getByRole('button', { name: '启用本机群聊' }).click()
await chat(removed).getByText(edited, { exact: true }).waitFor()
const temporary = '待撤回群消息 ' + id()
assert.equal(await send(windows, temporary), epoch)
const outgoing = chat(windows).getByRole('listitem').filter({ hasText: temporary })
await chat(owner).getByText(temporary, { exact: true }).waitFor()
await outgoing.getByRole('button', { name: '撤回', exact: true }).click()
await chat(windows).getByRole('button', { name: '确认撤回' }).click()
for (const page of pages) {
await chat(page).getByText('消息已撤回', { exact: true }).waitFor()
assert.equal(await chat(page).getByText(temporary, { exact: true }).count(), 0)
}
const contents = Buffer.from('Windows 群文件内容 ' + id() + '\n'.repeat(9000))
const filename = '群附件-' + id() + '.txt'
await sendFile(windows, filename, 'text/plain', contents)
@@ -202,6 +233,11 @@ test('Windows 与 Web 群聊加密投递文字、附件和语音,成员变更
assert.equal(await image.evaluate((element) => element.naturalWidth), 1)
await chat(windows).getByRole('button', { name: '关闭预览' }).click()
await image.waitFor({ state: 'detached' })
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' })
const voiceUploads = []
windows.on('request', (request) => {
@@ -237,7 +273,9 @@ test('Windows 与 Web 群聊加密投递文字、附件和语音,成员变更
assert.notEqual(await send(owner, second), epoch)
await chat(windows).getByText(second, { exact: true }).waitFor()
assert.equal(await removed.getByText(second, { exact: true }).count(), 0)
assert.equal(await chat(windows).getByText(first, { exact: true }).count(), 1)
const history = chat(windows).getByRole('listitem').filter({ hasText: edited })
assert.equal(await history.count(), 1)
assert.equal(await history.getByRole('button', { name: '编辑', exact: true }).count(), 0)
} catch (error) {
const status = await Promise.all(pages.map((page) => page.locator('[role=alert], .group-chat [role=status]').allTextContents()))
throw new Error(JSON.stringify(status), { cause: error })