|
| 1 | +import { createMemoryHistory } from "@tanstack/react-router"; |
| 2 | +import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; |
| 3 | +import type * as Context from "effect/Context"; |
| 4 | +import { expect, it, vi } from "vite-plus/test"; |
| 5 | +import { page, userEvent } from "vite-plus/test/browser"; |
| 6 | + |
| 7 | +import { AppRoot } from "~/AppRoot"; |
| 8 | +// The thread route loads ChatView lazily; its first transform would eat the test's timeout. |
| 9 | +import "~/components/ChatView"; |
| 10 | +import { __setClientSettingsForTests } from "~/hooks/useSettings"; |
| 11 | +import { getRouter } from "~/router"; |
| 12 | +import { |
| 13 | + ENVIRONMENT_ID, |
| 14 | + installFakeEnvironment, |
| 15 | + threadWithHistory, |
| 16 | + type FakeDriver, |
| 17 | +} from "../../test/fakeEnvironment"; |
| 18 | +import { act, render } from "../../test/render"; |
| 19 | + |
| 20 | +// The socket is the only fake layer; see test/appScenarios.renders.tsx. |
| 21 | +vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => { |
| 22 | + const [actual, { fakeDriver }, Layer] = await Promise.all([ |
| 23 | + importOriginal<{ readonly ConnectionDriver: Context.Key<unknown, FakeDriver> }>(), |
| 24 | + import("../../test/fakeEnvironment"), |
| 25 | + import("effect/Layer"), |
| 26 | + ]); |
| 27 | + return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) }; |
| 28 | +}); |
| 29 | + |
| 30 | +vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({ |
| 31 | + ...(await original()), |
| 32 | + trackRpcRequestSent: () => {}, |
| 33 | +})); |
| 34 | + |
| 35 | +it("keeps the title when dragging a search result from a collapsed folder", async () => { |
| 36 | + await page.viewport(1400, 900); |
| 37 | + const [first, second] = [threadWithHistory("visible", 1), threadWithHistory("search-target", 1)]; |
| 38 | + using _environment = installFakeEnvironment([first, second]); |
| 39 | + __setClientSettingsForTests({ |
| 40 | + ...DEFAULT_CLIENT_SETTINGS, |
| 41 | + boringSidebarEnabled: true, |
| 42 | + onboardingCompletedAt: "2026-01-01T00:00:00.000Z", |
| 43 | + }); |
| 44 | + const router = getRouter( |
| 45 | + createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${first.id}`] }), |
| 46 | + ); |
| 47 | + await router.load(); |
| 48 | + await using _app = await render(<AppRoot router={router} />, { |
| 49 | + // AppRoot brings its own router. |
| 50 | + router: false, |
| 51 | + }); |
| 52 | + const folder = page.getByRole("button", { name: /^render/ }); |
| 53 | + await expect.element(folder).toHaveAttribute("aria-expanded", "true"); |
| 54 | + await userEvent.click(folder); |
| 55 | + await expect.element(page.getByText(second.title, { exact: true })).not.toBeInTheDocument(); |
| 56 | + await userEvent.fill(page.getByRole("combobox", { name: "Search threads" }), "search-target"); |
| 57 | + const result = page.getByRole("option", { name: /Thread search-target/ }); |
| 58 | + await expect.element(result).toBeVisible(); |
| 59 | + const bounds = result.element().getBoundingClientRect(); |
| 60 | + const pointer = (type: string, x: number, y: number) => |
| 61 | + new PointerEvent(type, { |
| 62 | + bubbles: true, |
| 63 | + cancelable: true, |
| 64 | + pointerId: 1, |
| 65 | + isPrimary: true, |
| 66 | + button: 0, |
| 67 | + buttons: type === "pointerup" ? 0 : 1, |
| 68 | + clientX: x, |
| 69 | + clientY: y, |
| 70 | + }); |
| 71 | + using _release = { |
| 72 | + [Symbol.dispose]: () => document.dispatchEvent(pointer("pointerup", -100, 100)), |
| 73 | + }; |
| 74 | + await act(() => { |
| 75 | + result.element().dispatchEvent(pointer("pointerdown", bounds.x + 10, bounds.y + 10)); |
| 76 | + document.dispatchEvent(pointer("pointermove", -100, 100)); |
| 77 | + }); |
| 78 | + await vi.waitFor(() => { |
| 79 | + expect( |
| 80 | + document.querySelector('body > div[aria-hidden="true"].pointer-events-none')?.textContent, |
| 81 | + ).toBe(second.title); |
| 82 | + }); |
| 83 | +}); |
0 commit comments