mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-03 18:33:14 +08:00
feat: 刷新消息列表时间改为350ms
This commit is contained in:
@@ -229,6 +229,44 @@ test('CHAT-01 archive More menu is keyboard-safe and keeps the page usable', asy
|
||||
}
|
||||
})
|
||||
|
||||
test('CHAT-REALTIME-01 archive refreshes from a native message-shard event', async () => {
|
||||
const fixture = await launchTestApp()
|
||||
const pageErrors: Error[] = []
|
||||
fixture.page.on('pageerror', (error) => pageErrors.push(error))
|
||||
try {
|
||||
await fixture.setWindowContentSize({ width: 820, height: 600 })
|
||||
await fixture.page.getByText('产品测试群', { exact: true }).click()
|
||||
await expect(fixture.page.getByText('这是一条脱敏测试消息', { exact: true })).toBeVisible()
|
||||
|
||||
const result = await fixture.page.evaluate(() =>
|
||||
window.electron.ipcRenderer.invoke('test:messageChange', {
|
||||
md5: 'group-regular-md5',
|
||||
event: { db: 'message_0.db', table: 'message', action: 'update' },
|
||||
message: {
|
||||
id: 'msg-monitor',
|
||||
localId: 999,
|
||||
from: 'user',
|
||||
type: '普通文本',
|
||||
datetime: '2026-08-31 12:00:00',
|
||||
content: '消息',
|
||||
isSender: false,
|
||||
name: '测试成员',
|
||||
senderId: 'wxid_fixture_member',
|
||||
createTime: Math.floor(Date.now() / 1000),
|
||||
contentData: { type: 'text', content: '消息' }
|
||||
}
|
||||
})
|
||||
)
|
||||
expect(result).toEqual({ success: true })
|
||||
await expect(fixture.page.getByText('消息', { exact: true })).toBeVisible({
|
||||
timeout: 3_000
|
||||
})
|
||||
expect(pageErrors).toEqual([])
|
||||
} finally {
|
||||
await fixture.close()
|
||||
}
|
||||
})
|
||||
|
||||
test('CHAT-02 personal WeChat send dialog is keyboard-safe and fits the viewport', async () => {
|
||||
test.skip(process.platform !== 'darwin', 'Personal WeChat sending is currently macOS-only')
|
||||
const fixture = await launchTestApp()
|
||||
|
||||
@@ -606,6 +606,19 @@ handle('db:getMessages', (md5, startTime, endTime, options) => {
|
||||
if (options && options.limit) messages = messages.slice(-options.limit)
|
||||
return messages
|
||||
})
|
||||
handle('test:messageChange', (payload = {}) => {
|
||||
const md5 = String(payload.md5 || '')
|
||||
const message = payload.message
|
||||
if (md5 && message && Array.isArray(fixture.messages[md5])) {
|
||||
fixture.messages[md5].push(message)
|
||||
}
|
||||
const event = payload.event || { db: 'message_0.db', table: 'message', action: 'update' }
|
||||
const json = typeof event === 'string' ? event : JSON.stringify(event)
|
||||
for (const window of BrowserWindow.getAllWindows()) {
|
||||
if (!window.isDestroyed()) window.webContents.send('wcdb-change', { type: 'update', json })
|
||||
}
|
||||
return { success: true }
|
||||
})
|
||||
handle('db:getGroupSnapshot', (md5) =>
|
||||
md5.startsWith('group-')
|
||||
? {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
isRelevantMessageMonitorEvent,
|
||||
parseWcdbMonitorEvent
|
||||
} from '../../src/renderer/src/utils/message-monitor'
|
||||
|
||||
describe('message monitor events', () => {
|
||||
it('parses structured native events and normalizes empty fields', () => {
|
||||
expect(
|
||||
parseWcdbMonitorEvent('{"db":"message_0.db","table":"message","action":"update"}')
|
||||
).toEqual({
|
||||
db: 'message_0.db',
|
||||
table: 'message',
|
||||
action: 'update'
|
||||
})
|
||||
expect(parseWcdbMonitorEvent('{"table":" ","action":null}')).toEqual({})
|
||||
})
|
||||
|
||||
it('refreshes the active archive for message shard events without a session id', () => {
|
||||
expect(
|
||||
isRelevantMessageMonitorEvent('{"db":"message_0.db","table":"message","action":"update"}', [
|
||||
'group-md5',
|
||||
'room@chatroom'
|
||||
])
|
||||
).toBe(true)
|
||||
expect(
|
||||
isRelevantMessageMonitorEvent(
|
||||
'{"db":"/tmp/db_storage/message/Msg_1.db-wal","table":"database"}',
|
||||
['group-md5']
|
||||
)
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('ignores unrelated session events but keeps legacy action-only compatibility', () => {
|
||||
expect(
|
||||
isRelevantMessageMonitorEvent('{"db":"session.db","table":"Session"}', [
|
||||
'group-md5',
|
||||
'room@chatroom'
|
||||
])
|
||||
).toBe(false)
|
||||
expect(isRelevantMessageMonitorEvent('{"action":"update"}', ['group-md5'])).toBe(true)
|
||||
expect(isRelevantMessageMonitorEvent('not-json', ['group-md5'])).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user