import assert from "node:assert/strict";
import test from "node:test";
import { createSpeechFallback } from "../../lib/client/player/speech-fallback.ts";

test("selects a matching browser voice and exposes pause/resume/cancel", async () => {
  const calls = [];
  class Utterance { constructor(text) { this.text = text; } }
  const engine = {
    getVoices: () => [{ lang: "en-US", name: "English" }, { lang: "zh-CN", name: "中文" }],
    speak(value) { calls.push(["speak", value.text, value.voice?.lang, value.rate]); queueMicrotask(() => value.onend()); },
    pause() { calls.push(["pause"]); }, resume() { calls.push(["resume"]); }, cancel() { calls.push(["cancel"]); },
  };
  const fallback = createSpeechFallback({ engine, Utterance });
  await fallback.speak({ text: "你好", language: "zh-CN", rate: 1.5 });
  fallback.pause(); fallback.resume(); fallback.cancel();
  assert.deepEqual(calls, [["cancel"], ["speak", "你好", "zh-CN", 1.5], ["pause"], ["resume"], ["cancel"]]);
});
