fix: 增加手动复制退群信息 以及设置页面文案

This commit is contained in:
Wxw-Gu
2026-09-15 10:36:09 +08:00
parent 389a853560
commit ff212d594c
5 changed files with 160 additions and 3 deletions
@@ -4,6 +4,7 @@ import type { ReactElement } from 'react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { GroupExitMonitorWorkspace } from '../../src/renderer/src/features/group-exit-monitor/GroupExitMonitorWorkspace'
import type { GroupExitMonitorState } from '../../src/shared/group-exit-monitor'
import { formatGroupExitMonitorTime } from '../../src/shared/group-exit-monitor'
import type { Contact } from '../../src/shared/types'
import { TooltipProvider } from '../../src/renderer/src/components/ui'
@@ -327,6 +328,67 @@ describe('GroupExitMonitorWorkspace', () => {
expect(screen.queryByRole('heading', { name: '退群监测模板' })).not.toBeInTheDocument()
})
it('copies the exit notice built from the template saved on the management page', async () => {
const user = userEvent.setup()
const template = [
'[退群监测]',
'用户: {user}',
'群备注: {groupRemark}',
'微信号: {wxid}',
'人数: {previousCount}->{currentCount}',
'退群时间: {time}'
].join('\n')
const copyText = vi.fn().mockResolvedValue({ success: true })
window.api = {
getGroupExitMonitorState: vi
.fn()
.mockResolvedValue({ ...state, notificationTemplate: template }),
onGroupExitMonitorState: vi.fn(() => () => undefined),
copyText,
checkGroupExitMonitorNow: vi.fn().mockResolvedValue(state),
clearGroupExitMonitorEvents: vi.fn().mockResolvedValue(state)
} as typeof window.api
renderWorkspace(<GroupExitMonitorWorkspace dbReady />)
await user.click(
await screen.findByRole('button', { name: '复制退群信息:小艾退出了研发群' })
)
await waitFor(() => expect(copyText).toHaveBeenCalledTimes(1))
expect(copyText).toHaveBeenCalledWith(
[
'[退群监测]',
'用户: 小艾微信名',
'群备注: 小艾群备注',
'微信号: wxid_alice',
'人数: 240->239',
`退群时间: ${formatGroupExitMonitorTime(state.events[0].detectedAt)}`
].join('\n')
)
expect(await screen.findByText('已复制')).toBeVisible()
})
it('reports a clipboard failure and keeps the event list intact', async () => {
const user = userEvent.setup()
const copyText = vi.fn().mockResolvedValue({ success: false, error: '剪贴板不可用' })
window.api = {
getGroupExitMonitorState: vi.fn().mockResolvedValue(state),
onGroupExitMonitorState: vi.fn(() => () => undefined),
copyText,
checkGroupExitMonitorNow: vi.fn().mockResolvedValue(state),
clearGroupExitMonitorEvents: vi.fn().mockResolvedValue(state)
} as typeof window.api
renderWorkspace(<GroupExitMonitorWorkspace dbReady />)
await user.click(
await screen.findByRole('button', { name: '复制退群信息:小艾退出了研发群' })
)
expect(await screen.findByText('剪贴板不可用')).toBeVisible()
expect(screen.getByText('小艾退出了研发群')).toBeVisible()
expect(screen.queryByText('已复制')).not.toBeInTheDocument()
})
it('leaves every monitoring checkbox off for a new installation', async () => {
const user = userEvent.setup()
const newInstallState: GroupExitMonitorState = {
@@ -198,4 +198,14 @@ describe('PersonalWechatSendPage on Windows', () => {
expect(await screen.findByRole('spinbutton', { name: '微信发送能力端口' })).toBeVisible()
expect(screen.queryByRole('switch', { name: '保留 OneBot 进程' })).not.toBeInTheDocument()
})
it('shows the authorization notice with a README link on the Windows WeChat send page', async () => {
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
expect(await screen.findByText('发送能力授权')).toBeVisible()
expect(screen.getByText('发送能力属授权制,需要联系群主。请先加入交流群,然后在群内添加群主申请授权。')).toBeVisible()
const readmeLink = screen.getByRole('link', { name: '这里' })
expect(readmeLink).toHaveAttribute('href', 'https://github.com/Wxw-Gu/TraceMemo#-交流与反馈')
expect(readmeLink).toHaveAttribute('target', '_blank')
})
})