Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #4774: [Bug]: "Import Project" button does not work as expected #4775

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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