import { expect, test } from "@playwright/test"; import { completeOnboarding, rpc, signup } from "./helpers"; test("voice settings connect a key, speak a reply, and open a call", async ({ page }) => { const stamp = Date.now(); const userName = `Voice ${stamp}`; await signup(page, `voice-${stamp}@rakazo.test`, "password12", userName); await completeOnboarding(page); await page.getByRole("button", { name: "Call" }).click(); await expect(page.getByTestId("voice-settings")).toBeVisible(); await expect(page.getByText("Not configured")).toBeVisible(); await page.getByRole("button", { name: "Close voice settings" }).click(); await expect(page.getByTestId("voice-settings")).toHaveCount(0); const preparedOff = await rpc<{ ready: boolean }>(page, "voice/prepare", { text: "Hello there.", }); expect(preparedOff.ready).toBe(false); await page.getByRole("button", { name: new RegExp(userName) }).click(); await page.getByRole("button", { name: "Voice", exact: true }).click(); await expect(page.getByTestId("voice-settings")).toBeVisible(); await page.getByRole("button", { name: /Scripted/ }).click(); const apiKeyInput = page.getByPlaceholder(/Paste your API key/); await expect(apiKeyInput).toHaveAttribute("autocomplete", "new-password"); await apiKeyInput.fill("fake-scripted-voice-key"); await page.getByRole("button", { name: "Connect" }).click(); await expect(page.getByText("Connected", { exact: true }).first()).toBeVisible(); await expect(page.getByText(/Connected ยท Scripted/)).toBeVisible(); const spoken = page.waitForResponse( (response) => response.url().includes("/api/voice/speak") && response.ok(), ); await page.getByRole("button", { name: "Hear a sample" }).click(); const clip = await spoken; expect(clip.headers()["content-type"]).toContain("audio/mpeg"); const credentials = await rpc>( page, "voice/credentials", {}, ); expect(credentials).toEqual([expect.objectContaining({ hasKey: true, provider: "scripted" })]); expect(JSON.stringify(credentials)).not.toContain("fake-scripted-voice-key"); await page.getByRole("button", { name: "Close voice settings" }).click(); const composer = page.getByPlaceholder(/Message/); await composer.fill("say hello"); await page.keyboard.press("Enter"); // A reply can render more than one text bubble; speak the latest one. const speakReply = page.getByRole("button", { name: "Speak this reply" }).last(); await expect(speakReply).toBeVisible({ timeout: 30_000, }); const replySpoken = page.waitForResponse( (response) => response.url().includes("/api/voice/speak") && response.ok(), ); await speakReply.click(); await replySpoken; await page.getByRole("button", { name: "Call" }).click(); await expect(page.getByTestId("call-view")).toBeVisible(); await expect(page.getByRole("button", { name: "Hang up" })).toBeVisible(); await page.getByRole("button", { name: "Hang up" }).click(); await expect(page.getByTestId("call-view")).toHaveCount(0); });