The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { OlderSettledScope } from "@t3tools/client-runtime/state/threads"; |
| 2 | import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
| 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | import { userEvent } from "vite-plus/test/browser"; |
| 5 | |
| 6 | import { render } from "../../test/render"; |
| 7 | import { useOlderSettledShelf } from "./olderSettledShelf"; |
| 8 | |
| 9 | const environmentId = EnvironmentId.make("env-a"); |
| 10 | const first = ProjectId.make("project-a"); |
| 11 | const second = ProjectId.make("project-b"); |
| 12 | |
| 13 | function Shelf(props: { readonly scopes: ReadonlyArray<OlderSettledScope> }) { |
| 14 | const shelf = useOlderSettledShelf({ scopes: props.scopes, expanded: true, visibleCount: 0 }); |
| 15 | return ( |
| 16 | <> |
| 17 | <output>{shelf.pages.get(environmentId) ?? 0}</output> |
| 18 | <button type="button" onClick={() => shelf.grow(new Map([[environmentId, 1]]))}> |
| 19 | Grow |
| 20 | </button> |
| 21 | </> |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | describe("useOlderSettledShelf", () => { |
| 26 | it("keeps requested pages when the scope's projects reorder", async () => { |
| 27 | await using screen = await render( |
| 28 | <Shelf scopes={[{ environmentId, projectIds: [first, second] }]} />, |
| 29 | // A bare hook host; nothing here links or navigates. |
| 30 | { router: false }, |
| 31 | ); |
| 32 | await userEvent.click(screen.getByRole("button", { name: "Grow" })); |
| 33 | await expect.element(screen.getByRole("status")).toHaveTextContent("1"); |
| 34 | |
| 35 | // Loading a page can reorder the sidebar's projects; the shelf must not drop its pages. |
| 36 | await screen.rerender(<Shelf scopes={[{ environmentId, projectIds: [second, first] }]} />); |
| 37 | await expect.element(screen.getByRole("status")).toHaveTextContent("1"); |
| 38 | }); |
| 39 | }); |