import { describe, expect, it } from "vitest"; import { computeCanStartDictation } from "./message-input-state"; const connected = { isConnected: true } as never; const disconnected = { isConnected: false } as never; describe("computeCanStartDictation", () => { it("returns false when socket is disconnected", () => { expect( computeCanStartDictation({ client: disconnected, isReadyForDictation: true, disabled: false, dictationUnavailableMessage: null, }), ).toBe(false); }); it("returns false when isReadyForDictation is explicitly false", () => { expect( computeCanStartDictation({ client: connected, isReadyForDictation: false, disabled: false, dictationUnavailableMessage: null, }), ).toBe(false); }); it("returns true when connected and ready", () => { expect( computeCanStartDictation({ client: connected, isReadyForDictation: true, disabled: false, dictationUnavailableMessage: null, }), ).toBe(true); }); it("falls back to socket connected state when isReadyForDictation is undefined", () => { expect( computeCanStartDictation({ client: connected, isReadyForDictation: undefined, disabled: false, dictationUnavailableMessage: null, }), ).toBe(true); expect( computeCanStartDictation({ client: disconnected, isReadyForDictation: undefined, disabled: false, dictationUnavailableMessage: null, }), ).toBe(false); }); it("returns false when the input is disabled", () => { expect( computeCanStartDictation({ client: connected, isReadyForDictation: true, disabled: true, dictationUnavailableMessage: null, }), ).toBe(false); }); it("returns false when a dictation unavailable message is present", () => { expect( computeCanStartDictation({ client: connected, isReadyForDictation: true, disabled: false, dictationUnavailableMessage: "Microphone unavailable", }), ).toBe(false); }); it("returns false when client is null", () => { expect( computeCanStartDictation({ client: null, isReadyForDictation: true, disabled: false, dictationUnavailableMessage: null, }), ).toBe(false); }); });