@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
tsx 138 lines 4.38 KB
Raw
1 import { RegistryContext } from "@effect/atom-react";
2 import { Atom, AtomRegistry } from "effect/reactivity";
3 import { act, useLayoutEffect } from "react";
4 import { createRoot } from "react-dom/client";
5 import { expect, it, vi } from "vite-plus/test";
6
7 import {
8 NativePrimaryColumnContext,
9 NativeWorkspaceTabActivityContext,
10 } from "../../native/v5-workspace-context";
11
12 // The Thread in the detail column is the focused route on iPad split view.
13 vi.mock("@react-navigation/native", () => ({
14 useNavigation: () => ({ isFocused: () => false }),
15 }));
16
17 import {
18 recordHomeFocus,
19 recordHomeTransitionEnd,
20 recordHomeTransitionStart,
21 useAtomValueWhileVisible,
22 useHomeRouteVisible,
23 } from "./home-route-visibility";
24
25 const shellsAtom = Atom.make(0).pipe(Atom.keepAlive);
26
27 function setup() {
28 (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
29 const registry = AtomRegistry.make();
30 let latest: number | undefined;
31 function Probe() {
32 const visible = useHomeRouteVisible();
33 const value = useAtomValueWhileVisible(shellsAtom, visible);
34 useLayoutEffect(() => {
35 latest = value;
36 });
37 return null;
38 }
39 const root = createRoot(document.createElement("div"));
40 const sidebar = {
41 presented: true,
42 selectedThreadKey: "env-1:thread-1",
43 selectedPullRequestKey: null,
44 selectedIssueKey: null,
45 };
46 return {
47 registry,
48 get latest() {
49 return latest;
50 },
51 showHome() {
52 act(() =>
53 root.render(
54 <RegistryContext.Provider value={registry}>
55 <NativePrimaryColumnContext value={sidebar}>
56 <Probe />
57 </NativePrimaryColumnContext>
58 </RegistryContext.Provider>,
59 ),
60 );
61 },
62 /** A phone has no primary column: Home is the root page of its tab's slot. */
63 showHomeInTabSlot(active: boolean) {
64 act(() =>
65 root.render(
66 <RegistryContext.Provider value={registry}>
67 <NativeWorkspaceTabActivityContext value={{ active, isActive: () => active }}>
68 <Probe />
69 </NativeWorkspaceTabActivityContext>
70 </RegistryContext.Provider>,
71 ),
72 );
73 },
74 [Symbol.dispose]() {
75 act(() => root.unmount());
76 registry.dispose();
77 },
78 };
79 }
80
81 it("keeps the sidebar thread list live after switching tabs beside a focused Thread", () => {
82 using home = setup();
83 // The primary column appearing is the only navigation event Home gets on iPad.
84 recordHomeTransitionStart(false);
85 home.showHome();
86 act(() => home.registry.set(shellsAtom, 1));
87 expect(home.latest).toBe(1);
88
89 // Chats → PRs → Chats: Chats' column will-appear, then the PRs column's did-disappear.
90 act(() => {
91 recordHomeTransitionEnd(true, false);
92 recordHomeTransitionStart(false);
93 recordHomeTransitionEnd(true, false);
94 });
95 act(() => home.registry.set(shellsAtom, 2));
96
97 expect(home.latest, "new thread shells reach the sidebar list").toBe(2);
98 });
99
100 // Each phone tab slot shows its own copy of the Home route. PRs keeps Home focused; Settings
101 // is a route of its own.
102 it.each([
103 { tab: "PRs", homeFocusedUnderTab: true },
104 { tab: "Settings", homeFocusedUnderTab: false },
105 ])(
106 "keeps the phone thread list live after a round trip through $tab",
107 ({ homeFocusedUnderTab }) => {
108 using home = setup();
109 recordHomeFocus();
110 home.showHomeInTabSlot(true);
111 act(() => home.registry.set(shellsAtom, 1));
112 expect(home.latest).toBe(1);
113
114 // To the other tab: its slot will-appear, then the Chats slot's did-disappear.
115 act(() => {
116 recordHomeTransitionStart(false);
117 recordHomeTransitionEnd(true, homeFocusedUnderTab);
118 });
119 home.showHomeInTabSlot(false);
120 act(() => home.registry.set(shellsAtom, 2));
121 expect(home.latest, "the list under another tab holds its rows").toBe(1);
122
123 // Back to Chats: its slot will-appear, then the other slot's did-disappear comes last.
124 act(() => {
125 recordHomeFocus();
126 recordHomeTransitionStart(false);
127 recordHomeTransitionEnd(true, true);
128 });
129 home.showHomeInTabSlot(true);
130 act(() => home.registry.set(shellsAtom, 3));
131 expect(home.latest, "a server rename reaches the list").toBe(3);
132
133 // A pushed Thread takes the focus and still stops the list.
134 act(() => recordHomeTransitionEnd(true, false));
135 act(() => home.registry.set(shellsAtom, 4));
136 expect(home.latest, "the list under a Thread holds its rows").toBe(3);
137 },
138 );