Skip to content

Commit 91cff1a

Browse files
fix(mobile): type the draft route's resolved project from the project list
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent da06de1 commit 91cff1a

2 files changed

Lines changed: 55 additions & 44 deletions

File tree

‎apps/mobile/src/features/threads/NewTaskDraftRouteScreen.test.tsx‎

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -108,48 +108,56 @@ const connected: Snapshot["catalog"] = {
108108
it.each([
109109
["while the catalog reloads", { ...connected, isLoadingConnections: true }],
110110
["while the catalog stays ready", connected],
111-
])("checks the branch out once when a reconnect drops and restores the project %s", async (gap, gapCatalog) => {
112-
// Checkouts live in a module table keyed by route, so each case uses its own route.
113-
const routeKey = `thread-route ${gap}`;
114-
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
115-
const firstCheckout = Promise.withResolvers<unknown>();
116-
harness.checkout.mockReturnValueOnce(firstCheckout.promise);
117-
harness.checkout.mockResolvedValue(
118-
AsyncResult.success({ name: "feature", current: true, isDefault: false, worktreePath: null }),
119-
);
120-
harness.set({ projects: [project], catalog: connected });
121-
const draft = { environmentId: "env-1", projectId: "project-1", branch: "feature" };
122-
harness.route = { key: routeKey, name: "Thread", params: { draft } };
123-
124-
const container = document.createElement("div");
125-
const root = createRoot(container);
126-
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
127-
act(() =>
128-
root.render(
129-
<NewTaskDraftRouteScreen
130-
route={{ key: routeKey, name: "Thread", params: draft } as never}
131-
/>,
132-
),
133-
);
134-
await vi.waitFor(() => expect(harness.checkout).toHaveBeenCalledTimes(1));
135-
136-
// The connection drops while the checkout runs, then the project comes back.
137-
act(() => harness.set({ projects: [], catalog: gapCatalog }));
138-
act(() => harness.set({ projects: [project], catalog: connected }));
139-
await act(async () => {
140-
firstCheckout.resolve(
111+
])(
112+
"checks the branch out once when a reconnect drops and restores the project %s",
113+
async (gap, gapCatalog) => {
114+
// Checkouts live in a module table keyed by route, so each case uses its own route.
115+
const routeKey = `thread-route ${gap}`;
116+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
117+
const firstCheckout = Promise.withResolvers<unknown>();
118+
harness.checkout.mockReturnValueOnce(firstCheckout.promise);
119+
harness.checkout.mockResolvedValue(
141120
AsyncResult.success({ name: "feature", current: true, isDefault: false, worktreePath: null }),
142121
);
143-
});
122+
harness.set({ projects: [project], catalog: connected });
123+
const draft = { environmentId: "env-1", projectId: "project-1", branch: "feature" };
124+
harness.route = { key: routeKey, name: "Thread", params: { draft } };
144125

145-
await vi.waitFor(() =>
146-
expect(
147-
harness.checkout.mock.calls.length > 1 || container.textContent === "draft on feature",
148-
).toBe(true),
149-
);
150-
expect(harness.checkout).toHaveBeenCalledTimes(1);
151-
expect(container.textContent).toBe("draft on feature");
152-
});
126+
const container = document.createElement("div");
127+
const root = createRoot(container);
128+
using _root = { [Symbol.dispose]: () => act(() => root.unmount()) };
129+
act(() =>
130+
root.render(
131+
<NewTaskDraftRouteScreen
132+
route={{ key: routeKey, name: "Thread", params: draft } as never}
133+
/>,
134+
),
135+
);
136+
await vi.waitFor(() => expect(harness.checkout).toHaveBeenCalledTimes(1));
137+
138+
// The connection drops while the checkout runs, then the project comes back.
139+
act(() => harness.set({ projects: [], catalog: gapCatalog }));
140+
act(() => harness.set({ projects: [project], catalog: connected }));
141+
await act(async () => {
142+
firstCheckout.resolve(
143+
AsyncResult.success({
144+
name: "feature",
145+
current: true,
146+
isDefault: false,
147+
worktreePath: null,
148+
}),
149+
);
150+
});
151+
152+
await vi.waitFor(() =>
153+
expect(
154+
harness.checkout.mock.calls.length > 1 || container.textContent === "draft on feature",
155+
).toBe(true),
156+
);
157+
expect(harness.checkout).toHaveBeenCalledTimes(1);
158+
expect(container.textContent).toBe("draft on feature");
159+
},
160+
);
153161

154162
it("hands the draft screen the same project ref across re-renders", async () => {
155163
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;

‎apps/mobile/src/features/threads/NewTaskDraftRouteScreen.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,19 @@ export function NewTaskDraftRouteScreen({ route }: StaticScreenProps<NewTaskDraf
119119
);
120120
// A project can drop out of the list and come back while its catalog stays ready. The checkout
121121
// keeps the last project this route resolved, so that gap reads the same checkout.
122-
const [resolvedProject, setResolvedProject] = useState<{
123-
readonly environmentId: string;
124-
readonly workspaceRoot: string;
125-
} | null>(null);
122+
const [resolvedProject, setResolvedProject] = useState<Pick<
123+
NonNullable<typeof project>,
124+
"environmentId" | "workspaceRoot"
125+
> | null>(null);
126126
if (
127127
project &&
128128
(resolvedProject?.environmentId !== project.environmentId ||
129129
resolvedProject.workspaceRoot !== project.workspaceRoot)
130130
) {
131-
setResolvedProject({ environmentId: project.environmentId, workspaceRoot: project.workspaceRoot });
131+
setResolvedProject({
132+
environmentId: project.environmentId,
133+
workspaceRoot: project.workspaceRoot,
134+
});
132135
}
133136
const checkoutProject = project ?? resolvedProject;
134137
const workspaceRoot = project?.workspaceRoot;

0 commit comments

Comments
 (0)