| 1 | import React from "react"; |
| 2 | import { createRoot } from "react-dom/client"; |
| 3 | import { ErrorMessage } from "../src/components/ErrorMessage"; |
| 4 | import { LocaleProvider, preloadLocale, useI18n } from "../src/lib/i18n"; |
| 5 | import { ToastProvider, useToast } from "../src/lib/toast"; |
| 6 | import "../src/styles.css"; |
| 7 | |
| 8 | await Promise.all([preloadLocale("zh"), preloadLocale("zh-TW")]); |
| 9 | function Fixture() { |
| 10 | const { setPref } = useI18n(); |
| 11 | const { showToast } = useToast(); |
| 12 | return <main style={{ maxWidth: 760, margin: "40px auto", padding: 24 }}> |
| 13 | <h1>错误提示验证</h1> |
| 14 | <nav style={{ display: "flex", gap: 12, margin: "24px 0" }}> |
| 15 | <button onClick={() => setPref("zh")}>简体中文</button> |
| 16 | <button onClick={() => setPref("zh-TW")}>繁體中文</button> |
| 17 | <button onClick={() => setPref("en")}>English</button> |
| 18 | <button onClick={() => showToast("HTTP 503: upstream unavailable; trace=browser-fixture", "error")}>测试错误弹窗</button> |
| 19 | </nav> |
| 20 | {[ |
| 21 | ["模型连接", "dial tcp: connection refused"], |
| 22 | ["服务限流", "HTTP 429: too many requests"], |
| 23 | ["历史会话", "读取会话失败:unrecognized storage record revision"], |
| 24 | ["文件操作", "open /tmp/数据.txt: permission denied"], |
| 25 | ["工具连接", "MCP server unavailable"], |
| 26 | ["未知异常", "unknown library fault <script>not executable</script>"], |
| 27 | ].map(([title, error]) => <section key={title} style={{ marginBottom: 24 }}> |
| 28 | <h2 style={{ fontSize: 15 }}>{title}</h2><p role="alert"><ErrorMessage error={error} /></p> |
| 29 | </section>)} |
| 30 | </main>; |
| 31 | } |
| 32 | createRoot(document.getElementById("root")!).render(<LocaleProvider><ToastProvider><Fixture /></ToastProvider></LocaleProvider>); |
| 33 |