import { act, render, screen } from "@testing-library/react"; import { WidgetHost } from "./WidgetHost"; import { useSessionStore } from "../store/sessionStore"; import { setLocale } from "../i18n"; afterEach(() => { act(() => { setLocale("en"); useSessionStore.getState().resetSession(); }); }); test("gate chrome follows UI locale while model questions and choices remain in their session language", () => { useSessionStore.setState({ pendingWidget: { id: "approval", widget: "select", title: "Domanda del revisore", options: [ { id: "approve", label: "Salva e procedi", label_i18n: "Save and proceed" }, { id: "proposal", label: "Usa la data del ricovero" }, ], } }); render(); expect(screen.getByRole("button", { name: "Save and proceed" })).toBeInTheDocument(); expect(screen.getByText("Domanda del revisore")).toBeInTheDocument(); expect(screen.getByRole("button", { name: "Usa la data del ricovero" })).toBeInTheDocument(); act(() => setLocale("it")); expect(screen.getByRole("button", { name: "Salva e procedi" })).toBeInTheDocument(); expect(useSessionStore.getState().pendingWidget?.options?.[0].label).toBe("Salva e procedi"); }); test.each([ ["en", "it", "Save and proceed", "Other — specify"], ["it", "en", "Salva e procedi", "Altro: specifica"], ])("HITL controls follow question language %s even when the UI locale changes", (language, uiLocale, save, other) => { setLocale(uiLocale); useSessionStore.setState({ pendingWidget: { id: "language-gate", widget: "select", interaction_language: language, title: "Which admission date should be used?", options: [{ id: "approve", label: "Save and proceed", label_i18n: "Save and proceed" }], reserved: ["back", "exit", "other"], } }); render(); expect(screen.getByRole("button", { name: save })).toBeVisible(); expect(screen.getByRole("button", { name: other })).toBeVisible(); act(() => setLocale(language)); act(() => setLocale(uiLocale)); expect(screen.getByRole("button", { name: other })).toBeVisible(); expect(screen.getByText("Which admission date should be used?")).toBeVisible(); });