mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
fix(webui): prevent redundant thread and media reloads (#5164)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { act, render, screen } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { FilePreviewPanel } from "@/components/FilePreviewPanel";
|
||||
import { setAppLanguage } from "@/i18n";
|
||||
import { fetchFilePreview } from "@/lib/api";
|
||||
|
||||
vi.mock("@/components/CodeBlock", () => ({
|
||||
@@ -34,7 +35,8 @@ vi.mock("@/lib/api", async (importOriginal) => {
|
||||
});
|
||||
|
||||
describe("FilePreviewPanel", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
await setAppLanguage("en");
|
||||
vi.mocked(fetchFilePreview).mockReset();
|
||||
});
|
||||
|
||||
@@ -73,4 +75,32 @@ describe("FilePreviewPanel", () => {
|
||||
await user.click(closeButton);
|
||||
expect(onClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("updates translated chrome without refetching the open file", async () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
path: "/workspace/notes.md",
|
||||
display_path: "notes.md",
|
||||
language: "markdown",
|
||||
content: "# Notes",
|
||||
truncated: false,
|
||||
});
|
||||
|
||||
render(
|
||||
<FilePreviewPanel
|
||||
sessionKey="websocket:chat-1"
|
||||
path="notes.md"
|
||||
token="tok"
|
||||
onClose={() => {}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await screen.findByTestId("mock-code-block");
|
||||
expect(fetchFilePreview).toHaveBeenCalledTimes(1);
|
||||
|
||||
await act(async () => {
|
||||
await setAppLanguage("zh-CN");
|
||||
});
|
||||
|
||||
expect(fetchFilePreview).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user