test(CloneModal): add smoke test for useAudioRecorder hook
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { renderHook } from "@testing-library/react"
|
||||
import { useAudioRecorder } from "@/components/voice/CloneModal/hooks/useAudioRecorder"
|
||||
|
||||
// Mock MediaRecorder
|
||||
const mockMediaRecorder = {
|
||||
start: vi.fn(),
|
||||
stop: vi.fn(),
|
||||
pause: vi.fn(),
|
||||
resume: vi.fn(),
|
||||
mimeType: "audio/webm",
|
||||
state: "inactive",
|
||||
ondataavailable: null,
|
||||
onstop: null,
|
||||
}
|
||||
|
||||
vi.stubGlobal(
|
||||
"MediaRecorder",
|
||||
vi.fn().mockImplementation(() => mockMediaRecorder),
|
||||
)
|
||||
|
||||
vi.stubGlobal("navigator", {
|
||||
mediaDevices: {
|
||||
getUserMedia: vi.fn().mockResolvedValue({
|
||||
getTracks: () => [{ stop: vi.fn() }],
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
describe("useAudioRecorder", () => {
|
||||
it("returns initial state", () => {
|
||||
const { result } = renderHook(() => useAudioRecorder())
|
||||
expect(result.current.isRecording).toBe(false)
|
||||
expect(result.current.duration).toBe(0)
|
||||
expect(typeof result.current.startRecording).toBe("function")
|
||||
expect(typeof result.current.stopRecording).toBe("function")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user