Spaces:
Running

File size: 1,187 Bytes
0a1e948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { useSyncExternalStore } from "react";

/**
 * The `speechToText` mock the dictation component tests share. Each file calls
 * it from its own `vi.mock`, because those calls are hoisted above the
 * imports and only run their factory later.
 */
export async function speechToTextMock() {
  const { DictationError: RealDictationError } = await import(
    "@/modules/speechToText"
  );
  return {
    DictationError: RealDictationError,
    getDictationEngine: vi.fn(() => "wasm" as const),
    startDictation: vi.fn(),
  };
}

/** A `notifications` stub that only records what was shown. */
export function notificationsStub() {
  return { notifications: { show: vi.fn() } };
}

/**
 * `create-pubsub/react` subscribing for real, so a channel written mid-test
 * re-renders the component the way it does in the app.
 */
export function pubSubReactMock() {
  return {
    usePubSub: (pubSub: [unknown, unknown, unknown]) => {
      const [publish, subscribe, get] = pubSub as [
        unknown,
        (listener: () => void) => () => void,
        () => unknown,
      ];
      const value = useSyncExternalStore(subscribe, get, get);
      return [value, publish];
    },
  };
}