Skip to content

Commit

Permalink
Fix issue #4774: '[Bug]: "Import Project" button does not work as exp…
Browse files Browse the repository at this point in the history
…ected'
  • Loading branch information
openhands-agent committed Nov 6, 2024
1 parent e497438 commit f4fc6cb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
74 changes: 74 additions & 0 deletions frontend/__tests__/import-project.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { render, screen, fireEvent } from "@testing-library/react";
import { Provider } from "react-redux";
import store from "../src/store";
import { describe, it, expect, vi } from "vitest";
import { createMemoryRouter, RouterProvider } from "react-router-dom";

const mockNavigate = vi.fn();

// Mock the Remix components
vi.mock("@remix-run/react", async () => {
const actual = await vi.importActual("@remix-run/react");
return {
...actual,
useLoaderData: () => ({
repositories: null,
githubAuthUrl: null,
}),
useRouteLoaderData: () => null,
useNavigate: () => mockNavigate,
Await: ({ children }) => children(null),
Form: ({ children, onSubmit }: any) => (
<form onSubmit={(e) => { e.preventDefault(); onSubmit?.(e); }}>
{children}
</form>
),
};
});

// Mock the SuggestionBox component
vi.mock("../src/components/github-repositories-suggestion-box", () => ({
GitHubRepositoriesSuggestionBox: () => null,
}));

// Mock the SuggestionBubble component
vi.mock("../src/components/suggestion-bubble", () => ({
SuggestionBubble: () => null,
}));

// Mock the ChatInput component
vi.mock("../src/components/chat-input", () => ({
ChatInput: () => null,
}));

describe("Import Project", () => {
it("should not navigate immediately after selecting a zip file", async () => {
// Import the component after mocking
const { default: Home } = await import("../src/routes/_oh._index/route");

const router = createMemoryRouter([
{
path: "/",
element: (
<Provider store={store}>
<Home />
</Provider>
),
},
]);

render(<RouterProvider router={router} />);

// Find the file input
const fileInput = screen.getByLabelText("Upload a .zip");

// Create a mock file
const file = new File(["dummy content"], "test.zip", { type: "application/zip" });

// Simulate file selection
fireEvent.change(fileInput, { target: { files: [file] } });

// Verify that navigate was not called
expect(mockNavigate).not.toHaveBeenCalled();
});
});
1 change: 0 additions & 1 deletion frontend/src/routes/_oh._index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ function Home() {
if (event.target.files) {
const zip = event.target.files[0];
setImportedFile(zip);
navigate("/app");
} else {
// TODO: handle error
}
Expand Down

0 comments on commit f4fc6cb

Please sign in to comment.