| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import { afterEach, describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { appAtomRegistry } from "../../state/atom-registry"; |
| 5 | import { createDraft } from "./scheduledTaskDraft"; |
| 6 | import { |
| 7 | readScheduledTaskEditor, |
| 8 | scheduledTaskEditorSessionAtom, |
| 9 | startScheduledTaskEditor, |
| 10 | updateScheduledTaskEditor, |
| 11 | } from "./scheduled-task-editor-state"; |
| 12 | |
| 13 | afterEach(() => appAtomRegistry.set(scheduledTaskEditorSessionAtom, null)); |
| 14 | |
| 15 | describe("scheduled task voice draft", () => { |
| 16 | const editor = { |
| 17 | environmentId: EnvironmentId.make("environment"), |
| 18 | environmentLabel: "Environment", |
| 19 | draft: createDraft(null, null), |
| 20 | }; |
| 21 | |
| 22 | it("keeps the prompt outside the screen and retains its original change baseline", () => { |
| 23 | startScheduledTaskEditor(editor); |
| 24 | const original = appAtomRegistry.get(scheduledTaskEditorSessionAtom)!; |
| 25 | const ownerKey = `scheduled-task:${original.id}`; |
| 26 | updateScheduledTaskEditor( |
| 27 | (current) => |
| 28 | current && { |
| 29 | ...current, |
| 30 | draft: { ...current.draft, prompt: "spoken prompt" }, |
| 31 | }, |
| 32 | null, |
| 33 | ); |
| 34 | |
| 35 | expect(readScheduledTaskEditor(ownerKey, null)?.draft.prompt).toBe("spoken prompt"); |
| 36 | expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.initial).toBe(editor); |
| 37 | }); |
| 38 | |
| 39 | it("rejects an old voice target when another task opens in the same environment", () => { |
| 40 | startScheduledTaskEditor(editor); |
| 41 | const original = appAtomRegistry.get(scheduledTaskEditorSessionAtom)!; |
| 42 | startScheduledTaskEditor({ ...editor, draft: { ...editor.draft, prompt: "other task" } }); |
| 43 | |
| 44 | expect(readScheduledTaskEditor(`scheduled-task:${original.id}`, editor)).toBeNull(); |
| 45 | expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current?.draft.prompt).toBe( |
| 46 | "other task", |
| 47 | ); |
| 48 | }); |
| 49 | |
| 50 | it("does not restore the default prompt after the editor is discarded", () => { |
| 51 | startScheduledTaskEditor(null); |
| 52 | const session = appAtomRegistry.get(scheduledTaskEditorSessionAtom)!; |
| 53 | expect(readScheduledTaskEditor(`scheduled-task:${session.id}`, editor)).toBeNull(); |
| 54 | updateScheduledTaskEditor((current) => current, editor); |
| 55 | expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current).toBeNull(); |
| 56 | }); |
| 57 | }); |