prompt-transient-state.test.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { expect, test } from "bun:test"
  2. import { createRoot, createSignal } from "solid-js"
  3. import { createPromptInputTransientState } from "@/components/prompt-input/transient-state"
  4. test("resets transient prompt input state when the prompt session changes", () => {
  5. createRoot((dispose) => {
  6. const [identity, setIdentity] = createSignal("A")
  7. const [state, setState] = createPromptInputTransientState(identity, 3)
  8. setState({
  9. popover: "slash",
  10. slashMenu: true,
  11. slashMenuQuery: "compact",
  12. historyIndex: 2,
  13. savedPrompt: {
  14. prompt: [{ type: "text", content: "draft-A", start: 0, end: 7 }],
  15. comments: [],
  16. },
  17. draggingType: "image",
  18. mode: "shell",
  19. applyingHistory: true,
  20. variantOpen: true,
  21. })
  22. setIdentity("B")
  23. expect(state).toMatchObject({
  24. popover: null,
  25. slashMenu: false,
  26. slashMenuQuery: "",
  27. historyIndex: -1,
  28. savedPrompt: null,
  29. placeholder: 3,
  30. draggingType: null,
  31. mode: "normal",
  32. applyingHistory: false,
  33. variantOpen: false,
  34. })
  35. dispose()
  36. })
  37. })