The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { expect, it, vi } from "vite-plus/test"; |
| 2 | import { page } from "vite-plus/test/browser"; |
| 3 | |
| 4 | import { act, render } from "../../../test/render"; |
| 5 | import { VoiceInputSetup } from "./VoiceInputSetup"; |
| 6 | |
| 7 | function wizard(open: boolean) { |
| 8 | return ( |
| 9 | <VoiceInputSetup |
| 10 | open={open} |
| 11 | step={1} |
| 12 | environmentId={null} |
| 13 | status={null} |
| 14 | model={null} |
| 15 | language={null} |
| 16 | downloading={false} |
| 17 | error={null} |
| 18 | onOpenChange={() => {}} |
| 19 | onRetryCatalog={null} |
| 20 | onDownload={() => {}} |
| 21 | onCancelDownload={() => {}} |
| 22 | onStartRecording={() => {}} |
| 23 | /> |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | it.each([ |
| 28 | { latest: "succeeds", showsError: false }, |
| 29 | { latest: "fails", showsError: true }, |
| 30 | ] as const)( |
| 31 | "ignores a superseded microphone refresh when the latest one $latest", |
| 32 | async ({ latest, showsError }) => { |
| 33 | await using screen = await render(wizard(false)); |
| 34 | const old = Promise.withResolvers<MediaDeviceInfo[]>(); |
| 35 | const current = Promise.withResolvers<MediaDeviceInfo[]>(); |
| 36 | const mediaDevices = navigator.mediaDevices; |
| 37 | using _enumeration = vi |
| 38 | .spyOn(mediaDevices, "enumerateDevices") |
| 39 | .mockReturnValueOnce(old.promise) |
| 40 | .mockReturnValueOnce(current.promise); |
| 41 | |
| 42 | await screen.rerender(wizard(true)); |
| 43 | const picker = page.getByRole("combobox", { name: "Microphone", exact: true }); |
| 44 | const alert = page.getByRole("alert").filter({ hasText: "Couldn’t list microphones" }); |
| 45 | await expect.element(picker).toBeDisabled(); |
| 46 | |
| 47 | await act(async () => { |
| 48 | mediaDevices.dispatchEvent(new Event("devicechange")); |
| 49 | if (latest === "fails") current.reject(new Error("Enumeration failed")); |
| 50 | else current.resolve([]); |
| 51 | }); |
| 52 | await expect.element(picker).toBeEnabled(); |
| 53 | |
| 54 | await act(async () => { |
| 55 | if (latest === "succeeds") old.reject(new Error("Superseded enumeration failed")); |
| 56 | else old.resolve([]); |
| 57 | }); |
| 58 | expect(alert.query() !== null).toBe(showsError); |
| 59 | }, |
| 60 | ); |