| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { voiceInputFreezesEditor } from "@t3tools/client-runtime/voice-input"; |
| 3 | |
| 4 | import { resolveVoiceComposerPresentation } from "./voiceInputPresentation"; |
| 5 | |
| 6 | describe("resolveVoiceComposerPresentation", () => { |
| 7 | it("maps voice states to stable composer actions and editor read-only state", () => { |
| 8 | expect( |
| 9 | resolveVoiceComposerPresentation({ phase: "idle", error: null, errorAction: null }, 0), |
| 10 | ).toEqual({ |
| 11 | leadingAction: null, |
| 12 | trailingAction: "mic", |
| 13 | showsSend: true, |
| 14 | statusKind: null, |
| 15 | statusLabel: null, |
| 16 | confirmationEnabled: false, |
| 17 | }); |
| 18 | expect( |
| 19 | resolveVoiceComposerPresentation({ phase: "preparing", error: null, errorAction: null }, 0), |
| 20 | ).toMatchObject({ |
| 21 | leadingAction: "cancel", |
| 22 | trailingAction: "confirm", |
| 23 | showsSend: false, |
| 24 | statusLabel: "Preparing", |
| 25 | confirmationEnabled: false, |
| 26 | }); |
| 27 | expect( |
| 28 | resolveVoiceComposerPresentation({ phase: "recording", error: null, errorAction: null }, 64), |
| 29 | ).toMatchObject({ |
| 30 | leadingAction: "cancel", |
| 31 | trailingAction: "confirm", |
| 32 | showsSend: false, |
| 33 | statusLabel: "Recording 1:04", |
| 34 | confirmationEnabled: true, |
| 35 | }); |
| 36 | expect( |
| 37 | resolveVoiceComposerPresentation( |
| 38 | { phase: "transcribing", error: null, errorAction: null }, |
| 39 | 0, |
| 40 | ), |
| 41 | ).toMatchObject({ |
| 42 | statusLabel: "Transcribing", |
| 43 | confirmationEnabled: false, |
| 44 | }); |
| 45 | expect( |
| 46 | resolveVoiceComposerPresentation( |
| 47 | { phase: "error", error: "Microphone unavailable", errorAction: "retry" }, |
| 48 | 0, |
| 49 | ), |
| 50 | ).toMatchObject({ |
| 51 | leadingAction: null, |
| 52 | trailingAction: "mic", |
| 53 | showsSend: true, |
| 54 | statusKind: "error", |
| 55 | statusLabel: "Microphone unavailable", |
| 56 | }); |
| 57 | |
| 58 | expect(voiceInputFreezesEditor({ phase: "preparing", error: null, errorAction: null })).toBe( |
| 59 | true, |
| 60 | ); |
| 61 | expect(voiceInputFreezesEditor({ phase: "recording", error: null, errorAction: null })).toBe( |
| 62 | true, |
| 63 | ); |
| 64 | expect(voiceInputFreezesEditor({ phase: "transcribing", error: null, errorAction: null })).toBe( |
| 65 | true, |
| 66 | ); |
| 67 | expect(voiceInputFreezesEditor({ phase: "idle", error: null, errorAction: null })).toBe(false); |
| 68 | }); |
| 69 | }); |