@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 89 lines 3.04 KB
Raw
1 import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 import { expect, it, vi } from "vite-plus/test";
3
4 import { act, render } from "../../../test/render";
5 import { DraftId, useComposerDraftStore } from "../../composerDraftStore";
6 import { removeLocalStorageItem } from "../../hooks/useLocalStorage";
7 import { isMacPlatform } from "../../lib/utils";
8 import {
9 PROMPT_STASH_STORAGE_KEY,
10 usePromptStashStore,
11 writePromptStashStorageForTest,
12 } from "../../promptStashStore";
13 import {
14 addPreparingComposerImages,
15 countPreparingComposerImages,
16 removePreparingComposerImages,
17 } from "./preparingComposerImages";
18 import { useComposerStash } from "./useComposerStash";
19
20 type StashInput = Parameters<typeof useComposerStash>[0];
21
22 function Harness({ input }: { input: StashInput }) {
23 useComposerStash(input);
24 return null;
25 }
26
27 it("keeps the draft when stashing while a pasted image is still compressing", async () => {
28 const target = DraftId.make("stash-preparing-image");
29 using _draft = {
30 [Symbol.dispose]: () => useComposerDraftStore.getState().clearComposerContent(target),
31 };
32 using _stash = {
33 [Symbol.dispose]: () => {
34 writePromptStashStorageForTest("");
35 removeLocalStorageItem(PROMPT_STASH_STORAGE_KEY);
36 },
37 };
38 addPreparingComposerImages(target, [
39 {
40 id: "pasted",
41 name: "shot.png",
42 file: new File(["png"], "shot.png", { type: "image/png" }),
43 hidden: false,
44 },
45 ]);
46 using _preparing = {
47 [Symbol.dispose]: () => removePreparingComposerImages(target, new Set(["pasted"])),
48 };
49 const environmentId = EnvironmentId.make("stash-env");
50 const promptRef = { current: "Describe this screenshot" };
51 const input = {
52 environmentId,
53 composerDraftTarget: target,
54 promptRef,
55 readAttachmentDraft: () => ({ images: [], files: [] }),
56 readTerminalContexts: () => [],
57 routeThreadRef: { environmentId, threadId: ThreadId.make("stash-thread") },
58 projectSelectionRequired: false,
59 pendingUserInputs: [],
60 activePendingProgress: null,
61 prompt: promptRef.current,
62 composerMenuOpen: false,
63 isComposerCollapsedMobile: false,
64 composerPreviewAnnotations: [],
65 composerReviewComments: [],
66 composerThreadContexts: [],
67 attachmentTargetKey: target,
68 isComposerDraftTargetOpen: () => true,
69 composerEditorRef: { current: null },
70 isRevertingCheckpoint: () => false,
71 pendingThreadImportsRef: { current: new Map() },
72 setComposerCursor: vi.fn(),
73 setComposerTrigger: vi.fn(),
74 importContextRecords: () => new Map(),
75 expandMobileComposer: vi.fn(),
76 } satisfies StashInput;
77 await using _screen = await render(<Harness input={input} />);
78
79 const mod = isMacPlatform(navigator.platform) ? { metaKey: true } : { ctrlKey: true };
80 await act(() => {
81 window.dispatchEvent(
82 new KeyboardEvent("keydown", { key: "s", ...mod, bubbles: true, cancelable: true }),
83 );
84 });
85
86 expect(usePromptStashStore.getState().entries).toEqual([]);
87 expect(promptRef.current).toBe("Describe this screenshot");
88 expect(countPreparingComposerImages(target)).toBe(1);
89 });