mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat: mac发送完整支持4.1.13以上版本, 完善授权
This commit is contained in:
1 parent
9db08dba1a
commit
8c162969ff
18 files changed
+1841
-238
No files matched your search
@@ -58,7 +58,25 @@ describe('PersonalWechatSendPage on macOS', () => {
|
||||
value: {
|
||||
getPersonalWechatSendCapability: getCapability,
|
||||
getPersonalWechatSenderStatus: getSenderStatus,
|
||||
rebindPersonalWechatSender: rebindSender
|
||||
rebindPersonalWechatSender: rebindSender,
|
||||
// 发送能力授权卡所需的两个入口。页面在 Native 档位会调用它们,
|
||||
// 缺 mock 会让 refresh 抛错、整页停在错误态。
|
||||
getMacSendRuntimeAvailability: vi.fn(async () => ({
|
||||
state: 'available',
|
||||
message: '微信发送组件可用'
|
||||
})),
|
||||
getMacLicenseStatus: vi.fn(async () => ({
|
||||
deviceId: null,
|
||||
state: 'unlicensed',
|
||||
authorized: false,
|
||||
source: 'none',
|
||||
features: [],
|
||||
lastCheckedAt: null,
|
||||
licenseExpiresAt: null,
|
||||
tokenExpiresAt: null,
|
||||
message: '当前设备暂无发送能力授权'
|
||||
})),
|
||||
refreshMacLicense: vi.fn()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -66,7 +84,9 @@ describe('PersonalWechatSendPage on macOS', () => {
|
||||
it('shows the native runtime readiness', async () => {
|
||||
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
|
||||
|
||||
expect(await screen.findByText('微信消息发送已配置完成')).toBeVisible()
|
||||
// 页面重构后「就绪」的落点从 SetupGuide 尾部文案变成了「微信发送环境」卡片的状态标签;
|
||||
// 断言改到新位置,语义仍是“运行时准备好了”。
|
||||
expect(await screen.findByText('运行环境已就绪')).toBeVisible()
|
||||
expect(screen.getAllByText('已就绪')).not.toHaveLength(0)
|
||||
expect(screen.queryByText('查看支持的微信版本')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('高级诊断')).not.toBeInTheDocument()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { PersonalWechatSetupGuide } from '../../src/renderer/src/components/chat/PersonalWechatSetupGuide'
|
||||
@@ -41,6 +41,10 @@ describe('personal WeChat unavailable product state', () => {
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
getMacSendRuntimeAvailability: vi.fn(async () => ({
|
||||
state: 'available',
|
||||
message: '微信发送组件可用'
|
||||
})),
|
||||
getPersonalWechatSendCapability: vi.fn(async () => ({
|
||||
supported: true,
|
||||
ready: false,
|
||||
@@ -50,7 +54,19 @@ describe('personal WeChat unavailable product state', () => {
|
||||
message: '暂无发送能力',
|
||||
error: '暂无发送能力'
|
||||
})),
|
||||
getPersonalWechatSenderStatus: vi.fn(async () => unavailableStatus)
|
||||
getPersonalWechatSenderStatus: vi.fn(async () => unavailableStatus),
|
||||
getMacLicenseStatus: vi.fn(async () => ({
|
||||
deviceId: `mac_${'c'.repeat(64)}`,
|
||||
state: 'unlicensed',
|
||||
authorized: false,
|
||||
source: 'none',
|
||||
features: [],
|
||||
lastCheckedAt: null,
|
||||
licenseExpiresAt: null,
|
||||
tokenExpiresAt: null,
|
||||
message: '当前设备暂无发送能力授权'
|
||||
})),
|
||||
refreshMacLicense: vi.fn()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -85,12 +101,195 @@ describe('personal WeChat unavailable product state', () => {
|
||||
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
|
||||
|
||||
expect(await screen.findByRole('heading', { name: '先准备好微信消息功能' })).toBeVisible()
|
||||
expect(screen.getByRole('button', { name: '绑定微信' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: '授权后可绑定微信' })).toBeDisabled()
|
||||
expect(screen.getByRole('region', { name: '微信发送环境' })).toBeVisible()
|
||||
expect(screen.getByText('运行时正常')).toBeVisible()
|
||||
expect(screen.getByText('微信已绑定')).toBeVisible()
|
||||
expect(screen.getByText('发送组件正常')).toBeVisible()
|
||||
expect(screen.getByRole('button', { name: '首次使用配置' })).toHaveAttribute(
|
||||
'aria-expanded',
|
||||
'true'
|
||||
)
|
||||
expect(await screen.findByRole('region', { name: '发送能力授权' })).toBeVisible()
|
||||
expect(screen.queryByText(/发送能力属授权制,需要联系群主/)).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('link', { name: '这里' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByText(/manifest|dylib|runtime missing|文件缺失/i)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows real environment status and keeps first-use details collapsed when ready', async () => {
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
getMacSendRuntimeAvailability: vi.fn(async () => ({
|
||||
state: 'available',
|
||||
message: '微信发送组件可用'
|
||||
})),
|
||||
getPersonalWechatSendCapability: vi.fn(async () => ({
|
||||
supported: true,
|
||||
ready: true,
|
||||
status: 'ready',
|
||||
capabilities: { text: true, image: true, voice: true },
|
||||
senderStatus: readyStatus,
|
||||
message: '已就绪'
|
||||
})),
|
||||
getPersonalWechatSenderStatus: vi.fn(async () => readyStatus),
|
||||
getMacLicenseStatus: vi.fn(async () => ({
|
||||
...licenseStatus,
|
||||
state: 'revoked',
|
||||
authorized: false
|
||||
})),
|
||||
refreshMacLicense: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
|
||||
|
||||
expect(await screen.findByText('运行环境已就绪')).toBeVisible()
|
||||
expect(screen.getAllByText('正常')).toHaveLength(3)
|
||||
expect(screen.getByRole('button', { name: '授权后可开始发送' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: '首次使用配置' })).toHaveAttribute(
|
||||
'aria-expanded',
|
||||
'false'
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: '绑定微信' })).not.toBeInTheDocument()
|
||||
expect(await screen.findByText('授权已撤销')).toBeVisible()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '首次使用配置' }))
|
||||
expect(screen.getByRole('button', { name: '首次使用配置' })).toHaveAttribute(
|
||||
'aria-expanded',
|
||||
'true'
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: '绑定微信' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: '开始发送' })).not.toBeInTheDocument()
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(2)
|
||||
expect(screen.getByText('每个微信进程只能绑定一次')).toBeVisible()
|
||||
expect(screen.getByText(/4\.1\.13以下请保持微信未登录窗口状态/)).toBeVisible()
|
||||
expect(screen.getByText('4.1.13以上登录状态微信直接点击“绑定微信”')).toBeVisible()
|
||||
expect(screen.queryByText('能力检测')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('文字消息')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('图片消息')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('语音消息')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('copies the full device id and shows refresh loading without disabling copy', async () => {
|
||||
const deviceId = `mac_${'a'.repeat(64)}`
|
||||
let resolveRefresh: ((value: typeof licenseStatus) => void) | undefined
|
||||
const refreshMacLicense = vi.fn(
|
||||
() => new Promise<typeof licenseStatus>((resolve) => (resolveRefresh = resolve))
|
||||
)
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
configurable: true,
|
||||
value: { writeText: vi.fn(async () => undefined) }
|
||||
})
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
getMacSendRuntimeAvailability: vi.fn(async () => ({
|
||||
state: 'available',
|
||||
message: '微信发送组件可用'
|
||||
})),
|
||||
getPersonalWechatSendCapability: vi.fn(async () => ({
|
||||
supported: true,
|
||||
ready: false,
|
||||
status: 'unconfigured',
|
||||
capabilities: { text: false, image: false, voice: false },
|
||||
senderStatus: readyStatus,
|
||||
message: '未配置'
|
||||
})),
|
||||
getPersonalWechatSenderStatus: vi.fn(async () => readyStatus),
|
||||
getMacLicenseStatus: vi.fn(async () => ({ ...licenseStatus, deviceId, state: 'expired' })),
|
||||
refreshMacLicense
|
||||
}
|
||||
})
|
||||
|
||||
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
|
||||
const copyButton = await screen.findByRole('button', { name: '复制完整设备 ID' })
|
||||
fireEvent.click(copyButton)
|
||||
await waitFor(() => expect(navigator.clipboard.writeText).toHaveBeenCalledWith(deviceId))
|
||||
expect(await screen.findByText('授权已过期')).toBeVisible()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '重新检测授权' }))
|
||||
expect(await screen.findByRole('button', { name: '检测中…' })).toBeDisabled()
|
||||
expect(copyButton).toBeEnabled()
|
||||
resolveRefresh?.({ ...licenseStatus, deviceId, state: 'valid', authorized: true })
|
||||
})
|
||||
|
||||
it('does not query or render License when the send runtime is unavailable', async () => {
|
||||
const getMacLicenseStatus = vi.fn()
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
getMacSendRuntimeAvailability: vi.fn(async () => ({
|
||||
state: 'unavailable',
|
||||
message: '当前版本没有微信发送能力'
|
||||
})),
|
||||
getMacLicenseStatus,
|
||||
getPersonalWechatSendCapability: vi.fn(),
|
||||
getPersonalWechatSenderStatus: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
|
||||
|
||||
expect(await screen.findByRole('button', { name: '当前版本没有微信发送能力' })).toBeDisabled()
|
||||
expect(screen.getByText(/发送能力属授权制,需要联系群主/)).toBeVisible()
|
||||
expect(screen.getByRole('link', { name: '这里' })).toHaveAttribute(
|
||||
'href',
|
||||
'https://github.com/Wxw-Gu/TraceMemo#-交流与反馈'
|
||||
)
|
||||
expect(screen.queryByText(/manifest|dylib|runtime missing|文件缺失/i)).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('region', { name: '发送能力授权' })).not.toBeInTheDocument()
|
||||
expect(getMacLicenseStatus).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows component failure without querying License when send runtime files are damaged', async () => {
|
||||
const getMacLicenseStatus = vi.fn()
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
getMacSendRuntimeAvailability: vi.fn(async () => ({
|
||||
state: 'component_error',
|
||||
message: '发送组件缺失或异常:manifest missing'
|
||||
})),
|
||||
getMacLicenseStatus,
|
||||
getPersonalWechatSendCapability: vi.fn(),
|
||||
getPersonalWechatSenderStatus: vi.fn()
|
||||
}
|
||||
})
|
||||
|
||||
render(<PersonalWechatSendPage onNotice={vi.fn()} />)
|
||||
|
||||
expect(await screen.findByRole('button', { name: '发送组件缺失或异常' })).toBeDisabled()
|
||||
expect(screen.getAllByText('发送组件缺失或异常').length).toBeGreaterThan(0)
|
||||
expect(screen.queryByText(/发送能力属授权制,需要联系群主/)).not.toBeInTheDocument()
|
||||
expect(getMacLicenseStatus).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('region', { name: '发送能力授权' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
const readyStatus: PersonalWechatSenderStatus = {
|
||||
...unavailableStatus,
|
||||
state: 'online',
|
||||
wechatRunning: true,
|
||||
wechatPid: 1234,
|
||||
boundWechatPid: 1234,
|
||||
endpointReady: true,
|
||||
runtimeReady: true,
|
||||
attachReady: true,
|
||||
baseAddressReady: true,
|
||||
canSend: true,
|
||||
canSendText: true,
|
||||
canSendImage: true,
|
||||
canSendVoice: true
|
||||
}
|
||||
|
||||
const licenseStatus = {
|
||||
deviceId: `mac_${'b'.repeat(64)}`,
|
||||
state: 'valid' as const,
|
||||
authorized: true,
|
||||
source: 'online' as const,
|
||||
features: ['wechat', 'api'],
|
||||
lastCheckedAt: '2026-11-04T09:44:00+08:00',
|
||||
licenseExpiresAt: '2027-11-03T00:00:00+08:00',
|
||||
tokenExpiresAt: null,
|
||||
message: '已授权'
|
||||
}
|
||||
Reference in new issue
Block a user