mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-04 12:57:39 +08:00
✨ feat(i18n): 推进多语言剩余切片闭环
- 补齐 DataGrid、DataViewer、DefinitionViewer、JVM 等模块多语言文案与回归测试 - 收口 JVM 前后端展示、诊断、监控和资源呈现相关多语言路径 - 更新六语言共享词典并保留 raw 边界
This commit is contained in:
169
frontend/src/components/ImportPreviewModal.test.tsx
Normal file
169
frontend/src/components/ImportPreviewModal.test.tsx
Normal file
@@ -0,0 +1,169 @@
|
||||
import React from "react";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { act, create, type ReactTestRenderer } from "react-test-renderer";
|
||||
|
||||
import { I18nProvider } from "../i18n/provider";
|
||||
import ImportPreviewModal from "./ImportPreviewModal";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
previewImportFile: vi.fn(),
|
||||
importDataWithProgress: vi.fn(),
|
||||
eventsOn: vi.fn(() => vi.fn()),
|
||||
eventsOff: vi.fn(),
|
||||
storeState: {
|
||||
connections: [
|
||||
{
|
||||
id: "conn-1",
|
||||
config: {
|
||||
type: "mysql",
|
||||
host: "localhost",
|
||||
port: 3306,
|
||||
user: "root",
|
||||
password: "",
|
||||
database: "app",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../store", () => ({
|
||||
useStore: (selector: (state: typeof mocks.storeState) => unknown) => selector(mocks.storeState),
|
||||
}));
|
||||
|
||||
vi.mock("../i18n/runtime", () => ({
|
||||
applyDayjsLocale: vi.fn(),
|
||||
syncLanguageRuntime: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../../wailsjs/go/app/App", () => ({
|
||||
PreviewImportFile: mocks.previewImportFile,
|
||||
ImportDataWithProgress: mocks.importDataWithProgress,
|
||||
}));
|
||||
|
||||
vi.mock("../../wailsjs/runtime/runtime", () => ({
|
||||
EventsOn: mocks.eventsOn,
|
||||
EventsOff: mocks.eventsOff,
|
||||
}));
|
||||
|
||||
vi.mock("antd", async () => {
|
||||
const React = await import("react");
|
||||
const Modal = ({
|
||||
children,
|
||||
footer,
|
||||
open,
|
||||
title,
|
||||
}: {
|
||||
children?: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
open?: boolean;
|
||||
title?: React.ReactNode;
|
||||
}) => (open ? React.createElement("section", null, title, children, footer) : null);
|
||||
const Table = ({ columns, dataSource }: { columns?: any[]; dataSource?: any[] }) =>
|
||||
React.createElement(
|
||||
"div",
|
||||
null,
|
||||
columns?.map((column) => React.createElement("span", { key: column.key || column.dataIndex }, column.title)),
|
||||
dataSource?.map((row, index) =>
|
||||
React.createElement(
|
||||
"div",
|
||||
{ key: index },
|
||||
Object.values(row).map((value, valueIndex) =>
|
||||
React.createElement("span", { key: valueIndex }, String(value)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return {
|
||||
Modal,
|
||||
Table,
|
||||
Alert: ({ message, description }: { message?: React.ReactNode; description?: React.ReactNode }) =>
|
||||
React.createElement("div", null, message, description),
|
||||
Progress: ({ percent }: { percent: number }) => React.createElement("div", null, `${percent}%`),
|
||||
Button: ({ children, onClick }: { children?: React.ReactNode; onClick?: () => void }) =>
|
||||
React.createElement("button", { onClick }, children),
|
||||
Space: ({ children }: { children?: React.ReactNode }) => React.createElement("div", null, children),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@ant-design/icons", async () => {
|
||||
const React = await import("react");
|
||||
const Icon = () => React.createElement("span", null);
|
||||
return {
|
||||
CheckCircleOutlined: Icon,
|
||||
CloseCircleOutlined: Icon,
|
||||
};
|
||||
});
|
||||
|
||||
const textContent = (node: any): string => {
|
||||
if (node === null || node === undefined) return "";
|
||||
if (typeof node === "string" || typeof node === "number") return String(node);
|
||||
if (Array.isArray(node)) return node.map((item) => textContent(item)).join("");
|
||||
return textContent(node.children || []);
|
||||
};
|
||||
|
||||
const renderImportPreview = async () => {
|
||||
let renderer!: ReactTestRenderer;
|
||||
await act(async () => {
|
||||
renderer = create(
|
||||
<I18nProvider preference="en-US" onPreferenceChange={() => undefined}>
|
||||
<ImportPreviewModal
|
||||
visible
|
||||
filePath="D:/imports/users.csv"
|
||||
connectionId="conn-1"
|
||||
dbName="app"
|
||||
tableName="users"
|
||||
onClose={vi.fn()}
|
||||
onSuccess={vi.fn()}
|
||||
/>
|
||||
</I18nProvider>,
|
||||
);
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
});
|
||||
return renderer;
|
||||
};
|
||||
|
||||
describe("ImportPreviewModal i18n", () => {
|
||||
beforeEach(() => {
|
||||
mocks.previewImportFile.mockResolvedValue({
|
||||
success: true,
|
||||
data: {
|
||||
columns: ["id", "user_name"],
|
||||
totalRows: 12,
|
||||
previewRows: [{ id: 1, user_name: "alice" }],
|
||||
},
|
||||
});
|
||||
mocks.importDataWithProgress.mockReset();
|
||||
mocks.eventsOn.mockClear();
|
||||
mocks.eventsOff.mockClear();
|
||||
});
|
||||
|
||||
it("renders preview chrome in the active language while preserving raw column names", async () => {
|
||||
const renderer = await renderImportPreview();
|
||||
const renderedText = textContent(renderer.toJSON());
|
||||
|
||||
expect(renderedText).toContain("Import data preview");
|
||||
expect(renderedText).toContain("12 rows and 2 fields");
|
||||
expect(renderedText).toContain("The first 5 rows are shown below. Start the import after confirming the data.");
|
||||
expect(renderedText).toContain("Field list:");
|
||||
expect(renderedText).toContain("Data preview (first 5 rows):");
|
||||
expect(renderedText).toContain("Cancel");
|
||||
expect(renderedText).toContain("Start import");
|
||||
expect(renderedText).toContain("id");
|
||||
expect(renderedText).toContain("user_name");
|
||||
});
|
||||
|
||||
it("does not keep migrated Chinese UI literals in ImportPreviewModal source", () => {
|
||||
const source = readFileSync(new URL("./ImportPreviewModal.tsx", import.meta.url), "utf8");
|
||||
|
||||
expect(source).not.toContain("导入数据预览");
|
||||
expect(source).not.toContain("开始导入");
|
||||
expect(source).not.toContain("加载预览数据...");
|
||||
expect(source).not.toContain("字段列表:");
|
||||
expect(source).not.toContain("数据预览(前 5 行):");
|
||||
expect(source).not.toContain("正在导入数据...");
|
||||
expect(source).not.toContain("错误日志:");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user