File size: 1,176 Bytes
cc678b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";

import { DemoPreview } from "./DemoPreview";

afterEach(() => vi.unstubAllGlobals());

describe("DemoPreview", () => {
  it("replays delivered, low-confidence, and blocked moments without browser APIs", () => {
    const getUserMedia = vi.fn();
    vi.stubGlobal("fetch", vi.fn());
    vi.stubGlobal("navigator", { mediaDevices: { getUserMedia } });
    render(<DemoPreview language="vi" />);

    fireEvent.click(screen.getByRole("button", { name: "Xem mô phỏng" }));
    expect(screen.getByText("Bản dịch được chuyển")).toBeInTheDocument();
    fireEvent.click(screen.getByRole("button", { name: "Xem tình huống tiếp theo" }));
    expect(screen.getByText("Độ tin cậy thấp", { exact: true })).toBeInTheDocument();
    fireEvent.click(screen.getByRole("button", { name: "Xem tình huống tiếp theo" }));
    expect(screen.getByText("Đã chặn, chờ bác sĩ xác nhận", { exact: true })).toBeInTheDocument();

    expect(fetch).not.toHaveBeenCalled();
    expect(getUserMedia).not.toHaveBeenCalled();
  });
});