Files
t3code/apps/web/src/state/waitForAtomValue.test.ts
T
Julius Marmingeandcodex 361df65ffb Map thread panel into title bar and sidebar
- Add thread-panel presentation logic for inline vs popover layouts
- Move thread details controls into the chat header/sidebar flow
- Add shared wait-for-atom helper and workspace display name parsing

Co-authored-by: codex <[email protected]>
2026-06-24 16:48:28 -07:00

58 lines
1.5 KiB
TypeScript

import { Atom, AtomRegistry } from "effect/unstable/reactivity";
import { describe, expect, it, vi } from "vite-plus/test";
import { waitForAtomValue } from "./waitForAtomValue";
describe("waitForAtomValue", () => {
it("returns immediately when the current value is ready", async () => {
const registry = AtomRegistry.make();
const atom = Atom.make("ready");
await expect(
waitForAtomValue({
registry,
atom,
predicate: (value) => value === "ready",
timeoutMs: 1_000,
}),
).resolves.toBe(true);
registry.dispose();
});
it("waits until a subscribed atom becomes ready", async () => {
const registry = AtomRegistry.make();
const atom = Atom.make("pending");
const result = waitForAtomValue({
registry,
atom,
predicate: (value) => value === "ready",
timeoutMs: 1_000,
});
registry.set(atom, "ready");
await expect(result).resolves.toBe(true);
registry.dispose();
});
it("returns false and unsubscribes when readiness times out", async () => {
vi.useFakeTimers();
const registry = AtomRegistry.make();
const atom = Atom.make("pending");
const result = waitForAtomValue({
registry,
atom,
predicate: (value) => value === "ready",
timeoutMs: 1_000,
});
await vi.advanceTimersByTimeAsync(1_000);
await expect(result).resolves.toBe(false);
registry.set(atom, "ready");
registry.dispose();
vi.useRealTimers();
});
});