|
1 | 1 | import { useLayoutEffect } from "react"; |
2 | 2 | import { expect, it, vi } from "vite-plus/test"; |
3 | 3 | import { page, userEvent } from "vite-plus/test/browser"; |
| 4 | +import * as Deferred from "effect/Deferred"; |
4 | 5 | import * as Effect from "effect/Effect"; |
5 | 6 | import * as Option from "effect/Option"; |
6 | 7 | import type { PreparedConnection } from "@t3tools/client-runtime/connection"; |
| 8 | +import { getEnvironmentSpeechModels } from "@t3tools/client-runtime/voice-input"; |
7 | 9 | import { |
8 | 10 | DEFAULT_CLIENT_SETTINGS, |
9 | 11 | DEFAULT_SERVER_SETTINGS, |
@@ -129,11 +131,12 @@ vi.mock("@t3tools/client-runtime/voice-input", async (importOriginal) => ({ |
129 | 131 | if (mocks.selectionFails) throw new Error("selection failed"); |
130 | 132 | return { models: mocks.models }; |
131 | 133 | }), |
132 | | - getEnvironmentSpeechModels: () => |
| 134 | + getEnvironmentSpeechModels: vi.fn(() => |
133 | 135 | Effect.sync(() => { |
134 | 136 | if (mocks.catalogOffline) throw new Error("Catalog offline"); |
135 | 137 | return { models: mocks.models }; |
136 | 138 | }), |
| 139 | + ), |
137 | 140 | postProcessEnvironmentTranscript: ( |
138 | 141 | prepared: PreparedConnection, |
139 | 142 | transcript: string, |
@@ -445,6 +448,29 @@ it.each([ |
445 | 448 | }, |
446 | 449 | ); |
447 | 450 |
|
| 451 | +it("closes setup when dictation is cancelled during a catalog read", async () => { |
| 452 | + setup({ destination: "env-a" }); |
| 453 | + mocks.modelState = "missing-model"; |
| 454 | + mocks.settings = { speechLanguage: "en" }; |
| 455 | + mocks.models = [catalogModel("current", ["en"], true)]; |
| 456 | + const response = Deferred.makeUnsafe<{ models: EnvironmentSpeechModel[] }>(); |
| 457 | + vi.mocked(getEnvironmentSpeechModels).mockReturnValueOnce(Deferred.await(response)); |
| 458 | + await using _screen = await render(<Probe showWizard />); |
| 459 | + let firstStart!: Promise<void>; |
| 460 | + await act(() => { |
| 461 | + firstStart = mocks.voice.start(); |
| 462 | + }); |
| 463 | + await expect.element(page.getByText("Loading transcription models…")).toBeVisible(); |
| 464 | + await act(() => mocks.voice.cancel()); |
| 465 | + expect(mocks.voice.setup.open).toBe(false); |
| 466 | + |
| 467 | + await act(() => mocks.voice.start()); |
| 468 | + Deferred.doneUnsafe(response, Effect.succeed({ models: [catalogModel("stale", ["en"], true)] })); |
| 469 | + await act(() => firstStart); |
| 470 | + await expect.element(page.getByRole("heading", { name: "current" })).toBeVisible(); |
| 471 | + expect(mocks.microphoneRequests).toEqual([]); |
| 472 | +}); |
| 473 | + |
448 | 474 | it.each([true, false])( |
449 | 475 | "never downloads the English default when no German recommendation is available (catalog offline: %s)", |
450 | 476 | async (offline) => { |
|
0 commit comments