feat(webui): add i18n support and locale switcher
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { act, render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
|
||||
import { ThreadComposer } from "@/components/thread/ThreadComposer";
|
||||
|
||||
describe("webui i18n", () => {
|
||||
it("switches UI copy and document locale through the language switcher", async () => {
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(
|
||||
<>
|
||||
<LanguageSwitcher />
|
||||
<ThreadComposer onSend={vi.fn()} />
|
||||
</>,
|
||||
);
|
||||
|
||||
expect(
|
||||
screen.getByPlaceholderText("Type your message…"),
|
||||
).toBeInTheDocument();
|
||||
expect(document.documentElement.lang).toBe("en");
|
||||
|
||||
await user.click(screen.getByRole("button", { name: "Change language" }));
|
||||
await user.click(screen.getByRole("menuitemradio", { name: /简体中文/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.documentElement.lang).toBe("zh-CN");
|
||||
});
|
||||
expect(localStorage.getItem("nanobot.locale")).toBe("zh-CN");
|
||||
expect(screen.getByPlaceholderText("输入消息…")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("updates the composer aria label when the language changes", async () => {
|
||||
render(<ThreadComposer onSend={vi.fn()} />);
|
||||
|
||||
await act(async () => {
|
||||
const { setAppLanguage } = await import("@/i18n");
|
||||
await setAppLanguage("ja");
|
||||
});
|
||||
|
||||
expect(screen.getByLabelText("メッセージ入力欄")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user