Skip to content

Commit 5f0c642

Browse files
committed
test(mobile): cover real settled shelf list reuse
1 parent b238f41 commit 5f0c642

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import { act, useLayoutEffect } from "react";
22
import { createRoot } from "react-dom/client";
3+
import { RegistryContext } from "@effect/atom-react";
4+
import type { OlderSettledShelfEnvironment } from "@t3tools/client-runtime/state/threads";
35
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
6+
import { AtomRegistry } from "effect/reactivity";
47
import { expect, it, vi } from "vite-plus/test";
58

69
import { makeThreadShellFixture } from "../../test-fixtures";
710
import { useThreadListV2 } from "./useThreadListV2";
811

9-
vi.mock("../../state/olderSettledShelf", () => {
10-
const isListed = () => true;
11-
const unloadedCount = () => 0;
12+
vi.mock("../../state/threads", async () => {
13+
const { Atom } = await import("effect/reactivity");
14+
const shelf = Atom.make<ReadonlyMap<EnvironmentId, OlderSettledShelfEnvironment>>(new Map());
1215
return {
13-
useOlderSettledShelf: () => ({ isListed, unloadedCount }),
14-
useOlderSettledShelfGrowth: () => undefined,
16+
olderSettledThreads: { shelfAtom: () => shelf },
17+
threadFamilies: { mountRows: () => () => {} },
1518
};
1619
});
20+
vi.mock("../../state/atom-registry", () => ({ appAtomRegistry: undefined }));
1721

1822
it("reuses a large thread list across tab renders and updates when its inputs change", async () => {
1923
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
2024
using _globals = { [Symbol.dispose]: () => vi.unstubAllGlobals() };
25+
const registry = AtomRegistry.make();
26+
using _registry = { [Symbol.dispose]: () => registry.dispose() };
2127
const environmentId = EnvironmentId.make("environment-1");
2228
const otherEnvironmentId = EnvironmentId.make("environment-2");
2329
const threads = Array.from({ length: 1200 }, (_, index) =>
@@ -54,6 +60,13 @@ it("reuses a large thread list across tab renders and updates when its inputs ch
5460
};
5561
const seen: Array<ReturnType<typeof useThreadListV2>> = [];
5662
function Probe(props: { input: typeof input; tab: string }) {
63+
return (
64+
<RegistryContext value={registry}>
65+
<ListProbe {...props} />
66+
</RegistryContext>
67+
);
68+
}
69+
function ListProbe(props: { input: typeof input; tab: string }) {
5770
const result = useThreadListV2(props.input);
5871
useLayoutEffect(() => {
5972
seen.push(result);
@@ -70,6 +83,10 @@ it("reuses a large thread list across tab renders and updates when its inputs ch
7083

7184
for (const tab of ["pullRequests", "chats", "settings", "chats"]) {
7285
await act(async () => root.render(<Probe input={{ ...input }} tab={tab} />));
86+
expect(seen.at(-1)!.olderSettledShelf.isListed).toBe(initial.olderSettledShelf.isListed);
87+
expect(seen.at(-1)!.olderSettledShelf.unloadedCount).toBe(
88+
initial.olderSettledShelf.unloadedCount,
89+
);
7390
expect(seen.at(-1)!.layout).toBe(initial.layout);
7491
expect(seen.at(-1)!.items).toBe(initial.items);
7592
}

0 commit comments

Comments
 (0)