|
|
@@ -2,24 +2,16 @@ import { screen } from "@testing-library/react";
|
|
|
import userEvent from "@testing-library/user-event";
|
|
|
import { renderWithProviders } from "test-utils";
|
|
|
import { describe, it, expect, vi, Mock, afterEach } from "vitest";
|
|
|
-import { uploadFiles, listFiles } from "#/services/fileService";
|
|
|
import toast from "#/utils/toast";
|
|
|
import AgentState from "#/types/AgentState";
|
|
|
import FileExplorer from "#/components/file-explorer/FileExplorer";
|
|
|
+import OpenHands from "#/api/open-hands";
|
|
|
|
|
|
const toastSpy = vi.spyOn(toast, "error");
|
|
|
+const uploadFilesSpy = vi.spyOn(OpenHands, "uploadFiles");
|
|
|
+const getFilesSpy = vi.spyOn(OpenHands, "getFiles");
|
|
|
|
|
|
vi.mock("../../services/fileService", async () => ({
|
|
|
- listFiles: vi.fn(async (path: string = "/") => {
|
|
|
- if (path === "/") {
|
|
|
- return Promise.resolve(["folder1/", "file1.ts"]);
|
|
|
- }
|
|
|
- if (path === "/folder1/" || path === "folder1/") {
|
|
|
- return Promise.resolve(["file2.ts"]);
|
|
|
- }
|
|
|
- return Promise.resolve([]);
|
|
|
- }),
|
|
|
-
|
|
|
uploadFiles: vi.fn(),
|
|
|
}));
|
|
|
|
|
|
@@ -42,7 +34,7 @@ describe.skip("FileExplorer", () => {
|
|
|
|
|
|
expect(await screen.findByText("folder1")).toBeInTheDocument();
|
|
|
expect(await screen.findByText("file1.ts")).toBeInTheDocument();
|
|
|
- expect(listFiles).toHaveBeenCalledTimes(1); // once for root
|
|
|
+ expect(getFilesSpy).toHaveBeenCalledTimes(1); // once for root
|
|
|
});
|
|
|
|
|
|
it.todo("should render an empty workspace");
|
|
|
@@ -53,12 +45,12 @@ describe.skip("FileExplorer", () => {
|
|
|
|
|
|
expect(await screen.findByText("folder1")).toBeInTheDocument();
|
|
|
expect(await screen.findByText("file1.ts")).toBeInTheDocument();
|
|
|
- expect(listFiles).toHaveBeenCalledTimes(1); // once for root
|
|
|
+ expect(getFilesSpy).toHaveBeenCalledTimes(1); // once for root
|
|
|
|
|
|
const refreshButton = screen.getByTestId("refresh");
|
|
|
await user.click(refreshButton);
|
|
|
|
|
|
- expect(listFiles).toHaveBeenCalledTimes(2); // once for root, once for refresh button
|
|
|
+ expect(getFilesSpy).toHaveBeenCalledTimes(2); // once for root, once for refresh button
|
|
|
});
|
|
|
|
|
|
it("should toggle the explorer visibility when clicking the toggle button", async () => {
|
|
|
@@ -84,15 +76,15 @@ describe.skip("FileExplorer", () => {
|
|
|
await user.upload(uploadFileInput, file);
|
|
|
|
|
|
// TODO: Improve this test by passing expected argument to `uploadFiles`
|
|
|
- expect(uploadFiles).toHaveBeenCalledOnce();
|
|
|
- expect(listFiles).toHaveBeenCalled();
|
|
|
+ expect(uploadFilesSpy).toHaveBeenCalledOnce();
|
|
|
+ expect(getFilesSpy).toHaveBeenCalled();
|
|
|
|
|
|
const file2 = new File([""], "file-name-2");
|
|
|
const uploadDirInput = await screen.findByTestId("file-input");
|
|
|
await user.upload(uploadDirInput, [file, file2]);
|
|
|
|
|
|
- expect(uploadFiles).toHaveBeenCalledTimes(2);
|
|
|
- expect(listFiles).toHaveBeenCalled();
|
|
|
+ expect(uploadFilesSpy).toHaveBeenCalledTimes(2);
|
|
|
+ expect(getFilesSpy).toHaveBeenCalled();
|
|
|
});
|
|
|
|
|
|
it.todo("should upload files when dragging them to the explorer", () => {
|
|
|
@@ -104,7 +96,7 @@ describe.skip("FileExplorer", () => {
|
|
|
it.todo("should download a file");
|
|
|
|
|
|
it("should display an error toast if file upload fails", async () => {
|
|
|
- (uploadFiles as Mock).mockRejectedValue(new Error());
|
|
|
+ (uploadFilesSpy as Mock).mockRejectedValue(new Error());
|
|
|
const user = userEvent.setup();
|
|
|
renderFileExplorerWithRunningAgentState();
|
|
|
|
|
|
@@ -113,7 +105,7 @@ describe.skip("FileExplorer", () => {
|
|
|
|
|
|
await user.upload(uploadFileInput, file);
|
|
|
|
|
|
- expect(uploadFiles).rejects.toThrow();
|
|
|
+ expect(uploadFilesSpy).rejects.toThrow();
|
|
|
expect(toastSpy).toHaveBeenCalledWith(
|
|
|
expect.stringContaining("upload-error"),
|
|
|
expect.any(String),
|