2023-09-26 11:35:52 +03:00
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
2023-07-05 10:30:22 +03:00
|
|
|
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";
|
2023-09-28 16:39:30 +03:00
|
|
|
import { KnowledgeToFeedProvider } from "@/lib/context/KnowledgeToFeedProvider";
|
2023-07-05 10:30:22 +03:00
|
|
|
import {
|
|
|
|
SupabaseContextMock,
|
|
|
|
SupabaseProviderMock,
|
|
|
|
} from "@/lib/context/SupabaseProvider/mocks/SupabaseProviderMock";
|
|
|
|
|
2023-07-05 19:33:18 +03:00
|
|
|
import SelectedChatPage from "../page";
|
2023-07-05 10:30:22 +03:00
|
|
|
|
2023-09-26 11:35:52 +03:00
|
|
|
const queryClient = new QueryClient();
|
|
|
|
|
2023-07-05 10:30:22 +03:00
|
|
|
vi.mock("@/lib/context/ChatProvider/ChatProvider", () => ({
|
|
|
|
ChatContext: ChatContextMock,
|
|
|
|
ChatProvider: ChatProviderMock,
|
|
|
|
}));
|
|
|
|
|
2023-08-30 10:45:11 +03:00
|
|
|
vi.mock("next/navigation", () => ({
|
|
|
|
useRouter: () => ({ replace: vi.fn() }),
|
|
|
|
useParams: () => ({ chatId: "1" }),
|
|
|
|
}));
|
|
|
|
|
2023-07-05 10:30:22 +03:00
|
|
|
vi.mock("@/lib/context/SupabaseProvider/supabase-provider", () => ({
|
|
|
|
SupabaseContext: SupabaseContextMock,
|
|
|
|
}));
|
|
|
|
|
|
|
|
vi.mock("@/lib/context/BrainProvider/brain-provider", () => ({
|
|
|
|
BrainContext: BrainContextMock,
|
|
|
|
}));
|
|
|
|
|
2023-09-08 10:57:21 +03:00
|
|
|
vi.mock("@/lib/api/chat/useChatApi", () => ({
|
|
|
|
useChatApi: () => ({
|
|
|
|
getHistory: () => [],
|
|
|
|
}),
|
|
|
|
}));
|
2023-09-26 19:41:02 +03:00
|
|
|
|
|
|
|
vi.mock("@/lib/hooks", async () => {
|
|
|
|
const actual = await vi.importActual<typeof import("@/lib/hooks")>(
|
|
|
|
"@/lib/hooks"
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...actual,
|
|
|
|
useAxios: () => ({
|
|
|
|
axiosInstance: {
|
|
|
|
get: vi.fn(() => ({ data: [] })),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2023-09-13 14:47:12 +03:00
|
|
|
vi.mock("@tanstack/react-query", async () => {
|
|
|
|
const actual = await vi.importActual<typeof import("@tanstack/react-query")>(
|
|
|
|
"@tanstack/react-query"
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...actual,
|
|
|
|
useQuery: () => ({
|
|
|
|
data: {},
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
2023-09-08 10:57:21 +03:00
|
|
|
|
2023-07-05 10:30:22 +03:00
|
|
|
describe("Chat page", () => {
|
|
|
|
it("should render chat page correctly", () => {
|
2023-08-07 15:13:41 +03:00
|
|
|
const { getByTestId } = render(
|
2023-09-28 16:39:30 +03:00
|
|
|
<KnowledgeToFeedProvider>
|
2023-09-28 12:29:55 +03:00
|
|
|
<QueryClientProvider client={queryClient}>
|
|
|
|
<ChatProviderMock>
|
|
|
|
<SupabaseProviderMock>
|
|
|
|
<BrainProviderMock>
|
|
|
|
<SelectedChatPage />,
|
|
|
|
</BrainProviderMock>
|
|
|
|
</SupabaseProviderMock>
|
|
|
|
</ChatProviderMock>
|
|
|
|
</QueryClientProvider>
|
2023-09-28 16:39:30 +03:00
|
|
|
</KnowledgeToFeedProvider>
|
2023-07-05 10:30:22 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId("chat-page")).toBeDefined();
|
|
|
|
expect(getByTestId("chat-input")).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|