fix(frontend): double file upload on drag and drop (#2284)

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
This commit is contained in:
Antoine Dewez 2024-03-04 11:06:08 -08:00 committed by GitHub
parent ecc8eb6366
commit ff914b9d0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 123 deletions

View File

@ -1,120 +0,0 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { render } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import {
BrainContextMock,
BrainProviderMock,
} from "@/lib/context/BrainProvider/mocks/BrainProviderMock";
import {
ChatContextMock,
ChatProviderMock,
} from "@/lib/context/ChatProvider/mocks/ChatProviderMock";
import { KnowledgeToFeedProvider } from "@/lib/context/KnowledgeToFeedProvider";
import { MenuProvider } from "@/lib/context/MenuProvider/Menu-provider";
import {
SupabaseContextMock,
SupabaseProviderMock,
} from "@/lib/context/SupabaseProvider/mocks/SupabaseProviderMock";
import SelectedChatPage from "../page";
const queryClient = new QueryClient();
vi.mock("@/lib/context/ChatProvider/ChatProvider", () => ({
ChatContext: ChatContextMock,
ChatProvider: ChatProviderMock,
}));
vi.mock("@/lib/context/ChatsProvider/hooks/useChatsContext", () => ({
useChatsContext: () => ({
allChats: [
{
chat_id: 1,
name: "Chat 1",
creation_time: new Date().toISOString(),
},
{
chat_id: 2,
name: "Chat 2",
creation_time: new Date().toISOString(),
},
],
deleteChat: vi.fn(),
setAllChats: vi.fn(),
setIsLoading: vi.fn(),
}),
}));
vi.mock("next/navigation", () => ({
useRouter: () => ({ replace: vi.fn() }),
useParams: () => ({ chatId: "1" }),
usePathname: () => "/chat/1",
}));
vi.mock("@/lib/context/SupabaseProvider/supabase-provider", () => ({
SupabaseContext: SupabaseContextMock,
}));
vi.mock("@/lib/context/BrainProvider/brain-provider", () => ({
BrainContext: BrainContextMock,
}));
vi.mock("@/lib/api/chat/useChatApi", () => ({
useChatApi: () => ({
getHistory: () => [],
}),
}));
vi.mock("@/lib/hooks", async () => {
const actual = await vi.importActual<typeof import("@/lib/hooks")>(
"@/lib/hooks"
);
return {
...actual,
useAxios: () => ({
axiosInstance: {
get: vi.fn(() => ({ data: [] })),
},
}),
};
});
vi.mock("@tanstack/react-query", async () => {
const actual = await vi.importActual<typeof import("@tanstack/react-query")>(
"@tanstack/react-query"
);
return {
...actual,
useQuery: () => ({
data: {},
}),
};
});
vi.mock(
"../components/ActionsBar/components/ChatInput/components/ChatEditor/ChatEditor",
() => ({
ChatEditor: () => <div data-testid="chat-input" />,
})
);
vi.mock("../hooks/useChatNotificationsSync", () => ({
useChatNotificationsSync: vi.fn(),
}));
describe("Chat page", () => {
it("should render chat page correctly", () => {
const { getByTestId } = render(
<KnowledgeToFeedProvider>
<QueryClientProvider client={queryClient}>
<ChatProviderMock>
<SupabaseProviderMock>
<BrainProviderMock>
<MenuProvider>
<SelectedChatPage />,
</MenuProvider>
</BrainProviderMock>
</SupabaseProviderMock>
</ChatProviderMock>
</QueryClientProvider>
</KnowledgeToFeedProvider>
);
expect(getByTestId("chat-page")).toBeDefined();
expect(getByTestId("chat-input")).toBeDefined();
});
});

View File

@ -25,7 +25,8 @@ const SelectedChatPage = (): JSX.Element => {
const { getRootProps } = useCustomDropzone();
const { isMobile } = useDevice();
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
const { setShouldDisplayFeedCard, shouldDisplayFeedCard } =
useKnowledgeToFeedContext();
const { setIsBrainCreationModalOpened } = useBrainCreationContext();
const { currentBrain, setCurrentBrainId } = useBrainContext();
@ -81,8 +82,7 @@ const SelectedChatPage = (): JSX.Element => {
</div>
<div
className={styles.chat_page_container}
data-testid="chat-page"
{...getRootProps()}
{...(shouldDisplayFeedCard ? {} : getRootProps())}
>
<div
className={cn(