mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-17 19:47:08 +08:00
test: 建立桌面端自动化回归测试体系并完善跨平台 CI
(cherry picked from commit 74267ae2f63f8256c3da84b04f5b330e6e9d4c67)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { VoicePlayer } from '../../src/renderer/src/components/VoicePlayer'
|
||||
|
||||
const play = vi.fn(() => Promise.resolve())
|
||||
const pause = vi.fn()
|
||||
|
||||
class FakeAudio {
|
||||
preload = ''
|
||||
src = ''
|
||||
duration = 1
|
||||
currentTime = 0
|
||||
onloadedmetadata: (() => void) | null = null
|
||||
ontimeupdate: (() => void) | null = null
|
||||
onended: (() => void) | null = null
|
||||
play = play
|
||||
pause = pause
|
||||
load = vi.fn()
|
||||
removeAttribute = vi.fn()
|
||||
}
|
||||
|
||||
describe('VoicePlayer', () => {
|
||||
beforeEach(() => {
|
||||
play.mockClear()
|
||||
pause.mockClear()
|
||||
vi.stubGlobal('Audio', FakeAudio)
|
||||
window.api = {
|
||||
getVoiceData: vi.fn().mockResolvedValue({
|
||||
success: true,
|
||||
data: 'UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQAAAAA='
|
||||
})
|
||||
} as typeof window.api
|
||||
})
|
||||
|
||||
it('waits for decrypted bytes and calls play on the first click', async () => {
|
||||
const { container } = render(
|
||||
<VoicePlayer sessionId="filehelper" localId={11} createTime={1785553200} duration={1} />
|
||||
)
|
||||
await userEvent.click(container.querySelector('.voice-message') as HTMLElement)
|
||||
|
||||
await waitFor(() => expect(window.api.getVoiceData).toHaveBeenCalledOnce())
|
||||
await waitFor(() => expect(play).toHaveBeenCalledOnce())
|
||||
expect(container.querySelector('.voice-icon')).toHaveClass('playing')
|
||||
expect(screen.queryByText('当前版本暂不支持播放')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user