File size: 867 Bytes
96f2542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { describe, expect, it } from "vitest";
import { Recorder } from "@/lib/audio";

describe("Recorder state machine", () => {
  it("starts in idle", () => {
    const r = new Recorder();
    expect(r.state).toBe("idle");
  });

  it("transitions idle -> requesting on start()", () => {
    const r = new Recorder();
    r.requestStart();
    expect(r.state).toBe("requesting");
  });

  it("transitions to error on permission denial", async () => {
    const r = new Recorder({
      getUserMedia: () => Promise.reject(new Error("denied")),
    });
    await r.start().catch(() => {});
    expect(r.state).toBe("error");
    expect(r.lastError?.message).toBe("denied");
  });

  it("ignores stop() in idle", async () => {
    const r = new Recorder();
    const result = await r.stop();
    expect(r.state).toBe("idle");
    expect(result).toBeNull();
  });
});