|
1 | 1 | import { act, screen, waitFor, within } from "@testing-library/react"; |
2 | 2 | import userEvent from "@testing-library/user-event"; |
3 | 3 | import { HttpResponse, http } from "msw"; |
| 4 | +import { onlineManager } from "react-query"; |
4 | 5 | import { toast } from "sonner"; |
5 | 6 | import { |
6 | 7 | afterEach, |
@@ -347,6 +348,29 @@ describe("AgentCreatePage project assignment", () => { |
347 | 348 | await screen.findByRole("heading", { name: MockChatProject.name }); |
348 | 349 | }); |
349 | 350 |
|
| 351 | + it("keeps loading while the refetch of a cached list is paused offline", async () => { |
| 352 | + enableExperiments("chat-projects"); |
| 353 | + serveProjects(MockChatProject); |
| 354 | + |
| 355 | + const { router, queryClient } = renderAgentsRoutes("/agents"); |
| 356 | + await screen.findByRole("button", { name: "Create chat" }); |
| 357 | + // The test client's offlineFirst mode would fetch anyway; the app |
| 358 | + // uses the default online mode, which pauses the fetch. |
| 359 | + queryClient.setQueryDefaults(chatProjectsKey, { networkMode: "online" }); |
| 360 | + onlineManager.setOnline(false); |
| 361 | + try { |
| 362 | + act(() => { |
| 363 | + queryClient.setQueryData(chatProjectsKey, []); |
| 364 | + void router.navigate(projectPath(MockChatProject.id)); |
| 365 | + }); |
| 366 | + |
| 367 | + await screen.findByRole("status", { name: "Loading project" }); |
| 368 | + expect(screen.queryByText("Project not found")).not.toBeInTheDocument(); |
| 369 | + } finally { |
| 370 | + onlineManager.setOnline(true); |
| 371 | + } |
| 372 | + }); |
| 373 | + |
350 | 374 | it("shows the plain composer on /agents after a project list is cached", async () => { |
351 | 375 | enableExperiments("chat-projects"); |
352 | 376 | serveProjects(MockChatProject); |
|
0 commit comments