dialog-session-list.test.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { describe, expect, test } from "bun:test"
  2. import { createDialogSessionListQuery, loadDialogSessionList } from "../../src/component/dialog-session-list"
  3. describe("dialog session list", () => {
  4. test("requests root sessions for the default browse list", () => {
  5. expect(createDialogSessionListQuery({ filter: { path: "packages/tui" } })).toEqual({
  6. roots: true,
  7. limit: 100,
  8. path: "packages/tui",
  9. })
  10. })
  11. test("requests root sessions for search results", () => {
  12. expect(createDialogSessionListQuery({ search: " deploy ", filter: { scope: "project" } })).toEqual({
  13. roots: true,
  14. limit: 30,
  15. search: "deploy",
  16. scope: "project",
  17. })
  18. })
  19. test("keeps the cache usable while the root request is pending", async () => {
  20. let resolve!: (result: { data: string[] }) => void
  21. const pending = loadDialogSessionList<string>({
  22. filter: {},
  23. list: () => new Promise((done) => (resolve = done)),
  24. })
  25. expect(await Promise.race([pending, Promise.resolve("pending")])).toBe("pending")
  26. resolve({ data: ["root"] })
  27. expect(await pending).toEqual(["root"])
  28. })
  29. test("falls back when the root request returns an error response", async () => {
  30. expect(await loadDialogSessionList({ filter: {}, list: async () => ({}) })).toBeUndefined()
  31. })
  32. test("falls back when the root request rejects", async () => {
  33. expect(
  34. await loadDialogSessionList({
  35. filter: {},
  36. list: () => Promise.reject(new Error("offline")),
  37. }),
  38. ).toBeUndefined()
  39. })
  40. })